From ec05778d5718a7912e506764d443a78d6a6179e3 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 5 Nov 2012 22:41:51 +0000 Subject: Converted tabs to spaces with tabconv. --- src/tests/base64.cpp | 126 ++++---- src/tests/bigmyriad.cpp | 26 +- src/tests/blowfish.cpp | 118 +++---- src/tests/bnfcompile.cpp | 750 ++++++++++++++++++++++----------------------- src/tests/bzip2.cpp | 38 +-- src/tests/deflate.cpp | 78 ++--- src/tests/lzma.cpp | 78 ++--- src/tests/myriadfs.cpp | 64 ++-- src/tests/optparser.cpp | 126 ++++---- src/tests/parser.cpp | 576 +++++++++++++++++----------------- src/tests/print.cpp | 28 +- src/tests/random.cpp | 62 ++-- src/tests/regex.cpp | 42 +-- src/tests/settings.cpp | 12 +- src/tests/synchroqueue.cpp | 198 ++++++------ src/tests/taf.cpp | 52 ++-- src/tests/threadid.cpp | 78 ++--- src/tests/utf.cpp | 112 +++---- src/tests/uuid.cpp | 8 +- 19 files changed, 1286 insertions(+), 1286 deletions(-) (limited to 'src/tests') 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 @@ int main( int argc, char *argv[] ) { - argc--,argv++; + argc--,argv++; - if( argc < 3 ) - return 0; + if( argc < 3 ) + return 0; - if( argv[0][0] == 'e' ) - { - argv++; - Bu::File fIn( argv[0], Bu::File::Read ); - Bu::File fOut( argv[1], Bu::File::WriteNew ); - Bu::Base64 bOut( fOut ); + if( argv[0][0] == 'e' ) + { + argv++; + Bu::File fIn( argv[0], Bu::File::Read ); + Bu::File fOut( argv[1], Bu::File::WriteNew ); + Bu::Base64 bOut( fOut ); - char buf[900]; - for(;;) - { - int iRead = fIn.read( buf, 900 ); - bOut.write( buf, iRead ); - if( iRead < 900 ) - break; - } - } - else if( argv[0][0] == 'd' ) - { - argv++; - Bu::File fIn( argv[0], Bu::File::Read ); - Bu::File fOut( argv[1], Bu::File::WriteNew ); - Bu::Base64 bIn( fIn ); + char buf[900]; + for(;;) + { + int iRead = fIn.read( buf, 900 ); + bOut.write( buf, iRead ); + if( iRead < 900 ) + break; + } + } + else if( argv[0][0] == 'd' ) + { + argv++; + Bu::File fIn( argv[0], Bu::File::Read ); + Bu::File fOut( argv[1], Bu::File::WriteNew ); + Bu::Base64 bIn( fIn ); - char buf[1024]; - for(;;) - { - int iRead = bIn.read( buf, 1024 ); - printf("Read %d bytes.\n", iRead ); - fOut.write( buf, iRead ); - if( iRead == 0 ) - break; - } - } - else if( argv[0][0] == 'D' ) - { - argv++; - Bu::MemBuf mIn; - { - Bu::File fIn( argv[0], Bu::File::Read ); - char buf[1024]; - for(;;) - { - int iRead = fIn.read( buf, 1024 ); - mIn.write( buf, iRead ); - if( iRead < 1024 ) - break; - } - mIn.setPos( 0 ); - } - Bu::File fOut( argv[1], Bu::File::WriteNew ); - Bu::Base64 bIn( mIn ); + char buf[1024]; + for(;;) + { + int iRead = bIn.read( buf, 1024 ); + printf("Read %d bytes.\n", iRead ); + fOut.write( buf, iRead ); + if( iRead == 0 ) + break; + } + } + else if( argv[0][0] == 'D' ) + { + argv++; + Bu::MemBuf mIn; + { + Bu::File fIn( argv[0], Bu::File::Read ); + char buf[1024]; + for(;;) + { + int iRead = fIn.read( buf, 1024 ); + mIn.write( buf, iRead ); + if( iRead < 1024 ) + break; + } + mIn.setPos( 0 ); + } + Bu::File fOut( argv[1], Bu::File::WriteNew ); + Bu::Base64 bIn( mIn ); - char buf[1024]; - for(;;) - { - int iRead = bIn.read( buf, 1024 ); - printf("Read %d bytes.\n", iRead ); - fOut.write( buf, iRead ); - if( iRead == 0 ) - break; - } - } + char buf[1024]; + for(;;) + { + int iRead = bIn.read( buf, 1024 ); + printf("Read %d bytes.\n", iRead ); + fOut.write( buf, iRead ); + if( iRead == 0 ) + break; + } + } - return 0; + return 0; } 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 @@ int main() { - Bu::File f("big.myr", Bu::File::Read|Bu::File::Write|Bu::File::Create ); - Bu::Myriad m( f, 2048 ); + Bu::File f("big.myr", Bu::File::Read|Bu::File::Write|Bu::File::Create ); + Bu::Myriad m( f, 2048 ); - char *buf = new char[1024*1024*10]; - memset( buf, 0, 1024*1024*10 ); + char *buf = new char[1024*1024*10]; + memset( buf, 0, 1024*1024*10 ); - for( int j = 0; j < 250; j++ ) - { - m.openStream( m.createStream() ).write( buf, 1024*1024*10 ); -// m.sync(); - printf("\r%03d%%", (j+1)*100/250 ); - fflush( stdout ); - } + for( int j = 0; j < 250; j++ ) + { + m.openStream( m.createStream() ).write( buf, 1024*1024*10 ); +// m.sync(); + printf("\r%03d%%", (j+1)*100/250 ); + fflush( stdout ); + } - printf("\n\n"); + printf("\n\n"); - return 0; + return 0; } 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] ={ int main( int argc, char *argv[] ) { - MemBuf mb; - { - BlowfishEcb bf( mb ); - bf.setPassword( "01234567" ); - for( int j = 0; j < 4; j++ ) - { - bf.write("this is a test!!"+j, 1 ); - } - bf.write("this is a test!!"+4, 12 ); - } - mb.setPos( 0 ); - BlowfishEcb bf( mb ); - bf.setPassword( "01234567" ); - for( int j = 0; j < 3; j++ ) - { - char c; - bf.read( &c, 1 ); - sio << "char: '" << c << "'" << sio.nl; - } + MemBuf mb; + { + BlowfishEcb bf( mb ); + bf.setPassword( "01234567" ); + for( int j = 0; j < 4; j++ ) + { + bf.write("this is a test!!"+j, 1 ); + } + bf.write("this is a test!!"+4, 12 ); + } + mb.setPos( 0 ); + BlowfishEcb bf( mb ); + bf.setPassword( "01234567" ); + for( int j = 0; j < 3; j++ ) + { + char c; + bf.read( &c, 1 ); + sio << "char: '" << c << "'" << sio.nl; + } - char buf[100]; - int iR = bf.read( buf, 100 ); - buf[iR] = '\0'; - sio << "Got(" << iR << ") = '" << buf << "'" << sio.nl; + char buf[100]; + int iR = bf.read( buf, 100 ); + buf[iR] = '\0'; + sio << "Got(" << iR << ") = '" << buf << "'" << sio.nl; - return 0; + return 0; - for( int j = 0; j < 34; j++ ) - { - MemBuf mb; - BlowfishEcb bf( mb ); - bf.setPassword( decodeStr( testdat[j][0] ) ); - bf.write( decodeStr( testdat[j][1] ) ); - sio << "Test " << j << ": " << (mb.getString() == decodeStr( testdat[j][2] )) << " (" << encodeStr( mb.getString(), true ) << " == " << testdat[j][2] << ")" << sio.nl; + for( int j = 0; j < 34; j++ ) + { + MemBuf mb; + BlowfishEcb bf( mb ); + bf.setPassword( decodeStr( testdat[j][0] ) ); + bf.write( decodeStr( testdat[j][1] ) ); + sio << "Test " << j << ": " << (mb.getString() == decodeStr( testdat[j][2] )) << " (" << encodeStr( mb.getString(), true ) << " == " << testdat[j][2] << ")" << sio.nl; - mb.setPos( 0 ); - BlowfishEcb bf2( mb ); - bf2.setPassword( decodeStr( testdat[j][0] ) ); - char buf[8]; - bf2.read( buf, 8 ); - - sio << " - Back: " << (Bu::String(testdat[j][1]) == encodeStr(String(buf,8),true)) << sio.nl; - } + mb.setPos( 0 ); + BlowfishEcb bf2( mb ); + bf2.setPassword( decodeStr( testdat[j][0] ) ); + char buf[8]; + bf2.read( buf, 8 ); + + sio << " - Back: " << (Bu::String(testdat[j][1]) == encodeStr(String(buf,8),true)) << sio.nl; + } - { - File fIn("data.plain", File::Read ); - File fOut("data.crypt", File::WriteNew ); + { + File fIn("data.plain", File::Read ); + File fOut("data.crypt", File::WriteNew ); - BlowfishOfb bOut( fOut ); - bOut.setIv("01234567"); - bOut.setPassword("abcdefghijklmnop"); - bOut.write( fIn.readAll() ); - } - { - File fIn("data.java", File::Read ); - File fOut("data.stuff", File::WriteNew ); + BlowfishOfb bOut( fOut ); + bOut.setIv("01234567"); + bOut.setPassword("abcdefghijklmnop"); + bOut.write( fIn.readAll() ); + } + { + File fIn("data.java", File::Read ); + File fOut("data.stuff", File::WriteNew ); - BlowfishOfb bIn( fIn ); - bIn.setIv("01234567"); - bIn.setPassword("abcdefghijklmnop"); - char buf[64]; - bIn.read( buf, 64 ); - fOut.write( buf, 64 ); - sio << sio.nl << "All done." << sio.nl; - } + BlowfishOfb bIn( fIn ); + bIn.setIv("01234567"); + bIn.setPassword("abcdefghijklmnop"); + char buf[64]; + bIn.read( buf, 64 ); + fOut.write( buf, 64 ); + sio << sio.nl << "All done." << sio.nl; + } - return 0; + return 0; } 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; enum TokenType { - tokIdentifier, - tokColon, - tokOr, - tokSemiColon, - tokTokens, - tokEquals, - tokOpenCurly, - tokCloseCurly, - tokOpenSquare, - tokCloseSquare, - - tokEos=-1 + tokIdentifier, + tokColon, + tokOr, + tokSemiColon, + tokTokens, + tokEquals, + tokOpenCurly, + tokCloseCurly, + tokOpenSquare, + tokCloseSquare, + + tokEos=-1 }; class BnfLexer : public Lexer { public: - BnfLexer( Stream &rSrc ) : - rSrc( rSrc ) - { - } - - virtual ~BnfLexer() - { - } - - virtual Token *nextToken() - { - char cBuf; - - for(;;) - { - if( qbIn.getSize() == 0 ) - { - char buf[4096]; - qbIn.write( buf, rSrc.read( buf, 4096 ) ); - - if( rSrc.isEos() && qbIn.getSize() == 0 ) - return new Token( tokEos ); - } - qbIn.peek( &cBuf, 1 ); - if( (cBuf >= 'a' && cBuf <= 'z') || - (cBuf >= 'A' && cBuf <= 'Z') || - (cBuf >= '0' && cBuf <= '9') || - cBuf == '_' ) - { - sBuf.append( cBuf ); - qbIn.seek( 1 ); - } - else if( sBuf.isSet() ) - { - if( sBuf == "tokens" ) - { - sBuf.clear(); - return new Token( tokTokens ); - } - else - { - Token *pRet = new Token( tokIdentifier, sBuf ); - sBuf.clear(); - return pRet; - } - } - else - { - switch( cBuf ) - { - case ' ': - case '\t': - case '\n': - case '\r': - qbIn.seek( 1 ); - continue; - - case ':': - qbIn.seek( 1 ); - return new Token( tokColon ); - - case ';': - qbIn.seek( 1 ); - return new Token( tokSemiColon ); - - case '|': - qbIn.seek( 1 ); - return new Token( tokOr ); - - case '=': - qbIn.seek( 1 ); - return new Token( tokEquals ); - - case '[': - qbIn.seek( 1 ); - return new Token( tokOpenSquare ); - - case ']': - qbIn.seek( 1 ); - return new Token( tokCloseSquare ); - - case '{': - qbIn.seek( 1 ); - return new Token( tokOpenCurly ); - - case '}': - qbIn.seek( 1 ); - return new Token( tokCloseCurly ); - - default: - throw ExceptionBase("Unexpected character '%c'.", - cBuf ); - break; - } - } - } - } - - virtual String tokenToString( const Token &t ) - { - switch( (TokenType)t.iToken ) - { - case tokIdentifier: return "tokIdentifier"; - case tokColon: return "tokColon"; - case tokOr: return "tokOr"; - case tokSemiColon: return "tokSemiColon"; - case tokTokens: return "tokTokens"; - case tokEquals: return "tokEquals"; - case tokOpenCurly: return "tokOpenCurly"; - case tokCloseCurly: return "tokCloseCurly"; - case tokOpenSquare: return "tokOpenSquare"; - case tokCloseSquare: return "tokCloseSquare"; - case tokEos: return "tokEos"; - } - - return "???"; - } + BnfLexer( Stream &rSrc ) : + rSrc( rSrc ) + { + } + + virtual ~BnfLexer() + { + } + + virtual Token *nextToken() + { + char cBuf; + + for(;;) + { + if( qbIn.getSize() == 0 ) + { + char buf[4096]; + qbIn.write( buf, rSrc.read( buf, 4096 ) ); + + if( rSrc.isEos() && qbIn.getSize() == 0 ) + return new Token( tokEos ); + } + qbIn.peek( &cBuf, 1 ); + if( (cBuf >= 'a' && cBuf <= 'z') || + (cBuf >= 'A' && cBuf <= 'Z') || + (cBuf >= '0' && cBuf <= '9') || + cBuf == '_' ) + { + sBuf.append( cBuf ); + qbIn.seek( 1 ); + } + else if( sBuf.isSet() ) + { + if( sBuf == "tokens" ) + { + sBuf.clear(); + return new Token( tokTokens ); + } + else + { + Token *pRet = new Token( tokIdentifier, sBuf ); + sBuf.clear(); + return pRet; + } + } + else + { + switch( cBuf ) + { + case ' ': + case '\t': + case '\n': + case '\r': + qbIn.seek( 1 ); + continue; + + case ':': + qbIn.seek( 1 ); + return new Token( tokColon ); + + case ';': + qbIn.seek( 1 ); + return new Token( tokSemiColon ); + + case '|': + qbIn.seek( 1 ); + return new Token( tokOr ); + + case '=': + qbIn.seek( 1 ); + return new Token( tokEquals ); + + case '[': + qbIn.seek( 1 ); + return new Token( tokOpenSquare ); + + case ']': + qbIn.seek( 1 ); + return new Token( tokCloseSquare ); + + case '{': + qbIn.seek( 1 ); + return new Token( tokOpenCurly ); + + case '}': + qbIn.seek( 1 ); + return new Token( tokCloseCurly ); + + default: + throw ExceptionBase("Unexpected character '%c'.", + cBuf ); + break; + } + } + } + } + + virtual String tokenToString( const Token &t ) + { + switch( (TokenType)t.iToken ) + { + case tokIdentifier: return "tokIdentifier"; + case tokColon: return "tokColon"; + case tokOr: return "tokOr"; + case tokSemiColon: return "tokSemiColon"; + case tokTokens: return "tokTokens"; + case tokEquals: return "tokEquals"; + case tokOpenCurly: return "tokOpenCurly"; + case tokCloseCurly: return "tokCloseCurly"; + case tokOpenSquare: return "tokOpenSquare"; + case tokCloseSquare: return "tokCloseSquare"; + case tokEos: return "tokEos"; + } + + return "???"; + } private: - Stream &rSrc; - QueueBuf qbIn; - String sBuf; + Stream &rSrc; + QueueBuf qbIn; + String sBuf; }; class BnfParser { public: - BnfParser( BnfLexer &l ) : - l( l ), - pCur( NULL ), - iLastToken( 0 ) - { - } - - virtual ~BnfParser() - { - delete pCur; - pCur = NULL; - } - - void parse() - { - for(;;) - { - next(); - switch( pCur->iToken ) - { - case tokTokens: - tokens(); - break; - - case tokIdentifier: - nonTerminal(); - break; - - case tokEos: - return; - break; - - default: - tokenError("tokTokens, tokIdentifier, or tokEos"); - } - } - } + BnfParser( BnfLexer &l ) : + l( l ), + pCur( NULL ), + iLastToken( 0 ) + { + } + + virtual ~BnfParser() + { + delete pCur; + pCur = NULL; + } + + void parse() + { + for(;;) + { + next(); + switch( pCur->iToken ) + { + case tokTokens: + tokens(); + break; + + case tokIdentifier: + nonTerminal(); + break; + + case tokEos: + return; + break; + + default: + tokenError("tokTokens, tokIdentifier, or tokEos"); + } + } + } private: - void tokens() - { - next(); - if( pCur->iToken != tokEquals ) - tokenError("tokEquals"); - for(;;) - { - next(); - if( pCur->iToken == tokIdentifier ) - { - hTokens.insert( pCur->vExtra.get(), ++iLastToken ); - sio << "Added token[" << iLastToken << "]: " - << pCur->vExtra.get() << sio.nl; - } - else if( pCur->iToken == tokSemiColon ) - break; - else - tokenError("tokIdentifier or tokSemiColon"); - } - } - - void nonTerminal() - { - Bu::String sNtName = pCur->vExtra.get(); - Parser::NonTerminal nt; - p.addNonTerminal( sNtName ); - sio.incIndent(); - sio << "Created non-terminal: " << sNtName << sio.nl; - - next(); - if( pCur->iToken != tokColon ) - tokenError("tokColon"); - production( nt ); - for(;;) - { - switch( pCur->iToken ) - { - case tokOr: - production( nt ); - break; - - case tokSemiColon: - p.setNonTerminal( sNtName, nt ); - sio.decIndent(); - sio << "Closing non-terminal." << sio.nl; - return; - - default: - tokenError("tkOr or tokSemiColon"); - break; - } - } - } - - void production( Parser::NonTerminal &nt ) - { - sio.incIndent(); - sio << "Adding new production:" << sio.nl; - Parser::Production pr; - bool bAnything = false; - for(;;) - { - next(); - switch( pCur->iToken ) - { - case tokIdentifier: - { - const Bu::String &sName = - pCur->vExtra.get(); - if( hTokens.has( sName ) ) - { - pr.append( - Parser::State( - Parser::State::typeTerminal, - hTokens.get( sName ) - ) - ); - sio << "Added terminal " << sName << sio.nl; - } - else - { - if( !p.hasNonTerminal( sName ) ) - { - p.addNonTerminal( sName ); - } - pr.append( - Parser::State( - Parser::State::typeNonTerminal, - p.getNonTerminalId( sName ) - ) - ); - sio << "Added non-terminal " << sName << sio.nl; - } - } - break; - - case tokOpenSquare: - { - next(); - if( pCur->iToken != tokIdentifier ) - tokenError("tokIdentifier"); - Bu::String sName = - pCur->vExtra.get(); - next(); - if( pCur->iToken != tokCloseSquare ) - tokenError("tokCloseSquare"); - - if( !hTokens.has( sName ) ) - throw ExceptionBase("Only token names may be " - "enclosed in square brackets."); - - pr.append( - Parser::State( - Parser::State::typeTerminalPush, - hTokens.get( sName ) - ) - ); - sio << "Added terminal-push " << sName << sio.nl; - } - break; - - case tokOpenCurly: - { - next(); - if( pCur->iToken != tokIdentifier ) - tokenError("tokIdentifier"); - Bu::String sName = - pCur->vExtra.get(); - next(); - if( pCur->iToken != tokCloseCurly ) - tokenError("tokCloseCurly"); - - if( !p.hasReduction( sName ) ) - p.addReduction( sName ); - - pr.append( - Parser::State( - Parser::State::typeReduction, - p.getReductionId( sName ) - ) - ); - sio << "Added reduction " << sName << sio.nl; - } - break; - - case tokOr: - case tokSemiColon: - if( bAnything ) - { - nt.addProduction( pr ); - sio.decIndent(); - sio << "Closing production." << sio.nl; - } - else - { - nt.setCanSkip(); - sio.decIndent(); - sio << "Closing empty production." << sio.nl; - } - return; - - default: - tokenError("tokIdentifier, tokOpenSquare, tokOr, " - "tokOpenCurly, or tokSemiColon"); - } - } - } + void tokens() + { + next(); + if( pCur->iToken != tokEquals ) + tokenError("tokEquals"); + for(;;) + { + next(); + if( pCur->iToken == tokIdentifier ) + { + hTokens.insert( pCur->vExtra.get(), ++iLastToken ); + sio << "Added token[" << iLastToken << "]: " + << pCur->vExtra.get() << sio.nl; + } + else if( pCur->iToken == tokSemiColon ) + break; + else + tokenError("tokIdentifier or tokSemiColon"); + } + } + + void nonTerminal() + { + Bu::String sNtName = pCur->vExtra.get(); + Parser::NonTerminal nt; + p.addNonTerminal( sNtName ); + sio.incIndent(); + sio << "Created non-terminal: " << sNtName << sio.nl; + + next(); + if( pCur->iToken != tokColon ) + tokenError("tokColon"); + production( nt ); + for(;;) + { + switch( pCur->iToken ) + { + case tokOr: + production( nt ); + break; + + case tokSemiColon: + p.setNonTerminal( sNtName, nt ); + sio.decIndent(); + sio << "Closing non-terminal." << sio.nl; + return; + + default: + tokenError("tkOr or tokSemiColon"); + break; + } + } + } + + void production( Parser::NonTerminal &nt ) + { + sio.incIndent(); + sio << "Adding new production:" << sio.nl; + Parser::Production pr; + bool bAnything = false; + for(;;) + { + next(); + switch( pCur->iToken ) + { + case tokIdentifier: + { + const Bu::String &sName = + pCur->vExtra.get(); + if( hTokens.has( sName ) ) + { + pr.append( + Parser::State( + Parser::State::typeTerminal, + hTokens.get( sName ) + ) + ); + sio << "Added terminal " << sName << sio.nl; + } + else + { + if( !p.hasNonTerminal( sName ) ) + { + p.addNonTerminal( sName ); + } + pr.append( + Parser::State( + Parser::State::typeNonTerminal, + p.getNonTerminalId( sName ) + ) + ); + sio << "Added non-terminal " << sName << sio.nl; + } + } + break; + + case tokOpenSquare: + { + next(); + if( pCur->iToken != tokIdentifier ) + tokenError("tokIdentifier"); + Bu::String sName = + pCur->vExtra.get(); + next(); + if( pCur->iToken != tokCloseSquare ) + tokenError("tokCloseSquare"); + + if( !hTokens.has( sName ) ) + throw ExceptionBase("Only token names may be " + "enclosed in square brackets."); + + pr.append( + Parser::State( + Parser::State::typeTerminalPush, + hTokens.get( sName ) + ) + ); + sio << "Added terminal-push " << sName << sio.nl; + } + break; + + case tokOpenCurly: + { + next(); + if( pCur->iToken != tokIdentifier ) + tokenError("tokIdentifier"); + Bu::String sName = + pCur->vExtra.get(); + next(); + if( pCur->iToken != tokCloseCurly ) + tokenError("tokCloseCurly"); + + if( !p.hasReduction( sName ) ) + p.addReduction( sName ); + + pr.append( + Parser::State( + Parser::State::typeReduction, + p.getReductionId( sName ) + ) + ); + sio << "Added reduction " << sName << sio.nl; + } + break; + + case tokOr: + case tokSemiColon: + if( bAnything ) + { + nt.addProduction( pr ); + sio.decIndent(); + sio << "Closing production." << sio.nl; + } + else + { + nt.setCanSkip(); + sio.decIndent(); + sio << "Closing empty production." << sio.nl; + } + return; + + default: + tokenError("tokIdentifier, tokOpenSquare, tokOr, " + "tokOpenCurly, or tokSemiColon"); + } + } + } private: - void next() - { - delete pCur; - pCur = l.nextToken(); - } - - void tokenError( const String &s ) - { - throw ExceptionBase( ("Expected " + s + " but found " - + l.tokenToString( *pCur ) + ".").getStr() ); - } + void next() + { + delete pCur; + pCur = l.nextToken(); + } + + void tokenError( const String &s ) + { + throw ExceptionBase( ("Expected " + s + " but found " + + l.tokenToString( *pCur ) + ".").getStr() ); + } private: - typedef Bu::Hash TokenHash; - TokenHash hTokens; - BnfLexer &l; - BnfLexer::Token *pCur; - int iLastToken; - Parser p; + typedef Bu::Hash TokenHash; + TokenHash hTokens; + BnfLexer &l; + BnfLexer::Token *pCur; + int iLastToken; + Parser p; }; int main( int argc, char *argv[] ) { - if( argc < 2 ) - { - println("Provide an input filename as the first parameter."); - return 0; - } - File fIn( argv[1], File::Read ); + if( argc < 2 ) + { + println("Provide an input filename as the first parameter."); + return 0; + } + File fIn( argv[1], File::Read ); - BnfLexer bl( fIn ); - BnfParser parser( bl ); + BnfLexer bl( fIn ); + BnfParser parser( bl ); - parser.parse(); + parser.parse(); /* - for(;;) - { - Lexer::Token *pTok = bl.nextToken(); - sio << bl.tokenToString(*pTok); - if( pTok->vExtra.isSet() ) - { - sio << " - " << pTok->vExtra; - } - sio << sio.nl; - if( pTok->iToken == tokEos ) - break; - } + for(;;) + { + Lexer::Token *pTok = bl.nextToken(); + sio << bl.tokenToString(*pTok); + if( pTok->vExtra.isSet() ) + { + sio << " - " << pTok->vExtra; + } + sio << sio.nl; + if( pTok->iToken == tokEos ) + break; + } */ - return 0; + return 0; } 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 @@ int main( int argc, char *argv[] ) { - if( argc < 3 ) - { - printf("usage: %s \n", argv[0] ); - return -1; - } + if( argc < 3 ) + { + printf("usage: %s \n", argv[0] ); + return -1; + } - char buf[1024]; - size_t nRead; + char buf[1024]; + size_t nRead; - Bu::File fin( argv[1], Bu::File::Read ); - - Bu::File f( argv[2], Bu::File::WriteNew ); - Bu::BZip2 bz2( f ); + Bu::File fin( argv[1], Bu::File::Read ); + + Bu::File f( argv[2], Bu::File::WriteNew ); + Bu::BZip2 bz2( f ); - for(;;) - { - nRead = fin.read( buf, 1024 ); - if( nRead > 0 ) - bz2.write( buf, nRead ); - if( fin.isEos() ) - break; - } + for(;;) + { + nRead = fin.read( buf, 1024 ); + if( nRead > 0 ) + bz2.write( buf, nRead ); + if( fin.isEos() ) + break; + } } 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 @@ int main( int argc, char *argv[] ) { - if( argc < 3 ) - { - printf("usage: %s \n", argv[0] ); - return -1; - } - - char buf[1024]; - size_t nRead; - - /* - Bu::File fin( argv[1], Bu::File::Read ); - fin.seek( 4 ); - Bu::Deflate def( fin ); - - Bu::File f( argv[2], Bu::File::WriteNew ); - - for(;;) - { - nRead = def.read( buf, 1024 ); - if( nRead > 0 ) - f.write( buf, nRead ); - if( def.isEos() ) - break; - } - */ - - Bu::File fin( argv[1], Bu::File::Read ); - - Bu::File f( argv[2], Bu::File::WriteNew ); - Bu::Deflate def( f, 9, Bu::Deflate::Gzip ); - - for(;;) - { - nRead = fin.read( buf, 1024 ); - if( nRead > 0 ) - def.write( buf, nRead ); - if( fin.isEos() ) - break; - } + if( argc < 3 ) + { + printf("usage: %s \n", argv[0] ); + return -1; + } + + char buf[1024]; + size_t nRead; + + /* + Bu::File fin( argv[1], Bu::File::Read ); + fin.seek( 4 ); + Bu::Deflate def( fin ); + + Bu::File f( argv[2], Bu::File::WriteNew ); + + for(;;) + { + nRead = def.read( buf, 1024 ); + if( nRead > 0 ) + f.write( buf, nRead ); + if( def.isEos() ) + break; + } + */ + + Bu::File fin( argv[1], Bu::File::Read ); + + Bu::File f( argv[2], Bu::File::WriteNew ); + Bu::Deflate def( f, 9, Bu::Deflate::Gzip ); + + for(;;) + { + nRead = fin.read( buf, 1024 ); + if( nRead > 0 ) + def.write( buf, nRead ); + if( fin.isEos() ) + break; + } } 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 @@ int main( int argc, char *argv[] ) { - if( argc < 3 ) - { - printf("usage: %s \n", argv[0] ); - return -1; - } - - char buf[1024]; - size_t nRead; - - /* - Bu::File fin( argv[1], Bu::File::Read ); - fin.seek( 4 ); - Bu::Deflate def( fin ); - - Bu::File f( argv[2], Bu::File::WriteNew ); - - for(;;) - { - nRead = def.read( buf, 1024 ); - if( nRead > 0 ) - f.write( buf, nRead ); - if( def.isEos() ) - break; - } - */ - - Bu::File fin( argv[1], Bu::File::Read ); - - Bu::File f( argv[2], Bu::File::WriteNew ); - Bu::Lzma def( f, 9 ); - - for(;;) - { - nRead = fin.read( buf, 1024 ); - if( nRead > 0 ) - def.write( buf, nRead ); - if( fin.isEos() ) - break; - } + if( argc < 3 ) + { + printf("usage: %s \n", argv[0] ); + return -1; + } + + char buf[1024]; + size_t nRead; + + /* + Bu::File fin( argv[1], Bu::File::Read ); + fin.seek( 4 ); + Bu::Deflate def( fin ); + + Bu::File f( argv[2], Bu::File::WriteNew ); + + for(;;) + { + nRead = def.read( buf, 1024 ); + if( nRead > 0 ) + f.write( buf, nRead ); + if( def.isEos() ) + break; + } + */ + + Bu::File fin( argv[1], Bu::File::Read ); + + Bu::File f( argv[2], Bu::File::WriteNew ); + Bu::Lzma def( f, 9 ); + + for(;;) + { + nRead = fin.read( buf, 1024 ); + if( nRead > 0 ) + def.write( buf, nRead ); + if( fin.isEos() ) + break; + } } 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; int main() { -// Bu::MemBuf mb; - Bu::File mb("store.myr", File::Read|File::Write|File::Create ); - Bu::MyriadFs mfs( mb, 512 ); +// Bu::MemBuf mb; + Bu::File mb("store.myr", File::Read|File::Write|File::Create ); + Bu::MyriadFs mfs( mb, 512 ); - sio << "Creating dirs..." << sio.nl; - mfs.create("/etc", Bu::MyriadFs::typeDir|0755 ); - mfs.create("/dev", Bu::MyriadFs::typeDir|0755 ); - mfs.create("/usr", Bu::MyriadFs::typeDir|0755 ); + sio << "Creating dirs..." << sio.nl; + mfs.create("/etc", Bu::MyriadFs::typeDir|0755 ); + mfs.create("/dev", Bu::MyriadFs::typeDir|0755 ); + mfs.create("/usr", Bu::MyriadFs::typeDir|0755 ); - mfs.create("/dev/null", Bu::MyriadFs::typeChrDev|0666, 1, 3 ); - mfs.create("/dev/zero", Bu::MyriadFs::typeChrDev|0666, 1, 5 ); - mfs.create("/dev/sda", Bu::MyriadFs::typeBlkDev|0660, 8, 0 ); + mfs.create("/dev/null", Bu::MyriadFs::typeChrDev|0666, 1, 3 ); + mfs.create("/dev/zero", Bu::MyriadFs::typeChrDev|0666, 1, 5 ); + mfs.create("/dev/sda", Bu::MyriadFs::typeBlkDev|0660, 8, 0 ); - sio << "Creating files..." << sio.nl; - { - Bu::MyriadStream ms = mfs.open("/hello", Bu::MyriadFs::Read ); - ms.write("world!"); - } - { - Bu::MyriadStream ms = mfs.open("/etc/hello", Bu::MyriadFs::Read ); - ms.write("world, again!"); - } + sio << "Creating files..." << sio.nl; + { + Bu::MyriadStream ms = mfs.open("/hello", Bu::MyriadFs::Read ); + ms.write("world!"); + } + { + Bu::MyriadStream ms = mfs.open("/etc/hello", Bu::MyriadFs::Read ); + ms.write("world, again!"); + } - sio << "Reading files..." << sio.nl; - { - Bu::MyriadStream ms = mfs.open("/hello", Bu::MyriadFs::Read ); - char buf[512]; - buf[ms.read( buf, 512 )] = '\0'; - sio << "read: '" << buf << "'" << sio.nl; - } - { - Bu::MyriadStream ms = mfs.open("/etc/hello", Bu::MyriadFs::Read ); - char buf[512]; - buf[ms.read( buf, 512 )] = '\0'; - sio << "read: '" << buf << "'" << sio.nl; - } + sio << "Reading files..." << sio.nl; + { + Bu::MyriadStream ms = mfs.open("/hello", Bu::MyriadFs::Read ); + char buf[512]; + buf[ms.read( buf, 512 )] = '\0'; + sio << "read: '" << buf << "'" << sio.nl; + } + { + Bu::MyriadStream ms = mfs.open("/etc/hello", Bu::MyriadFs::Read ); + char buf[512]; + buf[ms.read( buf, 512 )] = '\0'; + sio << "read: '" << buf << "'" << sio.nl; + } } 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; class Opts : public Bu::OptParser { public: - Opts() : - iBob( 542 ), - bVal( false ) - { - addHelpBanner("optparser - Test some option things..."); + Opts() : + iBob( 542 ), + bVal( false ) + { + addHelpBanner("optparser - Test some option things..."); - addHelpBanner("\nThis section represents options that actually have " - "callbacks, or in the case of the new system, signals/slots. They " - "all take parameters, but if they return 0 then it will be as " - "though they hadn't and the next thing will be processed normally.", - true - ); - addOption( slot( this, &Opts::yesparam ), 'x', "things", - "This is the first test parameter. It calls a function, and " - "takes a parameter." - ); - addOption( slot( this, &Opts::noparam ), 'y', "stuff", - "This is the second test parameter. It does not take " - "parameters. However, I do want to make this part much longer to " - "see how it looks when you add way too much text to one of these " - "things. It can't really be that bad, right?" - ); + addHelpBanner("\nThis section represents options that actually have " + "callbacks, or in the case of the new system, signals/slots. They " + "all take parameters, but if they return 0 then it will be as " + "though they hadn't and the next thing will be processed normally.", + true + ); + addOption( slot( this, &Opts::yesparam ), 'x', "things", + "This is the first test parameter. It calls a function, and " + "takes a parameter." + ); + addOption( slot( this, &Opts::noparam ), 'y', "stuff", + "This is the second test parameter. It does not take " + "parameters. However, I do want to make this part much longer to " + "see how it looks when you add way too much text to one of these " + "things. It can't really be that bad, right?" + ); - addHelpBanner("\nThis section represents options with no callback or " - "signal, but do have a variable to update. They use the Formatter " - "system and therefore it's very, very flexible. Any data type " - "you can read with a formatter you can set via parameter.", - true - ); - addOption( sVar, 's', "str", "Set a variable, see what it does."); - addOption( bVal, 'b', "bool", "It's a thing."); - addOption( iBob, "bob", "Change iBob to whatever you want."); - addOption( dBob, 'd', "Change dBob to whatever you want."); + addHelpBanner("\nThis section represents options with no callback or " + "signal, but do have a variable to update. They use the Formatter " + "system and therefore it's very, very flexible. Any data type " + "you can read with a formatter you can set via parameter.", + true + ); + addOption( sVar, 's', "str", "Set a variable, see what it does."); + addOption( bVal, 'b', "bool", "It's a thing."); + addOption( iBob, "bob", "Change iBob to whatever you want."); + addOption( dBob, 'd', "Change dBob to whatever you want."); - setOverride("str", "Bob!"); - setHelpDefault("bob", "=542"); - setOverride("bool", true ); - - addHelpOption(); + setOverride("str", "Bob!"); + setHelpDefault("bob", "=542"); + setOverride("bool", true ); + + addHelpOption(); - setNonOption( slot( this, &Opts::nonOption ) ); - } + setNonOption( slot( this, &Opts::nonOption ) ); + } - int yesparam( StrArray aParams ) - { - sio << " - yesparam" << aParams << sio.nl; - return 1; - } + int yesparam( StrArray aParams ) + { + sio << " - yesparam" << aParams << sio.nl; + return 1; + } - int noparam( StrArray aParams ) - { - sio << " - noparam" << aParams << sio.nl; - return 0; - } + int noparam( StrArray aParams ) + { + sio << " - noparam" << aParams << sio.nl; + return 0; + } - int nonOption( StrArray aParams ) - { - sio << " - nonOption" << aParams << sio.nl; - return aParams.getSize()-1; - } + int nonOption( StrArray aParams ) + { + sio << " - nonOption" << aParams << sio.nl; + return aParams.getSize()-1; + } - int iBob; - float dBob; - Bu::String sVar; - bool bVal; + int iBob; + float dBob; + Bu::String sVar; + bool bVal; }; int main( int argc, char *argv[] ) { - Opts o; + Opts o; - o.parse( argc, argv ); + o.parse( argc, argv ); - sio << "sVar = \"" << o.sVar << "\"" << sio.nl; - sio << "iBob = " << o.iBob << sio.nl; - sio << "dBob = " << o.dBob << sio.nl; - sio << "bVal = " << o.bVal << sio.nl; + sio << "sVar = \"" << o.sVar << "\"" << sio.nl; + sio << "iBob = " << o.iBob << sio.nl; + sio << "dBob = " << o.dBob << sio.nl; + sio << "bVal = " << o.bVal << sio.nl; } 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; enum Tok { - tokNumber, - tokPlus, - tokMinus, - tokDivide, - tokMultiply, - tokOpenParen, - tokCloseParen, - tokCompute, - tokEndOfInput=-1 + tokNumber, + tokPlus, + tokMinus, + tokDivide, + tokMultiply, + tokOpenParen, + tokCloseParen, + tokCompute, + tokEndOfInput=-1 }; Bu::Formatter &operator<<( Bu::Formatter &f, Tok e ) { - switch( e ) - { - case tokNumber: return f << "tokNumber"; - case tokPlus: return f << "tokPlus"; - case tokMinus: return f << "tokMinus"; - case tokDivide: return f << "tokDivide"; - case tokMultiply: return f << "tokMultiply"; - case tokOpenParen: return f << "tokOpenParen"; - case tokCloseParen: return f << "tokCloseParen"; - case tokCompute: return f << "tokCompute"; - case tokEndOfInput: return f << "tokEndOfInput"; - } - - return f << "***error***"; + switch( e ) + { + case tokNumber: return f << "tokNumber"; + case tokPlus: return f << "tokPlus"; + case tokMinus: return f << "tokMinus"; + case tokDivide: return f << "tokDivide"; + case tokMultiply: return f << "tokMultiply"; + case tokOpenParen: return f << "tokOpenParen"; + case tokCloseParen: return f << "tokCloseParen"; + case tokCompute: return f << "tokCompute"; + case tokEndOfInput: return f << "tokEndOfInput"; + } + + return f << "***error***"; } class MathLexer : public Lexer { public: - MathLexer( Bu::Stream &rSrc ) : - rSrc( rSrc ) - { - } - - virtual ~MathLexer() - { - } - - enum TokenTypes - { - tokStuff - }; - - virtual Token *nextToken() - { - for(;;) - { - if( qbIn.getSize() == 0 ) - { - char buf[4096]; - qbIn.write( buf, rSrc.read( buf, 4096 ) ); - - if( rSrc.isEos() && qbIn.getSize() == 0 ) - return new Token( tokEndOfInput ); - } - - char b; - qbIn.peek( &b, 1 ); - switch( b ) - { - case '+': - qbIn.seek( 1 ); - return new Token( tokPlus ); - - case '-': - qbIn.seek( 1 ); - return new Token( tokMinus ); - - case '/': - qbIn.seek( 1 ); - return new Token( tokDivide ); - - case '*': - qbIn.seek( 1 ); - return new Token( tokMultiply ); - - case ' ': - case '\t': - case '\n': - qbIn.seek( 1 ); - break; - - case '=': - qbIn.seek( 1 ); - return new Token( tokCompute ); - - case '(': - qbIn.seek( 1 ); - return new Token( tokOpenParen ); - - case ')': - qbIn.seek( 1 ); - return new Token( tokCloseParen ); - - case '.': - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - { - Bu::String sTmp; - sTmp += b; - qbIn.seek( 1 ); - for(;;) - { - qbIn.peek( &b, 1 ); - if( b != '.' && (b < '0' || b > '9') ) - { - sio << "!! Convert '" << sTmp << "' to " - << strtod( sTmp.getStr(), NULL ) << sio.nl; - return new Token( - tokNumber, strtod( sTmp.getStr(), NULL ) - ); - } - qbIn.seek( 1 ); - sTmp += b; - } - } - break; - - default: - throw Bu::ExceptionBase("Unexpected character '%c'.", b ); - } - } - } + MathLexer( Bu::Stream &rSrc ) : + rSrc( rSrc ) + { + } + + virtual ~MathLexer() + { + } + + enum TokenTypes + { + tokStuff + }; + + virtual Token *nextToken() + { + for(;;) + { + if( qbIn.getSize() == 0 ) + { + char buf[4096]; + qbIn.write( buf, rSrc.read( buf, 4096 ) ); + + if( rSrc.isEos() && qbIn.getSize() == 0 ) + return new Token( tokEndOfInput ); + } + + char b; + qbIn.peek( &b, 1 ); + switch( b ) + { + case '+': + qbIn.seek( 1 ); + return new Token( tokPlus ); + + case '-': + qbIn.seek( 1 ); + return new Token( tokMinus ); + + case '/': + qbIn.seek( 1 ); + return new Token( tokDivide ); + + case '*': + qbIn.seek( 1 ); + return new Token( tokMultiply ); + + case ' ': + case '\t': + case '\n': + qbIn.seek( 1 ); + break; + + case '=': + qbIn.seek( 1 ); + return new Token( tokCompute ); + + case '(': + qbIn.seek( 1 ); + return new Token( tokOpenParen ); + + case ')': + qbIn.seek( 1 ); + return new Token( tokCloseParen ); + + case '.': + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + { + Bu::String sTmp; + sTmp += b; + qbIn.seek( 1 ); + for(;;) + { + qbIn.peek( &b, 1 ); + if( b != '.' && (b < '0' || b > '9') ) + { + sio << "!! Convert '" << sTmp << "' to " + << strtod( sTmp.getStr(), NULL ) << sio.nl; + return new Token( + tokNumber, strtod( sTmp.getStr(), NULL ) + ); + } + qbIn.seek( 1 ); + sTmp += b; + } + } + break; + + default: + throw Bu::ExceptionBase("Unexpected character '%c'.", b ); + } + } + } private: - Bu::Stream &rSrc; - QueueBuf qbIn; + Bu::Stream &rSrc; + QueueBuf qbIn; }; void redAdd( Bu::Parser &p ) { - Lexer::Token *a = p.popToken(); - Lexer::Token *b = p.popToken(); + Lexer::Token *a = p.popToken(); + Lexer::Token *b = p.popToken(); - sio << "Add! " << b->vExtra.get() << " + " - << a->vExtra.get() << sio.nl; + sio << "Add! " << b->vExtra.get() << " + " + << a->vExtra.get() << sio.nl; - Lexer::Token *c = new Lexer::Token( tokNumber, - b->vExtra.get() + a->vExtra.get() - ); - p.pushToken( c ); + Lexer::Token *c = new Lexer::Token( tokNumber, + b->vExtra.get() + a->vExtra.get() + ); + p.pushToken( c ); - delete a; - delete b; + delete a; + delete b; } void redSubtract( Bu::Parser &p ) { - Lexer::Token *a = p.popToken(); - Lexer::Token *b = p.popToken(); + Lexer::Token *a = p.popToken(); + Lexer::Token *b = p.popToken(); - sio << "Subtract! " << b->vExtra.get() << " - " - << a->vExtra.get() << sio.nl; + sio << "Subtract! " << b->vExtra.get() << " - " + << a->vExtra.get() << sio.nl; - Lexer::Token *c = new Lexer::Token( tokNumber, - b->vExtra.get() - a->vExtra.get() - ); - p.pushToken( c ); + Lexer::Token *c = new Lexer::Token( tokNumber, + b->vExtra.get() - a->vExtra.get() + ); + p.pushToken( c ); - delete a; - delete b; + delete a; + delete b; } void redPrint( Bu::Parser &p ) { - Lexer::Token *a = p.popToken(); - sio << "Print! = " << a->vExtra.get() << sio.nl; - delete a; + Lexer::Token *a = p.popToken(); + sio << "Print! = " << a->vExtra.get() << sio.nl; + delete a; } /* Basic grammer example: @@ -227,143 +227,143 @@ void redPrint( Bu::Parser &p ) int main( int argc, char *argv[] ) { - if( argc < 2 ) - { - println("Provide an input filename as the first parameter."); - return 0; - } - File fIn( argv[1], File::Read ); - - Parser p; - - p.addNonTerminal("expr"); - p.addNonTerminal("expr-sub1"); - p.addNonTerminal("expr-sub2"); - { - Parser::NonTerminal nt; - nt.addProduction( - Parser::Production( - Parser::State( - Parser::State::typeTerminal, - tokPlus - ) - ).append( - Parser::State( - Parser::State::typeNonTerminal, - p.getNonTerminalId("expr") - ) - ).append( - Parser::State( - Parser::State::typeReduction, - p.addReduction("add") - ) - ) - ); - nt.addProduction( - Parser::Production( - Parser::State( - Parser::State::typeTerminal, - tokMinus - ) - ).append( - Parser::State( - Parser::State::typeNonTerminal, - p.getNonTerminalId("expr") - ) - ).append( - Parser::State( - Parser::State::typeReduction, - p.addReduction("subtract") - ) - ) - ); - nt.addProduction( - Parser::Production( - ) - ); - nt.setCanSkip(); - p.setNonTerminal("expr-sub2", nt ); - } - { - Parser::NonTerminal nt; - nt.addProduction( - Parser::Production( - Parser::State( - Parser::State::typeTerminalPush, - tokNumber - ) - ) - ); - nt.addProduction( - Parser::Production( - Parser::State( - Parser::State::typeTerminal, - tokOpenParen - ) - ).append( - Parser::State( - Parser::State::typeNonTerminal, - p.getNonTerminalId("expr") - ) - ).append( - Parser::State( - Parser::State::typeTerminal, - tokCloseParen - ) - ) - ); - p.setNonTerminal("expr-sub1", nt ); - } - { - Parser::NonTerminal nt; - nt.addProduction( - Parser::Production( - Parser::State( - Parser::State::typeNonTerminal, - p.getNonTerminalId("expr-sub1") - ) - ).append( - Parser::State( - Parser::State::typeNonTerminal, - p.getNonTerminalId("expr-sub2") - ) - ) - ); - p.setNonTerminal("expr", nt ); - } - { - Parser::NonTerminal nt; - nt.addProduction( - Parser::Production( - Parser::State( - Parser::State::typeNonTerminal, - p.getNonTerminalId("expr") - ) - ).append( - Parser::State( - Parser::State::typeTerminal, - tokCompute - ) - ).append( - Parser::State( - Parser::State::typeReduction, - p.addReduction("print") - ) - ) - ); - p.addNonTerminal("input", nt ); - } - - p.setRootNonTerminal("input"); - - p.setReduction("add", Bu::slot( &redAdd ) ); - p.setReduction("subtract", Bu::slot( &redSubtract ) ); - p.setReduction("print", Bu::slot( &redPrint ) ); - - p.pushLexer( new MathLexer( fIn ) ); - - p.parse(); - - return 0; + if( argc < 2 ) + { + println("Provide an input filename as the first parameter."); + return 0; + } + File fIn( argv[1], File::Read ); + + Parser p; + + p.addNonTerminal("expr"); + p.addNonTerminal("expr-sub1"); + p.addNonTerminal("expr-sub2"); + { + Parser::NonTerminal nt; + nt.addProduction( + Parser::Production( + Parser::State( + Parser::State::typeTerminal, + tokPlus + ) + ).append( + Parser::State( + Parser::State::typeNonTerminal, + p.getNonTerminalId("expr") + ) + ).append( + Parser::State( + Parser::State::typeReduction, + p.addReduction("add") + ) + ) + ); + nt.addProduction( + Parser::Production( + Parser::State( + Parser::State::typeTerminal, + tokMinus + ) + ).append( + Parser::State( + Parser::State::typeNonTerminal, + p.getNonTerminalId("expr") + ) + ).append( + Parser::State( + Parser::State::typeReduction, + p.addReduction("subtract") + ) + ) + ); + nt.addProduction( + Parser::Production( + ) + ); + nt.setCanSkip(); + p.setNonTerminal("expr-sub2", nt ); + } + { + Parser::NonTerminal nt; + nt.addProduction( + Parser::Production( + Parser::State( + Parser::State::typeTerminalPush, + tokNumber + ) + ) + ); + nt.addProduction( + Parser::Production( + Parser::State( + Parser::State::typeTerminal, + tokOpenParen + ) + ).append( + Parser::State( + Parser::State::typeNonTerminal, + p.getNonTerminalId("expr") + ) + ).append( + Parser::State( + Parser::State::typeTerminal, + tokCloseParen + ) + ) + ); + p.setNonTerminal("expr-sub1", nt ); + } + { + Parser::NonTerminal nt; + nt.addProduction( + Parser::Production( + Parser::State( + Parser::State::typeNonTerminal, + p.getNonTerminalId("expr-sub1") + ) + ).append( + Parser::State( + Parser::State::typeNonTerminal, + p.getNonTerminalId("expr-sub2") + ) + ) + ); + p.setNonTerminal("expr", nt ); + } + { + Parser::NonTerminal nt; + nt.addProduction( + Parser::Production( + Parser::State( + Parser::State::typeNonTerminal, + p.getNonTerminalId("expr") + ) + ).append( + Parser::State( + Parser::State::typeTerminal, + tokCompute + ) + ).append( + Parser::State( + Parser::State::typeReduction, + p.addReduction("print") + ) + ) + ); + p.addNonTerminal("input", nt ); + } + + p.setRootNonTerminal("input"); + + p.setReduction("add", Bu::slot( &redAdd ) ); + p.setReduction("subtract", Bu::slot( &redSubtract ) ); + p.setReduction("print", Bu::slot( &redPrint ) ); + + p.pushLexer( new MathLexer( fIn ) ); + + p.parse(); + + return 0; } 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 @@ int upper() { - static int iVal = 1; - return iVal++; + static int iVal = 1; + return iVal++; } int main() { - Bu::print("hello there %1!\n").arg("Bob"); + Bu::print("hello there %1!\n").arg("Bob"); - Bu::println("This is %1 crazy, like %2 times over!"). - arg("totally").arg( 47.2 ).end(); - Bu::println("This is unsubstituted?"); + Bu::println("This is %1 crazy, like %2 times over!"). + arg("totally").arg( 47.2 ).end(); + Bu::println("This is unsubstituted?"); - Bu::serr << "This is error text." << Bu::serr.nl; - Bu::println( Bu::serr, "This is also error text?"); + Bu::serr << "This is error text." << Bu::serr.nl; + Bu::println( Bu::serr, "This is also error text?"); - Bu::println("This is %{1}000 - %{1}.").arg( 34, Bu::Fmt().width(10).fill('0') ); + Bu::println("This is %{1}000 - %{1}.").arg( 34, Bu::Fmt().width(10).fill('0') ); - Bu::String s = Bu::String("hello %1").arg("bob %1").end().toLower().arg("yo"); + Bu::String s = Bu::String("hello %1").arg("bob %1").end().toLower().arg("yo"); - Bu::println( s ); - Bu::println("Hello %%1"); + Bu::println( s ); + Bu::println("Hello %%1"); - Bu::println("Nums: %1, %2, %3, %4, %5, %6").arg( upper() ).arg( upper() ).arg( upper() ).arg( upper() ).arg( upper() ).arg( upper() ); + Bu::println("Nums: %1, %2, %3, %4, %5, %6").arg( upper() ).arg( upper() ).arg( upper() ).arg( upper() ).arg( upper() ).arg( upper() ); - return 0; + return 0; } 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; template void coverage() { - T rand; - rand.seed( time( NULL ) ); - - uint32_t uBucket[78]; - memset( uBucket, 0, sizeof(uint32_t)*78 ); - - for( int j = 0; j < 1000000; j++ ) - { - uBucket[(int)(((uint32_t)rand.rand())/(double)(0xfffffffful)*78+0.5)]++; - } - - uint32_t uMax = 0; - for( int j = 0; j < 78; j++ ) - { - if( uMax < uBucket[j] ) - uMax = uBucket[j]; - } - - for( int y = 20; y >= 1; y-- ) - { - uint32_t iT = (uint32_t)((y/20.0)*uMax); - for( int x = 0; x < 78; x++ ) - { - sio << ((iT<=uBucket[x])?"#":" "); - } - sio << sio.nl; - } + T rand; + rand.seed( time( NULL ) ); + + uint32_t uBucket[78]; + memset( uBucket, 0, sizeof(uint32_t)*78 ); + + for( int j = 0; j < 1000000; j++ ) + { + uBucket[(int)(((uint32_t)rand.rand())/(double)(0xfffffffful)*78+0.5)]++; + } + + uint32_t uMax = 0; + for( int j = 0; j < 78; j++ ) + { + if( uMax < uBucket[j] ) + uMax = uBucket[j]; + } + + for( int y = 20; y >= 1; y-- ) + { + uint32_t iT = (uint32_t)((y/20.0)*uMax); + for( int x = 0; x < 78; x++ ) + { + sio << ((iT<=uBucket[x])?"#":" "); + } + sio << sio.nl; + } } int main() { - coverage(); - coverage(); - coverage(); + coverage(); + coverage(); + coverage(); - return 0; + return 0; } 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; void compile( const Bu::String &s, Bu::RegExEngine &ree ) { - int iRoot = ree.addState(); - int iCur = iRoot; - for( Bu::String::const_iterator i = s.begin(); i; i++ ) - { - int iNext = -1; - if( i+1 ) - iNext = ree.addState(); - ree.addCompletion( iCur, *i, *i, iNext ); - iCur = iNext; - } + int iRoot = ree.addState(); + int iCur = iRoot; + for( Bu::String::const_iterator i = s.begin(); i; i++ ) + { + int iNext = -1; + if( i+1 ) + iNext = ree.addState(); + ree.addCompletion( iCur, *i, *i, iNext ); + iCur = iNext; + } } int main() { - Bu::String sRegEx("abcd"); - Bu::String sMatch("abcdefg"); + Bu::String sRegEx("abcd"); + Bu::String sMatch("abcdefg"); - Bu::RegExEngine ree; + Bu::RegExEngine ree; - compile( sRegEx, ree ); + compile( sRegEx, ree ); - bool bRet; - int iSize, iCompletion; - bRet = ree.match( sMatch, iSize, iCompletion ); + bool bRet; + int iSize, iCompletion; + bRet = ree.match( sMatch, iSize, iCompletion ); - sio << "Matched: " << bRet << sio.nl - << "Size: " << iSize << sio.nl - << "Completion: " << iCompletion << sio.nl; + sio << "Matched: " << bRet << sio.nl + << "Size: " << iSize << sio.nl + << "Completion: " << iCompletion << sio.nl; - return 0; + return 0; } 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; int main() { - Bu::Settings s("Xagasoft", "Settings"); + Bu::Settings s("Xagasoft", "Settings"); - sio << s.get("Something", "BAD").get() << sio.nl; - sio << s.get("general/path", "BAD").get() << sio.nl; - sio << s.get("general/magic", "BAD").get() << sio.nl; + sio << s.get("Something", "BAD").get() << sio.nl; + sio << s.get("general/path", "BAD").get() << sio.nl; + sio << s.get("general/magic", "BAD").get() << sio.nl; - s.set("Something", "bob"); - s.set("general/path", "E:\\Place"); + s.set("Something", "bob"); + s.set("general/path", "E:\\Place"); } 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 @@ class Thing { public: - Thing( int x ) : - x( x ), - y( 0 ) - { - } - - int x; - int y; + Thing( int x ) : + x( x ), + y( 0 ) + { + } + + int x; + int y; }; typedef Bu::SynchroQueue ThingQueue; @@ -23,109 +23,109 @@ Bu::Condition cWorkDone; void workDone() { - mWorkDone.lock(); - iWorkDone--; - if( iWorkDone == 0 ) - { - mWorkDone.unlock(); - cWorkDone.lock(); - cWorkDone.signal(); - cWorkDone.unlock(); - return; - } - mWorkDone.unlock(); + mWorkDone.lock(); + iWorkDone--; + if( iWorkDone == 0 ) + { + mWorkDone.unlock(); + cWorkDone.lock(); + cWorkDone.signal(); + cWorkDone.unlock(); + return; + } + mWorkDone.unlock(); } class ThingEater : public Bu::Thread { public: - ThingEater( ThingQueue &qThing ) : - qThing( qThing ) - { - } - - bool bRunning; - - void setRunning( bool b ) - { - mRunning.lock(); - bRunning = b; - mRunning.unlock(); - } - - bool isRunning() - { - mRunning.lock(); - bool b = bRunning; - mRunning.unlock(); - return b; - } + ThingEater( ThingQueue &qThing ) : + qThing( qThing ) + { + } + + bool bRunning; + + void setRunning( bool b ) + { + mRunning.lock(); + bRunning = b; + mRunning.unlock(); + } + + bool isRunning() + { + mRunning.lock(); + bool b = bRunning; + mRunning.unlock(); + return b; + } protected: - virtual void run() - { - setRunning( true ); - while( isRunning() ) - { - Thing *pThing = qThing.dequeue( 0, 250000 ); - if( pThing == NULL ) - continue; - - pThing->y = pThing->x*2; - usleep( 10000 ); - - workDone(); - } - } - - ThingQueue &qThing; - Bu::Mutex mRunning; + virtual void run() + { + setRunning( true ); + while( isRunning() ) + { + Thing *pThing = qThing.dequeue( 0, 250000 ); + if( pThing == NULL ) + continue; + + pThing->y = pThing->x*2; + usleep( 10000 ); + + workDone(); + } + } + + ThingQueue &qThing; + Bu::Mutex mRunning; }; typedef Bu::List ThingEaterList; int main() { - ThingQueue qThing; - ThingEaterList lEater; - - mWorkDone.lock(); - iWorkDone = 1000; - mWorkDone.unlock(); - - for( int j = 0; j < 5; j++ ) - lEater.append( new ThingEater( qThing ) ); - - for( ThingEaterList::iterator i = lEater.begin(); i; i++ ) - (*i)->start(); - - for( int j = 0; j < 1000; j++ ) - { - qThing.enqueue( new Thing( j ) ); - } - - mWorkDone.lock(); - mWorkDone.unlock(); - cWorkDone.lock(); - for(;;) - { - mWorkDone.lock(); - if( iWorkDone == 0 ) - { - mWorkDone.unlock(); - break; - } - mWorkDone.unlock(); - cWorkDone.wait(); - } - cWorkDone.unlock(); - - for( ThingEaterList::iterator i = lEater.begin(); i; i++ ) - (*i)->setRunning( false ); - - for( ThingEaterList::iterator i = lEater.begin(); i; i++ ) - (*i)->join(); - - return 0; + ThingQueue qThing; + ThingEaterList lEater; + + mWorkDone.lock(); + iWorkDone = 1000; + mWorkDone.unlock(); + + for( int j = 0; j < 5; j++ ) + lEater.append( new ThingEater( qThing ) ); + + for( ThingEaterList::iterator i = lEater.begin(); i; i++ ) + (*i)->start(); + + for( int j = 0; j < 1000; j++ ) + { + qThing.enqueue( new Thing( j ) ); + } + + mWorkDone.lock(); + mWorkDone.unlock(); + cWorkDone.lock(); + for(;;) + { + mWorkDone.lock(); + if( iWorkDone == 0 ) + { + mWorkDone.unlock(); + break; + } + mWorkDone.unlock(); + cWorkDone.wait(); + } + cWorkDone.unlock(); + + for( ThingEaterList::iterator i = lEater.begin(); i; i++ ) + (*i)->setRunning( false ); + + for( ThingEaterList::iterator i = lEater.begin(); i; i++ ) + (*i)->join(); + + return 0; } 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 @@ int main( int argc, char *argv[] ) { - if( argc == 1 ) - { - Bu::File f("test.taf", Bu::File::Read ); - Bu::TafReader tr( f ); + if( argc == 1 ) + { + Bu::File f("test.taf", Bu::File::Read ); + Bu::TafReader tr( f ); - Bu::TafGroup *pGroup = tr.readGroup(); - - { - Bu::File fo("out.taf", Bu::File::Write|Bu::File::Create ); - Bu::TafWriter tw( fo ); - tw.writeGroup( pGroup ); - } + Bu::TafGroup *pGroup = tr.readGroup(); + + { + Bu::File fo("out.taf", Bu::File::Write|Bu::File::Create ); + Bu::TafWriter tw( fo ); + tw.writeGroup( pGroup ); + } - delete pGroup; - } - else if( argc == 3 ) - { - Bu::File f( argv[1], Bu::File::Read ); - Bu::TafReader tr( f ); + delete pGroup; + } + else if( argc == 3 ) + { + Bu::File f( argv[1], Bu::File::Read ); + Bu::TafReader tr( f ); - Bu::TafGroup *pGroup = tr.readGroup(); - - { - Bu::File fo( argv[2], Bu::File::Write|Bu::File::Create ); - Bu::TafWriter tw( fo ); - tw.writeGroup( pGroup ); - } + Bu::TafGroup *pGroup = tr.readGroup(); + + { + Bu::File fo( argv[2], Bu::File::Write|Bu::File::Create ); + Bu::TafWriter tw( fo ); + tw.writeGroup( pGroup ); + } - delete pGroup; - } + delete pGroup; + } } 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; class CopyThing { public: - CopyThing() - { - TRACE(); - tidHome = Thread::currentThread(); - } - - CopyThing( const CopyThing &rSrc ) - { - TRACE(); - tidHome = Thread::currentThread(); - sio << "Same thread? " << (tidHome == rSrc.tidHome) << sio.nl; - } - - void doThings() - { - TRACE(); - if( tidHome != Thread::currentThread() ) - sio << "Different threads, hard copy here." << sio.nl; - else - sio << "Same thread, everything is cool." << sio.nl; - } + CopyThing() + { + TRACE(); + tidHome = Thread::currentThread(); + } + + CopyThing( const CopyThing &rSrc ) + { + TRACE(); + tidHome = Thread::currentThread(); + sio << "Same thread? " << (tidHome == rSrc.tidHome) << sio.nl; + } + + void doThings() + { + TRACE(); + if( tidHome != Thread::currentThread() ) + sio << "Different threads, hard copy here." << sio.nl; + else + sio << "Same thread, everything is cool." << sio.nl; + } private: - ThreadId tidHome; + ThreadId tidHome; }; class SubThread : public Thread { public: - SubThread( CopyThing &src ) : - src( src ) - { - src.doThings(); - } + SubThread( CopyThing &src ) : + src( src ) + { + src.doThings(); + } protected: - void run() - { - src.doThings(); - sio << "run-Child is me? " << (getId() == Thread::currentThread()) << sio.nl; - } + void run() + { + src.doThings(); + sio << "run-Child is me? " << (getId() == Thread::currentThread()) << sio.nl; + } private: - CopyThing src; + CopyThing src; }; int main( int argc, char *argv[] ) { - CopyThing a; + CopyThing a; - SubThread st( a ); - st.start(); + SubThread st( a ); + st.start(); - sio << "Child is me? " << (st.getId() == Thread::currentThread()) << sio.nl; + sio << "Child is me? " << (st.getId() == Thread::currentThread()) << sio.nl; - st.join(); + st.join(); - return 0; + return 0; } 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; int main() { - sio << "Code: " << Bu::__calcHashCode( Bu::UtfString("Hello there") ) - << sio.nl; + sio << "Code: " << Bu::__calcHashCode( Bu::UtfString("Hello there") ) + << sio.nl; - Bu::File fIn("utf8.in", Bu::File::Read ); - Bu::String sUtf8; - char buf[4096]; - while( !fIn.isEos() ) - { - int iAmnt = fIn.read( buf, 4096 ); - sUtf8.append( buf, iAmnt ); - } - Bu::UtfString us( sUtf8, Bu::UtfString::Utf8 ); - us.debug(); - { - Bu::File fOut("utf8.out", Bu::File::WriteNew ); - us.write( fOut, Bu::UtfString::Utf8 ); - } - { - Bu::File fOut("utf16.out", Bu::File::WriteNew ); - us.write( fOut, Bu::UtfString::Utf16 ); - } - { - Bu::File fOut("utf16le.out", Bu::File::WriteNew ); - us.write( fOut, Bu::UtfString::Utf16le ); - } - { - Bu::File fOut("utf16be.out", Bu::File::WriteNew ); - us.write( fOut, Bu::UtfString::Utf16be ); - } - { - Bu::File fOut("utf32.out", Bu::File::WriteNew ); - us.write( fOut, Bu::UtfString::Utf32 ); - } - { - Bu::File fOut("utf32le.out", Bu::File::WriteNew ); - us.write( fOut, Bu::UtfString::Utf32le ); - } - { - Bu::File fOut("utf32be.out", Bu::File::WriteNew ); - us.write( fOut, Bu::UtfString::Utf32be ); - } + Bu::File fIn("utf8.in", Bu::File::Read ); + Bu::String sUtf8; + char buf[4096]; + while( !fIn.isEos() ) + { + int iAmnt = fIn.read( buf, 4096 ); + sUtf8.append( buf, iAmnt ); + } + Bu::UtfString us( sUtf8, Bu::UtfString::Utf8 ); + us.debug(); + { + Bu::File fOut("utf8.out", Bu::File::WriteNew ); + us.write( fOut, Bu::UtfString::Utf8 ); + } + { + Bu::File fOut("utf16.out", Bu::File::WriteNew ); + us.write( fOut, Bu::UtfString::Utf16 ); + } + { + Bu::File fOut("utf16le.out", Bu::File::WriteNew ); + us.write( fOut, Bu::UtfString::Utf16le ); + } + { + Bu::File fOut("utf16be.out", Bu::File::WriteNew ); + us.write( fOut, Bu::UtfString::Utf16be ); + } + { + Bu::File fOut("utf32.out", Bu::File::WriteNew ); + us.write( fOut, Bu::UtfString::Utf32 ); + } + { + Bu::File fOut("utf32le.out", Bu::File::WriteNew ); + us.write( fOut, Bu::UtfString::Utf32le ); + } + { + Bu::File fOut("utf32be.out", Bu::File::WriteNew ); + us.write( fOut, Bu::UtfString::Utf32be ); + } - /* - argc--, argv++; + /* + argc--, argv++; - for( char **sFile = argv; *sFile; sFile++ ) - { - Bu::File fIn( *sFile, Bu::File::Read ); - Bu::String sUtf8; - char buf[4096]; - while( !fIn.isEos() ) - { - int iAmnt = fIn.read( buf, 4096 ); - sUtf8.append( buf, iAmnt ); - } - Bu::UtfString us( sUtf8, Bu::UtfString::Utf16 ); + for( char **sFile = argv; *sFile; sFile++ ) + { + Bu::File fIn( *sFile, Bu::File::Read ); + Bu::String sUtf8; + char buf[4096]; + while( !fIn.isEos() ) + { + int iAmnt = fIn.read( buf, 4096 ); + sUtf8.append( buf, iAmnt ); + } + Bu::UtfString us( sUtf8, Bu::UtfString::Utf16 ); - us.debug(); - } - */ + us.debug(); + } + */ } 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; int main() { - Uuid i = Uuid::gen(); + Uuid i = Uuid::gen(); - sio << i.toString() << sio.nl; - sio << "Version: " << i.getVersion() << sio.nl; + sio << i.toString() << sio.nl; + sio << "Version: " << i.getVersion() << sio.nl; - return 0; + return 0; } -- cgit v1.2.3