diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
commit | ec05778d5718a7912e506764d443a78d6a6179e3 (patch) | |
tree | 78a9a01532180030c095acefc45763f07c14edb8 /src/tests | |
parent | b20414ac1fe80a71a90601f4cd1767fa7014a9ba (diff) | |
download | libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.gz libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.bz2 libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.xz libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.zip |
Converted tabs to spaces with tabconv.
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/base64.cpp | 126 | ||||
-rw-r--r-- | src/tests/bigmyriad.cpp | 26 | ||||
-rw-r--r-- | src/tests/blowfish.cpp | 118 | ||||
-rw-r--r-- | src/tests/bnfcompile.cpp | 750 | ||||
-rw-r--r-- | src/tests/bzip2.cpp | 38 | ||||
-rw-r--r-- | src/tests/deflate.cpp | 78 | ||||
-rw-r--r-- | src/tests/lzma.cpp | 78 | ||||
-rw-r--r-- | src/tests/myriadfs.cpp | 64 | ||||
-rw-r--r-- | src/tests/optparser.cpp | 126 | ||||
-rw-r--r-- | src/tests/parser.cpp | 576 | ||||
-rw-r--r-- | src/tests/print.cpp | 28 | ||||
-rw-r--r-- | src/tests/random.cpp | 62 | ||||
-rw-r--r-- | src/tests/regex.cpp | 42 | ||||
-rw-r--r-- | src/tests/settings.cpp | 12 | ||||
-rw-r--r-- | src/tests/synchroqueue.cpp | 198 | ||||
-rw-r--r-- | src/tests/taf.cpp | 52 | ||||
-rw-r--r-- | src/tests/threadid.cpp | 78 | ||||
-rw-r--r-- | src/tests/utf.cpp | 112 | ||||
-rw-r--r-- | src/tests/uuid.cpp | 8 |
19 files changed, 1286 insertions, 1286 deletions
diff --git a/src/tests/base64.cpp b/src/tests/base64.cpp index 1e1892d..640118a 100644 --- a/src/tests/base64.cpp +++ b/src/tests/base64.cpp | |||
@@ -11,73 +11,73 @@ | |||
11 | 11 | ||
12 | int main( int argc, char *argv[] ) | 12 | int main( int argc, char *argv[] ) |
13 | { | 13 | { |
14 | argc--,argv++; | 14 | argc--,argv++; |
15 | 15 | ||
16 | if( argc < 3 ) | 16 | if( argc < 3 ) |
17 | return 0; | 17 | return 0; |
18 | 18 | ||
19 | if( argv[0][0] == 'e' ) | 19 | if( argv[0][0] == 'e' ) |
20 | { | 20 | { |
21 | argv++; | 21 | argv++; |
22 | Bu::File fIn( argv[0], Bu::File::Read ); | 22 | Bu::File fIn( argv[0], Bu::File::Read ); |
23 | Bu::File fOut( argv[1], Bu::File::WriteNew ); | 23 | Bu::File fOut( argv[1], Bu::File::WriteNew ); |
24 | Bu::Base64 bOut( fOut ); | 24 | Bu::Base64 bOut( fOut ); |
25 | 25 | ||
26 | char buf[900]; | 26 | char buf[900]; |
27 | for(;;) | 27 | for(;;) |
28 | { | 28 | { |
29 | int iRead = fIn.read( buf, 900 ); | 29 | int iRead = fIn.read( buf, 900 ); |
30 | bOut.write( buf, iRead ); | 30 | bOut.write( buf, iRead ); |
31 | if( iRead < 900 ) | 31 | if( iRead < 900 ) |
32 | break; | 32 | break; |
33 | } | 33 | } |
34 | } | 34 | } |
35 | else if( argv[0][0] == 'd' ) | 35 | else if( argv[0][0] == 'd' ) |
36 | { | 36 | { |
37 | argv++; | 37 | argv++; |
38 | Bu::File fIn( argv[0], Bu::File::Read ); | 38 | Bu::File fIn( argv[0], Bu::File::Read ); |
39 | Bu::File fOut( argv[1], Bu::File::WriteNew ); | 39 | Bu::File fOut( argv[1], Bu::File::WriteNew ); |
40 | Bu::Base64 bIn( fIn ); | 40 | Bu::Base64 bIn( fIn ); |
41 | 41 | ||
42 | char buf[1024]; | 42 | char buf[1024]; |
43 | for(;;) | 43 | for(;;) |
44 | { | 44 | { |
45 | int iRead = bIn.read( buf, 1024 ); | 45 | int iRead = bIn.read( buf, 1024 ); |
46 | printf("Read %d bytes.\n", iRead ); | 46 | printf("Read %d bytes.\n", iRead ); |
47 | fOut.write( buf, iRead ); | 47 | fOut.write( buf, iRead ); |
48 | if( iRead == 0 ) | 48 | if( iRead == 0 ) |
49 | break; | 49 | break; |
50 | } | 50 | } |
51 | } | 51 | } |
52 | else if( argv[0][0] == 'D' ) | 52 | else if( argv[0][0] == 'D' ) |
53 | { | 53 | { |
54 | argv++; | 54 | argv++; |
55 | Bu::MemBuf mIn; | 55 | Bu::MemBuf mIn; |
56 | { | 56 | { |
57 | Bu::File fIn( argv[0], Bu::File::Read ); | 57 | Bu::File fIn( argv[0], Bu::File::Read ); |
58 | char buf[1024]; | 58 | char buf[1024]; |
59 | for(;;) | 59 | for(;;) |
60 | { | 60 | { |
61 | int iRead = fIn.read( buf, 1024 ); | 61 | int iRead = fIn.read( buf, 1024 ); |
62 | mIn.write( buf, iRead ); | 62 | mIn.write( buf, iRead ); |
63 | if( iRead < 1024 ) | 63 | if( iRead < 1024 ) |
64 | break; | 64 | break; |
65 | } | 65 | } |
66 | mIn.setPos( 0 ); | 66 | mIn.setPos( 0 ); |
67 | } | 67 | } |
68 | Bu::File fOut( argv[1], Bu::File::WriteNew ); | 68 | Bu::File fOut( argv[1], Bu::File::WriteNew ); |
69 | Bu::Base64 bIn( mIn ); | 69 | Bu::Base64 bIn( mIn ); |
70 | 70 | ||
71 | char buf[1024]; | 71 | char buf[1024]; |
72 | for(;;) | 72 | for(;;) |
73 | { | 73 | { |
74 | int iRead = bIn.read( buf, 1024 ); | 74 | int iRead = bIn.read( buf, 1024 ); |
75 | printf("Read %d bytes.\n", iRead ); | 75 | printf("Read %d bytes.\n", iRead ); |
76 | fOut.write( buf, iRead ); | 76 | fOut.write( buf, iRead ); |
77 | if( iRead == 0 ) | 77 | if( iRead == 0 ) |
78 | break; | 78 | break; |
79 | } | 79 | } |
80 | } | 80 | } |
81 | 81 | ||
82 | return 0; | 82 | return 0; |
83 | } | 83 | } |
diff --git a/src/tests/bigmyriad.cpp b/src/tests/bigmyriad.cpp index 6661bf1..9af301c 100644 --- a/src/tests/bigmyriad.cpp +++ b/src/tests/bigmyriad.cpp | |||
@@ -4,22 +4,22 @@ | |||
4 | 4 | ||
5 | int main() | 5 | int main() |
6 | { | 6 | { |
7 | Bu::File f("big.myr", Bu::File::Read|Bu::File::Write|Bu::File::Create ); | 7 | Bu::File f("big.myr", Bu::File::Read|Bu::File::Write|Bu::File::Create ); |
8 | Bu::Myriad m( f, 2048 ); | 8 | Bu::Myriad m( f, 2048 ); |
9 | 9 | ||
10 | char *buf = new char[1024*1024*10]; | 10 | char *buf = new char[1024*1024*10]; |
11 | memset( buf, 0, 1024*1024*10 ); | 11 | memset( buf, 0, 1024*1024*10 ); |
12 | 12 | ||
13 | for( int j = 0; j < 250; j++ ) | 13 | for( int j = 0; j < 250; j++ ) |
14 | { | 14 | { |
15 | m.openStream( m.createStream() ).write( buf, 1024*1024*10 ); | 15 | m.openStream( m.createStream() ).write( buf, 1024*1024*10 ); |
16 | // m.sync(); | 16 | // m.sync(); |
17 | printf("\r%03d%%", (j+1)*100/250 ); | 17 | printf("\r%03d%%", (j+1)*100/250 ); |
18 | fflush( stdout ); | 18 | fflush( stdout ); |
19 | } | 19 | } |
20 | 20 | ||
21 | printf("\n\n"); | 21 | printf("\n\n"); |
22 | 22 | ||
23 | return 0; | 23 | return 0; |
24 | } | 24 | } |
25 | 25 | ||
diff --git a/src/tests/blowfish.cpp b/src/tests/blowfish.cpp index 7c175d4..c0aba30 100644 --- a/src/tests/blowfish.cpp +++ b/src/tests/blowfish.cpp | |||
@@ -56,72 +56,72 @@ static const char *testdat[34][3] ={ | |||
56 | 56 | ||
57 | int main( int argc, char *argv[] ) | 57 | int main( int argc, char *argv[] ) |
58 | { | 58 | { |
59 | MemBuf mb; | 59 | MemBuf mb; |
60 | { | 60 | { |
61 | BlowfishEcb bf( mb ); | 61 | BlowfishEcb bf( mb ); |
62 | bf.setPassword( "01234567" ); | 62 | bf.setPassword( "01234567" ); |
63 | for( int j = 0; j < 4; j++ ) | 63 | for( int j = 0; j < 4; j++ ) |
64 | { | 64 | { |
65 | bf.write("this is a test!!"+j, 1 ); | 65 | bf.write("this is a test!!"+j, 1 ); |
66 | } | 66 | } |
67 | bf.write("this is a test!!"+4, 12 ); | 67 | bf.write("this is a test!!"+4, 12 ); |
68 | } | 68 | } |
69 | mb.setPos( 0 ); | 69 | mb.setPos( 0 ); |
70 | BlowfishEcb bf( mb ); | 70 | BlowfishEcb bf( mb ); |
71 | bf.setPassword( "01234567" ); | 71 | bf.setPassword( "01234567" ); |
72 | for( int j = 0; j < 3; j++ ) | 72 | for( int j = 0; j < 3; j++ ) |
73 | { | 73 | { |
74 | char c; | 74 | char c; |
75 | bf.read( &c, 1 ); | 75 | bf.read( &c, 1 ); |
76 | sio << "char: '" << c << "'" << sio.nl; | 76 | sio << "char: '" << c << "'" << sio.nl; |
77 | } | 77 | } |
78 | 78 | ||
79 | char buf[100]; | 79 | char buf[100]; |
80 | int iR = bf.read( buf, 100 ); | 80 | int iR = bf.read( buf, 100 ); |
81 | buf[iR] = '\0'; | 81 | buf[iR] = '\0'; |
82 | sio << "Got(" << iR << ") = '" << buf << "'" << sio.nl; | 82 | sio << "Got(" << iR << ") = '" << buf << "'" << sio.nl; |
83 | 83 | ||
84 | return 0; | 84 | return 0; |
85 | 85 | ||
86 | for( int j = 0; j < 34; j++ ) | 86 | for( int j = 0; j < 34; j++ ) |
87 | { | 87 | { |
88 | MemBuf mb; | 88 | MemBuf mb; |
89 | BlowfishEcb bf( mb ); | 89 | BlowfishEcb bf( mb ); |
90 | bf.setPassword( decodeStr<Hex>( testdat[j][0] ) ); | 90 | bf.setPassword( decodeStr<Hex>( testdat[j][0] ) ); |
91 | bf.write( decodeStr<Hex>( testdat[j][1] ) ); | 91 | bf.write( decodeStr<Hex>( testdat[j][1] ) ); |
92 | sio << "Test " << j << ": " << (mb.getString() == decodeStr<Hex>( testdat[j][2] )) << " (" << encodeStr<Hex>( mb.getString(), true ) << " == " << testdat[j][2] << ")" << sio.nl; | 92 | sio << "Test " << j << ": " << (mb.getString() == decodeStr<Hex>( testdat[j][2] )) << " (" << encodeStr<Hex>( mb.getString(), true ) << " == " << testdat[j][2] << ")" << sio.nl; |
93 | 93 | ||
94 | mb.setPos( 0 ); | 94 | mb.setPos( 0 ); |
95 | BlowfishEcb bf2( mb ); | 95 | BlowfishEcb bf2( mb ); |
96 | bf2.setPassword( decodeStr<Hex>( testdat[j][0] ) ); | 96 | bf2.setPassword( decodeStr<Hex>( testdat[j][0] ) ); |
97 | char buf[8]; | 97 | char buf[8]; |
98 | bf2.read( buf, 8 ); | 98 | bf2.read( buf, 8 ); |
99 | 99 | ||
100 | sio << " - Back: " << (Bu::String(testdat[j][1]) == encodeStr<Hex>(String(buf,8),true)) << sio.nl; | 100 | sio << " - Back: " << (Bu::String(testdat[j][1]) == encodeStr<Hex>(String(buf,8),true)) << sio.nl; |
101 | } | 101 | } |
102 | 102 | ||
103 | { | 103 | { |
104 | File fIn("data.plain", File::Read ); | 104 | File fIn("data.plain", File::Read ); |
105 | File fOut("data.crypt", File::WriteNew ); | 105 | File fOut("data.crypt", File::WriteNew ); |
106 | 106 | ||
107 | BlowfishOfb bOut( fOut ); | 107 | BlowfishOfb bOut( fOut ); |
108 | bOut.setIv("01234567"); | 108 | bOut.setIv("01234567"); |
109 | bOut.setPassword("abcdefghijklmnop"); | 109 | bOut.setPassword("abcdefghijklmnop"); |
110 | bOut.write( fIn.readAll() ); | 110 | bOut.write( fIn.readAll() ); |
111 | } | 111 | } |
112 | { | 112 | { |
113 | File fIn("data.java", File::Read ); | 113 | File fIn("data.java", File::Read ); |
114 | File fOut("data.stuff", File::WriteNew ); | 114 | File fOut("data.stuff", File::WriteNew ); |
115 | 115 | ||
116 | BlowfishOfb bIn( fIn ); | 116 | BlowfishOfb bIn( fIn ); |
117 | bIn.setIv("01234567"); | 117 | bIn.setIv("01234567"); |
118 | bIn.setPassword("abcdefghijklmnop"); | 118 | bIn.setPassword("abcdefghijklmnop"); |
119 | char buf[64]; | 119 | char buf[64]; |
120 | bIn.read( buf, 64 ); | 120 | bIn.read( buf, 64 ); |
121 | fOut.write( buf, 64 ); | 121 | fOut.write( buf, 64 ); |
122 | sio << sio.nl << "All done." << sio.nl; | 122 | sio << sio.nl << "All done." << sio.nl; |
123 | } | 123 | } |
124 | 124 | ||
125 | return 0; | 125 | return 0; |
126 | } | 126 | } |
127 | 127 | ||
diff --git a/src/tests/bnfcompile.cpp b/src/tests/bnfcompile.cpp index af7a0eb..40d410d 100644 --- a/src/tests/bnfcompile.cpp +++ b/src/tests/bnfcompile.cpp | |||
@@ -15,408 +15,408 @@ using namespace Bu; | |||
15 | 15 | ||
16 | enum TokenType | 16 | enum TokenType |
17 | { | 17 | { |
18 | tokIdentifier, | 18 | tokIdentifier, |
19 | tokColon, | 19 | tokColon, |
20 | tokOr, | 20 | tokOr, |
21 | tokSemiColon, | 21 | tokSemiColon, |
22 | tokTokens, | 22 | tokTokens, |
23 | tokEquals, | 23 | tokEquals, |
24 | tokOpenCurly, | 24 | tokOpenCurly, |
25 | tokCloseCurly, | 25 | tokCloseCurly, |
26 | tokOpenSquare, | 26 | tokOpenSquare, |
27 | tokCloseSquare, | 27 | tokCloseSquare, |
28 | 28 | ||
29 | tokEos=-1 | 29 | tokEos=-1 |
30 | }; | 30 | }; |
31 | 31 | ||
32 | class BnfLexer : public Lexer | 32 | class BnfLexer : public Lexer |
33 | { | 33 | { |
34 | public: | 34 | public: |
35 | BnfLexer( Stream &rSrc ) : | 35 | BnfLexer( Stream &rSrc ) : |
36 | rSrc( rSrc ) | 36 | rSrc( rSrc ) |
37 | { | 37 | { |
38 | } | 38 | } |
39 | 39 | ||
40 | virtual ~BnfLexer() | 40 | virtual ~BnfLexer() |
41 | { | 41 | { |
42 | } | 42 | } |
43 | 43 | ||
44 | virtual Token *nextToken() | 44 | virtual Token *nextToken() |
45 | { | 45 | { |
46 | char cBuf; | 46 | char cBuf; |
47 | 47 | ||
48 | for(;;) | 48 | for(;;) |
49 | { | 49 | { |
50 | if( qbIn.getSize() == 0 ) | 50 | if( qbIn.getSize() == 0 ) |
51 | { | 51 | { |
52 | char buf[4096]; | 52 | char buf[4096]; |
53 | qbIn.write( buf, rSrc.read( buf, 4096 ) ); | 53 | qbIn.write( buf, rSrc.read( buf, 4096 ) ); |
54 | 54 | ||
55 | if( rSrc.isEos() && qbIn.getSize() == 0 ) | 55 | if( rSrc.isEos() && qbIn.getSize() == 0 ) |
56 | return new Token( tokEos ); | 56 | return new Token( tokEos ); |
57 | } | 57 | } |
58 | qbIn.peek( &cBuf, 1 ); | 58 | qbIn.peek( &cBuf, 1 ); |
59 | if( (cBuf >= 'a' && cBuf <= 'z') || | 59 | if( (cBuf >= 'a' && cBuf <= 'z') || |
60 | (cBuf >= 'A' && cBuf <= 'Z') || | 60 | (cBuf >= 'A' && cBuf <= 'Z') || |
61 | (cBuf >= '0' && cBuf <= '9') || | 61 | (cBuf >= '0' && cBuf <= '9') || |
62 | cBuf == '_' ) | 62 | cBuf == '_' ) |
63 | { | 63 | { |
64 | sBuf.append( cBuf ); | 64 | sBuf.append( cBuf ); |
65 | qbIn.seek( 1 ); | 65 | qbIn.seek( 1 ); |
66 | } | 66 | } |
67 | else if( sBuf.isSet() ) | 67 | else if( sBuf.isSet() ) |
68 | { | 68 | { |
69 | if( sBuf == "tokens" ) | 69 | if( sBuf == "tokens" ) |
70 | { | 70 | { |
71 | sBuf.clear(); | 71 | sBuf.clear(); |
72 | return new Token( tokTokens ); | 72 | return new Token( tokTokens ); |
73 | } | 73 | } |
74 | else | 74 | else |
75 | { | 75 | { |
76 | Token *pRet = new Token( tokIdentifier, sBuf ); | 76 | Token *pRet = new Token( tokIdentifier, sBuf ); |
77 | sBuf.clear(); | 77 | sBuf.clear(); |
78 | return pRet; | 78 | return pRet; |
79 | } | 79 | } |
80 | } | 80 | } |
81 | else | 81 | else |
82 | { | 82 | { |
83 | switch( cBuf ) | 83 | switch( cBuf ) |
84 | { | 84 | { |
85 | case ' ': | 85 | case ' ': |
86 | case '\t': | 86 | case '\t': |
87 | case '\n': | 87 | case '\n': |
88 | case '\r': | 88 | case '\r': |
89 | qbIn.seek( 1 ); | 89 | qbIn.seek( 1 ); |
90 | continue; | 90 | continue; |
91 | 91 | ||
92 | case ':': | 92 | case ':': |
93 | qbIn.seek( 1 ); | 93 | qbIn.seek( 1 ); |
94 | return new Token( tokColon ); | 94 | return new Token( tokColon ); |
95 | 95 | ||
96 | case ';': | 96 | case ';': |
97 | qbIn.seek( 1 ); | 97 | qbIn.seek( 1 ); |
98 | return new Token( tokSemiColon ); | 98 | return new Token( tokSemiColon ); |
99 | 99 | ||
100 | case '|': | 100 | case '|': |
101 | qbIn.seek( 1 ); | 101 | qbIn.seek( 1 ); |
102 | return new Token( tokOr ); | 102 | return new Token( tokOr ); |
103 | 103 | ||
104 | case '=': | 104 | case '=': |
105 | qbIn.seek( 1 ); | 105 | qbIn.seek( 1 ); |
106 | return new Token( tokEquals ); | 106 | return new Token( tokEquals ); |
107 | 107 | ||
108 | case '[': | 108 | case '[': |
109 | qbIn.seek( 1 ); | 109 | qbIn.seek( 1 ); |
110 | return new Token( tokOpenSquare ); | 110 | return new Token( tokOpenSquare ); |
111 | 111 | ||
112 | case ']': | 112 | case ']': |
113 | qbIn.seek( 1 ); | 113 | qbIn.seek( 1 ); |
114 | return new Token( tokCloseSquare ); | 114 | return new Token( tokCloseSquare ); |
115 | 115 | ||
116 | case '{': | 116 | case '{': |
117 | qbIn.seek( 1 ); | 117 | qbIn.seek( 1 ); |
118 | return new Token( tokOpenCurly ); | 118 | return new Token( tokOpenCurly ); |
119 | 119 | ||
120 | case '}': | 120 | case '}': |
121 | qbIn.seek( 1 ); | 121 | qbIn.seek( 1 ); |
122 | return new Token( tokCloseCurly ); | 122 | return new Token( tokCloseCurly ); |
123 | 123 | ||
124 | default: | 124 | default: |
125 | throw ExceptionBase("Unexpected character '%c'.", | 125 | throw ExceptionBase("Unexpected character '%c'.", |
126 | cBuf ); | 126 | cBuf ); |
127 | break; | 127 | break; |
128 | } | 128 | } |
129 | } | 129 | } |
130 | } | 130 | } |
131 | } | 131 | } |
132 | 132 | ||
133 | virtual String tokenToString( const Token &t ) | 133 | virtual String tokenToString( const Token &t ) |
134 | { | 134 | { |
135 | switch( (TokenType)t.iToken ) | 135 | switch( (TokenType)t.iToken ) |
136 | { | 136 | { |
137 | case tokIdentifier: return "tokIdentifier"; | 137 | case tokIdentifier: return "tokIdentifier"; |
138 | case tokColon: return "tokColon"; | 138 | case tokColon: return "tokColon"; |
139 | case tokOr: return "tokOr"; | 139 | case tokOr: return "tokOr"; |
140 | case tokSemiColon: return "tokSemiColon"; | 140 | case tokSemiColon: return "tokSemiColon"; |
141 | case tokTokens: return "tokTokens"; | 141 | case tokTokens: return "tokTokens"; |
142 | case tokEquals: return "tokEquals"; | 142 | case tokEquals: return "tokEquals"; |
143 | case tokOpenCurly: return "tokOpenCurly"; | 143 | case tokOpenCurly: return "tokOpenCurly"; |
144 | case tokCloseCurly: return "tokCloseCurly"; | 144 | case tokCloseCurly: return "tokCloseCurly"; |
145 | case tokOpenSquare: return "tokOpenSquare"; | 145 | case tokOpenSquare: return "tokOpenSquare"; |
146 | case tokCloseSquare: return "tokCloseSquare"; | 146 | case tokCloseSquare: return "tokCloseSquare"; |
147 | case tokEos: return "tokEos"; | 147 | case tokEos: return "tokEos"; |
148 | } | 148 | } |
149 | 149 | ||
150 | return "???"; | 150 | return "???"; |
151 | } | 151 | } |
152 | 152 | ||
153 | private: | 153 | private: |
154 | Stream &rSrc; | 154 | Stream &rSrc; |
155 | QueueBuf qbIn; | 155 | QueueBuf qbIn; |
156 | String sBuf; | 156 | String sBuf; |
157 | }; | 157 | }; |
158 | 158 | ||
159 | class BnfParser | 159 | class BnfParser |
160 | { | 160 | { |
161 | public: | 161 | public: |
162 | BnfParser( BnfLexer &l ) : | 162 | BnfParser( BnfLexer &l ) : |
163 | l( l ), | 163 | l( l ), |
164 | pCur( NULL ), | 164 | pCur( NULL ), |
165 | iLastToken( 0 ) | 165 | iLastToken( 0 ) |
166 | { | 166 | { |
167 | } | 167 | } |
168 | 168 | ||
169 | virtual ~BnfParser() | 169 | virtual ~BnfParser() |
170 | { | 170 | { |
171 | delete pCur; | 171 | delete pCur; |
172 | pCur = NULL; | 172 | pCur = NULL; |
173 | } | 173 | } |
174 | 174 | ||
175 | void parse() | 175 | void parse() |
176 | { | 176 | { |
177 | for(;;) | 177 | for(;;) |
178 | { | 178 | { |
179 | next(); | 179 | next(); |
180 | switch( pCur->iToken ) | 180 | switch( pCur->iToken ) |
181 | { | 181 | { |
182 | case tokTokens: | 182 | case tokTokens: |
183 | tokens(); | 183 | tokens(); |
184 | break; | 184 | break; |
185 | 185 | ||
186 | case tokIdentifier: | 186 | case tokIdentifier: |
187 | nonTerminal(); | 187 | nonTerminal(); |
188 | break; | 188 | break; |
189 | 189 | ||
190 | case tokEos: | 190 | case tokEos: |
191 | return; | 191 | return; |
192 | break; | 192 | break; |
193 | 193 | ||
194 | default: | 194 | default: |
195 | tokenError("tokTokens, tokIdentifier, or tokEos"); | 195 | tokenError("tokTokens, tokIdentifier, or tokEos"); |
196 | } | 196 | } |
197 | } | 197 | } |
198 | } | 198 | } |
199 | 199 | ||
200 | private: | 200 | private: |
201 | void tokens() | 201 | void tokens() |
202 | { | 202 | { |
203 | next(); | 203 | next(); |
204 | if( pCur->iToken != tokEquals ) | 204 | if( pCur->iToken != tokEquals ) |
205 | tokenError("tokEquals"); | 205 | tokenError("tokEquals"); |
206 | for(;;) | 206 | for(;;) |
207 | { | 207 | { |
208 | next(); | 208 | next(); |
209 | if( pCur->iToken == tokIdentifier ) | 209 | if( pCur->iToken == tokIdentifier ) |
210 | { | 210 | { |
211 | hTokens.insert( pCur->vExtra.get<Bu::String>(), ++iLastToken ); | 211 | hTokens.insert( pCur->vExtra.get<Bu::String>(), ++iLastToken ); |
212 | sio << "Added token[" << iLastToken << "]: " | 212 | sio << "Added token[" << iLastToken << "]: " |
213 | << pCur->vExtra.get<Bu::String>() << sio.nl; | 213 | << pCur->vExtra.get<Bu::String>() << sio.nl; |
214 | } | 214 | } |
215 | else if( pCur->iToken == tokSemiColon ) | 215 | else if( pCur->iToken == tokSemiColon ) |
216 | break; | 216 | break; |
217 | else | 217 | else |
218 | tokenError("tokIdentifier or tokSemiColon"); | 218 | tokenError("tokIdentifier or tokSemiColon"); |
219 | } | 219 | } |
220 | } | 220 | } |
221 | 221 | ||
222 | void nonTerminal() | 222 | void nonTerminal() |
223 | { | 223 | { |
224 | Bu::String sNtName = pCur->vExtra.get<Bu::String>(); | 224 | Bu::String sNtName = pCur->vExtra.get<Bu::String>(); |
225 | Parser::NonTerminal nt; | 225 | Parser::NonTerminal nt; |
226 | p.addNonTerminal( sNtName ); | 226 | p.addNonTerminal( sNtName ); |
227 | sio.incIndent(); | 227 | sio.incIndent(); |
228 | sio << "Created non-terminal: " << sNtName << sio.nl; | 228 | sio << "Created non-terminal: " << sNtName << sio.nl; |
229 | 229 | ||
230 | next(); | 230 | next(); |
231 | if( pCur->iToken != tokColon ) | 231 | if( pCur->iToken != tokColon ) |
232 | tokenError("tokColon"); | 232 | tokenError("tokColon"); |
233 | production( nt ); | 233 | production( nt ); |
234 | for(;;) | 234 | for(;;) |
235 | { | 235 | { |
236 | switch( pCur->iToken ) | 236 | switch( pCur->iToken ) |
237 | { | 237 | { |
238 | case tokOr: | 238 | case tokOr: |
239 | production( nt ); | 239 | production( nt ); |
240 | break; | 240 | break; |
241 | 241 | ||
242 | case tokSemiColon: | 242 | case tokSemiColon: |
243 | p.setNonTerminal( sNtName, nt ); | 243 | p.setNonTerminal( sNtName, nt ); |
244 | sio.decIndent(); | 244 | sio.decIndent(); |
245 | sio << "Closing non-terminal." << sio.nl; | 245 | sio << "Closing non-terminal." << sio.nl; |
246 | return; | 246 | return; |
247 | 247 | ||
248 | default: | 248 | default: |
249 | tokenError("tkOr or tokSemiColon"); | 249 | tokenError("tkOr or tokSemiColon"); |
250 | break; | 250 | break; |
251 | } | 251 | } |
252 | } | 252 | } |
253 | } | 253 | } |
254 | 254 | ||
255 | void production( Parser::NonTerminal &nt ) | 255 | void production( Parser::NonTerminal &nt ) |
256 | { | 256 | { |
257 | sio.incIndent(); | 257 | sio.incIndent(); |
258 | sio << "Adding new production:" << sio.nl; | 258 | sio << "Adding new production:" << sio.nl; |
259 | Parser::Production pr; | 259 | Parser::Production pr; |
260 | bool bAnything = false; | 260 | bool bAnything = false; |
261 | for(;;) | 261 | for(;;) |
262 | { | 262 | { |
263 | next(); | 263 | next(); |
264 | switch( pCur->iToken ) | 264 | switch( pCur->iToken ) |
265 | { | 265 | { |
266 | case tokIdentifier: | 266 | case tokIdentifier: |
267 | { | 267 | { |
268 | const Bu::String &sName = | 268 | const Bu::String &sName = |
269 | pCur->vExtra.get<Bu::String>(); | 269 | pCur->vExtra.get<Bu::String>(); |
270 | if( hTokens.has( sName ) ) | 270 | if( hTokens.has( sName ) ) |
271 | { | 271 | { |
272 | pr.append( | 272 | pr.append( |
273 | Parser::State( | 273 | Parser::State( |
274 | Parser::State::typeTerminal, | 274 | Parser::State::typeTerminal, |
275 | hTokens.get( sName ) | 275 | hTokens.get( sName ) |
276 | ) | 276 | ) |
277 | ); | 277 | ); |
278 | sio << "Added terminal " << sName << sio.nl; | 278 | sio << "Added terminal " << sName << sio.nl; |
279 | } | 279 | } |
280 | else | 280 | else |
281 | { | 281 | { |
282 | if( !p.hasNonTerminal( sName ) ) | 282 | if( !p.hasNonTerminal( sName ) ) |
283 | { | 283 | { |
284 | p.addNonTerminal( sName ); | 284 | p.addNonTerminal( sName ); |
285 | } | 285 | } |
286 | pr.append( | 286 | pr.append( |
287 | Parser::State( | 287 | Parser::State( |
288 | Parser::State::typeNonTerminal, | 288 | Parser::State::typeNonTerminal, |
289 | p.getNonTerminalId( sName ) | 289 | p.getNonTerminalId( sName ) |
290 | ) | 290 | ) |
291 | ); | 291 | ); |
292 | sio << "Added non-terminal " << sName << sio.nl; | 292 | sio << "Added non-terminal " << sName << sio.nl; |
293 | } | 293 | } |
294 | } | 294 | } |
295 | break; | 295 | break; |
296 | 296 | ||
297 | case tokOpenSquare: | 297 | case tokOpenSquare: |
298 | { | 298 | { |
299 | next(); | 299 | next(); |
300 | if( pCur->iToken != tokIdentifier ) | 300 | if( pCur->iToken != tokIdentifier ) |
301 | tokenError("tokIdentifier"); | 301 | tokenError("tokIdentifier"); |
302 | Bu::String sName = | 302 | Bu::String sName = |
303 | pCur->vExtra.get<Bu::String>(); | 303 | pCur->vExtra.get<Bu::String>(); |
304 | next(); | 304 | next(); |
305 | if( pCur->iToken != tokCloseSquare ) | 305 | if( pCur->iToken != tokCloseSquare ) |
306 | tokenError("tokCloseSquare"); | 306 | tokenError("tokCloseSquare"); |
307 | 307 | ||
308 | if( !hTokens.has( sName ) ) | 308 | if( !hTokens.has( sName ) ) |
309 | throw ExceptionBase("Only token names may be " | 309 | throw ExceptionBase("Only token names may be " |
310 | "enclosed in square brackets."); | 310 | "enclosed in square brackets."); |
311 | 311 | ||
312 | pr.append( | 312 | pr.append( |
313 | Parser::State( | 313 | Parser::State( |
314 | Parser::State::typeTerminalPush, | 314 | Parser::State::typeTerminalPush, |
315 | hTokens.get( sName ) | 315 | hTokens.get( sName ) |
316 | ) | 316 | ) |
317 | ); | 317 | ); |
318 | sio << "Added terminal-push " << sName << sio.nl; | 318 | sio << "Added terminal-push " << sName << sio.nl; |
319 | } | 319 | } |
320 | break; | 320 | break; |
321 | 321 | ||
322 | case tokOpenCurly: | 322 | case tokOpenCurly: |
323 | { | 323 | { |
324 | next(); | 324 | next(); |
325 | if( pCur->iToken != tokIdentifier ) | 325 | if( pCur->iToken != tokIdentifier ) |
326 | tokenError("tokIdentifier"); | 326 | tokenError("tokIdentifier"); |
327 | Bu::String sName = | 327 | Bu::String sName = |
328 | pCur->vExtra.get<Bu::String>(); | 328 | pCur->vExtra.get<Bu::String>(); |
329 | next(); | 329 | next(); |
330 | if( pCur->iToken != tokCloseCurly ) | 330 | if( pCur->iToken != tokCloseCurly ) |
331 | tokenError("tokCloseCurly"); | 331 | tokenError("tokCloseCurly"); |
332 | 332 | ||
333 | if( !p.hasReduction( sName ) ) | 333 | if( !p.hasReduction( sName ) ) |
334 | p.addReduction( sName ); | 334 | p.addReduction( sName ); |
335 | 335 | ||
336 | pr.append( | 336 | pr.append( |
337 | Parser::State( | 337 | Parser::State( |
338 | Parser::State::typeReduction, | 338 | Parser::State::typeReduction, |
339 | p.getReductionId( sName ) | 339 | p.getReductionId( sName ) |
340 | ) | 340 | ) |
341 | ); | 341 | ); |
342 | sio << "Added reduction " << sName << sio.nl; | 342 | sio << "Added reduction " << sName << sio.nl; |
343 | } | 343 | } |
344 | break; | 344 | break; |
345 | 345 | ||
346 | case tokOr: | 346 | case tokOr: |
347 | case tokSemiColon: | 347 | case tokSemiColon: |
348 | if( bAnything ) | 348 | if( bAnything ) |
349 | { | 349 | { |
350 | nt.addProduction( pr ); | 350 | nt.addProduction( pr ); |
351 | sio.decIndent(); | 351 | sio.decIndent(); |
352 | sio << "Closing production." << sio.nl; | 352 | sio << "Closing production." << sio.nl; |
353 | } | 353 | } |
354 | else | 354 | else |
355 | { | 355 | { |
356 | nt.setCanSkip(); | 356 | nt.setCanSkip(); |
357 | sio.decIndent(); | 357 | sio.decIndent(); |
358 | sio << "Closing empty production." << sio.nl; | 358 | sio << "Closing empty production." << sio.nl; |
359 | } | 359 | } |
360 | return; | 360 | return; |
361 | 361 | ||
362 | default: | 362 | default: |
363 | tokenError("tokIdentifier, tokOpenSquare, tokOr, " | 363 | tokenError("tokIdentifier, tokOpenSquare, tokOr, " |
364 | "tokOpenCurly, or tokSemiColon"); | 364 | "tokOpenCurly, or tokSemiColon"); |
365 | } | 365 | } |
366 | } | 366 | } |
367 | } | 367 | } |
368 | 368 | ||
369 | private: | 369 | private: |
370 | void next() | 370 | void next() |
371 | { | 371 | { |
372 | delete pCur; | 372 | delete pCur; |
373 | pCur = l.nextToken(); | 373 | pCur = l.nextToken(); |
374 | } | 374 | } |
375 | 375 | ||
376 | void tokenError( const String &s ) | 376 | void tokenError( const String &s ) |
377 | { | 377 | { |
378 | throw ExceptionBase( ("Expected " + s + " but found " | 378 | throw ExceptionBase( ("Expected " + s + " but found " |
379 | + l.tokenToString( *pCur ) + ".").getStr() ); | 379 | + l.tokenToString( *pCur ) + ".").getStr() ); |
380 | } | 380 | } |
381 | 381 | ||
382 | private: | 382 | private: |
383 | typedef Bu::Hash<Bu::String, int> TokenHash; | 383 | typedef Bu::Hash<Bu::String, int> TokenHash; |
384 | TokenHash hTokens; | 384 | TokenHash hTokens; |
385 | BnfLexer &l; | 385 | BnfLexer &l; |
386 | BnfLexer::Token *pCur; | 386 | BnfLexer::Token *pCur; |
387 | int iLastToken; | 387 | int iLastToken; |
388 | Parser p; | 388 | Parser p; |
389 | }; | 389 | }; |
390 | 390 | ||
391 | int main( int argc, char *argv[] ) | 391 | int main( int argc, char *argv[] ) |
392 | { | 392 | { |
393 | if( argc < 2 ) | 393 | if( argc < 2 ) |
394 | { | 394 | { |
395 | println("Provide an input filename as the first parameter."); | 395 | println("Provide an input filename as the first parameter."); |
396 | return 0; | 396 | return 0; |
397 | } | 397 | } |
398 | File fIn( argv[1], File::Read ); | 398 | File fIn( argv[1], File::Read ); |
399 | 399 | ||
400 | BnfLexer bl( fIn ); | 400 | BnfLexer bl( fIn ); |
401 | BnfParser parser( bl ); | 401 | BnfParser parser( bl ); |
402 | 402 | ||
403 | parser.parse(); | 403 | parser.parse(); |
404 | 404 | ||
405 | /* | 405 | /* |
406 | for(;;) | 406 | for(;;) |
407 | { | 407 | { |
408 | Lexer::Token *pTok = bl.nextToken(); | 408 | Lexer::Token *pTok = bl.nextToken(); |
409 | sio << bl.tokenToString(*pTok); | 409 | sio << bl.tokenToString(*pTok); |
410 | if( pTok->vExtra.isSet() ) | 410 | if( pTok->vExtra.isSet() ) |
411 | { | 411 | { |
412 | sio << " - " << pTok->vExtra; | 412 | sio << " - " << pTok->vExtra; |
413 | } | 413 | } |
414 | sio << sio.nl; | 414 | sio << sio.nl; |
415 | if( pTok->iToken == tokEos ) | 415 | if( pTok->iToken == tokEos ) |
416 | break; | 416 | break; |
417 | } | 417 | } |
418 | */ | 418 | */ |
419 | 419 | ||
420 | return 0; | 420 | return 0; |
421 | } | 421 | } |
422 | 422 | ||
diff --git a/src/tests/bzip2.cpp b/src/tests/bzip2.cpp index 1b6fc2f..26bb9bd 100644 --- a/src/tests/bzip2.cpp +++ b/src/tests/bzip2.cpp | |||
@@ -10,27 +10,27 @@ | |||
10 | 10 | ||
11 | int main( int argc, char *argv[] ) | 11 | int main( int argc, char *argv[] ) |
12 | { | 12 | { |
13 | if( argc < 3 ) | 13 | if( argc < 3 ) |
14 | { | 14 | { |
15 | printf("usage: %s <in> <out>\n", argv[0] ); | 15 | printf("usage: %s <in> <out>\n", argv[0] ); |
16 | return -1; | 16 | return -1; |
17 | } | 17 | } |
18 | 18 | ||
19 | char buf[1024]; | 19 | char buf[1024]; |
20 | size_t nRead; | 20 | size_t nRead; |
21 | 21 | ||
22 | Bu::File fin( argv[1], Bu::File::Read ); | 22 | Bu::File fin( argv[1], Bu::File::Read ); |
23 | 23 | ||
24 | Bu::File f( argv[2], Bu::File::WriteNew ); | 24 | Bu::File f( argv[2], Bu::File::WriteNew ); |
25 | Bu::BZip2 bz2( f ); | 25 | Bu::BZip2 bz2( f ); |
26 | 26 | ||
27 | for(;;) | 27 | for(;;) |
28 | { | 28 | { |
29 | nRead = fin.read( buf, 1024 ); | 29 | nRead = fin.read( buf, 1024 ); |
30 | if( nRead > 0 ) | 30 | if( nRead > 0 ) |
31 | bz2.write( buf, nRead ); | 31 | bz2.write( buf, nRead ); |
32 | if( fin.isEos() ) | 32 | if( fin.isEos() ) |
33 | break; | 33 | break; |
34 | } | 34 | } |
35 | } | 35 | } |
36 | 36 | ||
diff --git a/src/tests/deflate.cpp b/src/tests/deflate.cpp index 8290ed5..89640e1 100644 --- a/src/tests/deflate.cpp +++ b/src/tests/deflate.cpp | |||
@@ -10,44 +10,44 @@ | |||
10 | 10 | ||
11 | int main( int argc, char *argv[] ) | 11 | int main( int argc, char *argv[] ) |
12 | { | 12 | { |
13 | if( argc < 3 ) | 13 | if( argc < 3 ) |
14 | { | 14 | { |
15 | printf("usage: %s <in> <out>\n", argv[0] ); | 15 | printf("usage: %s <in> <out>\n", argv[0] ); |
16 | return -1; | 16 | return -1; |
17 | } | 17 | } |
18 | 18 | ||
19 | char buf[1024]; | 19 | char buf[1024]; |
20 | size_t nRead; | 20 | size_t nRead; |
21 | 21 | ||
22 | /* | 22 | /* |
23 | Bu::File fin( argv[1], Bu::File::Read ); | 23 | Bu::File fin( argv[1], Bu::File::Read ); |
24 | fin.seek( 4 ); | 24 | fin.seek( 4 ); |
25 | Bu::Deflate def( fin ); | 25 | Bu::Deflate def( fin ); |
26 | 26 | ||
27 | Bu::File f( argv[2], Bu::File::WriteNew ); | 27 | Bu::File f( argv[2], Bu::File::WriteNew ); |
28 | 28 | ||
29 | for(;;) | 29 | for(;;) |
30 | { | 30 | { |
31 | nRead = def.read( buf, 1024 ); | 31 | nRead = def.read( buf, 1024 ); |
32 | if( nRead > 0 ) | 32 | if( nRead > 0 ) |
33 | f.write( buf, nRead ); | 33 | f.write( buf, nRead ); |
34 | if( def.isEos() ) | 34 | if( def.isEos() ) |
35 | break; | 35 | break; |
36 | } | 36 | } |
37 | */ | 37 | */ |
38 | 38 | ||
39 | Bu::File fin( argv[1], Bu::File::Read ); | 39 | Bu::File fin( argv[1], Bu::File::Read ); |
40 | 40 | ||
41 | Bu::File f( argv[2], Bu::File::WriteNew ); | 41 | Bu::File f( argv[2], Bu::File::WriteNew ); |
42 | Bu::Deflate def( f, 9, Bu::Deflate::Gzip ); | 42 | Bu::Deflate def( f, 9, Bu::Deflate::Gzip ); |
43 | 43 | ||
44 | for(;;) | 44 | for(;;) |
45 | { | 45 | { |
46 | nRead = fin.read( buf, 1024 ); | 46 | nRead = fin.read( buf, 1024 ); |
47 | if( nRead > 0 ) | 47 | if( nRead > 0 ) |
48 | def.write( buf, nRead ); | 48 | def.write( buf, nRead ); |
49 | if( fin.isEos() ) | 49 | if( fin.isEos() ) |
50 | break; | 50 | break; |
51 | } | 51 | } |
52 | } | 52 | } |
53 | 53 | ||
diff --git a/src/tests/lzma.cpp b/src/tests/lzma.cpp index 596c396..7d4d1eb 100644 --- a/src/tests/lzma.cpp +++ b/src/tests/lzma.cpp | |||
@@ -10,44 +10,44 @@ | |||
10 | 10 | ||
11 | int main( int argc, char *argv[] ) | 11 | int main( int argc, char *argv[] ) |
12 | { | 12 | { |
13 | if( argc < 3 ) | 13 | if( argc < 3 ) |
14 | { | 14 | { |
15 | printf("usage: %s <in> <out>\n", argv[0] ); | 15 | printf("usage: %s <in> <out>\n", argv[0] ); |
16 | return -1; | 16 | return -1; |
17 | } | 17 | } |
18 | 18 | ||
19 | char buf[1024]; | 19 | char buf[1024]; |
20 | size_t nRead; | 20 | size_t nRead; |
21 | 21 | ||
22 | /* | 22 | /* |
23 | Bu::File fin( argv[1], Bu::File::Read ); | 23 | Bu::File fin( argv[1], Bu::File::Read ); |
24 | fin.seek( 4 ); | 24 | fin.seek( 4 ); |
25 | Bu::Deflate def( fin ); | 25 | Bu::Deflate def( fin ); |
26 | 26 | ||
27 | Bu::File f( argv[2], Bu::File::WriteNew ); | 27 | Bu::File f( argv[2], Bu::File::WriteNew ); |
28 | 28 | ||
29 | for(;;) | 29 | for(;;) |
30 | { | 30 | { |
31 | nRead = def.read( buf, 1024 ); | 31 | nRead = def.read( buf, 1024 ); |
32 | if( nRead > 0 ) | 32 | if( nRead > 0 ) |
33 | f.write( buf, nRead ); | 33 | f.write( buf, nRead ); |
34 | if( def.isEos() ) | 34 | if( def.isEos() ) |
35 | break; | 35 | break; |
36 | } | 36 | } |
37 | */ | 37 | */ |
38 | 38 | ||
39 | Bu::File fin( argv[1], Bu::File::Read ); | 39 | Bu::File fin( argv[1], Bu::File::Read ); |
40 | 40 | ||
41 | Bu::File f( argv[2], Bu::File::WriteNew ); | 41 | Bu::File f( argv[2], Bu::File::WriteNew ); |
42 | Bu::Lzma def( f, 9 ); | 42 | Bu::Lzma def( f, 9 ); |
43 | 43 | ||
44 | for(;;) | 44 | for(;;) |
45 | { | 45 | { |
46 | nRead = fin.read( buf, 1024 ); | 46 | nRead = fin.read( buf, 1024 ); |
47 | if( nRead > 0 ) | 47 | if( nRead > 0 ) |
48 | def.write( buf, nRead ); | 48 | def.write( buf, nRead ); |
49 | if( fin.isEos() ) | 49 | if( fin.isEos() ) |
50 | break; | 50 | break; |
51 | } | 51 | } |
52 | } | 52 | } |
53 | 53 | ||
diff --git a/src/tests/myriadfs.cpp b/src/tests/myriadfs.cpp index f57f02d..cb6c6c3 100644 --- a/src/tests/myriadfs.cpp +++ b/src/tests/myriadfs.cpp | |||
@@ -8,41 +8,41 @@ using namespace Bu; | |||
8 | 8 | ||
9 | int main() | 9 | int main() |
10 | { | 10 | { |
11 | // Bu::MemBuf mb; | 11 | // Bu::MemBuf mb; |
12 | Bu::File mb("store.myr", File::Read|File::Write|File::Create ); | 12 | Bu::File mb("store.myr", File::Read|File::Write|File::Create ); |
13 | Bu::MyriadFs mfs( mb, 512 ); | 13 | Bu::MyriadFs mfs( mb, 512 ); |
14 | 14 | ||
15 | sio << "Creating dirs..." << sio.nl; | 15 | sio << "Creating dirs..." << sio.nl; |
16 | mfs.create("/etc", Bu::MyriadFs::typeDir|0755 ); | 16 | mfs.create("/etc", Bu::MyriadFs::typeDir|0755 ); |
17 | mfs.create("/dev", Bu::MyriadFs::typeDir|0755 ); | 17 | mfs.create("/dev", Bu::MyriadFs::typeDir|0755 ); |
18 | mfs.create("/usr", Bu::MyriadFs::typeDir|0755 ); | 18 | mfs.create("/usr", Bu::MyriadFs::typeDir|0755 ); |
19 | 19 | ||
20 | mfs.create("/dev/null", Bu::MyriadFs::typeChrDev|0666, 1, 3 ); | 20 | mfs.create("/dev/null", Bu::MyriadFs::typeChrDev|0666, 1, 3 ); |
21 | mfs.create("/dev/zero", Bu::MyriadFs::typeChrDev|0666, 1, 5 ); | 21 | mfs.create("/dev/zero", Bu::MyriadFs::typeChrDev|0666, 1, 5 ); |
22 | mfs.create("/dev/sda", Bu::MyriadFs::typeBlkDev|0660, 8, 0 ); | 22 | mfs.create("/dev/sda", Bu::MyriadFs::typeBlkDev|0660, 8, 0 ); |
23 | 23 | ||
24 | sio << "Creating files..." << sio.nl; | 24 | sio << "Creating files..." << sio.nl; |
25 | { | 25 | { |
26 | Bu::MyriadStream ms = mfs.open("/hello", Bu::MyriadFs::Read ); | 26 | Bu::MyriadStream ms = mfs.open("/hello", Bu::MyriadFs::Read ); |
27 | ms.write("world!"); | 27 | ms.write("world!"); |
28 | } | 28 | } |
29 | { | 29 | { |
30 | Bu::MyriadStream ms = mfs.open("/etc/hello", Bu::MyriadFs::Read ); | 30 | Bu::MyriadStream ms = mfs.open("/etc/hello", Bu::MyriadFs::Read ); |
31 | ms.write("world, again!"); | 31 | ms.write("world, again!"); |
32 | } | 32 | } |
33 | 33 | ||
34 | sio << "Reading files..." << sio.nl; | 34 | sio << "Reading files..." << sio.nl; |
35 | { | 35 | { |
36 | Bu::MyriadStream ms = mfs.open("/hello", Bu::MyriadFs::Read ); | 36 | Bu::MyriadStream ms = mfs.open("/hello", Bu::MyriadFs::Read ); |
37 | char buf[512]; | 37 | char buf[512]; |
38 | buf[ms.read( buf, 512 )] = '\0'; | 38 | buf[ms.read( buf, 512 )] = '\0'; |
39 | sio << "read: '" << buf << "'" << sio.nl; | 39 | sio << "read: '" << buf << "'" << sio.nl; |
40 | } | 40 | } |
41 | { | 41 | { |
42 | Bu::MyriadStream ms = mfs.open("/etc/hello", Bu::MyriadFs::Read ); | 42 | Bu::MyriadStream ms = mfs.open("/etc/hello", Bu::MyriadFs::Read ); |
43 | char buf[512]; | 43 | char buf[512]; |
44 | buf[ms.read( buf, 512 )] = '\0'; | 44 | buf[ms.read( buf, 512 )] = '\0'; |
45 | sio << "read: '" << buf << "'" << sio.nl; | 45 | sio << "read: '" << buf << "'" << sio.nl; |
46 | } | 46 | } |
47 | } | 47 | } |
48 | 48 | ||
diff --git a/src/tests/optparser.cpp b/src/tests/optparser.cpp index 772cebc..05e5168 100644 --- a/src/tests/optparser.cpp +++ b/src/tests/optparser.cpp | |||
@@ -12,82 +12,82 @@ using namespace Bu; | |||
12 | class Opts : public Bu::OptParser | 12 | class Opts : public Bu::OptParser |
13 | { | 13 | { |
14 | public: | 14 | public: |
15 | Opts() : | 15 | Opts() : |
16 | iBob( 542 ), | 16 | iBob( 542 ), |
17 | bVal( false ) | 17 | bVal( false ) |
18 | { | 18 | { |
19 | addHelpBanner("optparser - Test some option things..."); | 19 | addHelpBanner("optparser - Test some option things..."); |
20 | 20 | ||
21 | addHelpBanner("\nThis section represents options that actually have " | 21 | addHelpBanner("\nThis section represents options that actually have " |
22 | "callbacks, or in the case of the new system, signals/slots. They " | 22 | "callbacks, or in the case of the new system, signals/slots. They " |
23 | "all take parameters, but if they return 0 then it will be as " | 23 | "all take parameters, but if they return 0 then it will be as " |
24 | "though they hadn't and the next thing will be processed normally.", | 24 | "though they hadn't and the next thing will be processed normally.", |
25 | true | 25 | true |
26 | ); | 26 | ); |
27 | addOption( slot( this, &Opts::yesparam ), 'x', "things", | 27 | addOption( slot( this, &Opts::yesparam ), 'x', "things", |
28 | "This is the first test parameter. It calls a function, and " | 28 | "This is the first test parameter. It calls a function, and " |
29 | "takes a parameter." | 29 | "takes a parameter." |
30 | ); | 30 | ); |
31 | addOption( slot( this, &Opts::noparam ), 'y', "stuff", | 31 | addOption( slot( this, &Opts::noparam ), 'y', "stuff", |
32 | "This is the second test parameter. It does not take " | 32 | "This is the second test parameter. It does not take " |
33 | "parameters. However, I do want to make this part much longer to " | 33 | "parameters. However, I do want to make this part much longer to " |
34 | "see how it looks when you add way too much text to one of these " | 34 | "see how it looks when you add way too much text to one of these " |
35 | "things. It can't really be that bad, right?" | 35 | "things. It can't really be that bad, right?" |
36 | ); | 36 | ); |
37 | 37 | ||
38 | addHelpBanner("\nThis section represents options with no callback or " | 38 | addHelpBanner("\nThis section represents options with no callback or " |
39 | "signal, but do have a variable to update. They use the Formatter " | 39 | "signal, but do have a variable to update. They use the Formatter " |
40 | "system and therefore it's very, very flexible. Any data type " | 40 | "system and therefore it's very, very flexible. Any data type " |
41 | "you can read with a formatter you can set via parameter.", | 41 | "you can read with a formatter you can set via parameter.", |
42 | true | 42 | true |
43 | ); | 43 | ); |
44 | addOption( sVar, 's', "str", "Set a variable, see what it does."); | 44 | addOption( sVar, 's', "str", "Set a variable, see what it does."); |
45 | addOption( bVal, 'b', "bool", "It's a thing."); | 45 | addOption( bVal, 'b', "bool", "It's a thing."); |
46 | addOption( iBob, "bob", "Change iBob to whatever you want."); | 46 | addOption( iBob, "bob", "Change iBob to whatever you want."); |
47 | addOption( dBob, 'd', "Change dBob to whatever you want."); | 47 | addOption( dBob, 'd', "Change dBob to whatever you want."); |
48 | 48 | ||
49 | setOverride("str", "Bob!"); | 49 | setOverride("str", "Bob!"); |
50 | setHelpDefault("bob", "=542"); | 50 | setHelpDefault("bob", "=542"); |
51 | setOverride("bool", true ); | 51 | setOverride("bool", true ); |
52 | 52 | ||
53 | addHelpOption(); | 53 | addHelpOption(); |
54 | 54 | ||
55 | setNonOption( slot( this, &Opts::nonOption ) ); | 55 | setNonOption( slot( this, &Opts::nonOption ) ); |
56 | } | 56 | } |
57 | 57 | ||
58 | int yesparam( StrArray aParams ) | 58 | int yesparam( StrArray aParams ) |
59 | { | 59 | { |
60 | sio << " - yesparam" << aParams << sio.nl; | 60 | sio << " - yesparam" << aParams << sio.nl; |
61 | return 1; | 61 | return 1; |
62 | } | 62 | } |
63 | 63 | ||
64 | int noparam( StrArray aParams ) | 64 | int noparam( StrArray aParams ) |
65 | { | 65 | { |
66 | sio << " - noparam" << aParams << sio.nl; | 66 | sio << " - noparam" << aParams << sio.nl; |
67 | return 0; | 67 | return 0; |
68 | } | 68 | } |
69 | 69 | ||
70 | int nonOption( StrArray aParams ) | 70 | int nonOption( StrArray aParams ) |
71 | { | 71 | { |
72 | sio << " - nonOption" << aParams << sio.nl; | 72 | sio << " - nonOption" << aParams << sio.nl; |
73 | return aParams.getSize()-1; | 73 | return aParams.getSize()-1; |
74 | } | 74 | } |
75 | 75 | ||
76 | int iBob; | 76 | int iBob; |
77 | float dBob; | 77 | float dBob; |
78 | Bu::String sVar; | 78 | Bu::String sVar; |
79 | bool bVal; | 79 | bool bVal; |
80 | }; | 80 | }; |
81 | 81 | ||
82 | int main( int argc, char *argv[] ) | 82 | int main( int argc, char *argv[] ) |
83 | { | 83 | { |
84 | Opts o; | 84 | Opts o; |
85 | 85 | ||
86 | o.parse( argc, argv ); | 86 | o.parse( argc, argv ); |
87 | 87 | ||
88 | sio << "sVar = \"" << o.sVar << "\"" << sio.nl; | 88 | sio << "sVar = \"" << o.sVar << "\"" << sio.nl; |
89 | sio << "iBob = " << o.iBob << sio.nl; | 89 | sio << "iBob = " << o.iBob << sio.nl; |
90 | sio << "dBob = " << o.dBob << sio.nl; | 90 | sio << "dBob = " << o.dBob << sio.nl; |
91 | sio << "bVal = " << o.bVal << sio.nl; | 91 | sio << "bVal = " << o.bVal << sio.nl; |
92 | } | 92 | } |
93 | 93 | ||
diff --git a/src/tests/parser.cpp b/src/tests/parser.cpp index af53bc8..6ad722f 100644 --- a/src/tests/parser.cpp +++ b/src/tests/parser.cpp | |||
@@ -16,185 +16,185 @@ using namespace Bu; | |||
16 | 16 | ||
17 | enum Tok | 17 | enum Tok |
18 | { | 18 | { |
19 | tokNumber, | 19 | tokNumber, |
20 | tokPlus, | 20 | tokPlus, |
21 | tokMinus, | 21 | tokMinus, |
22 | tokDivide, | 22 | tokDivide, |
23 | tokMultiply, | 23 | tokMultiply, |
24 | tokOpenParen, | 24 | tokOpenParen, |
25 | tokCloseParen, | 25 | tokCloseParen, |
26 | tokCompute, | 26 | tokCompute, |
27 | tokEndOfInput=-1 | 27 | tokEndOfInput=-1 |
28 | }; | 28 | }; |
29 | 29 | ||
30 | Bu::Formatter &operator<<( Bu::Formatter &f, Tok e ) | 30 | Bu::Formatter &operator<<( Bu::Formatter &f, Tok e ) |
31 | { | 31 | { |
32 | switch( e ) | 32 | switch( e ) |
33 | { | 33 | { |
34 | case tokNumber: return f << "tokNumber"; | 34 | case tokNumber: return f << "tokNumber"; |
35 | case tokPlus: return f << "tokPlus"; | 35 | case tokPlus: return f << "tokPlus"; |
36 | case tokMinus: return f << "tokMinus"; | 36 | case tokMinus: return f << "tokMinus"; |
37 | case tokDivide: return f << "tokDivide"; | 37 | case tokDivide: return f << "tokDivide"; |
38 | case tokMultiply: return f << "tokMultiply"; | 38 | case tokMultiply: return f << "tokMultiply"; |
39 | case tokOpenParen: return f << "tokOpenParen"; | 39 | case tokOpenParen: return f << "tokOpenParen"; |
40 | case tokCloseParen: return f << "tokCloseParen"; | 40 | case tokCloseParen: return f << "tokCloseParen"; |
41 | case tokCompute: return f << "tokCompute"; | 41 | case tokCompute: return f << "tokCompute"; |
42 | case tokEndOfInput: return f << "tokEndOfInput"; | 42 | case tokEndOfInput: return f << "tokEndOfInput"; |
43 | } | 43 | } |
44 | 44 | ||
45 | return f << "***error***"; | 45 | return f << "***error***"; |
46 | } | 46 | } |
47 | 47 | ||
48 | class MathLexer : public Lexer | 48 | class MathLexer : public Lexer |
49 | { | 49 | { |
50 | public: | 50 | public: |
51 | MathLexer( Bu::Stream &rSrc ) : | 51 | MathLexer( Bu::Stream &rSrc ) : |
52 | rSrc( rSrc ) | 52 | rSrc( rSrc ) |
53 | { | 53 | { |
54 | } | 54 | } |
55 | 55 | ||
56 | virtual ~MathLexer() | 56 | virtual ~MathLexer() |
57 | { | 57 | { |
58 | } | 58 | } |
59 | 59 | ||
60 | enum TokenTypes | 60 | enum TokenTypes |
61 | { | 61 | { |
62 | tokStuff | 62 | tokStuff |
63 | }; | 63 | }; |
64 | 64 | ||
65 | virtual Token *nextToken() | 65 | virtual Token *nextToken() |
66 | { | 66 | { |
67 | for(;;) | 67 | for(;;) |
68 | { | 68 | { |
69 | if( qbIn.getSize() == 0 ) | 69 | if( qbIn.getSize() == 0 ) |
70 | { | 70 | { |
71 | char buf[4096]; | 71 | char buf[4096]; |
72 | qbIn.write( buf, rSrc.read( buf, 4096 ) ); | 72 | qbIn.write( buf, rSrc.read( buf, 4096 ) ); |
73 | 73 | ||
74 | if( rSrc.isEos() && qbIn.getSize() == 0 ) | 74 | if( rSrc.isEos() && qbIn.getSize() == 0 ) |
75 | return new Token( tokEndOfInput ); | 75 | return new Token( tokEndOfInput ); |
76 | } | 76 | } |
77 | 77 | ||
78 | char b; | 78 | char b; |
79 | qbIn.peek( &b, 1 ); | 79 | qbIn.peek( &b, 1 ); |
80 | switch( b ) | 80 | switch( b ) |
81 | { | 81 | { |
82 | case '+': | 82 | case '+': |
83 | qbIn.seek( 1 ); | 83 | qbIn.seek( 1 ); |
84 | return new Token( tokPlus ); | 84 | return new Token( tokPlus ); |
85 | 85 | ||
86 | case '-': | 86 | case '-': |
87 | qbIn.seek( 1 ); | 87 | qbIn.seek( 1 ); |
88 | return new Token( tokMinus ); | 88 | return new Token( tokMinus ); |
89 | 89 | ||
90 | case '/': | 90 | case '/': |
91 | qbIn.seek( 1 ); | 91 | qbIn.seek( 1 ); |
92 | return new Token( tokDivide ); | 92 | return new Token( tokDivide ); |
93 | 93 | ||
94 | case '*': | 94 | case '*': |
95 | qbIn.seek( 1 ); | 95 | qbIn.seek( 1 ); |
96 | return new Token( tokMultiply ); | 96 | return new Token( tokMultiply ); |
97 | 97 | ||
98 | case ' ': | 98 | case ' ': |
99 | case '\t': | 99 | case '\t': |
100 | case '\n': | 100 | case '\n': |
101 | qbIn.seek( 1 ); | 101 | qbIn.seek( 1 ); |
102 | break; | 102 | break; |
103 | 103 | ||
104 | case '=': | 104 | case '=': |
105 | qbIn.seek( 1 ); | 105 | qbIn.seek( 1 ); |
106 | return new Token( tokCompute ); | 106 | return new Token( tokCompute ); |
107 | 107 | ||
108 | case '(': | 108 | case '(': |
109 | qbIn.seek( 1 ); | 109 | qbIn.seek( 1 ); |
110 | return new Token( tokOpenParen ); | 110 | return new Token( tokOpenParen ); |
111 | 111 | ||
112 | case ')': | 112 | case ')': |
113 | qbIn.seek( 1 ); | 113 | qbIn.seek( 1 ); |
114 | return new Token( tokCloseParen ); | 114 | return new Token( tokCloseParen ); |
115 | 115 | ||
116 | case '.': | 116 | case '.': |
117 | case '0': | 117 | case '0': |
118 | case '1': | 118 | case '1': |
119 | case '2': | 119 | case '2': |
120 | case '3': | 120 | case '3': |
121 | case '4': | 121 | case '4': |
122 | case '5': | 122 | case '5': |
123 | case '6': | 123 | case '6': |
124 | case '7': | 124 | case '7': |
125 | case '8': | 125 | case '8': |
126 | case '9': | 126 | case '9': |
127 | { | 127 | { |
128 | Bu::String sTmp; | 128 | Bu::String sTmp; |
129 | sTmp += b; | 129 | sTmp += b; |
130 | qbIn.seek( 1 ); | 130 | qbIn.seek( 1 ); |
131 | for(;;) | 131 | for(;;) |
132 | { | 132 | { |
133 | qbIn.peek( &b, 1 ); | 133 | qbIn.peek( &b, 1 ); |
134 | if( b != '.' && (b < '0' || b > '9') ) | 134 | if( b != '.' && (b < '0' || b > '9') ) |
135 | { | 135 | { |
136 | sio << "!! Convert '" << sTmp << "' to " | 136 | sio << "!! Convert '" << sTmp << "' to " |
137 | << strtod( sTmp.getStr(), NULL ) << sio.nl; | 137 | << strtod( sTmp.getStr(), NULL ) << sio.nl; |
138 | return new Token( | 138 | return new Token( |
139 | tokNumber, strtod( sTmp.getStr(), NULL ) | 139 | tokNumber, strtod( sTmp.getStr(), NULL ) |
140 | ); | 140 | ); |
141 | } | 141 | } |
142 | qbIn.seek( 1 ); | 142 | qbIn.seek( 1 ); |
143 | sTmp += b; | 143 | sTmp += b; |
144 | } | 144 | } |
145 | } | 145 | } |
146 | break; | 146 | break; |
147 | 147 | ||
148 | default: | 148 | default: |
149 | throw Bu::ExceptionBase("Unexpected character '%c'.", b ); | 149 | throw Bu::ExceptionBase("Unexpected character '%c'.", b ); |
150 | } | 150 | } |
151 | } | 151 | } |
152 | } | 152 | } |
153 | 153 | ||
154 | private: | 154 | private: |
155 | Bu::Stream &rSrc; | 155 | Bu::Stream &rSrc; |
156 | QueueBuf qbIn; | 156 | QueueBuf qbIn; |
157 | }; | 157 | }; |
158 | 158 | ||
159 | void redAdd( Bu::Parser &p ) | 159 | void redAdd( Bu::Parser &p ) |
160 | { | 160 | { |
161 | Lexer::Token *a = p.popToken(); | 161 | Lexer::Token *a = p.popToken(); |
162 | Lexer::Token *b = p.popToken(); | 162 | Lexer::Token *b = p.popToken(); |
163 | 163 | ||
164 | sio << "Add! " << b->vExtra.get<double>() << " + " | 164 | sio << "Add! " << b->vExtra.get<double>() << " + " |
165 | << a->vExtra.get<double>() << sio.nl; | 165 | << a->vExtra.get<double>() << sio.nl; |
166 | 166 | ||
167 | Lexer::Token *c = new Lexer::Token( tokNumber, | 167 | Lexer::Token *c = new Lexer::Token( tokNumber, |
168 | b->vExtra.get<double>() + a->vExtra.get<double>() | 168 | b->vExtra.get<double>() + a->vExtra.get<double>() |
169 | ); | 169 | ); |
170 | p.pushToken( c ); | 170 | p.pushToken( c ); |
171 | 171 | ||
172 | delete a; | 172 | delete a; |
173 | delete b; | 173 | delete b; |
174 | } | 174 | } |
175 | 175 | ||
176 | void redSubtract( Bu::Parser &p ) | 176 | void redSubtract( Bu::Parser &p ) |
177 | { | 177 | { |
178 | Lexer::Token *a = p.popToken(); | 178 | Lexer::Token *a = p.popToken(); |
179 | Lexer::Token *b = p.popToken(); | 179 | Lexer::Token *b = p.popToken(); |
180 | 180 | ||
181 | sio << "Subtract! " << b->vExtra.get<double>() << " - " | 181 | sio << "Subtract! " << b->vExtra.get<double>() << " - " |
182 | << a->vExtra.get<double>() << sio.nl; | 182 | << a->vExtra.get<double>() << sio.nl; |
183 | 183 | ||
184 | Lexer::Token *c = new Lexer::Token( tokNumber, | 184 | Lexer::Token *c = new Lexer::Token( tokNumber, |
185 | b->vExtra.get<double>() - a->vExtra.get<double>() | 185 | b->vExtra.get<double>() - a->vExtra.get<double>() |
186 | ); | 186 | ); |
187 | p.pushToken( c ); | 187 | p.pushToken( c ); |
188 | 188 | ||
189 | delete a; | 189 | delete a; |
190 | delete b; | 190 | delete b; |
191 | } | 191 | } |
192 | 192 | ||
193 | void redPrint( Bu::Parser &p ) | 193 | void redPrint( Bu::Parser &p ) |
194 | { | 194 | { |
195 | Lexer::Token *a = p.popToken(); | 195 | Lexer::Token *a = p.popToken(); |
196 | sio << "Print! = " << a->vExtra.get<double>() << sio.nl; | 196 | sio << "Print! = " << a->vExtra.get<double>() << sio.nl; |
197 | delete a; | 197 | delete a; |
198 | } | 198 | } |
199 | 199 | ||
200 | /* Basic grammer example: | 200 | /* Basic grammer example: |
@@ -227,143 +227,143 @@ void redPrint( Bu::Parser &p ) | |||
227 | 227 | ||
228 | int main( int argc, char *argv[] ) | 228 | int main( int argc, char *argv[] ) |
229 | { | 229 | { |
230 | if( argc < 2 ) | 230 | if( argc < 2 ) |
231 | { | 231 | { |
232 | println("Provide an input filename as the first parameter."); | 232 | println("Provide an input filename as the first parameter."); |
233 | return 0; | 233 | return 0; |
234 | } | 234 | } |
235 | File fIn( argv[1], File::Read ); | 235 | File fIn( argv[1], File::Read ); |
236 | 236 | ||
237 | Parser p; | 237 | Parser p; |
238 | 238 | ||
239 | p.addNonTerminal("expr"); | 239 | p.addNonTerminal("expr"); |
240 | p.addNonTerminal("expr-sub1"); | 240 | p.addNonTerminal("expr-sub1"); |
241 | p.addNonTerminal("expr-sub2"); | 241 | p.addNonTerminal("expr-sub2"); |
242 | { | 242 | { |
243 | Parser::NonTerminal nt; | 243 | Parser::NonTerminal nt; |
244 | nt.addProduction( | 244 | nt.addProduction( |
245 | Parser::Production( | 245 | Parser::Production( |
246 | Parser::State( | 246 | Parser::State( |
247 | Parser::State::typeTerminal, | 247 | Parser::State::typeTerminal, |
248 | tokPlus | 248 | tokPlus |
249 | ) | 249 | ) |
250 | ).append( | 250 | ).append( |
251 | Parser::State( | 251 | Parser::State( |
252 | Parser::State::typeNonTerminal, | 252 | Parser::State::typeNonTerminal, |
253 | p.getNonTerminalId("expr") | 253 | p.getNonTerminalId("expr") |
254 | ) | 254 | ) |
255 | ).append( | 255 | ).append( |
256 | Parser::State( | 256 | Parser::State( |
257 | Parser::State::typeReduction, | 257 | Parser::State::typeReduction, |
258 | p.addReduction("add") | 258 | p.addReduction("add") |
259 | ) | 259 | ) |
260 | ) | 260 | ) |
261 | ); | 261 | ); |
262 | nt.addProduction( | 262 | nt.addProduction( |
263 | Parser::Production( | 263 | Parser::Production( |
264 | Parser::State( | 264 | Parser::State( |
265 | Parser::State::typeTerminal, | 265 | Parser::State::typeTerminal, |
266 | tokMinus | 266 | tokMinus |
267 | ) | 267 | ) |
268 | ).append( | 268 | ).append( |
269 | Parser::State( | 269 | Parser::State( |
270 | Parser::State::typeNonTerminal, | 270 | Parser::State::typeNonTerminal, |
271 | p.getNonTerminalId("expr") | 271 | p.getNonTerminalId("expr") |
272 | ) | 272 | ) |
273 | ).append( | 273 | ).append( |
274 | Parser::State( | 274 | Parser::State( |
275 | Parser::State::typeReduction, | 275 | Parser::State::typeReduction, |
276 | p.addReduction("subtract") | 276 | p.addReduction("subtract") |
277 | ) | 277 | ) |
278 | ) | 278 | ) |
279 | ); | 279 | ); |
280 | nt.addProduction( | 280 | nt.addProduction( |
281 | Parser::Production( | 281 | Parser::Production( |
282 | ) | 282 | ) |
283 | ); | 283 | ); |
284 | nt.setCanSkip(); | 284 | nt.setCanSkip(); |
285 | p.setNonTerminal("expr-sub2", nt ); | 285 | p.setNonTerminal("expr-sub2", nt ); |
286 | } | 286 | } |
287 | { | 287 | { |
288 | Parser::NonTerminal nt; | 288 | Parser::NonTerminal nt; |
289 | nt.addProduction( | 289 | nt.addProduction( |
290 | Parser::Production( | 290 | Parser::Production( |
291 | Parser::State( | 291 | Parser::State( |
292 | Parser::State::typeTerminalPush, | 292 | Parser::State::typeTerminalPush, |
293 | tokNumber | 293 | tokNumber |
294 | ) | 294 | ) |
295 | ) | 295 | ) |
296 | ); | 296 | ); |
297 | nt.addProduction( | 297 | nt.addProduction( |
298 | Parser::Production( | 298 | Parser::Production( |
299 | Parser::State( | 299 | Parser::State( |
300 | Parser::State::typeTerminal, | 300 | Parser::State::typeTerminal, |
301 | tokOpenParen | 301 | tokOpenParen |
302 | ) | 302 | ) |
303 | ).append( | 303 | ).append( |
304 | Parser::State( | 304 | Parser::State( |
305 | Parser::State::typeNonTerminal, | 305 | Parser::State::typeNonTerminal, |
306 | p.getNonTerminalId("expr") | 306 | p.getNonTerminalId("expr") |
307 | ) | 307 | ) |
308 | ).append( | 308 | ).append( |
309 | Parser::State( | 309 | Parser::State( |
310 | Parser::State::typeTerminal, | 310 | Parser::State::typeTerminal, |
311 | tokCloseParen | 311 | tokCloseParen |
312 | ) | 312 | ) |
313 | ) | 313 | ) |
314 | ); | 314 | ); |
315 | p.setNonTerminal("expr-sub1", nt ); | 315 | p.setNonTerminal("expr-sub1", nt ); |
316 | } | 316 | } |
317 | { | 317 | { |
318 | Parser::NonTerminal nt; | 318 | Parser::NonTerminal nt; |
319 | nt.addProduction( | 319 | nt.addProduction( |
320 | Parser::Production( | 320 | Parser::Production( |
321 | Parser::State( | 321 | Parser::State( |
322 | Parser::State::typeNonTerminal, | 322 | Parser::State::typeNonTerminal, |
323 | p.getNonTerminalId("expr-sub1") | 323 | p.getNonTerminalId("expr-sub1") |
324 | ) | 324 | ) |
325 | ).append( | 325 | ).append( |
326 | Parser::State( | 326 | Parser::State( |
327 | Parser::State::typeNonTerminal, | 327 | Parser::State::typeNonTerminal, |
328 | p.getNonTerminalId("expr-sub2") | 328 | p.getNonTerminalId("expr-sub2") |
329 | ) | 329 | ) |
330 | ) | 330 | ) |
331 | ); | 331 | ); |
332 | p.setNonTerminal("expr", nt ); | 332 | p.setNonTerminal("expr", nt ); |
333 | } | 333 | } |
334 | { | 334 | { |
335 | Parser::NonTerminal nt; | 335 | Parser::NonTerminal nt; |
336 | nt.addProduction( | 336 | nt.addProduction( |
337 | Parser::Production( | 337 | Parser::Production( |
338 | Parser::State( | 338 | Parser::State( |
339 | Parser::State::typeNonTerminal, | 339 | Parser::State::typeNonTerminal, |
340 | p.getNonTerminalId("expr") | 340 | p.getNonTerminalId("expr") |
341 | ) | 341 | ) |
342 | ).append( | 342 | ).append( |
343 | Parser::State( | 343 | Parser::State( |
344 | Parser::State::typeTerminal, | 344 | Parser::State::typeTerminal, |
345 | tokCompute | 345 | tokCompute |
346 | ) | 346 | ) |
347 | ).append( | 347 | ).append( |
348 | Parser::State( | 348 | Parser::State( |
349 | Parser::State::typeReduction, | 349 | Parser::State::typeReduction, |
350 | p.addReduction("print") | 350 | p.addReduction("print") |
351 | ) | 351 | ) |
352 | ) | 352 | ) |
353 | ); | 353 | ); |
354 | p.addNonTerminal("input", nt ); | 354 | p.addNonTerminal("input", nt ); |
355 | } | 355 | } |
356 | 356 | ||
357 | p.setRootNonTerminal("input"); | 357 | p.setRootNonTerminal("input"); |
358 | 358 | ||
359 | p.setReduction("add", Bu::slot( &redAdd ) ); | 359 | p.setReduction("add", Bu::slot( &redAdd ) ); |
360 | p.setReduction("subtract", Bu::slot( &redSubtract ) ); | 360 | p.setReduction("subtract", Bu::slot( &redSubtract ) ); |
361 | p.setReduction("print", Bu::slot( &redPrint ) ); | 361 | p.setReduction("print", Bu::slot( &redPrint ) ); |
362 | 362 | ||
363 | p.pushLexer( new MathLexer( fIn ) ); | 363 | p.pushLexer( new MathLexer( fIn ) ); |
364 | 364 | ||
365 | p.parse(); | 365 | p.parse(); |
366 | 366 | ||
367 | return 0; | 367 | return 0; |
368 | } | 368 | } |
369 | 369 | ||
diff --git a/src/tests/print.cpp b/src/tests/print.cpp index c6fe053..bee8cf8 100644 --- a/src/tests/print.cpp +++ b/src/tests/print.cpp | |||
@@ -2,30 +2,30 @@ | |||
2 | 2 | ||
3 | int upper() | 3 | int upper() |
4 | { | 4 | { |
5 | static int iVal = 1; | 5 | static int iVal = 1; |
6 | return iVal++; | 6 | return iVal++; |
7 | } | 7 | } |
8 | 8 | ||
9 | int main() | 9 | int main() |
10 | { | 10 | { |
11 | Bu::print("hello there %1!\n").arg("Bob"); | 11 | Bu::print("hello there %1!\n").arg("Bob"); |
12 | 12 | ||
13 | Bu::println("This is %1 crazy, like %2 times over!"). | 13 | Bu::println("This is %1 crazy, like %2 times over!"). |
14 | arg("totally").arg( 47.2 ).end(); | 14 | arg("totally").arg( 47.2 ).end(); |
15 | Bu::println("This is unsubstituted?"); | 15 | Bu::println("This is unsubstituted?"); |
16 | 16 | ||
17 | Bu::serr << "This is error text." << Bu::serr.nl; | 17 | Bu::serr << "This is error text." << Bu::serr.nl; |
18 | Bu::println( Bu::serr, "This is also error text?"); | 18 | Bu::println( Bu::serr, "This is also error text?"); |
19 | 19 | ||
20 | Bu::println("This is %{1}000 - %{1}.").arg( 34, Bu::Fmt().width(10).fill('0') ); | 20 | Bu::println("This is %{1}000 - %{1}.").arg( 34, Bu::Fmt().width(10).fill('0') ); |
21 | 21 | ||
22 | Bu::String s = Bu::String("hello %1").arg("bob %1").end().toLower().arg("yo"); | 22 | Bu::String s = Bu::String("hello %1").arg("bob %1").end().toLower().arg("yo"); |
23 | 23 | ||
24 | Bu::println( s ); | 24 | Bu::println( s ); |
25 | Bu::println("Hello %%1"); | 25 | Bu::println("Hello %%1"); |
26 | 26 | ||
27 | Bu::println("Nums: %1, %2, %3, %4, %5, %6").arg( upper() ).arg( upper() ).arg( upper() ).arg( upper() ).arg( upper() ).arg( upper() ); | 27 | Bu::println("Nums: %1, %2, %3, %4, %5, %6").arg( upper() ).arg( upper() ).arg( upper() ).arg( upper() ).arg( upper() ).arg( upper() ); |
28 | 28 | ||
29 | return 0; | 29 | return 0; |
30 | } | 30 | } |
31 | 31 | ||
diff --git a/src/tests/random.cpp b/src/tests/random.cpp index 3799803..e48c543 100644 --- a/src/tests/random.cpp +++ b/src/tests/random.cpp | |||
@@ -9,41 +9,41 @@ using namespace Bu; | |||
9 | template<typename T> | 9 | template<typename T> |
10 | void coverage() | 10 | void coverage() |
11 | { | 11 | { |
12 | T rand; | 12 | T rand; |
13 | rand.seed( time( NULL ) ); | 13 | rand.seed( time( NULL ) ); |
14 | 14 | ||
15 | uint32_t uBucket[78]; | 15 | uint32_t uBucket[78]; |
16 | memset( uBucket, 0, sizeof(uint32_t)*78 ); | 16 | memset( uBucket, 0, sizeof(uint32_t)*78 ); |
17 | 17 | ||
18 | for( int j = 0; j < 1000000; j++ ) | 18 | for( int j = 0; j < 1000000; j++ ) |
19 | { | 19 | { |
20 | uBucket[(int)(((uint32_t)rand.rand())/(double)(0xfffffffful)*78+0.5)]++; | 20 | uBucket[(int)(((uint32_t)rand.rand())/(double)(0xfffffffful)*78+0.5)]++; |
21 | } | 21 | } |
22 | 22 | ||
23 | uint32_t uMax = 0; | 23 | uint32_t uMax = 0; |
24 | for( int j = 0; j < 78; j++ ) | 24 | for( int j = 0; j < 78; j++ ) |
25 | { | 25 | { |
26 | if( uMax < uBucket[j] ) | 26 | if( uMax < uBucket[j] ) |
27 | uMax = uBucket[j]; | 27 | uMax = uBucket[j]; |
28 | } | 28 | } |
29 | 29 | ||
30 | for( int y = 20; y >= 1; y-- ) | 30 | for( int y = 20; y >= 1; y-- ) |
31 | { | 31 | { |
32 | uint32_t iT = (uint32_t)((y/20.0)*uMax); | 32 | uint32_t iT = (uint32_t)((y/20.0)*uMax); |
33 | for( int x = 0; x < 78; x++ ) | 33 | for( int x = 0; x < 78; x++ ) |
34 | { | 34 | { |
35 | sio << ((iT<=uBucket[x])?"#":" "); | 35 | sio << ((iT<=uBucket[x])?"#":" "); |
36 | } | 36 | } |
37 | sio << sio.nl; | 37 | sio << sio.nl; |
38 | } | 38 | } |
39 | } | 39 | } |
40 | 40 | ||
41 | int main() | 41 | int main() |
42 | { | 42 | { |
43 | coverage<RandomBasic>(); | 43 | coverage<RandomBasic>(); |
44 | coverage<RandomCmwc>(); | 44 | coverage<RandomCmwc>(); |
45 | coverage<RandomSystem>(); | 45 | coverage<RandomSystem>(); |
46 | 46 | ||
47 | return 0; | 47 | return 0; |
48 | } | 48 | } |
49 | 49 | ||
diff --git a/src/tests/regex.cpp b/src/tests/regex.cpp index 82c3466..7e4188e 100644 --- a/src/tests/regex.cpp +++ b/src/tests/regex.cpp | |||
@@ -6,35 +6,35 @@ using namespace Bu; | |||
6 | 6 | ||
7 | void compile( const Bu::String &s, Bu::RegExEngine<char> &ree ) | 7 | void compile( const Bu::String &s, Bu::RegExEngine<char> &ree ) |
8 | { | 8 | { |
9 | int iRoot = ree.addState(); | 9 | int iRoot = ree.addState(); |
10 | int iCur = iRoot; | 10 | int iCur = iRoot; |
11 | for( Bu::String::const_iterator i = s.begin(); i; i++ ) | 11 | for( Bu::String::const_iterator i = s.begin(); i; i++ ) |
12 | { | 12 | { |
13 | int iNext = -1; | 13 | int iNext = -1; |
14 | if( i+1 ) | 14 | if( i+1 ) |
15 | iNext = ree.addState(); | 15 | iNext = ree.addState(); |
16 | ree.addCompletion( iCur, *i, *i, iNext ); | 16 | ree.addCompletion( iCur, *i, *i, iNext ); |
17 | iCur = iNext; | 17 | iCur = iNext; |
18 | } | 18 | } |
19 | } | 19 | } |
20 | 20 | ||
21 | int main() | 21 | int main() |
22 | { | 22 | { |
23 | Bu::String sRegEx("abcd"); | 23 | Bu::String sRegEx("abcd"); |
24 | Bu::String sMatch("abcdefg"); | 24 | Bu::String sMatch("abcdefg"); |
25 | 25 | ||
26 | Bu::RegExEngine<char> ree; | 26 | Bu::RegExEngine<char> ree; |
27 | 27 | ||
28 | compile( sRegEx, ree ); | 28 | compile( sRegEx, ree ); |
29 | 29 | ||
30 | bool bRet; | 30 | bool bRet; |
31 | int iSize, iCompletion; | 31 | int iSize, iCompletion; |
32 | bRet = ree.match( sMatch, iSize, iCompletion ); | 32 | bRet = ree.match( sMatch, iSize, iCompletion ); |
33 | 33 | ||
34 | sio << "Matched: " << bRet << sio.nl | 34 | sio << "Matched: " << bRet << sio.nl |
35 | << "Size: " << iSize << sio.nl | 35 | << "Size: " << iSize << sio.nl |
36 | << "Completion: " << iCompletion << sio.nl; | 36 | << "Completion: " << iCompletion << sio.nl; |
37 | 37 | ||
38 | return 0; | 38 | return 0; |
39 | } | 39 | } |
40 | 40 | ||
diff --git a/src/tests/settings.cpp b/src/tests/settings.cpp index 2caa015..cf998ed 100644 --- a/src/tests/settings.cpp +++ b/src/tests/settings.cpp | |||
@@ -5,14 +5,14 @@ using namespace Bu; | |||
5 | 5 | ||
6 | int main() | 6 | int main() |
7 | { | 7 | { |
8 | Bu::Settings s("Xagasoft", "Settings"); | 8 | Bu::Settings s("Xagasoft", "Settings"); |
9 | 9 | ||
10 | sio << s.get("Something", "BAD").get() << sio.nl; | 10 | sio << s.get("Something", "BAD").get() << sio.nl; |
11 | sio << s.get("general/path", "BAD").get() << sio.nl; | 11 | sio << s.get("general/path", "BAD").get() << sio.nl; |
12 | sio << s.get("general/magic", "BAD").get() << sio.nl; | 12 | sio << s.get("general/magic", "BAD").get() << sio.nl; |
13 | 13 | ||
14 | s.set("Something", "bob"); | 14 | s.set("Something", "bob"); |
15 | s.set("general/path", "E:\\Place"); | 15 | s.set("general/path", "E:\\Place"); |
16 | 16 | ||
17 | } | 17 | } |
18 | 18 | ||
diff --git a/src/tests/synchroqueue.cpp b/src/tests/synchroqueue.cpp index 980a4a3..9e8c787 100644 --- a/src/tests/synchroqueue.cpp +++ b/src/tests/synchroqueue.cpp | |||
@@ -5,14 +5,14 @@ | |||
5 | class Thing | 5 | class Thing |
6 | { | 6 | { |
7 | public: | 7 | public: |
8 | Thing( int x ) : | 8 | Thing( int x ) : |
9 | x( x ), | 9 | x( x ), |
10 | y( 0 ) | 10 | y( 0 ) |
11 | { | 11 | { |
12 | } | 12 | } |
13 | 13 | ||
14 | int x; | 14 | int x; |
15 | int y; | 15 | int y; |
16 | }; | 16 | }; |
17 | 17 | ||
18 | typedef Bu::SynchroQueue<Thing *> ThingQueue; | 18 | typedef Bu::SynchroQueue<Thing *> ThingQueue; |
@@ -23,109 +23,109 @@ Bu::Condition cWorkDone; | |||
23 | 23 | ||
24 | void workDone() | 24 | void workDone() |
25 | { | 25 | { |
26 | mWorkDone.lock(); | 26 | mWorkDone.lock(); |
27 | iWorkDone--; | 27 | iWorkDone--; |
28 | if( iWorkDone == 0 ) | 28 | if( iWorkDone == 0 ) |
29 | { | 29 | { |
30 | mWorkDone.unlock(); | 30 | mWorkDone.unlock(); |
31 | cWorkDone.lock(); | 31 | cWorkDone.lock(); |
32 | cWorkDone.signal(); | 32 | cWorkDone.signal(); |
33 | cWorkDone.unlock(); | 33 | cWorkDone.unlock(); |
34 | return; | 34 | return; |
35 | } | 35 | } |
36 | mWorkDone.unlock(); | 36 | mWorkDone.unlock(); |
37 | } | 37 | } |
38 | 38 | ||
39 | class ThingEater : public Bu::Thread | 39 | class ThingEater : public Bu::Thread |
40 | { | 40 | { |
41 | public: | 41 | public: |
42 | ThingEater( ThingQueue &qThing ) : | 42 | ThingEater( ThingQueue &qThing ) : |
43 | qThing( qThing ) | 43 | qThing( qThing ) |
44 | { | 44 | { |
45 | } | 45 | } |
46 | 46 | ||
47 | bool bRunning; | 47 | bool bRunning; |
48 | 48 | ||
49 | void setRunning( bool b ) | 49 | void setRunning( bool b ) |
50 | { | 50 | { |
51 | mRunning.lock(); | 51 | mRunning.lock(); |
52 | bRunning = b; | 52 | bRunning = b; |
53 | mRunning.unlock(); | 53 | mRunning.unlock(); |
54 | } | 54 | } |
55 | 55 | ||
56 | bool isRunning() | 56 | bool isRunning() |
57 | { | 57 | { |
58 | mRunning.lock(); | 58 | mRunning.lock(); |
59 | bool b = bRunning; | 59 | bool b = bRunning; |
60 | mRunning.unlock(); | 60 | mRunning.unlock(); |
61 | return b; | 61 | return b; |
62 | } | 62 | } |
63 | 63 | ||
64 | protected: | 64 | protected: |
65 | virtual void run() | 65 | virtual void run() |
66 | { | 66 | { |
67 | setRunning( true ); | 67 | setRunning( true ); |
68 | while( isRunning() ) | 68 | while( isRunning() ) |
69 | { | 69 | { |
70 | Thing *pThing = qThing.dequeue( 0, 250000 ); | 70 | Thing *pThing = qThing.dequeue( 0, 250000 ); |
71 | if( pThing == NULL ) | 71 | if( pThing == NULL ) |
72 | continue; | 72 | continue; |
73 | 73 | ||
74 | pThing->y = pThing->x*2; | 74 | pThing->y = pThing->x*2; |
75 | usleep( 10000 ); | 75 | usleep( 10000 ); |
76 | 76 | ||
77 | workDone(); | 77 | workDone(); |
78 | } | 78 | } |
79 | } | 79 | } |
80 | 80 | ||
81 | ThingQueue &qThing; | 81 | ThingQueue &qThing; |
82 | Bu::Mutex mRunning; | 82 | Bu::Mutex mRunning; |
83 | }; | 83 | }; |
84 | 84 | ||
85 | typedef Bu::List<ThingEater *> ThingEaterList; | 85 | typedef Bu::List<ThingEater *> ThingEaterList; |
86 | 86 | ||
87 | int main() | 87 | int main() |
88 | { | 88 | { |
89 | ThingQueue qThing; | 89 | ThingQueue qThing; |
90 | ThingEaterList lEater; | 90 | ThingEaterList lEater; |
91 | 91 | ||
92 | mWorkDone.lock(); | 92 | mWorkDone.lock(); |
93 | iWorkDone = 1000; | 93 | iWorkDone = 1000; |
94 | mWorkDone.unlock(); | 94 | mWorkDone.unlock(); |
95 | 95 | ||
96 | for( int j = 0; j < 5; j++ ) | 96 | for( int j = 0; j < 5; j++ ) |
97 | lEater.append( new ThingEater( qThing ) ); | 97 | lEater.append( new ThingEater( qThing ) ); |
98 | 98 | ||
99 | for( ThingEaterList::iterator i = lEater.begin(); i; i++ ) | 99 | for( ThingEaterList::iterator i = lEater.begin(); i; i++ ) |
100 | (*i)->start(); | 100 | (*i)->start(); |
101 | 101 | ||
102 | for( int j = 0; j < 1000; j++ ) | 102 | for( int j = 0; j < 1000; j++ ) |
103 | { | 103 | { |
104 | qThing.enqueue( new Thing( j ) ); | 104 | qThing.enqueue( new Thing( j ) ); |
105 | } | 105 | } |
106 | 106 | ||
107 | mWorkDone.lock(); | 107 | mWorkDone.lock(); |
108 | mWorkDone.unlock(); | 108 | mWorkDone.unlock(); |
109 | cWorkDone.lock(); | 109 | cWorkDone.lock(); |
110 | for(;;) | 110 | for(;;) |
111 | { | 111 | { |
112 | mWorkDone.lock(); | 112 | mWorkDone.lock(); |
113 | if( iWorkDone == 0 ) | 113 | if( iWorkDone == 0 ) |
114 | { | 114 | { |
115 | mWorkDone.unlock(); | 115 | mWorkDone.unlock(); |
116 | break; | 116 | break; |
117 | } | 117 | } |
118 | mWorkDone.unlock(); | 118 | mWorkDone.unlock(); |
119 | cWorkDone.wait(); | 119 | cWorkDone.wait(); |
120 | } | 120 | } |
121 | cWorkDone.unlock(); | 121 | cWorkDone.unlock(); |
122 | 122 | ||
123 | for( ThingEaterList::iterator i = lEater.begin(); i; i++ ) | 123 | for( ThingEaterList::iterator i = lEater.begin(); i; i++ ) |
124 | (*i)->setRunning( false ); | 124 | (*i)->setRunning( false ); |
125 | 125 | ||
126 | for( ThingEaterList::iterator i = lEater.begin(); i; i++ ) | 126 | for( ThingEaterList::iterator i = lEater.begin(); i; i++ ) |
127 | (*i)->join(); | 127 | (*i)->join(); |
128 | 128 | ||
129 | return 0; | 129 | return 0; |
130 | } | 130 | } |
131 | 131 | ||
diff --git a/src/tests/taf.cpp b/src/tests/taf.cpp index e4354f7..0ba551f 100644 --- a/src/tests/taf.cpp +++ b/src/tests/taf.cpp | |||
@@ -10,35 +10,35 @@ | |||
10 | 10 | ||
11 | int main( int argc, char *argv[] ) | 11 | int main( int argc, char *argv[] ) |
12 | { | 12 | { |
13 | if( argc == 1 ) | 13 | if( argc == 1 ) |
14 | { | 14 | { |
15 | Bu::File f("test.taf", Bu::File::Read ); | 15 | Bu::File f("test.taf", Bu::File::Read ); |
16 | Bu::TafReader tr( f ); | 16 | Bu::TafReader tr( f ); |
17 | 17 | ||
18 | Bu::TafGroup *pGroup = tr.readGroup(); | 18 | Bu::TafGroup *pGroup = tr.readGroup(); |
19 | 19 | ||
20 | { | 20 | { |
21 | Bu::File fo("out.taf", Bu::File::Write|Bu::File::Create ); | 21 | Bu::File fo("out.taf", Bu::File::Write|Bu::File::Create ); |
22 | Bu::TafWriter tw( fo ); | 22 | Bu::TafWriter tw( fo ); |
23 | tw.writeGroup( pGroup ); | 23 | tw.writeGroup( pGroup ); |
24 | } | 24 | } |
25 | 25 | ||
26 | delete pGroup; | 26 | delete pGroup; |
27 | } | 27 | } |
28 | else if( argc == 3 ) | 28 | else if( argc == 3 ) |
29 | { | 29 | { |
30 | Bu::File f( argv[1], Bu::File::Read ); | 30 | Bu::File f( argv[1], Bu::File::Read ); |
31 | Bu::TafReader tr( f ); | 31 | Bu::TafReader tr( f ); |
32 | 32 | ||
33 | Bu::TafGroup *pGroup = tr.readGroup(); | 33 | Bu::TafGroup *pGroup = tr.readGroup(); |
34 | 34 | ||
35 | { | 35 | { |
36 | Bu::File fo( argv[2], Bu::File::Write|Bu::File::Create ); | 36 | Bu::File fo( argv[2], Bu::File::Write|Bu::File::Create ); |
37 | Bu::TafWriter tw( fo ); | 37 | Bu::TafWriter tw( fo ); |
38 | tw.writeGroup( pGroup ); | 38 | tw.writeGroup( pGroup ); |
39 | } | 39 | } |
40 | 40 | ||
41 | delete pGroup; | 41 | delete pGroup; |
42 | } | 42 | } |
43 | } | 43 | } |
44 | 44 | ||
diff --git a/src/tests/threadid.cpp b/src/tests/threadid.cpp index 9ff99df..dfea504 100644 --- a/src/tests/threadid.cpp +++ b/src/tests/threadid.cpp | |||
@@ -9,64 +9,64 @@ using namespace Bu; | |||
9 | class CopyThing | 9 | class CopyThing |
10 | { | 10 | { |
11 | public: | 11 | public: |
12 | CopyThing() | 12 | CopyThing() |
13 | { | 13 | { |
14 | TRACE(); | 14 | TRACE(); |
15 | tidHome = Thread::currentThread(); | 15 | tidHome = Thread::currentThread(); |
16 | } | 16 | } |
17 | 17 | ||
18 | CopyThing( const CopyThing &rSrc ) | 18 | CopyThing( const CopyThing &rSrc ) |
19 | { | 19 | { |
20 | TRACE(); | 20 | TRACE(); |
21 | tidHome = Thread::currentThread(); | 21 | tidHome = Thread::currentThread(); |
22 | sio << "Same thread? " << (tidHome == rSrc.tidHome) << sio.nl; | 22 | sio << "Same thread? " << (tidHome == rSrc.tidHome) << sio.nl; |
23 | } | 23 | } |
24 | 24 | ||
25 | void doThings() | 25 | void doThings() |
26 | { | 26 | { |
27 | TRACE(); | 27 | TRACE(); |
28 | if( tidHome != Thread::currentThread() ) | 28 | if( tidHome != Thread::currentThread() ) |
29 | sio << "Different threads, hard copy here." << sio.nl; | 29 | sio << "Different threads, hard copy here." << sio.nl; |
30 | else | 30 | else |
31 | sio << "Same thread, everything is cool." << sio.nl; | 31 | sio << "Same thread, everything is cool." << sio.nl; |
32 | } | 32 | } |
33 | 33 | ||
34 | private: | 34 | private: |
35 | ThreadId tidHome; | 35 | ThreadId tidHome; |
36 | }; | 36 | }; |
37 | 37 | ||
38 | class SubThread : public Thread | 38 | class SubThread : public Thread |
39 | { | 39 | { |
40 | public: | 40 | public: |
41 | SubThread( CopyThing &src ) : | 41 | SubThread( CopyThing &src ) : |
42 | src( src ) | 42 | src( src ) |
43 | { | 43 | { |
44 | src.doThings(); | 44 | src.doThings(); |
45 | } | 45 | } |
46 | 46 | ||
47 | protected: | 47 | protected: |
48 | void run() | 48 | void run() |
49 | { | 49 | { |
50 | src.doThings(); | 50 | src.doThings(); |
51 | sio << "run-Child is me? " << (getId() == Thread::currentThread()) << sio.nl; | 51 | sio << "run-Child is me? " << (getId() == Thread::currentThread()) << sio.nl; |
52 | } | 52 | } |
53 | 53 | ||
54 | private: | 54 | private: |
55 | CopyThing src; | 55 | CopyThing src; |
56 | }; | 56 | }; |
57 | 57 | ||
58 | int main( int argc, char *argv[] ) | 58 | int main( int argc, char *argv[] ) |
59 | { | 59 | { |
60 | CopyThing a; | 60 | CopyThing a; |
61 | 61 | ||
62 | SubThread st( a ); | 62 | SubThread st( a ); |
63 | st.start(); | 63 | st.start(); |
64 | 64 | ||
65 | sio << "Child is me? " << (st.getId() == Thread::currentThread()) << sio.nl; | 65 | sio << "Child is me? " << (st.getId() == Thread::currentThread()) << sio.nl; |
66 | 66 | ||
67 | st.join(); | 67 | st.join(); |
68 | 68 | ||
69 | 69 | ||
70 | return 0; | 70 | return 0; |
71 | } | 71 | } |
72 | 72 | ||
diff --git a/src/tests/utf.cpp b/src/tests/utf.cpp index 923b611..40d4194 100644 --- a/src/tests/utf.cpp +++ b/src/tests/utf.cpp | |||
@@ -7,65 +7,65 @@ using namespace Bu; | |||
7 | 7 | ||
8 | int main() | 8 | int main() |
9 | { | 9 | { |
10 | sio << "Code: " << Bu::__calcHashCode( Bu::UtfString("Hello there") ) | 10 | sio << "Code: " << Bu::__calcHashCode( Bu::UtfString("Hello there") ) |
11 | << sio.nl; | 11 | << sio.nl; |
12 | 12 | ||
13 | Bu::File fIn("utf8.in", Bu::File::Read ); | 13 | Bu::File fIn("utf8.in", Bu::File::Read ); |
14 | Bu::String sUtf8; | 14 | Bu::String sUtf8; |
15 | char buf[4096]; | 15 | char buf[4096]; |
16 | while( !fIn.isEos() ) | 16 | while( !fIn.isEos() ) |
17 | { | 17 | { |
18 | int iAmnt = fIn.read( buf, 4096 ); | 18 | int iAmnt = fIn.read( buf, 4096 ); |
19 | sUtf8.append( buf, iAmnt ); | 19 | sUtf8.append( buf, iAmnt ); |
20 | } | 20 | } |
21 | Bu::UtfString us( sUtf8, Bu::UtfString::Utf8 ); | 21 | Bu::UtfString us( sUtf8, Bu::UtfString::Utf8 ); |
22 | us.debug(); | 22 | us.debug(); |
23 | { | 23 | { |
24 | Bu::File fOut("utf8.out", Bu::File::WriteNew ); | 24 | Bu::File fOut("utf8.out", Bu::File::WriteNew ); |
25 | us.write( fOut, Bu::UtfString::Utf8 ); | 25 | us.write( fOut, Bu::UtfString::Utf8 ); |
26 | } | 26 | } |
27 | { | 27 | { |
28 | Bu::File fOut("utf16.out", Bu::File::WriteNew ); | 28 | Bu::File fOut("utf16.out", Bu::File::WriteNew ); |
29 | us.write( fOut, Bu::UtfString::Utf16 ); | 29 | us.write( fOut, Bu::UtfString::Utf16 ); |
30 | } | 30 | } |
31 | { | 31 | { |
32 | Bu::File fOut("utf16le.out", Bu::File::WriteNew ); | 32 | Bu::File fOut("utf16le.out", Bu::File::WriteNew ); |
33 | us.write( fOut, Bu::UtfString::Utf16le ); | 33 | us.write( fOut, Bu::UtfString::Utf16le ); |
34 | } | 34 | } |
35 | { | 35 | { |
36 | Bu::File fOut("utf16be.out", Bu::File::WriteNew ); | 36 | Bu::File fOut("utf16be.out", Bu::File::WriteNew ); |
37 | us.write( fOut, Bu::UtfString::Utf16be ); | 37 | us.write( fOut, Bu::UtfString::Utf16be ); |
38 | } | 38 | } |
39 | { | 39 | { |
40 | Bu::File fOut("utf32.out", Bu::File::WriteNew ); | 40 | Bu::File fOut("utf32.out", Bu::File::WriteNew ); |
41 | us.write( fOut, Bu::UtfString::Utf32 ); | 41 | us.write( fOut, Bu::UtfString::Utf32 ); |
42 | } | 42 | } |
43 | { | 43 | { |
44 | Bu::File fOut("utf32le.out", Bu::File::WriteNew ); | 44 | Bu::File fOut("utf32le.out", Bu::File::WriteNew ); |
45 | us.write( fOut, Bu::UtfString::Utf32le ); | 45 | us.write( fOut, Bu::UtfString::Utf32le ); |
46 | } | 46 | } |
47 | { | 47 | { |
48 | Bu::File fOut("utf32be.out", Bu::File::WriteNew ); | 48 | Bu::File fOut("utf32be.out", Bu::File::WriteNew ); |
49 | us.write( fOut, Bu::UtfString::Utf32be ); | 49 | us.write( fOut, Bu::UtfString::Utf32be ); |
50 | } | 50 | } |
51 | 51 | ||
52 | /* | 52 | /* |
53 | argc--, argv++; | 53 | argc--, argv++; |
54 | 54 | ||
55 | for( char **sFile = argv; *sFile; sFile++ ) | 55 | for( char **sFile = argv; *sFile; sFile++ ) |
56 | { | 56 | { |
57 | Bu::File fIn( *sFile, Bu::File::Read ); | 57 | Bu::File fIn( *sFile, Bu::File::Read ); |
58 | Bu::String sUtf8; | 58 | Bu::String sUtf8; |
59 | char buf[4096]; | 59 | char buf[4096]; |
60 | while( !fIn.isEos() ) | 60 | while( !fIn.isEos() ) |
61 | { | 61 | { |
62 | int iAmnt = fIn.read( buf, 4096 ); | 62 | int iAmnt = fIn.read( buf, 4096 ); |
63 | sUtf8.append( buf, iAmnt ); | 63 | sUtf8.append( buf, iAmnt ); |
64 | } | 64 | } |
65 | Bu::UtfString us( sUtf8, Bu::UtfString::Utf16 ); | 65 | Bu::UtfString us( sUtf8, Bu::UtfString::Utf16 ); |
66 | 66 | ||
67 | us.debug(); | 67 | us.debug(); |
68 | } | 68 | } |
69 | */ | 69 | */ |
70 | } | 70 | } |
71 | 71 | ||
diff --git a/src/tests/uuid.cpp b/src/tests/uuid.cpp index d612ad5..152ba26 100644 --- a/src/tests/uuid.cpp +++ b/src/tests/uuid.cpp | |||
@@ -12,11 +12,11 @@ using namespace Bu; | |||
12 | 12 | ||
13 | int main() | 13 | int main() |
14 | { | 14 | { |
15 | Uuid i = Uuid::gen(); | 15 | Uuid i = Uuid::gen(); |
16 | 16 | ||
17 | sio << i.toString() << sio.nl; | 17 | sio << i.toString() << sio.nl; |
18 | sio << "Version: " << i.getVersion() << sio.nl; | 18 | sio << "Version: " << i.getVersion() << sio.nl; |
19 | 19 | ||
20 | return 0; | 20 | return 0; |
21 | } | 21 | } |
22 | 22 | ||