diff options
| -rw-r--r-- | default.bld | 31 | ||||
| -rw-r--r-- | src/base64.cpp | 47 | ||||
| -rw-r--r-- | src/base64.h | 4 | ||||
| -rw-r--r-- | src/bzip2.cpp | 97 | ||||
| -rw-r--r-- | src/bzip2.h | 5 | ||||
| -rw-r--r-- | src/condition.cpp (renamed from src/itocondition.cpp) | 14 | ||||
| -rw-r--r-- | src/condition.h (renamed from src/itocondition.h) | 16 | ||||
| -rw-r--r-- | src/conduit.cpp | 8 | ||||
| -rw-r--r-- | src/conduit.h | 8 | ||||
| -rw-r--r-- | src/deflate.cpp | 249 | ||||
| -rw-r--r-- | src/deflate.h | 66 | ||||
| -rw-r--r-- | src/doxy/groups.dox | 5 | ||||
| -rw-r--r-- | src/formatter.h | 6 | ||||
| -rw-r--r-- | src/hex.cpp | 69 | ||||
| -rw-r--r-- | src/hex.h | 57 | ||||
| -rw-r--r-- | src/itolocker.cpp | 13 | ||||
| -rw-r--r-- | src/itolocker.h | 18 | ||||
| -rw-r--r-- | src/itoserver.cpp | 2 | ||||
| -rw-r--r-- | src/itoserver.h | 18 | ||||
| -rw-r--r-- | src/lzma.cpp | 248 | ||||
| -rw-r--r-- | src/lzma.h | 59 | ||||
| -rw-r--r-- | src/mutex.cpp (renamed from src/itomutex.cpp) | 12 | ||||
| -rw-r--r-- | src/mutex.h (renamed from src/itomutex.h) | 10 | ||||
| -rw-r--r-- | src/mutexlocker.cpp | 24 | ||||
| -rw-r--r-- | src/mutexlocker.h | 21 | ||||
| -rw-r--r-- | src/myriad.cpp | 4 | ||||
| -rw-r--r-- | src/myriadfs.cpp | 8 | ||||
| -rw-r--r-- | src/optparser.cpp | 2 | ||||
| -rw-r--r-- | src/programchain.cpp | 104 | ||||
| -rw-r--r-- | src/programchain.h | 99 | ||||
| -rw-r--r-- | src/programlink.cpp | 63 | ||||
| -rw-r--r-- | src/programlink.h | 106 | ||||
| -rw-r--r-- | src/sha1.h | 2 | ||||
| -rw-r--r-- | src/sio.cpp | 23 | ||||
| -rw-r--r-- | src/sio.h | 6 | ||||
| -rw-r--r-- | src/strfilter.h | 124 | ||||
| -rw-r--r-- | src/string.h | 2 | ||||
| -rw-r--r-- | src/synchroatom.h (renamed from src/itoatom.h) | 17 | ||||
| -rw-r--r-- | src/synchrocounter.cpp (renamed from src/itocounter.cpp) | 2 | ||||
| -rw-r--r-- | src/synchrocounter.h (renamed from src/itocounter.h) | 14 | ||||
| -rw-r--r-- | src/synchroheap.cpp (renamed from src/itoheap.cpp) | 2 | ||||
| -rw-r--r-- | src/synchroheap.h (renamed from src/itoheap.h) | 21 | ||||
| -rw-r--r-- | src/synchroqueue.h (renamed from src/itoqueue.h) | 20 | ||||
| -rw-r--r-- | src/tests/deflate.cpp | 53 | ||||
| -rw-r--r-- | src/tests/lzma.cpp | 53 | ||||
| -rw-r--r-- | src/tests/myriadfs.cpp | 2 | ||||
| -rw-r--r-- | src/tests/utf.cpp | 2 | ||||
| -rw-r--r-- | src/thread.cpp (renamed from src/ito.cpp) | 20 | ||||
| -rw-r--r-- | src/thread.h (renamed from src/ito.h) | 24 | ||||
| -rw-r--r-- | src/tools/bnfcompile.cpp | 5 | ||||
| -rw-r--r-- | src/tools/myriad.cpp | 2 | ||||
| -rw-r--r-- | src/tools/parser.cpp | 5 | ||||
| -rw-r--r-- | src/unit/base64.unit | 28 | ||||
| -rw-r--r-- | src/utfstring.cpp | 8 |
54 files changed, 1341 insertions, 587 deletions
diff --git a/default.bld b/default.bld index 8f98db0..5660e99 100644 --- a/default.bld +++ b/default.bld | |||
| @@ -17,7 +17,7 @@ CXXFLAGS += "-ggdb -W -Wall -I."; | |||
| 17 | 17 | ||
| 18 | action "default" | 18 | action "default" |
| 19 | { | 19 | { |
| 20 | build: [targets("header-links"), "libbu++.a", | 20 | build: ["header-links", "libbu++.a", |
| 21 | targets("tools")]; | 21 | targets("tools")]; |
| 22 | } | 22 | } |
| 23 | 23 | ||
| @@ -28,7 +28,7 @@ action "pkg" | |||
| 28 | 28 | ||
| 29 | action "all" | 29 | action "all" |
| 30 | { | 30 | { |
| 31 | build: [targets("header-links"), "libbu++.a", | 31 | build: ["header-links", "libbu++.a", |
| 32 | targets("tools"), targets("tests")]; | 32 | targets("tools"), targets("tests")]; |
| 33 | } | 33 | } |
| 34 | 34 | ||
| @@ -60,6 +60,7 @@ target "src/version.h" | |||
| 60 | target "src/signals.h" | 60 | target "src/signals.h" |
| 61 | { | 61 | { |
| 62 | input "gensigs.bld"; | 62 | input "gensigs.bld"; |
| 63 | display "generate"; | ||
| 63 | profile "build" | 64 | profile "build" |
| 64 | { | 65 | { |
| 65 | genSigs( OUTPUT ); | 66 | genSigs( OUTPUT ); |
| @@ -80,7 +81,8 @@ target [files("src/*.h").replace("src/", "bu/"), "bu/autoconfig.h", | |||
| 80 | input OUTPUT.replace("bu/","src/"); | 81 | input OUTPUT.replace("bu/","src/"); |
| 81 | profile "build" | 82 | profile "build" |
| 82 | { | 83 | { |
| 83 | execute("mkdir -p $(dirname ${OUTPUT}); ln -s ../${INPUT} ${OUTPUT}"); | 84 | DIR = OUTPUT.dirName(); |
| 85 | execute("mkdir -p ${DIR}; ln -s ../${INPUT} ${OUTPUT}"); | ||
| 84 | } | 86 | } |
| 85 | } | 87 | } |
| 86 | 88 | ||
| @@ -91,7 +93,18 @@ target files("src/compat/*.h").replace("src/", "bu/") | |||
| 91 | input OUTPUT.replace("bu/","src/"); | 93 | input OUTPUT.replace("bu/","src/"); |
| 92 | profile "build" | 94 | profile "build" |
| 93 | { | 95 | { |
| 94 | execute("mkdir -p $(dirname ${OUTPUT}); ln -s ../../${INPUT} ${OUTPUT}"); | 96 | DIR = OUTPUT.dirName(); |
| 97 | execute("mkdir -p ${DIR}; ln -s ../../${INPUT} ${OUTPUT}"); | ||
| 98 | } | ||
| 99 | } | ||
| 100 | |||
| 101 | target "header-links" | ||
| 102 | { | ||
| 103 | input targets("header-links"); | ||
| 104 | display "symlinks"; | ||
| 105 | profile "build" | ||
| 106 | { | ||
| 107 | condition always; | ||
| 95 | } | 108 | } |
| 96 | } | 109 | } |
| 97 | 110 | ||
| @@ -167,6 +180,16 @@ target ["tests/bzip2", "tests/streamstack"] | |||
| 167 | LDFLAGS += "-lbz2"; | 180 | LDFLAGS += "-lbz2"; |
| 168 | } | 181 | } |
| 169 | 182 | ||
| 183 | target ["tests/deflate", "tests/enc"] | ||
| 184 | { | ||
| 185 | LDFLAGS += "-lz"; | ||
| 186 | } | ||
| 187 | |||
| 188 | target ["tests/lzma"] | ||
| 189 | { | ||
| 190 | LDFLAGS += "-llzma"; | ||
| 191 | } | ||
| 192 | |||
| 170 | target ["tests/itoserver", "tests/socketblock", "tests/itoheap", | 193 | target ["tests/itoserver", "tests/socketblock", "tests/itoheap", |
| 171 | "tests/itoqueue1", "tests/itoqueue2", "tests/conduit"] | 194 | "tests/itoqueue1", "tests/itoqueue2", "tests/conduit"] |
| 172 | { | 195 | { |
diff --git a/src/base64.cpp b/src/base64.cpp index 18a18e5..4d659f0 100644 --- a/src/base64.cpp +++ b/src/base64.cpp | |||
| @@ -13,7 +13,7 @@ const char Bu::Base64::tblEnc[65] = { | |||
| 13 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" | 13 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" |
| 14 | }; | 14 | }; |
| 15 | 15 | ||
| 16 | Bu::Base64::Base64( Bu::Stream &rNext ) : | 16 | Bu::Base64::Base64( Bu::Stream &rNext, int iChunkSize ) : |
| 17 | Bu::Filter( rNext ), | 17 | Bu::Filter( rNext ), |
| 18 | iBPos( 0 ), | 18 | iBPos( 0 ), |
| 19 | iBuf( 0 ), | 19 | iBuf( 0 ), |
| @@ -22,7 +22,9 @@ Bu::Base64::Base64( Bu::Stream &rNext ) : | |||
| 22 | bEosIn( false ), | 22 | bEosIn( false ), |
| 23 | iTotalIn( 0 ), | 23 | iTotalIn( 0 ), |
| 24 | iTotalOut( 0 ), | 24 | iTotalOut( 0 ), |
| 25 | eMode( Nothing ) | 25 | eMode( Nothing ), |
| 26 | iChunkSize( iChunkSize ), | ||
| 27 | iCurChunk( 0 ) | ||
| 26 | { | 28 | { |
| 27 | start(); | 29 | start(); |
| 28 | 30 | ||
| @@ -62,11 +64,12 @@ Bu::Base64::~Base64() | |||
| 62 | 64 | ||
| 63 | void Bu::Base64::start() | 65 | void Bu::Base64::start() |
| 64 | { | 66 | { |
| 67 | iCurChunk = 0; | ||
| 65 | } | 68 | } |
| 66 | 69 | ||
| 67 | Bu::size Bu::Base64::stop() | 70 | Bu::size Bu::Base64::stop() |
| 68 | { | 71 | { |
| 69 | // if( eMode |= Encode ) | 72 | if( eMode == Encode ) |
| 70 | { | 73 | { |
| 71 | char outBuf[4]; | 74 | char outBuf[4]; |
| 72 | int iBUsed = 4-(3-iBPos); | 75 | int iBUsed = 4-(3-iBPos); |
| @@ -80,17 +83,30 @@ Bu::size Bu::Base64::stop() | |||
| 80 | { | 83 | { |
| 81 | outBuf[k] = '='; | 84 | outBuf[k] = '='; |
| 82 | } | 85 | } |
| 83 | iTotalOut += rNext.write( outBuf, 4 ); | 86 | iCurChunk += 4; |
| 87 | if( iChunkSize && iCurChunk >= iChunkSize ) | ||
| 88 | { | ||
| 89 | iCurChunk = iCurChunk-iChunkSize; | ||
| 90 | iTotalOut += rNext.write( outBuf, 4-iCurChunk ); | ||
| 91 | iTotalOut += rNext.write("\r\n", 2 ); | ||
| 92 | iTotalOut += rNext.write( outBuf+(4-iCurChunk), iCurChunk ); | ||
| 93 | } | ||
| 94 | else | ||
| 95 | iTotalOut += rNext.write( outBuf, 4 ); | ||
| 84 | return iTotalOut; | 96 | return iTotalOut; |
| 85 | } | 97 | } |
| 86 | // else | 98 | else |
| 87 | // { | 99 | { |
| 88 | return iTotalIn; | 100 | return iTotalIn; |
| 89 | // } | 101 | } |
| 90 | } | 102 | } |
| 91 | 103 | ||
| 92 | Bu::size Bu::Base64::read( void *pBuf, Bu::size nBytes ) | 104 | Bu::size Bu::Base64::read( void *pBuf, Bu::size nBytes ) |
| 93 | { | 105 | { |
| 106 | if( eMode == Encode ) | ||
| 107 | throw Bu::Base64Exception("Cannot read from an output stream."); | ||
| 108 | eMode = Decode; | ||
| 109 | |||
| 94 | if( bEosIn == true && iRPos == iChars ) | 110 | if( bEosIn == true && iRPos == iChars ) |
| 95 | return 0; | 111 | return 0; |
| 96 | Bu::size sIn = 0; | 112 | Bu::size sIn = 0; |
| @@ -118,6 +134,8 @@ Bu::size Bu::Base64::read( void *pBuf, Bu::size nBytes ) | |||
| 118 | { | 134 | { |
| 119 | if( rNext.isEos() ) | 135 | if( rNext.isEos() ) |
| 120 | { | 136 | { |
| 137 | if( iRPos == 0 ) | ||
| 138 | iRPos = iChars; | ||
| 121 | bEosIn = true; | 139 | bEosIn = true; |
| 122 | if( j != 0 ) | 140 | if( j != 0 ) |
| 123 | { | 141 | { |
| @@ -155,6 +173,10 @@ Bu::size Bu::Base64::read( void *pBuf, Bu::size nBytes ) | |||
| 155 | 173 | ||
| 156 | Bu::size Bu::Base64::write( const void *pBuf, Bu::size nBytes ) | 174 | Bu::size Bu::Base64::write( const void *pBuf, Bu::size nBytes ) |
| 157 | { | 175 | { |
| 176 | if( eMode == Decode ) | ||
| 177 | throw Bu::Base64Exception("Cannot write to an input stream."); | ||
| 178 | eMode = Encode; | ||
| 179 | |||
| 158 | Bu::size sOut = 0; | 180 | Bu::size sOut = 0; |
| 159 | char outBuf[4]; | 181 | char outBuf[4]; |
| 160 | for( Bu::size j = 0; j < nBytes; j++ ) | 182 | for( Bu::size j = 0; j < nBytes; j++ ) |
| @@ -166,7 +188,16 @@ Bu::size Bu::Base64::write( const void *pBuf, Bu::size nBytes ) | |||
| 166 | { | 188 | { |
| 167 | outBuf[3-k] = tblEnc[(iBuf>>(6*k))&0x3f]; | 189 | outBuf[3-k] = tblEnc[(iBuf>>(6*k))&0x3f]; |
| 168 | } | 190 | } |
| 169 | sOut += rNext.write( outBuf, 4 ); | 191 | iCurChunk += 4; |
| 192 | if( iChunkSize && iCurChunk >= iChunkSize ) | ||
| 193 | { | ||
| 194 | iCurChunk = iCurChunk-iChunkSize; | ||
| 195 | sOut += rNext.write( outBuf, 4-iCurChunk ); | ||
| 196 | sOut += rNext.write("\r\n", 2 ); | ||
| 197 | sOut += rNext.write( outBuf+(4-iCurChunk), iCurChunk ); | ||
| 198 | } | ||
| 199 | else | ||
| 200 | sOut += rNext.write( outBuf, 4 ); | ||
| 170 | iBPos = iBuf = 0; | 201 | iBPos = iBuf = 0; |
| 171 | } | 202 | } |
| 172 | } | 203 | } |
diff --git a/src/base64.h b/src/base64.h index 53d7860..c081ac1 100644 --- a/src/base64.h +++ b/src/base64.h | |||
| @@ -22,7 +22,7 @@ namespace Bu | |||
| 22 | class Base64 : public Bu::Filter | 22 | class Base64 : public Bu::Filter |
| 23 | { | 23 | { |
| 24 | public: | 24 | public: |
| 25 | Base64( Bu::Stream &rNext ); | 25 | Base64( Bu::Stream &rNext, int iChunkSize=0 ); |
| 26 | virtual ~Base64(); | 26 | virtual ~Base64(); |
| 27 | 27 | ||
| 28 | virtual void start(); | 28 | virtual void start(); |
| @@ -51,6 +51,8 @@ namespace Bu | |||
| 51 | Decode = 0x02, | 51 | Decode = 0x02, |
| 52 | }; | 52 | }; |
| 53 | Mode eMode; | 53 | Mode eMode; |
| 54 | int iChunkSize; | ||
| 55 | int iCurChunk; | ||
| 54 | }; | 56 | }; |
| 55 | }; | 57 | }; |
| 56 | 58 | ||
diff --git a/src/bzip2.cpp b/src/bzip2.cpp index 5c35a26..ca007b0 100644 --- a/src/bzip2.cpp +++ b/src/bzip2.cpp | |||
| @@ -8,10 +8,15 @@ | |||
| 8 | #include "bu/bzip2.h" | 8 | #include "bu/bzip2.h" |
| 9 | #include "bu/trace.h" | 9 | #include "bu/trace.h" |
| 10 | 10 | ||
| 11 | #include <bzlib.h> | ||
| 12 | |||
| 13 | #define pState ((bz_stream *)prState) | ||
| 14 | |||
| 11 | using namespace Bu; | 15 | using namespace Bu; |
| 12 | 16 | ||
| 13 | Bu::BZip2::BZip2( Bu::Stream &rNext, int nCompression ) : | 17 | Bu::BZip2::BZip2( Bu::Stream &rNext, int nCompression ) : |
| 14 | Bu::Filter( rNext ), | 18 | Bu::Filter( rNext ), |
| 19 | prState( NULL ), | ||
| 15 | nCompression( nCompression ), | 20 | nCompression( nCompression ), |
| 16 | sTotalOut( 0 ) | 21 | sTotalOut( 0 ) |
| 17 | { | 22 | { |
| @@ -28,25 +33,29 @@ Bu::BZip2::~BZip2() | |||
| 28 | void Bu::BZip2::start() | 33 | void Bu::BZip2::start() |
| 29 | { | 34 | { |
| 30 | TRACE(); | 35 | TRACE(); |
| 31 | bzState.state = NULL; | ||
| 32 | bzState.bzalloc = NULL; | ||
| 33 | bzState.bzfree = NULL; | ||
| 34 | bzState.opaque = NULL; | ||
| 35 | 36 | ||
| 36 | nBufSize = 50000; | 37 | prState = new bz_stream; |
| 38 | pState->state = NULL; | ||
| 39 | pState->bzalloc = NULL; | ||
| 40 | pState->bzfree = NULL; | ||
| 41 | pState->opaque = NULL; | ||
| 42 | |||
| 43 | nBufSize = 64*1024; | ||
| 37 | pBuf = new char[nBufSize]; | 44 | pBuf = new char[nBufSize]; |
| 38 | } | 45 | } |
| 39 | 46 | ||
| 40 | Bu::size Bu::BZip2::stop() | 47 | Bu::size Bu::BZip2::stop() |
| 41 | { | 48 | { |
| 42 | TRACE(); | 49 | TRACE(); |
| 43 | if( bzState.state ) | 50 | if( pState->state ) |
| 44 | { | 51 | { |
| 45 | if( bReading ) | 52 | if( bReading ) |
| 46 | { | 53 | { |
| 47 | BZ2_bzDecompressEnd( &bzState ); | 54 | BZ2_bzDecompressEnd( pState ); |
| 48 | delete[] pBuf; | 55 | delete[] pBuf; |
| 49 | pBuf = NULL; | 56 | pBuf = NULL; |
| 57 | delete pState; | ||
| 58 | prState = NULL; | ||
| 50 | return 0; | 59 | return 0; |
| 51 | } | 60 | } |
| 52 | else | 61 | else |
| @@ -54,21 +63,23 @@ Bu::size Bu::BZip2::stop() | |||
| 54 | // Bu::size sTotal = 0; | 63 | // Bu::size sTotal = 0; |
| 55 | for(;;) | 64 | for(;;) |
| 56 | { | 65 | { |
| 57 | bzState.next_in = NULL; | 66 | pState->next_in = NULL; |
| 58 | bzState.avail_in = 0; | 67 | pState->avail_in = 0; |
| 59 | bzState.avail_out = nBufSize; | 68 | pState->avail_out = nBufSize; |
| 60 | bzState.next_out = pBuf; | 69 | pState->next_out = pBuf; |
| 61 | int res = BZ2_bzCompress( &bzState, BZ_FINISH ); | 70 | int res = BZ2_bzCompress( pState, BZ_FINISH ); |
| 62 | if( bzState.avail_out < nBufSize ) | 71 | if( pState->avail_out < nBufSize ) |
| 63 | { | 72 | { |
| 64 | sTotalOut += rNext.write( pBuf, nBufSize-bzState.avail_out ); | 73 | sTotalOut += rNext.write( pBuf, nBufSize-pState->avail_out ); |
| 65 | } | 74 | } |
| 66 | if( res == BZ_STREAM_END ) | 75 | if( res == BZ_STREAM_END ) |
| 67 | break; | 76 | break; |
| 68 | } | 77 | } |
| 69 | BZ2_bzCompressEnd( &bzState ); | 78 | BZ2_bzCompressEnd( pState ); |
| 70 | delete[] pBuf; | 79 | delete[] pBuf; |
| 71 | pBuf = NULL; | 80 | pBuf = NULL; |
| 81 | delete pState; | ||
| 82 | prState = NULL; | ||
| 72 | return sTotalOut; | 83 | return sTotalOut; |
| 73 | } | 84 | } |
| 74 | } | 85 | } |
| @@ -122,42 +133,42 @@ void Bu::BZip2::bzError( int code ) | |||
| 122 | Bu::size Bu::BZip2::read( void *pData, Bu::size nBytes ) | 133 | Bu::size Bu::BZip2::read( void *pData, Bu::size nBytes ) |
| 123 | { | 134 | { |
| 124 | TRACE( pData, nBytes ); | 135 | TRACE( pData, nBytes ); |
| 125 | if( !bzState.state ) | 136 | if( !pState->state ) |
| 126 | { | 137 | { |
| 127 | bReading = true; | 138 | bReading = true; |
| 128 | BZ2_bzDecompressInit( &bzState, 0, 0 ); | 139 | BZ2_bzDecompressInit( pState, 0, 0 ); |
| 129 | bzState.next_in = pBuf; | 140 | pState->next_in = pBuf; |
| 130 | bzState.avail_in = 0; | 141 | pState->avail_in = 0; |
| 131 | } | 142 | } |
| 132 | if( bReading == false ) | 143 | if( bReading == false ) |
| 133 | throw ExceptionBase("This bzip2 filter is in writing mode, you can't read."); | 144 | throw ExceptionBase("This bzip2 filter is in writing mode, you can't read."); |
| 134 | 145 | ||
| 135 | int nRead = 0; | 146 | int nRead = 0; |
| 136 | int nReadTotal = bzState.total_out_lo32; | 147 | int nReadTotal = pState->total_out_lo32; |
| 137 | bzState.next_out = (char *)pData; | 148 | pState->next_out = (char *)pData; |
| 138 | bzState.avail_out = nBytes; | 149 | pState->avail_out = nBytes; |
| 139 | for(;;) | 150 | for(;;) |
| 140 | { | 151 | { |
| 141 | int ret = BZ2_bzDecompress( &bzState ); | 152 | int ret = BZ2_bzDecompress( pState ); |
| 142 | 153 | ||
| 143 | nReadTotal += nRead-bzState.avail_out; | 154 | nReadTotal += nRead-pState->avail_out; |
| 144 | 155 | ||
| 145 | if( ret == BZ_STREAM_END ) | 156 | if( ret == BZ_STREAM_END ) |
| 146 | { | 157 | { |
| 147 | if( bzState.avail_in > 0 ) | 158 | if( pState->avail_in > 0 ) |
| 148 | { | 159 | { |
| 149 | if( rNext.isSeekable() ) | 160 | if( rNext.isSeekable() ) |
| 150 | { | 161 | { |
| 151 | rNext.seek( -bzState.avail_in ); | 162 | rNext.seek( -pState->avail_in ); |
| 152 | } | 163 | } |
| 153 | } | 164 | } |
| 154 | return nBytes-bzState.avail_out; | 165 | return nBytes-pState->avail_out; |
| 155 | } | 166 | } |
| 156 | bzError( ret ); | 167 | bzError( ret ); |
| 157 | 168 | ||
| 158 | if( bzState.avail_out ) | 169 | if( pState->avail_out ) |
| 159 | { | 170 | { |
| 160 | if( bzState.avail_in == 0 ) | 171 | if( pState->avail_in == 0 ) |
| 161 | { | 172 | { |
| 162 | nRead = rNext.read( pBuf, nBufSize ); | 173 | nRead = rNext.read( pBuf, nBufSize ); |
| 163 | if( nRead == 0 && rNext.isEos() ) | 174 | if( nRead == 0 && rNext.isEos() ) |
| @@ -165,13 +176,13 @@ Bu::size Bu::BZip2::read( void *pData, Bu::size nBytes ) | |||
| 165 | throw Bu::ExceptionBase("Premature end of underlying " | 176 | throw Bu::ExceptionBase("Premature end of underlying " |
| 166 | "stream found reading bzip2 stream."); | 177 | "stream found reading bzip2 stream."); |
| 167 | } | 178 | } |
| 168 | bzState.next_in = pBuf; | 179 | pState->next_in = pBuf; |
| 169 | bzState.avail_in = nRead; | 180 | pState->avail_in = nRead; |
| 170 | } | 181 | } |
| 171 | } | 182 | } |
| 172 | else | 183 | else |
| 173 | { | 184 | { |
| 174 | return nBytes-bzState.avail_out; | 185 | return nBytes-pState->avail_out; |
| 175 | } | 186 | } |
| 176 | } | 187 | } |
| 177 | return 0; | 188 | return 0; |
| @@ -180,29 +191,29 @@ Bu::size Bu::BZip2::read( void *pData, Bu::size nBytes ) | |||
| 180 | Bu::size Bu::BZip2::write( const void *pData, Bu::size nBytes ) | 191 | Bu::size Bu::BZip2::write( const void *pData, Bu::size nBytes ) |
| 181 | { | 192 | { |
| 182 | TRACE( pData, nBytes ); | 193 | TRACE( pData, nBytes ); |
| 183 | if( !bzState.state ) | 194 | if( !pState->state ) |
| 184 | { | 195 | { |
| 185 | bReading = false; | 196 | bReading = false; |
| 186 | BZ2_bzCompressInit( &bzState, nCompression, 0, 30 ); | 197 | BZ2_bzCompressInit( pState, nCompression, 0, 30 ); |
| 187 | } | 198 | } |
| 188 | if( bReading == true ) | 199 | if( bReading == true ) |
| 189 | throw ExceptionBase("This bzip2 filter is in reading mode, you can't write."); | 200 | throw ExceptionBase("This bzip2 filter is in reading mode, you can't write."); |
| 190 | 201 | ||
| 191 | // Bu::size sTotalOut = 0; | 202 | // Bu::size sTotalOut = 0; |
| 192 | bzState.next_in = (char *)pData; | 203 | pState->next_in = (char *)pData; |
| 193 | bzState.avail_in = nBytes; | 204 | pState->avail_in = nBytes; |
| 194 | for(;;) | 205 | for(;;) |
| 195 | { | 206 | { |
| 196 | bzState.avail_out = nBufSize; | 207 | pState->avail_out = nBufSize; |
| 197 | bzState.next_out = pBuf; | 208 | pState->next_out = pBuf; |
| 198 | 209 | ||
| 199 | bzError( BZ2_bzCompress( &bzState, BZ_RUN ) ); | 210 | bzError( BZ2_bzCompress( pState, BZ_RUN ) ); |
| 200 | 211 | ||
| 201 | if( bzState.avail_out < nBufSize ) | 212 | if( pState->avail_out < nBufSize ) |
| 202 | { | 213 | { |
| 203 | sTotalOut += rNext.write( pBuf, nBufSize-bzState.avail_out ); | 214 | sTotalOut += rNext.write( pBuf, nBufSize-pState->avail_out ); |
| 204 | } | 215 | } |
| 205 | if( bzState.avail_in == 0 ) | 216 | if( pState->avail_in == 0 ) |
| 206 | break; | 217 | break; |
| 207 | } | 218 | } |
| 208 | 219 | ||
| @@ -212,7 +223,7 @@ Bu::size Bu::BZip2::write( const void *pData, Bu::size nBytes ) | |||
| 212 | bool Bu::BZip2::isOpen() | 223 | bool Bu::BZip2::isOpen() |
| 213 | { | 224 | { |
| 214 | TRACE(); | 225 | TRACE(); |
| 215 | return (bzState.state != NULL); | 226 | return (pState->state != NULL); |
| 216 | } | 227 | } |
| 217 | 228 | ||
| 218 | Bu::size Bu::BZip2::getCompressedSize() | 229 | Bu::size Bu::BZip2::getCompressedSize() |
diff --git a/src/bzip2.h b/src/bzip2.h index 6da3dff..9a8d172 100644 --- a/src/bzip2.h +++ b/src/bzip2.h | |||
| @@ -9,15 +9,16 @@ | |||
| 9 | #define BU_BZIP2_H | 9 | #define BU_BZIP2_H |
| 10 | 10 | ||
| 11 | #include <stdint.h> | 11 | #include <stdint.h> |
| 12 | #include <bzlib.h> | ||
| 13 | 12 | ||
| 14 | #include "bu/filter.h" | 13 | #include "bu/filter.h" |
| 15 | 14 | ||
| 16 | namespace Bu | 15 | namespace Bu |
| 17 | { | 16 | { |
| 18 | /** | 17 | /** |
| 18 | * Provides BZip2 type compression and decompression. | ||
| 19 | * | 19 | * |
| 20 | *@ingroup Streams | 20 | *@ingroup Streams |
| 21 | *@ingroup Compression | ||
| 21 | */ | 22 | */ |
| 22 | class BZip2 : public Bu::Filter | 23 | class BZip2 : public Bu::Filter |
| 23 | { | 24 | { |
| @@ -36,7 +37,7 @@ namespace Bu | |||
| 36 | 37 | ||
| 37 | private: | 38 | private: |
| 38 | void bzError( int code ); | 39 | void bzError( int code ); |
| 39 | bz_stream bzState; | 40 | void *prState; |
| 40 | bool bReading; | 41 | bool bReading; |
| 41 | int nCompression; | 42 | int nCompression; |
| 42 | char *pBuf; | 43 | char *pBuf; |
diff --git a/src/itocondition.cpp b/src/condition.cpp index 3d8db60..2f55ce2 100644 --- a/src/itocondition.cpp +++ b/src/condition.cpp | |||
| @@ -7,24 +7,24 @@ | |||
| 7 | 7 | ||
| 8 | #include <sys/time.h> | 8 | #include <sys/time.h> |
| 9 | 9 | ||
| 10 | #include "bu/itocondition.h" | 10 | #include "bu/condition.h" |
| 11 | 11 | ||
| 12 | Bu::ItoCondition::ItoCondition() | 12 | Bu::Condition::Condition() |
| 13 | { | 13 | { |
| 14 | pthread_cond_init( &cond, NULL ); | 14 | pthread_cond_init( &cond, NULL ); |
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | Bu::ItoCondition::~ItoCondition() | 17 | Bu::Condition::~Condition() |
| 18 | { | 18 | { |
| 19 | pthread_cond_destroy( &cond ); | 19 | pthread_cond_destroy( &cond ); |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | int Bu::ItoCondition::wait() | 22 | int Bu::Condition::wait() |
| 23 | { | 23 | { |
| 24 | return pthread_cond_wait( &cond, &mutex ); | 24 | return pthread_cond_wait( &cond, &mutex ); |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | int Bu::ItoCondition::wait( int nSec, int nUSec ) | 27 | int Bu::Condition::wait( int nSec, int nUSec ) |
| 28 | { | 28 | { |
| 29 | struct timeval now; | 29 | struct timeval now; |
| 30 | struct timespec timeout; | 30 | struct timespec timeout; |
| @@ -37,12 +37,12 @@ int Bu::ItoCondition::wait( int nSec, int nUSec ) | |||
| 37 | return pthread_cond_timedwait( &cond, &mutex, &timeout ); | 37 | return pthread_cond_timedwait( &cond, &mutex, &timeout ); |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | int Bu::ItoCondition::signal() | 40 | int Bu::Condition::signal() |
| 41 | { | 41 | { |
| 42 | return pthread_cond_signal( &cond ); | 42 | return pthread_cond_signal( &cond ); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | int Bu::ItoCondition::broadcast() | 45 | int Bu::Condition::broadcast() |
| 46 | { | 46 | { |
| 47 | return pthread_cond_broadcast( &cond ); | 47 | return pthread_cond_broadcast( &cond ); |
| 48 | } | 48 | } |
diff --git a/src/itocondition.h b/src/condition.h index 88e8d6c..71634f5 100644 --- a/src/itocondition.h +++ b/src/condition.h | |||
| @@ -5,25 +5,25 @@ | |||
| 5 | * terms of the license contained in the file LICENSE. | 5 | * terms of the license contained in the file LICENSE. |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | #ifndef BU_ITO_CONDITION_H | 8 | #ifndef BU_CONDITION_H |
| 9 | #define BU_ITO_CONDITION_H | 9 | #define BU_CONDITION_H |
| 10 | 10 | ||
| 11 | #include <pthread.h> | 11 | #include <pthread.h> |
| 12 | 12 | ||
| 13 | #include "itomutex.h" | 13 | #include "bu/mutex.h" |
| 14 | 14 | ||
| 15 | namespace Bu | 15 | namespace Bu |
| 16 | { | 16 | { |
| 17 | /** | 17 | /** |
| 18 | * Ito condition. This is a fairly simple condition mechanism. As you may | 18 | * Ito condition. This is a fairly simple condition mechanism. As you may |
| 19 | * notice this class inherits from the ItoMutex class, this is because all | 19 | * notice this class inherits from the Mutex class, this is because all |
| 20 | * conditions must be within a locked block. The standard usage of a | 20 | * conditions must be within a locked block. The standard usage of a |
| 21 | * condition is to pause one thread, perhaps indefinately, until another | 21 | * condition is to pause one thread, perhaps indefinately, until another |
| 22 | * thread signals that it is alright to procede. | 22 | * thread signals that it is alright to procede. |
| 23 | * <br> | 23 | * <br> |
| 24 | * Standard usage for the thread that wants to wait is as follows: | 24 | * Standard usage for the thread that wants to wait is as follows: |
| 25 | * <pre> | 25 | * <pre> |
| 26 | * ItoCondition cond; | 26 | * Condition cond; |
| 27 | * ... // Perform setup and enter your run loop | 27 | * ... // Perform setup and enter your run loop |
| 28 | * cond.lock(); | 28 | * cond.lock(); |
| 29 | * while( !isFinished() ) // Could be anything you're waiting for | 29 | * while( !isFinished() ) // Could be anything you're waiting for |
| @@ -36,18 +36,18 @@ namespace Bu | |||
| 36 | * or broadcast. See both of those functions for the difference. | 36 | * or broadcast. See both of those functions for the difference. |
| 37 | *@ingroup Threading | 37 | *@ingroup Threading |
| 38 | */ | 38 | */ |
| 39 | class ItoCondition : public ItoMutex | 39 | class Condition : public Mutex |
| 40 | { | 40 | { |
| 41 | public: | 41 | public: |
| 42 | /** | 42 | /** |
| 43 | * Create a condition. | 43 | * Create a condition. |
| 44 | */ | 44 | */ |
| 45 | ItoCondition(); | 45 | Condition(); |
| 46 | 46 | ||
| 47 | /** | 47 | /** |
| 48 | * Destroy a condition. | 48 | * Destroy a condition. |
| 49 | */ | 49 | */ |
| 50 | ~ItoCondition(); | 50 | ~Condition(); |
| 51 | 51 | ||
| 52 | /** | 52 | /** |
| 53 | * Wait forever, or until signalled. This has to be called from within | 53 | * Wait forever, or until signalled. This has to be called from within |
diff --git a/src/conduit.cpp b/src/conduit.cpp index cfa93d8..c9ccdc4 100644 --- a/src/conduit.cpp +++ b/src/conduit.cpp | |||
| @@ -116,15 +116,15 @@ Bu::size Bu::Conduit::tell() | |||
| 116 | return sRet; | 116 | return sRet; |
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | void Bu::Conduit::seek( Bu::size offset ) | 119 | void Bu::Conduit::seek( Bu::size ) |
| 120 | { | 120 | { |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | void Bu::Conduit::setPos( Bu::size pos ) | 123 | void Bu::Conduit::setPos( Bu::size ) |
| 124 | { | 124 | { |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | void Bu::Conduit::setPosEnd( Bu::size pos ) | 127 | void Bu::Conduit::setPosEnd( Bu::size ) |
| 128 | { | 128 | { |
| 129 | } | 129 | } |
| 130 | 130 | ||
| @@ -203,7 +203,7 @@ void Bu::Conduit::setBlocking( bool bBlocking ) | |||
| 203 | im.unlock(); | 203 | im.unlock(); |
| 204 | } | 204 | } |
| 205 | 205 | ||
| 206 | void Bu::Conduit::setSize( Bu::size iSize ) | 206 | void Bu::Conduit::setSize( Bu::size ) |
| 207 | { | 207 | { |
| 208 | } | 208 | } |
| 209 | 209 | ||
diff --git a/src/conduit.h b/src/conduit.h index 72b8d52..9babaaf 100644 --- a/src/conduit.h +++ b/src/conduit.h | |||
| @@ -11,8 +11,8 @@ | |||
| 11 | #include "bu/stream.h" | 11 | #include "bu/stream.h" |
| 12 | #include "bu/string.h" | 12 | #include "bu/string.h" |
| 13 | #include "bu/queuebuf.h" | 13 | #include "bu/queuebuf.h" |
| 14 | #include "bu/itomutex.h" | 14 | #include "bu/mutex.h" |
| 15 | #include "bu/itocondition.h" | 15 | #include "bu/condition.h" |
| 16 | 16 | ||
| 17 | namespace Bu | 17 | namespace Bu |
| 18 | { | 18 | { |
| @@ -54,8 +54,8 @@ namespace Bu | |||
| 54 | 54 | ||
| 55 | private: | 55 | private: |
| 56 | QueueBuf qb; | 56 | QueueBuf qb; |
| 57 | mutable ItoMutex im; | 57 | mutable Mutex im; |
| 58 | ItoCondition cBlock; | 58 | Condition cBlock; |
| 59 | bool bBlocking; | 59 | bool bBlocking; |
| 60 | bool bOpen; | 60 | bool bOpen; |
| 61 | }; | 61 | }; |
diff --git a/src/deflate.cpp b/src/deflate.cpp new file mode 100644 index 0000000..2d925a7 --- /dev/null +++ b/src/deflate.cpp | |||
| @@ -0,0 +1,249 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libbu++ library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include "bu/deflate.h" | ||
| 9 | #include "bu/trace.h" | ||
| 10 | |||
| 11 | #include <zlib.h> | ||
| 12 | |||
| 13 | #define pState ((z_stream *)prState) | ||
| 14 | |||
| 15 | using namespace Bu; | ||
| 16 | |||
| 17 | Bu::Deflate::Deflate( Bu::Stream &rNext, int nCompression, Format eFmt ) : | ||
| 18 | Bu::Filter( rNext ), | ||
| 19 | prState( NULL ), | ||
| 20 | nCompression( nCompression ), | ||
| 21 | sTotalOut( 0 ), | ||
| 22 | eFmt( eFmt ), | ||
| 23 | bEos( false ) | ||
| 24 | { | ||
| 25 | TRACE( nCompression ); | ||
| 26 | start(); | ||
| 27 | } | ||
| 28 | |||
| 29 | Bu::Deflate::~Deflate() | ||
| 30 | { | ||
| 31 | TRACE(); | ||
| 32 | stop(); | ||
| 33 | } | ||
| 34 | |||
| 35 | void Bu::Deflate::start() | ||
| 36 | { | ||
| 37 | TRACE(); | ||
| 38 | prState = new z_stream; | ||
| 39 | pState->zalloc = NULL; | ||
| 40 | pState->zfree = NULL; | ||
| 41 | pState->opaque = NULL; | ||
| 42 | pState->state = NULL; | ||
| 43 | |||
| 44 | nBufSize = 64*1024; | ||
| 45 | pBuf = new char[nBufSize]; | ||
| 46 | } | ||
| 47 | |||
| 48 | Bu::size Bu::Deflate::stop() | ||
| 49 | { | ||
| 50 | TRACE(); | ||
| 51 | if( pState && pState->state ) | ||
| 52 | { | ||
| 53 | if( bReading ) | ||
| 54 | { | ||
| 55 | inflateEnd( pState ); | ||
| 56 | delete[] pBuf; | ||
| 57 | pBuf = NULL; | ||
| 58 | delete pState; | ||
| 59 | prState = NULL; | ||
| 60 | return 0; | ||
| 61 | } | ||
| 62 | else | ||
| 63 | { | ||
| 64 | for(;;) | ||
| 65 | { | ||
| 66 | pState->next_in = NULL; | ||
| 67 | pState->avail_in = 0; | ||
| 68 | pState->avail_out = nBufSize; | ||
| 69 | pState->next_out = (Bytef *)pBuf; | ||
| 70 | int res = deflate( pState, Z_FINISH ); | ||
| 71 | if( pState->avail_out < nBufSize ) | ||
| 72 | { | ||
| 73 | sTotalOut += rNext.write( pBuf, nBufSize-pState->avail_out ); | ||
| 74 | } | ||
| 75 | if( res == Z_STREAM_END ) | ||
| 76 | break; | ||
| 77 | } | ||
| 78 | deflateEnd( pState ); | ||
| 79 | delete[] pBuf; | ||
| 80 | pBuf = NULL; | ||
| 81 | delete pState; | ||
| 82 | prState = NULL; | ||
| 83 | return sTotalOut; | ||
| 84 | } | ||
| 85 | } | ||
| 86 | return 0; | ||
| 87 | } | ||
| 88 | |||
| 89 | void Bu::Deflate::zError( int code ) | ||
| 90 | { | ||
| 91 | TRACE( code ); | ||
| 92 | switch( code ) | ||
| 93 | { | ||
| 94 | case Z_OK: | ||
| 95 | case Z_STREAM_END: | ||
| 96 | case Z_NEED_DICT: | ||
| 97 | return; | ||
| 98 | |||
| 99 | case Z_ERRNO: | ||
| 100 | throw ExceptionBase("Deflate: Errno - %s", pState->msg ); | ||
| 101 | |||
| 102 | case Z_STREAM_ERROR: | ||
| 103 | throw ExceptionBase("Deflate: Stream Error - %s", pState->msg ); | ||
| 104 | |||
| 105 | case Z_DATA_ERROR: | ||
| 106 | throw ExceptionBase("Deflate: Data Error - %s", pState->msg ); | ||
| 107 | |||
| 108 | case Z_MEM_ERROR: | ||
| 109 | throw ExceptionBase("Deflate: Mem Error - %s", pState->msg ); | ||
| 110 | |||
| 111 | case Z_BUF_ERROR: | ||
| 112 | throw ExceptionBase("Deflate: Buf Error - %s", pState->msg ); | ||
| 113 | |||
| 114 | case Z_VERSION_ERROR: | ||
| 115 | throw ExceptionBase("Deflate: Version Error - %s", pState->msg ); | ||
| 116 | |||
| 117 | default: | ||
| 118 | throw ExceptionBase("Deflate: Unknown error encountered - %s.", pState->msg ); | ||
| 119 | |||
| 120 | } | ||
| 121 | } | ||
| 122 | |||
| 123 | Bu::size Bu::Deflate::read( void *pData, Bu::size nBytes ) | ||
| 124 | { | ||
| 125 | TRACE( pData, nBytes ); | ||
| 126 | if( !pState->state ) | ||
| 127 | { | ||
| 128 | bReading = true; | ||
| 129 | if( eFmt&AutoDetect ) | ||
| 130 | inflateInit2( pState, 32+15 ); // Auto-detect, large window | ||
| 131 | else if( eFmt == Raw ) | ||
| 132 | inflateInit2( pState, -15 ); // Raw | ||
| 133 | else if( eFmt == Zlib ) | ||
| 134 | inflateInit2( pState, 15 ); // Zlib | ||
| 135 | else if( eFmt == Gzip ) | ||
| 136 | inflateInit2( pState, 16+15 ); // GZip | ||
| 137 | else | ||
| 138 | throw Bu::ExceptionBase("Format mode for deflate read."); | ||
| 139 | pState->next_in = (Bytef *)pBuf; | ||
| 140 | pState->avail_in = 0; | ||
| 141 | } | ||
| 142 | if( bReading == false ) | ||
| 143 | throw ExceptionBase("This deflate filter is in writing mode, you can't read."); | ||
| 144 | |||
| 145 | int nRead = 0; | ||
| 146 | int nReadTotal = pState->total_out; | ||
| 147 | pState->next_out = (Bytef *)pData; | ||
| 148 | pState->avail_out = nBytes; | ||
| 149 | for(;;) | ||
| 150 | { | ||
| 151 | int ret = inflate( pState, Z_NO_FLUSH ); | ||
| 152 | nReadTotal += nRead-pState->avail_out; | ||
| 153 | |||
| 154 | if( ret == Z_STREAM_END ) | ||
| 155 | { | ||
| 156 | bEos = true; | ||
| 157 | if( pState->avail_in > 0 ) | ||
| 158 | { | ||
| 159 | if( rNext.isSeekable() ) | ||
| 160 | { | ||
| 161 | rNext.seek( -pState->avail_in ); | ||
| 162 | } | ||
| 163 | } | ||
| 164 | return nBytes-pState->avail_out; | ||
| 165 | } | ||
| 166 | if( ret != Z_BUF_ERROR ) | ||
| 167 | zError( ret ); | ||
| 168 | |||
| 169 | if( pState->avail_out ) | ||
| 170 | { | ||
| 171 | if( pState->avail_in == 0 ) | ||
| 172 | { | ||
| 173 | nRead = rNext.read( pBuf, nBufSize ); | ||
| 174 | if( nRead == 0 && rNext.isEos() ) | ||
| 175 | { | ||
| 176 | throw Bu::ExceptionBase("Premature end of underlying " | ||
| 177 | "stream found reading deflate stream."); | ||
| 178 | } | ||
| 179 | pState->next_in = (Bytef *)pBuf; | ||
| 180 | pState->avail_in = nRead; | ||
| 181 | } | ||
| 182 | } | ||
| 183 | else | ||
| 184 | { | ||
| 185 | return nBytes-pState->avail_out; | ||
| 186 | } | ||
| 187 | } | ||
| 188 | return 0; | ||
| 189 | } | ||
| 190 | |||
| 191 | Bu::size Bu::Deflate::write( const void *pData, Bu::size nBytes ) | ||
| 192 | { | ||
| 193 | TRACE( pData, nBytes ); | ||
| 194 | if( !pState->state ) | ||
| 195 | { | ||
| 196 | bReading = false; | ||
| 197 | int iFmt = eFmt&Gzip; | ||
| 198 | if( iFmt == Raw ) | ||
| 199 | deflateInit2( pState, nCompression, Z_DEFLATED, -15, 9, | ||
| 200 | Z_DEFAULT_STRATEGY ); | ||
| 201 | else if( iFmt == Zlib ) | ||
| 202 | deflateInit2( pState, nCompression, Z_DEFLATED, 15, 9, | ||
| 203 | Z_DEFAULT_STRATEGY ); | ||
| 204 | else if( iFmt == Gzip ) | ||
| 205 | deflateInit2( pState, nCompression, Z_DEFLATED, 16+15, 9, | ||
| 206 | Z_DEFAULT_STRATEGY ); | ||
| 207 | else | ||
| 208 | throw Bu::ExceptionBase("Invalid format for deflate."); | ||
| 209 | } | ||
| 210 | if( bReading == true ) | ||
| 211 | throw ExceptionBase("This deflate filter is in reading mode, you can't write."); | ||
| 212 | |||
| 213 | pState->next_in = (Bytef *)pData; | ||
| 214 | pState->avail_in = nBytes; | ||
| 215 | for(;;) | ||
| 216 | { | ||
| 217 | pState->avail_out = nBufSize; | ||
| 218 | pState->next_out = (Bytef *)pBuf; | ||
| 219 | |||
| 220 | zError( deflate( pState, Z_NO_FLUSH ) ); | ||
| 221 | |||
| 222 | if( pState->avail_out < nBufSize ) | ||
| 223 | { | ||
| 224 | sTotalOut += rNext.write( pBuf, nBufSize-pState->avail_out ); | ||
| 225 | } | ||
| 226 | if( pState->avail_in == 0 ) | ||
| 227 | break; | ||
| 228 | } | ||
| 229 | |||
| 230 | return nBytes; | ||
| 231 | } | ||
| 232 | |||
| 233 | bool Bu::Deflate::isOpen() | ||
| 234 | { | ||
| 235 | TRACE(); | ||
| 236 | return (pState != NULL && pState->state != NULL); | ||
| 237 | } | ||
| 238 | |||
| 239 | bool Bu::Deflate::isEos() | ||
| 240 | { | ||
| 241 | TRACE(); | ||
| 242 | return bEos; | ||
| 243 | } | ||
| 244 | |||
| 245 | Bu::size Bu::Deflate::getCompressedSize() | ||
| 246 | { | ||
| 247 | return sTotalOut; | ||
| 248 | } | ||
| 249 | |||
diff --git a/src/deflate.h b/src/deflate.h new file mode 100644 index 0000000..f835cfc --- /dev/null +++ b/src/deflate.h | |||
| @@ -0,0 +1,66 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libbu++ library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #ifndef BU_DEFLATE_H | ||
| 9 | #define BU_DEFLATE_H | ||
| 10 | |||
| 11 | #include <stdint.h> | ||
| 12 | |||
| 13 | #include "bu/filter.h" | ||
| 14 | |||
| 15 | namespace Bu | ||
| 16 | { | ||
| 17 | /** | ||
| 18 | * Provides Deflate (LZ77) support via zlib. This provides zlib, raw, and | ||
| 19 | * gzip stream types. By default it will autodetect the input type and | ||
| 20 | * encode into a raw deflate stream. | ||
| 21 | * | ||
| 22 | *@ingroup Streams | ||
| 23 | *@ingroup Compression | ||
| 24 | */ | ||
| 25 | class Deflate : public Bu::Filter | ||
| 26 | { | ||
| 27 | public: | ||
| 28 | enum Format | ||
| 29 | { | ||
| 30 | Raw = 0x01, | ||
| 31 | Zlib = 0x02, | ||
| 32 | Gzip = 0x03, | ||
| 33 | AutoDetect = 0x04, | ||
| 34 | |||
| 35 | AutoRaw = 0x04|0x01, | ||
| 36 | AutoZlib = 0x04|0x02, | ||
| 37 | AutoGzip = 0x04|0x03 | ||
| 38 | }; | ||
| 39 | |||
| 40 | Deflate( Bu::Stream &rNext, int nCompression=-1, Format eFmt=AutoZlib ); | ||
| 41 | virtual ~Deflate(); | ||
| 42 | |||
| 43 | virtual void start(); | ||
| 44 | virtual Bu::size stop(); | ||
| 45 | virtual Bu::size read( void *pBuf, Bu::size nBytes ); | ||
| 46 | virtual Bu::size write( const void *pBuf, Bu::size nBytes ); | ||
| 47 | |||
| 48 | virtual bool isOpen(); | ||
| 49 | virtual bool isEos(); | ||
| 50 | |||
| 51 | Bu::size getCompressedSize(); | ||
| 52 | |||
| 53 | private: | ||
| 54 | void zError( int code ); | ||
| 55 | void *prState; | ||
| 56 | bool bReading; | ||
| 57 | int nCompression; | ||
| 58 | char *pBuf; | ||
| 59 | uint32_t nBufSize; | ||
| 60 | Bu::size sTotalOut; | ||
| 61 | Format eFmt; | ||
| 62 | bool bEos; | ||
| 63 | }; | ||
| 64 | } | ||
| 65 | |||
| 66 | #endif | ||
diff --git a/src/doxy/groups.dox b/src/doxy/groups.dox index 479186a..6b7cd57 100644 --- a/src/doxy/groups.dox +++ b/src/doxy/groups.dox | |||
| @@ -29,3 +29,8 @@ | |||
| 29 | *@defgroup Streams Streams | 29 | *@defgroup Streams Streams |
| 30 | * Streams are for data. | 30 | * Streams are for data. |
| 31 | */ | 31 | */ |
| 32 | |||
| 33 | /** | ||
| 34 | *@defgroup Compression Compression | ||
| 35 | * Filters that give access to common compression libraries. | ||
| 36 | */ | ||
diff --git a/src/formatter.h b/src/formatter.h index 5840323..80a55ab 100644 --- a/src/formatter.h +++ b/src/formatter.h | |||
| @@ -135,7 +135,6 @@ namespace Bu | |||
| 135 | void ffmt( type f ) | 135 | void ffmt( type f ) |
| 136 | { | 136 | { |
| 137 | Bu::String fTmp; | 137 | Bu::String fTmp; |
| 138 | bool bNeg = false; | ||
| 139 | char cBase = fLast.bCaps?'A':'a'; | 138 | char cBase = fLast.bCaps?'A':'a'; |
| 140 | if( fLast.uRadix < 2 || fLast.uRadix > 36 ) | 139 | if( fLast.uRadix < 2 || fLast.uRadix > 36 ) |
| 141 | { | 140 | { |
| @@ -145,7 +144,6 @@ namespace Bu | |||
| 145 | 144 | ||
| 146 | if( signbit(f) ) | 145 | if( signbit(f) ) |
| 147 | { | 146 | { |
| 148 | bNeg = true; | ||
| 149 | f = -f; | 147 | f = -f; |
| 150 | fTmp += "-"; | 148 | fTmp += "-"; |
| 151 | } | 149 | } |
| @@ -228,7 +226,9 @@ namespace Bu | |||
| 228 | template<typename type> | 226 | template<typename type> |
| 229 | void fparse( type &f, const Bu::String &sBuf ) | 227 | void fparse( type &f, const Bu::String &sBuf ) |
| 230 | { | 228 | { |
| 231 | sscanf( sBuf.getStr(), "%f", &f ); | 229 | double fIn; |
| 230 | sscanf( sBuf.getStr(), "%lf", &fIn ); | ||
| 231 | f = fIn; | ||
| 232 | usedFormat(); | 232 | usedFormat(); |
| 233 | } | 233 | } |
| 234 | 234 | ||
diff --git a/src/hex.cpp b/src/hex.cpp new file mode 100644 index 0000000..2a04c6f --- /dev/null +++ b/src/hex.cpp | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libbu++ library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include "bu/hex.h" | ||
| 9 | |||
| 10 | Bu::Hex::Hex( Bu::Stream &rNext, bool bUpperCase, int iChunk ) : | ||
| 11 | Bu::Filter( rNext ), | ||
| 12 | iChunk( iChunk ), | ||
| 13 | iPos( 0 ), | ||
| 14 | iIn( 0 ), | ||
| 15 | sChrs(bUpperCase?"0123456789ABCDEF":"0123456789abcdef") | ||
| 16 | { | ||
| 17 | } | ||
| 18 | |||
| 19 | Bu::Hex::~Hex() | ||
| 20 | { | ||
| 21 | } | ||
| 22 | |||
| 23 | void Bu::Hex::start() | ||
| 24 | { | ||
| 25 | iPos = iIn = 0; | ||
| 26 | } | ||
| 27 | |||
| 28 | Bu::size Bu::Hex::stop() | ||
| 29 | { | ||
| 30 | return iPos; | ||
| 31 | } | ||
| 32 | |||
| 33 | Bu::size Bu::Hex::read( void *pBuf, Bu::size iBytes ) | ||
| 34 | { | ||
| 35 | Bu::size j; | ||
| 36 | uint8_t *puBuf = (uint8_t *)pBuf; | ||
| 37 | for( j = 0; j < iBytes; j++ ) | ||
| 38 | { | ||
| 39 | for(; iIn < 2; iIn++ ) | ||
| 40 | { | ||
| 41 | if( rNext.read( &cIn[iIn], 1 ) == 0 ) | ||
| 42 | return j; | ||
| 43 | if( cIn[iIn] == ' ' || cIn[iIn] == '\t' || | ||
| 44 | cIn[iIn] == '\n' || cIn[iIn] == '\r' ) | ||
| 45 | iIn--; | ||
| 46 | } | ||
| 47 | #define chr2nibble( c ) ((c>='0'&&c<='9')?(c-'0'):((c|0x60)-'a'+10)) | ||
| 48 | puBuf[j] = ((chr2nibble(cIn[0])<<4)|chr2nibble(cIn[1])); | ||
| 49 | iIn = 0; | ||
| 50 | } | ||
| 51 | return j; | ||
| 52 | } | ||
| 53 | |||
| 54 | Bu::size Bu::Hex::write( const void *pBuf, Bu::size iBytes ) | ||
| 55 | { | ||
| 56 | char cOut[2]; | ||
| 57 | uint8_t *puBuf = (uint8_t *)pBuf; | ||
| 58 | for( Bu::size j = 0; j < iBytes; j++ ) | ||
| 59 | { | ||
| 60 | cOut[0] = sChrs[(puBuf[j]&0xf0)>>4]; | ||
| 61 | cOut[1] = sChrs[(puBuf[j]&0x0f)]; | ||
| 62 | if( iChunk > 0 && iPos%iChunk == 0 && iPos>0 ) | ||
| 63 | rNext.write(" ", 1 ); | ||
| 64 | rNext.write( cOut, 2 ); | ||
| 65 | iPos++; | ||
| 66 | } | ||
| 67 | return iBytes; | ||
| 68 | } | ||
| 69 | |||
diff --git a/src/hex.h b/src/hex.h new file mode 100644 index 0000000..3595fae --- /dev/null +++ b/src/hex.h | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libbu++ library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #ifndef BU_HEX_H | ||
| 9 | #define BU_HEX_H | ||
| 10 | |||
| 11 | #include "bu/filter.h" | ||
| 12 | |||
| 13 | namespace Bu | ||
| 14 | { | ||
| 15 | /** | ||
| 16 | * This very simple filter encodes to/decodes from hex encoded string data. | ||
| 17 | * The primary use of this filter is in debugging, use it with | ||
| 18 | * Bu::encodeStr to easily create hex dumps of string data, even other raw | ||
| 19 | * structures. | ||
| 20 | * | ||
| 21 | *@code | ||
| 22 | Bu::println("Hexdump: " + Bu::encodeStr<Bu::Hex>("Test data ;)") ); | ||
| 23 | @endcode | ||
| 24 | * Or... | ||
| 25 | *@code | ||
| 26 | complex_struct data; | ||
| 27 | ... | ||
| 28 | Bu::println("Hexdump: " + | ||
| 29 | Bu::encodeStr<Bu::Hex>( | ||
| 30 | Bu::String( &data, sizeof(data) ) | ||
| 31 | ) | ||
| 32 | ); | ||
| 33 | @endcode | ||
| 34 | **/ | ||
| 35 | class Hex : public Bu::Filter | ||
| 36 | { | ||
| 37 | public: | ||
| 38 | Hex( Bu::Stream &rNext, bool bUpperCase=false, int iChunk=-1 ); | ||
| 39 | virtual ~Hex(); | ||
| 40 | |||
| 41 | virtual void start(); | ||
| 42 | virtual Bu::size stop(); | ||
| 43 | |||
| 44 | virtual Bu::size read( void *pBuf, Bu::size iBytes ); | ||
| 45 | virtual Bu::size write( const void *pBuf, Bu::size iBytes ); | ||
| 46 | using Bu::Stream::write; | ||
| 47 | |||
| 48 | private: | ||
| 49 | int iChunk; | ||
| 50 | Bu::size iPos; | ||
| 51 | char cIn[2]; | ||
| 52 | int iIn; | ||
| 53 | const char *sChrs; | ||
| 54 | }; | ||
| 55 | }; | ||
| 56 | |||
| 57 | #endif | ||
diff --git a/src/itolocker.cpp b/src/itolocker.cpp deleted file mode 100644 index 17e97fd..0000000 --- a/src/itolocker.cpp +++ /dev/null | |||
| @@ -1,13 +0,0 @@ | |||
| 1 | #include "bu/itolocker.h" | ||
| 2 | #include "bu/itomutex.h" | ||
| 3 | |||
| 4 | Bu::ItoLocker::ItoLocker( Bu::ItoMutex &mu ) : | ||
| 5 | mu( mu ) | ||
| 6 | { | ||
| 7 | mu.lock(); | ||
| 8 | } | ||
| 9 | |||
| 10 | Bu::ItoLocker::~ItoLocker() | ||
| 11 | { | ||
| 12 | mu.unlock(); | ||
| 13 | } | ||
diff --git a/src/itolocker.h b/src/itolocker.h deleted file mode 100644 index 76e5198..0000000 --- a/src/itolocker.h +++ /dev/null | |||
| @@ -1,18 +0,0 @@ | |||
| 1 | #ifndef BU_ITO_LOCKER_H | ||
| 2 | #define BU_ITO_LOCKER_H | ||
| 3 | |||
| 4 | namespace Bu | ||
| 5 | { | ||
| 6 | class ItoMutex; | ||
| 7 | class ItoLocker | ||
| 8 | { | ||
| 9 | public: | ||
| 10 | ItoLocker( ItoMutex &mu ); | ||
| 11 | virtual ~ItoLocker(); | ||
| 12 | |||
| 13 | private: | ||
| 14 | ItoMutex & mu; | ||
| 15 | }; | ||
| 16 | }; | ||
| 17 | |||
| 18 | #endif | ||
diff --git a/src/itoserver.cpp b/src/itoserver.cpp index 9f03417..c7165e2 100644 --- a/src/itoserver.cpp +++ b/src/itoserver.cpp | |||
| @@ -80,7 +80,7 @@ void Bu::ItoServer::run() | |||
| 80 | struct timeval xTimeout = { nTimeoutSec, nTimeoutUSec }; | 80 | struct timeval xTimeout = { nTimeoutSec, nTimeoutUSec }; |
| 81 | 81 | ||
| 82 | fd_set fdRead = fdActive; | 82 | fd_set fdRead = fdActive; |
| 83 | fd_set fdWrite = fdActive; | 83 | //fd_set fdWrite = fdActive; |
| 84 | fd_set fdException = fdActive; | 84 | fd_set fdException = fdActive; |
| 85 | 85 | ||
| 86 | if( TEMP_FAILURE_RETRY( select( FD_SETSIZE, &fdRead, NULL, &fdException, &xTimeout ) ) < 0 ) | 86 | if( TEMP_FAILURE_RETRY( select( FD_SETSIZE, &fdRead, NULL, &fdException, &xTimeout ) ) < 0 ) |
diff --git a/src/itoserver.h b/src/itoserver.h index 902c684..b1f5479 100644 --- a/src/itoserver.h +++ b/src/itoserver.h | |||
| @@ -16,9 +16,9 @@ | |||
| 16 | 16 | ||
| 17 | #include "bu/string.h" | 17 | #include "bu/string.h" |
| 18 | #include "bu/list.h" | 18 | #include "bu/list.h" |
| 19 | #include "bu/ito.h" | 19 | #include "bu/thread.h" |
| 20 | #include "bu/itomutex.h" | 20 | #include "bu/mutex.h" |
| 21 | #include "bu/itoqueue.h" | 21 | #include "bu/synchroqueue.h" |
| 22 | #include "bu/set.h" | 22 | #include "bu/set.h" |
| 23 | 23 | ||
| 24 | #include "bu/clientlink.h" | 24 | #include "bu/clientlink.h" |
| @@ -50,7 +50,7 @@ namespace Bu | |||
| 50 | * happening within the server itself, and actually makes it useful. | 50 | * happening within the server itself, and actually makes it useful. |
| 51 | *@ingroup Threading Serving | 51 | *@ingroup Threading Serving |
| 52 | */ | 52 | */ |
| 53 | class ItoServer : public Ito | 53 | class ItoServer : public Thread |
| 54 | { | 54 | { |
| 55 | friend class ItoClient; | 55 | friend class ItoClient; |
| 56 | friend class SrvClientLinkFactory; | 56 | friend class SrvClientLinkFactory; |
| @@ -74,7 +74,7 @@ namespace Bu | |||
| 74 | 74 | ||
| 75 | private: | 75 | private: |
| 76 | class SrvClientLink; | 76 | class SrvClientLink; |
| 77 | class ItoClient : public Ito | 77 | class ItoClient : public Thread |
| 78 | { | 78 | { |
| 79 | friend class Bu::ItoServer::SrvClientLink; | 79 | friend class Bu::ItoServer::SrvClientLink; |
| 80 | public: | 80 | public: |
| @@ -82,7 +82,7 @@ namespace Bu | |||
| 82 | int nTimeoutSec, int nTimeoutUSec ); | 82 | int nTimeoutSec, int nTimeoutUSec ); |
| 83 | virtual ~ItoClient(); | 83 | virtual ~ItoClient(); |
| 84 | 84 | ||
| 85 | typedef ItoQueue<Bu::String *> StringQueue; | 85 | typedef SynchroQueue<Bu::String *> StringQueue; |
| 86 | StringQueue qMsg; | 86 | StringQueue qMsg; |
| 87 | 87 | ||
| 88 | protected: | 88 | protected: |
| @@ -96,7 +96,7 @@ namespace Bu | |||
| 96 | int iPort; | 96 | int iPort; |
| 97 | int nTimeoutSec; | 97 | int nTimeoutSec; |
| 98 | int nTimeoutUSec; | 98 | int nTimeoutUSec; |
| 99 | ItoMutex imProto; | 99 | Mutex imProto; |
| 100 | }; | 100 | }; |
| 101 | 101 | ||
| 102 | class SrvClientLink : public Bu::ClientLink | 102 | class SrvClientLink : public Bu::ClientLink |
| @@ -129,10 +129,10 @@ namespace Bu | |||
| 129 | typedef Hash<int,TcpServerSocket *> ServerHash; | 129 | typedef Hash<int,TcpServerSocket *> ServerHash; |
| 130 | ServerHash hServers; | 130 | ServerHash hServers; |
| 131 | typedef Hash<int,ItoClient *> ClientHash; | 131 | typedef Hash<int,ItoClient *> ClientHash; |
| 132 | typedef ItoQueue<ItoClient *> ClientQueue; | 132 | typedef SynchroQueue<ItoClient *> ClientQueue; |
| 133 | ClientHash hClients; | 133 | ClientHash hClients; |
| 134 | ClientQueue qClientCleanup; | 134 | ClientQueue qClientCleanup; |
| 135 | ItoMutex imClients; | 135 | Mutex imClients; |
| 136 | 136 | ||
| 137 | void clientCleanup( int iSocket ); | 137 | void clientCleanup( int iSocket ); |
| 138 | }; | 138 | }; |
diff --git a/src/lzma.cpp b/src/lzma.cpp new file mode 100644 index 0000000..6ed0806 --- /dev/null +++ b/src/lzma.cpp | |||
| @@ -0,0 +1,248 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libbu++ library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include "bu/lzma.h" | ||
| 9 | #include "bu/trace.h" | ||
| 10 | |||
| 11 | #include <lzma.h> | ||
| 12 | |||
| 13 | #define pState ((lzma_stream *)prState) | ||
| 14 | |||
| 15 | using namespace Bu; | ||
| 16 | |||
| 17 | Bu::Lzma::Lzma( Bu::Stream &rNext, int nCompression, Format eFmt ) : | ||
| 18 | Bu::Filter( rNext ), | ||
| 19 | prState( NULL ), | ||
| 20 | nCompression( nCompression ), | ||
| 21 | sTotalOut( 0 ), | ||
| 22 | eFmt( eFmt ), | ||
| 23 | bEos( false ) | ||
| 24 | { | ||
| 25 | TRACE( nCompression ); | ||
| 26 | start(); | ||
| 27 | } | ||
| 28 | |||
| 29 | Bu::Lzma::~Lzma() | ||
| 30 | { | ||
| 31 | TRACE(); | ||
| 32 | stop(); | ||
| 33 | } | ||
| 34 | |||
| 35 | void Bu::Lzma::start() | ||
| 36 | { | ||
| 37 | TRACE(); | ||
| 38 | nBufSize = 64*1024; | ||
| 39 | pBuf = new char[nBufSize]; | ||
| 40 | } | ||
| 41 | |||
| 42 | Bu::size Bu::Lzma::stop() | ||
| 43 | { | ||
| 44 | TRACE(); | ||
| 45 | if( pState ) | ||
| 46 | { | ||
| 47 | if( bReading ) | ||
| 48 | { | ||
| 49 | lzma_end( pState ); | ||
| 50 | delete[] pBuf; | ||
| 51 | pBuf = NULL; | ||
| 52 | delete pState; | ||
| 53 | prState = NULL; | ||
| 54 | return 0; | ||
| 55 | } | ||
| 56 | else | ||
| 57 | { | ||
| 58 | for(;;) | ||
| 59 | { | ||
| 60 | pState->next_in = NULL; | ||
| 61 | pState->avail_in = 0; | ||
| 62 | pState->avail_out = nBufSize; | ||
| 63 | pState->next_out = (uint8_t *)pBuf; | ||
| 64 | int res = lzma_code( pState, LZMA_FINISH ); | ||
| 65 | if( pState->avail_out < nBufSize ) | ||
| 66 | { | ||
| 67 | sTotalOut += rNext.write( pBuf, nBufSize-pState->avail_out ); | ||
| 68 | } | ||
| 69 | if( res == LZMA_STREAM_END ) | ||
| 70 | break; | ||
| 71 | } | ||
| 72 | lzma_end( pState ); | ||
| 73 | delete[] pBuf; | ||
| 74 | pBuf = NULL; | ||
| 75 | delete pState; | ||
| 76 | prState = NULL; | ||
| 77 | return sTotalOut; | ||
| 78 | } | ||
| 79 | } | ||
| 80 | return 0; | ||
| 81 | } | ||
| 82 | |||
| 83 | void Bu::Lzma::lzmaError( int code ) | ||
| 84 | { | ||
| 85 | TRACE( code ); | ||
| 86 | switch( code ) | ||
| 87 | { | ||
| 88 | case LZMA_OK: | ||
| 89 | case LZMA_STREAM_END: | ||
| 90 | case LZMA_NO_CHECK: | ||
| 91 | case LZMA_UNSUPPORTED_CHECK: | ||
| 92 | break; | ||
| 93 | |||
| 94 | case LZMA_MEM_ERROR: | ||
| 95 | throw ExceptionBase("Lzma: Memory allocation error."); | ||
| 96 | |||
| 97 | case LZMA_MEMLIMIT_ERROR: | ||
| 98 | throw ExceptionBase("Lzma: Memory usage limit was reached."); | ||
| 99 | |||
| 100 | case LZMA_FORMAT_ERROR: | ||
| 101 | throw ExceptionBase("Lzma: File format not recognized."); | ||
| 102 | |||
| 103 | case LZMA_OPTIONS_ERROR: | ||
| 104 | throw ExceptionBase("Lzma: Invalid or unsupported options."); | ||
| 105 | |||
| 106 | case LZMA_DATA_ERROR: | ||
| 107 | throw ExceptionBase("Lzma: Data is corrupt."); | ||
| 108 | |||
| 109 | case LZMA_BUF_ERROR: | ||
| 110 | throw ExceptionBase("Lzma: No progress is possible."); | ||
| 111 | |||
| 112 | case LZMA_PROG_ERROR: | ||
| 113 | throw ExceptionBase("Lzma: Programming error."); | ||
| 114 | |||
| 115 | default: | ||
| 116 | throw ExceptionBase("Lzma: Unknown error encountered." ); | ||
| 117 | } | ||
| 118 | } | ||
| 119 | |||
| 120 | Bu::size Bu::Lzma::read( void *pData, Bu::size nBytes ) | ||
| 121 | { | ||
| 122 | TRACE( pData, nBytes ); | ||
| 123 | if( !pState ) | ||
| 124 | { | ||
| 125 | prState = new ::lzma_stream; | ||
| 126 | lzma_stream zEmpty = LZMA_STREAM_INIT; | ||
| 127 | Bu::memcpy( prState, &zEmpty, sizeof(lzma_stream) ); | ||
| 128 | |||
| 129 | bReading = true; | ||
| 130 | lzmaError( lzma_auto_decoder( pState, UINT64_MAX, 0 ) ); | ||
| 131 | pState->next_in = (uint8_t *)pBuf; | ||
| 132 | pState->avail_in = 0; | ||
| 133 | } | ||
| 134 | if( bReading == false ) | ||
| 135 | throw ExceptionBase("This lzma filter is in writing mode, you can't read."); | ||
| 136 | |||
| 137 | int nRead = 0; | ||
| 138 | int nReadTotal = pState->total_out; | ||
| 139 | pState->next_out = (uint8_t *)pData; | ||
| 140 | pState->avail_out = nBytes; | ||
| 141 | for(;;) | ||
| 142 | { | ||
| 143 | int ret = lzma_code( pState, LZMA_RUN ); | ||
| 144 | printf("inflate returned %d; avail in=%d, out=%d\n", ret, | ||
| 145 | pState->avail_in, pState->avail_out ); | ||
| 146 | |||
| 147 | nReadTotal += nRead-pState->avail_out; | ||
| 148 | |||
| 149 | if( ret == LZMA_STREAM_END ) | ||
| 150 | { | ||
| 151 | bEos = true; | ||
| 152 | if( pState->avail_in > 0 ) | ||
| 153 | { | ||
| 154 | if( rNext.isSeekable() ) | ||
| 155 | { | ||
| 156 | rNext.seek( -pState->avail_in ); | ||
| 157 | } | ||
| 158 | } | ||
| 159 | return nBytes-pState->avail_out; | ||
| 160 | } | ||
| 161 | // if( ret != LZMA_BUF_ERROR ) | ||
| 162 | lzmaError( ret ); | ||
| 163 | |||
| 164 | if( pState->avail_out ) | ||
| 165 | { | ||
| 166 | if( pState->avail_in == 0 ) | ||
| 167 | { | ||
| 168 | nRead = rNext.read( pBuf, nBufSize ); | ||
| 169 | if( nRead == 0 && rNext.isEos() ) | ||
| 170 | { | ||
| 171 | throw Bu::ExceptionBase("Premature end of underlying " | ||
| 172 | "stream found reading deflate stream."); | ||
| 173 | } | ||
| 174 | pState->next_in = (uint8_t *)pBuf; | ||
| 175 | pState->avail_in = nRead; | ||
| 176 | } | ||
| 177 | } | ||
| 178 | else | ||
| 179 | { | ||
| 180 | return nBytes-pState->avail_out; | ||
| 181 | } | ||
| 182 | } | ||
| 183 | return 0; | ||
| 184 | } | ||
| 185 | |||
| 186 | Bu::size Bu::Lzma::write( const void *pData, Bu::size nBytes ) | ||
| 187 | { | ||
| 188 | TRACE( pData, nBytes ); | ||
| 189 | if( !pState ) | ||
| 190 | { | ||
| 191 | prState = new ::lzma_stream; | ||
| 192 | lzma_stream zEmpty = LZMA_STREAM_INIT; | ||
| 193 | Bu::memcpy( prState, &zEmpty, sizeof(lzma_stream) ); | ||
| 194 | |||
| 195 | bReading = false; | ||
| 196 | if( eFmt == Xz ) | ||
| 197 | lzmaError( | ||
| 198 | lzma_easy_encoder( pState, nCompression, LZMA_CHECK_CRC64 ) | ||
| 199 | ); | ||
| 200 | else if( eFmt == LzmaAlone ) | ||
| 201 | { | ||
| 202 | lzma_options_lzma opt; | ||
| 203 | lzma_lzma_preset( &opt, nCompression ); | ||
| 204 | lzmaError( lzma_alone_encoder( pState, &opt ) ); | ||
| 205 | } | ||
| 206 | else | ||
| 207 | throw Bu::ExceptionBase("Invalid format for lzma."); | ||
| 208 | } | ||
| 209 | if( bReading == true ) | ||
| 210 | throw ExceptionBase("This lzma filter is in reading mode, you can't write."); | ||
| 211 | |||
| 212 | pState->next_in = (uint8_t *)pData; | ||
| 213 | pState->avail_in = nBytes; | ||
| 214 | for(;;) | ||
| 215 | { | ||
| 216 | pState->avail_out = nBufSize; | ||
| 217 | pState->next_out = (uint8_t *)pBuf; | ||
| 218 | |||
| 219 | lzmaError( lzma_code( pState, LZMA_RUN ) ); | ||
| 220 | |||
| 221 | if( pState->avail_out < nBufSize ) | ||
| 222 | { | ||
| 223 | sTotalOut += rNext.write( pBuf, nBufSize-pState->avail_out ); | ||
| 224 | } | ||
| 225 | if( pState->avail_in == 0 ) | ||
| 226 | break; | ||
| 227 | } | ||
| 228 | |||
| 229 | return nBytes; | ||
| 230 | } | ||
| 231 | |||
| 232 | bool Bu::Lzma::isOpen() | ||
| 233 | { | ||
| 234 | TRACE(); | ||
| 235 | return (pState != NULL); | ||
| 236 | } | ||
| 237 | |||
| 238 | bool Bu::Lzma::isEos() | ||
| 239 | { | ||
| 240 | TRACE(); | ||
| 241 | return bEos; | ||
| 242 | } | ||
| 243 | |||
| 244 | Bu::size Bu::Lzma::getCompressedSize() | ||
| 245 | { | ||
| 246 | return sTotalOut; | ||
| 247 | } | ||
| 248 | |||
diff --git a/src/lzma.h b/src/lzma.h new file mode 100644 index 0000000..090da8d --- /dev/null +++ b/src/lzma.h | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libbu++ library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #ifndef BU_LZMA_H | ||
| 9 | #define BU_LZMA_H | ||
| 10 | |||
| 11 | #include <stdint.h> | ||
| 12 | |||
| 13 | #include "bu/filter.h" | ||
| 14 | |||
| 15 | namespace Bu | ||
| 16 | { | ||
| 17 | /** | ||
| 18 | * Provides XZ compression and decompression, both LZMA1 (LzmaAlone) as | ||
| 19 | * well as the newer LZMA2 (xz) format. This uses .xz by default. | ||
| 20 | * | ||
| 21 | *@ingroup Streams | ||
| 22 | *@ingroup Compression | ||
| 23 | */ | ||
| 24 | class Lzma : public Bu::Filter | ||
| 25 | { | ||
| 26 | public: | ||
| 27 | enum Format | ||
| 28 | { | ||
| 29 | Xz = 0x01, | ||
| 30 | LzmaAlone = 0x02, | ||
| 31 | }; | ||
| 32 | |||
| 33 | Lzma( Bu::Stream &rNext, int nCompression=6, Format eFmt=Xz ); | ||
| 34 | virtual ~Lzma(); | ||
| 35 | |||
| 36 | virtual void start(); | ||
| 37 | virtual Bu::size stop(); | ||
| 38 | virtual Bu::size read( void *pBuf, Bu::size nBytes ); | ||
| 39 | virtual Bu::size write( const void *pBuf, Bu::size nBytes ); | ||
| 40 | |||
| 41 | virtual bool isOpen(); | ||
| 42 | virtual bool isEos(); | ||
| 43 | |||
| 44 | Bu::size getCompressedSize(); | ||
| 45 | |||
| 46 | private: | ||
| 47 | void lzmaError( int code ); | ||
| 48 | void *prState; | ||
| 49 | bool bReading; | ||
| 50 | int nCompression; | ||
| 51 | char *pBuf; | ||
| 52 | uint32_t nBufSize; | ||
| 53 | Bu::size sTotalOut; | ||
| 54 | Format eFmt; | ||
| 55 | bool bEos; | ||
| 56 | }; | ||
| 57 | } | ||
| 58 | |||
| 59 | #endif | ||
diff --git a/src/itomutex.cpp b/src/mutex.cpp index 8de6336..dbaaece 100644 --- a/src/itomutex.cpp +++ b/src/mutex.cpp | |||
| @@ -5,29 +5,29 @@ | |||
| 5 | * terms of the license contained in the file LICENSE. | 5 | * terms of the license contained in the file LICENSE. |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | #include "bu/itomutex.h" | 8 | #include "bu/mutex.h" |
| 9 | 9 | ||
| 10 | Bu::ItoMutex::ItoMutex() | 10 | Bu::Mutex::Mutex() |
| 11 | { | 11 | { |
| 12 | pthread_mutex_init( &mutex, NULL ); | 12 | pthread_mutex_init( &mutex, NULL ); |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | Bu::ItoMutex::~ItoMutex() | 15 | Bu::Mutex::~Mutex() |
| 16 | { | 16 | { |
| 17 | pthread_mutex_destroy( &mutex ); | 17 | pthread_mutex_destroy( &mutex ); |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | int Bu::ItoMutex::lock() | 20 | int Bu::Mutex::lock() |
| 21 | { | 21 | { |
| 22 | return pthread_mutex_lock( &mutex ); | 22 | return pthread_mutex_lock( &mutex ); |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | int Bu::ItoMutex::unlock() | 25 | int Bu::Mutex::unlock() |
| 26 | { | 26 | { |
| 27 | return pthread_mutex_unlock( &mutex ); | 27 | return pthread_mutex_unlock( &mutex ); |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | int Bu::ItoMutex::trylock() | 30 | int Bu::Mutex::trylock() |
| 31 | { | 31 | { |
| 32 | return pthread_mutex_trylock( &mutex ); | 32 | return pthread_mutex_trylock( &mutex ); |
| 33 | } | 33 | } |
diff --git a/src/itomutex.h b/src/mutex.h index 68a0c1d..b5c8b7a 100644 --- a/src/itomutex.h +++ b/src/mutex.h | |||
| @@ -5,8 +5,8 @@ | |||
| 5 | * terms of the license contained in the file LICENSE. | 5 | * terms of the license contained in the file LICENSE. |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | #ifndef BU_ITO_MUTEX_H | 8 | #ifndef BU_MUTEX_H |
| 9 | #define BU_ITO_MUTEX_H | 9 | #define BU_MUTEX_H |
| 10 | 10 | ||
| 11 | #include <pthread.h> | 11 | #include <pthread.h> |
| 12 | 12 | ||
| @@ -19,13 +19,13 @@ namespace Bu | |||
| 19 | * or initing them. | 19 | * or initing them. |
| 20 | *@ingroup Threading | 20 | *@ingroup Threading |
| 21 | */ | 21 | */ |
| 22 | class ItoMutex | 22 | class Mutex |
| 23 | { | 23 | { |
| 24 | public: | 24 | public: |
| 25 | /** | 25 | /** |
| 26 | * Create an unlocked mutex. | 26 | * Create an unlocked mutex. |
| 27 | */ | 27 | */ |
| 28 | ItoMutex(); | 28 | Mutex(); |
| 29 | 29 | ||
| 30 | /** | 30 | /** |
| 31 | * Destroy a mutex. This can only be done when a mutex is unlocked. | 31 | * Destroy a mutex. This can only be done when a mutex is unlocked. |
| @@ -33,7 +33,7 @@ namespace Bu | |||
| 33 | * wait for the mutex to unlock, the odds of which are usually farily | 33 | * wait for the mutex to unlock, the odds of which are usually farily |
| 34 | * low at deconstruction time. | 34 | * low at deconstruction time. |
| 35 | */ | 35 | */ |
| 36 | ~ItoMutex(); | 36 | ~Mutex(); |
| 37 | 37 | ||
| 38 | /** | 38 | /** |
| 39 | * Lock the mutex. This causes all future calls to lock on this | 39 | * Lock the mutex. This causes all future calls to lock on this |
diff --git a/src/mutexlocker.cpp b/src/mutexlocker.cpp new file mode 100644 index 0000000..90b730e --- /dev/null +++ b/src/mutexlocker.cpp | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | #include "bu/mutexlocker.h" | ||
| 2 | #include "bu/mutex.h" | ||
| 3 | |||
| 4 | Bu::MutexLocker::MutexLocker( Bu::Mutex &mu ) : | ||
| 5 | mu( mu ) | ||
| 6 | { | ||
| 7 | mu.lock(); | ||
| 8 | } | ||
| 9 | |||
| 10 | Bu::MutexLocker::~MutexLocker() | ||
| 11 | { | ||
| 12 | mu.unlock(); | ||
| 13 | } | ||
| 14 | |||
| 15 | void Bu::MutexLocker::unlock() | ||
| 16 | { | ||
| 17 | mu.unlock(); | ||
| 18 | } | ||
| 19 | |||
| 20 | void Bu::MutexLocker::relock() | ||
| 21 | { | ||
| 22 | mu.lock(); | ||
| 23 | } | ||
| 24 | |||
diff --git a/src/mutexlocker.h b/src/mutexlocker.h new file mode 100644 index 0000000..7c3c97e --- /dev/null +++ b/src/mutexlocker.h | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | #ifndef BU_MUTEX_LOCKER_H | ||
| 2 | #define BU_MUTEX_LOCKER_H | ||
| 3 | |||
| 4 | namespace Bu | ||
| 5 | { | ||
| 6 | class Mutex; | ||
| 7 | class MutexLocker | ||
| 8 | { | ||
| 9 | public: | ||
| 10 | MutexLocker( Mutex &mu ); | ||
| 11 | virtual ~MutexLocker(); | ||
| 12 | |||
| 13 | void unlock(); | ||
| 14 | void relock(); | ||
| 15 | |||
| 16 | private: | ||
| 17 | Mutex μ | ||
| 18 | }; | ||
| 19 | }; | ||
| 20 | |||
| 21 | #endif | ||
diff --git a/src/myriad.cpp b/src/myriad.cpp index b582df3..de44930 100644 --- a/src/myriad.cpp +++ b/src/myriad.cpp | |||
| @@ -128,7 +128,7 @@ void Bu::Myriad::initialize() | |||
| 128 | 128 | ||
| 129 | bsBlockUsed.setSize( iBlocks, true ); | 129 | bsBlockUsed.setSize( iBlocks, true ); |
| 130 | 130 | ||
| 131 | bool bCanSkip = false; // Can skip around, post initial header stream i/o | 131 | // bool bCanSkip = false; // Can skip around, post initial header stream i/o |
| 132 | MyriadStream *pIn = new MyriadStream( *this, pFakeHdr ); | 132 | MyriadStream *pIn = new MyriadStream( *this, pFakeHdr ); |
| 133 | pIn->setPos( sStore.tell() ); | 133 | pIn->setPos( sStore.tell() ); |
| 134 | for( int j = 0; j < iStreams; j++ ) | 134 | for( int j = 0; j < iStreams; j++ ) |
| @@ -156,7 +156,7 @@ void Bu::Myriad::initialize() | |||
| 156 | { | 156 | { |
| 157 | // sio << "Myriad: - End of prepartition, unlocking skipping." | 157 | // sio << "Myriad: - End of prepartition, unlocking skipping." |
| 158 | // << sio.nl; | 158 | // << sio.nl; |
| 159 | bCanSkip = true; | 159 | // bCanSkip = true; |
| 160 | MyriadStream *pTmp = new MyriadStream( *this, aStreams[0] ); | 160 | MyriadStream *pTmp = new MyriadStream( *this, aStreams[0] ); |
| 161 | // sio << "Myriad - Position = " << pIn->tell() << sio.nl; | 161 | // sio << "Myriad - Position = " << pIn->tell() << sio.nl; |
| 162 | pTmp->setPos( pIn->tell() ); | 162 | pTmp->setPos( pIn->tell() ); |
diff --git a/src/myriadfs.cpp b/src/myriadfs.cpp index cebae1c..6884a31 100644 --- a/src/myriadfs.cpp +++ b/src/myriadfs.cpp | |||
| @@ -112,7 +112,7 @@ void Bu::MyriadFs::stat( const Bu::String &sPath, Bu::MyriadFs::Stat &rBuf ) | |||
| 112 | stat( iNode, rBuf, is ); | 112 | stat( iNode, rBuf, is ); |
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | Bu::MyriadStream Bu::MyriadFs::open( const Bu::String &sPath, int iMode, | 115 | Bu::MyriadStream Bu::MyriadFs::open( const Bu::String &sPath, int /*iMode*/, |
| 116 | uint16_t uPerms ) | 116 | uint16_t uPerms ) |
| 117 | { | 117 | { |
| 118 | int32_t iParent = -1; | 118 | int32_t iParent = -1; |
| @@ -291,9 +291,9 @@ void Bu::MyriadFs::setTimes( const Bu::String &sPath, int64_t iATime, | |||
| 291 | void Bu::MyriadFs::unlink( const Bu::String &sPath ) | 291 | void Bu::MyriadFs::unlink( const Bu::String &sPath ) |
| 292 | { | 292 | { |
| 293 | int32_t iParent = -1; | 293 | int32_t iParent = -1; |
| 294 | int32_t iNode; | 294 | // int32_t iNode; |
| 295 | 295 | ||
| 296 | iNode = lookupInode( sPath, iParent ); | 296 | /*iNode =*/ lookupInode( sPath, iParent ); |
| 297 | 297 | ||
| 298 | Dir lDir = readDir( iParent ); | 298 | Dir lDir = readDir( iParent ); |
| 299 | 299 | ||
| @@ -660,7 +660,7 @@ void Bu::MyriadFs::destroyNode( int32_t iNode ) | |||
| 660 | Bu::MyriadStream is = mStore.openStream( 2 ); | 660 | Bu::MyriadStream is = mStore.openStream( 2 ); |
| 661 | 661 | ||
| 662 | // This will be overwritten with the last node | 662 | // This will be overwritten with the last node |
| 663 | int32_t iPosition = hNodeIndex.get( iNode ); | 663 | uint32_t iPosition = hNodeIndex.get( iNode ); |
| 664 | RawStat rsOld; | 664 | RawStat rsOld; |
| 665 | readInode( iNode, rsOld, is ); | 665 | readInode( iNode, rsOld, is ); |
| 666 | switch( (rsOld.uPerms&typeMask) ) | 666 | switch( (rsOld.uPerms&typeMask) ) |
diff --git a/src/optparser.cpp b/src/optparser.cpp index 74aba3e..050232c 100644 --- a/src/optparser.cpp +++ b/src/optparser.cpp | |||
| @@ -375,11 +375,9 @@ Bu::String Bu::OptParser::format( const Bu::String &sIn, int iWidth, | |||
| 375 | bool bSpace = false; | 375 | bool bSpace = false; |
| 376 | int iPrevLineLen; | 376 | int iPrevLineLen; |
| 377 | int iLineLen = 0; | 377 | int iLineLen = 0; |
| 378 | char c; | ||
| 379 | Bu::String::const_iterator iLastSpace, iStart; | 378 | Bu::String::const_iterator iLastSpace, iStart; |
| 380 | for( Bu::String::const_iterator i = iLastSpace = iStart = sIn.begin(); i; i++ ) | 379 | for( Bu::String::const_iterator i = iLastSpace = iStart = sIn.begin(); i; i++ ) |
| 381 | { | 380 | { |
| 382 | c = *i; | ||
| 383 | if( *i == ' ' ) | 381 | if( *i == ' ' ) |
| 384 | { | 382 | { |
| 385 | if( bSpace == false ) | 383 | if( bSpace == false ) |
diff --git a/src/programchain.cpp b/src/programchain.cpp deleted file mode 100644 index ce0c9cc..0000000 --- a/src/programchain.cpp +++ /dev/null | |||
| @@ -1,104 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libbu++ library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <stdlib.h> | ||
| 9 | #include "bu/programchain.h" | ||
| 10 | #include "bu/programlink.h" | ||
| 11 | |||
| 12 | using namespace Bu; | ||
| 13 | |||
| 14 | Bu::ProgramChain::ProgramChain() | ||
| 15 | { | ||
| 16 | } | ||
| 17 | |||
| 18 | Bu::ProgramChain::~ProgramChain() | ||
| 19 | { | ||
| 20 | } | ||
| 21 | |||
| 22 | bool Bu::ProgramChain::addLink( ProgramLink *pLink ) | ||
| 23 | { | ||
| 24 | if( pLink->init() == false ) | ||
| 25 | { | ||
| 26 | emergencyShutdown(); | ||
| 27 | return false; | ||
| 28 | } | ||
| 29 | |||
| 30 | lLink.append( pLink ); | ||
| 31 | |||
| 32 | pLink->setChain( this ); | ||
| 33 | |||
| 34 | return true; | ||
| 35 | } | ||
| 36 | |||
| 37 | ProgramLink *Bu::ProgramChain::getLink( const char *lpName ) | ||
| 38 | { | ||
| 39 | char a; | ||
| 40 | a = lpName[0]; | ||
| 41 | return NULL; | ||
| 42 | } | ||
| 43 | |||
| 44 | ProgramLink *Bu::ProgramChain::getBaseLink() | ||
| 45 | { | ||
| 46 | return NULL; | ||
| 47 | } | ||
| 48 | |||
| 49 | bool Bu::ProgramChain::execChainOnce() | ||
| 50 | { | ||
| 51 | for( Bu::List<Bu::ProgramLink *>::iterator i = lLink.begin(); | ||
| 52 | i != lLink.end(); i++ ) | ||
| 53 | { | ||
| 54 | if( (*i)->timeSlice() == false ) | ||
| 55 | { | ||
| 56 | emergencyShutdown(); | ||
| 57 | return false; | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | return true; | ||
| 62 | } | ||
| 63 | |||
| 64 | bool Bu::ProgramChain::enterChainLoop() | ||
| 65 | { | ||
| 66 | for(;;) | ||
| 67 | { | ||
| 68 | if( execChainOnce() == false ) | ||
| 69 | { | ||
| 70 | return false; | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | return true; | ||
| 75 | } | ||
| 76 | |||
| 77 | void Bu::ProgramChain::emergencyShutdown() | ||
| 78 | { | ||
| 79 | for( Bu::List<Bu::ProgramLink *>::iterator i = lLink.begin(); | ||
| 80 | i != lLink.end(); i++ ) | ||
| 81 | { | ||
| 82 | (*i)->deInit(); | ||
| 83 | delete *i; | ||
| 84 | } | ||
| 85 | lLink.clear(); | ||
| 86 | } | ||
| 87 | |||
| 88 | LinkMessage *Bu::ProgramChain::broadcastIRM( LinkMessage *pMsgOut, ProgramLink * /*pSender*/ ) | ||
| 89 | { | ||
| 90 | for( Bu::List<Bu::ProgramLink *>::iterator i = lLink.begin(); | ||
| 91 | i != lLink.end(); i++ ) | ||
| 92 | { | ||
| 93 | LinkMessage *pMsg = (*i)->processIRM( pMsgOut ); | ||
| 94 | if( pMsg != NULL ) | ||
| 95 | { | ||
| 96 | delete pMsgOut; | ||
| 97 | return pMsg; | ||
| 98 | } | ||
| 99 | } | ||
| 100 | |||
| 101 | delete pMsgOut; | ||
| 102 | return NULL; | ||
| 103 | } | ||
| 104 | |||
diff --git a/src/programchain.h b/src/programchain.h deleted file mode 100644 index 47797a2..0000000 --- a/src/programchain.h +++ /dev/null | |||
| @@ -1,99 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libbu++ library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #ifndef BU_PROGRAMCHAIN_H | ||
| 9 | #define BU_PROGRAMCHAIN_H | ||
| 10 | |||
| 11 | #include "bu/list.h" | ||
| 12 | #include "bu/linkmessage.h" | ||
| 13 | |||
| 14 | namespace Bu | ||
| 15 | { | ||
| 16 | class ProgramLink; | ||
| 17 | /** | ||
| 18 | * The Program Chain links together program "chunks" to more easily facilitate | ||
| 19 | * a generalized program loop with modular extensions. | ||
| 20 | */ | ||
| 21 | class ProgramChain | ||
| 22 | { | ||
| 23 | public: | ||
| 24 | /** | ||
| 25 | * Construct an empty chain. | ||
| 26 | */ | ||
| 27 | ProgramChain(); | ||
| 28 | |||
| 29 | /** | ||
| 30 | * Destroy your chain. | ||
| 31 | */ | ||
| 32 | virtual ~ProgramChain(); | ||
| 33 | |||
| 34 | /** | ||
| 35 | * Adds a link to the end of the chain. | ||
| 36 | *@param pLink A pointer to the link to add to the chain. | ||
| 37 | *@returns True if adding the link was successful, otherwise false | ||
| 38 | */ | ||
| 39 | bool addLink( Bu::ProgramLink *pLink ); | ||
| 40 | |||
| 41 | /** | ||
| 42 | * Gets a link by name. | ||
| 43 | *@param lpName The name of the link you're looking for. Every link has a | ||
| 44 | * name, apparently. | ||
| 45 | *@returns A pointer to the specified ProgramLink, or NULL if none were | ||
| 46 | * found matching your criteria. | ||
| 47 | */ | ||
| 48 | class ProgramLink *getLink( const char *lpName ); | ||
| 49 | |||
| 50 | /** | ||
| 51 | * Gets the very first link in the chain. | ||
| 52 | *@returns A pointer to the first link in the chain. | ||
| 53 | */ | ||
| 54 | class ProgramLink *getBaseLink(); | ||
| 55 | |||
| 56 | /** | ||
| 57 | * Runs through the chain once. Useful if you want to have more control | ||
| 58 | * over the operation of the chain. | ||
| 59 | *@returns true if every link returned true. If at least one link returns | ||
| 60 | * false, then returns false. | ||
| 61 | */ | ||
| 62 | bool execChainOnce(); | ||
| 63 | |||
| 64 | /** | ||
| 65 | * Enters the master chain loop, looping over the entire chain and | ||
| 66 | * executing every link's TimeSlice routine in order, over and over, until | ||
| 67 | * a link returns a false value. | ||
| 68 | *@returns False, always. It returns true unless a link returned false, | ||
| 69 | * but loops until a link does return false. | ||
| 70 | **/ | ||
| 71 | bool enterChainLoop(); | ||
| 72 | |||
| 73 | /** | ||
| 74 | * Broadcasts an Immediate Response Message to all active links, save the | ||
| 75 | * sender. Whatever link first responds with a non-null response message | ||
| 76 | * will have it's messages sent back to the broadcasting link as the returns | ||
| 77 | * of this function call. Therefore it is very important that all message | ||
| 78 | * processing code is handled in a fairly timely fasion. | ||
| 79 | *@param pMsgOut The message to broadcast in hopes of a response. | ||
| 80 | *@param pSender The message that sent out the message and doesn't want to | ||
| 81 | * receive it's own message. This should always just be "this". | ||
| 82 | *@returns The message that was returned by the first link to return a | ||
| 83 | * non-null response. If all messages return null responses then this also | ||
| 84 | * returns null. Please note that whoever calls this will be responsible | ||
| 85 | * for deleting the message returned by it, if non-null. | ||
| 86 | */ | ||
| 87 | class LinkMessage *broadcastIRM( LinkMessage *pMsgOut, ProgramLink *pSender ); | ||
| 88 | |||
| 89 | private: | ||
| 90 | /** | ||
| 91 | * Shuts down all operation no matter what point in the operation we were. | ||
| 92 | */ | ||
| 93 | void emergencyShutdown(); | ||
| 94 | Bu::List<Bu::ProgramLink *> lLink; /**< The linked list that contains all of the links. */ | ||
| 95 | }; | ||
| 96 | } | ||
| 97 | |||
| 98 | |||
| 99 | #endif | ||
diff --git a/src/programlink.cpp b/src/programlink.cpp deleted file mode 100644 index f9453c2..0000000 --- a/src/programlink.cpp +++ /dev/null | |||
| @@ -1,63 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libbu++ library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include "bu/programlink.h" | ||
| 9 | #include "bu/programchain.h" | ||
| 10 | |||
| 11 | using namespace Bu; | ||
| 12 | |||
| 13 | Bu::ProgramLink::ProgramLink() | ||
| 14 | { | ||
| 15 | } | ||
| 16 | |||
| 17 | Bu::ProgramLink::~ProgramLink() | ||
| 18 | { | ||
| 19 | } | ||
| 20 | |||
| 21 | LinkMessage *Bu::ProgramLink::sendIRM( LinkMessage *pMsgOut ) | ||
| 22 | { | ||
| 23 | return pChain->broadcastIRM( pMsgOut, this ); | ||
| 24 | } | ||
| 25 | |||
| 26 | void Bu::ProgramLink::setChain( ProgramChain *pNewChain ) | ||
| 27 | { | ||
| 28 | pChain = pNewChain; | ||
| 29 | } | ||
| 30 | |||
| 31 | /* | ||
| 32 | void ProgramLink::postMessage( LinkMessage *pMsg, int nLvl ) | ||
| 33 | { | ||
| 34 | if( nLvl == msgToChain ) | ||
| 35 | { | ||
| 36 | qMsgToChain.enqueue( pMsg ); | ||
| 37 | } | ||
| 38 | else if( nLvl == msgToLink ) | ||
| 39 | { | ||
| 40 | qMsgToLink.enqueue( pMsg ); | ||
| 41 | } | ||
| 42 | else | ||
| 43 | { | ||
| 44 | // ERROR! | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 48 | LinkMessage *ProgramLink::getMessage( int nLvl ) | ||
| 49 | { | ||
| 50 | if( nLvl == msgToChain ) | ||
| 51 | { | ||
| 52 | return (LinkMessage *)qMsgToChain.dequeue(); | ||
| 53 | } | ||
| 54 | else if( nLvl == msgToLink ) | ||
| 55 | { | ||
| 56 | return (LinkMessage *)qMsgToLink.dequeue(); | ||
| 57 | } | ||
| 58 | else | ||
| 59 | { | ||
| 60 | // ERROR! | ||
| 61 | } | ||
| 62 | } | ||
| 63 | */ | ||
diff --git a/src/programlink.h b/src/programlink.h deleted file mode 100644 index 36a605e..0000000 --- a/src/programlink.h +++ /dev/null | |||
| @@ -1,106 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libbu++ library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #ifndef BU_PROGRAMLINK_H | ||
| 9 | #define BU_PROGRAMLINK_H | ||
| 10 | |||
| 11 | #include "bu/linkmessage.h" | ||
| 12 | #include "bu/programchain.h" | ||
| 13 | |||
| 14 | namespace Bu | ||
| 15 | { | ||
| 16 | /** | ||
| 17 | * Program Link is the base class for any object that will be a piece of the | ||
| 18 | * main program chain loop. | ||
| 19 | */ | ||
| 20 | class ProgramLink | ||
| 21 | { | ||
| 22 | friend class Bu::ProgramChain; | ||
| 23 | public: | ||
| 24 | /** | ||
| 25 | * Construct a program link. | ||
| 26 | */ | ||
| 27 | ProgramLink(); | ||
| 28 | |||
| 29 | /** | ||
| 30 | * Deconstruct. | ||
| 31 | */ | ||
| 32 | virtual ~ProgramLink(); | ||
| 33 | |||
| 34 | /** | ||
| 35 | * Initialization code required for a link that wasn't performed in the | ||
| 36 | * constructor. | ||
| 37 | *@returns true if initialization was successful. A false value will halt | ||
| 38 | * the chain. | ||
| 39 | */ | ||
| 40 | virtual bool init()=0; | ||
| 41 | |||
| 42 | /** | ||
| 43 | * DeInitialization code that should happen, but doesn't belong in the | ||
| 44 | * destructor. | ||
| 45 | *@returns true means everything worked, false means failure, but is | ||
| 46 | * meaningless. | ||
| 47 | */ | ||
| 48 | virtual bool deInit()=0; | ||
| 49 | |||
| 50 | /** | ||
| 51 | * Executed once per link per chain pass. Contains the guts of the program. | ||
| 52 | *@returns true if everything went well. A false value will halt the chain. | ||
| 53 | */ | ||
| 54 | virtual bool timeSlice()=0; | ||
| 55 | |||
| 56 | /** | ||
| 57 | * This must be handled in order to process Instant Response Messages. | ||
| 58 | * This function should return null on all messages that it doesn't | ||
| 59 | * understand how to handle, and construct new messages to return to sender | ||
| 60 | * in the cases where it does understand. | ||
| 61 | *@param pMsgIn The message that must be processed. | ||
| 62 | *@returns Either a new message in cases where a response is required, | ||
| 63 | * or null if nothing needs to be done by this link. | ||
| 64 | */ | ||
| 65 | virtual LinkMessage *processIRM( LinkMessage *pMsgIn ) = 0; | ||
| 66 | |||
| 67 | /** | ||
| 68 | * Broadcast a LinkMessage to all other links in the system. Each other | ||
| 69 | * link will get a call of their processIRM function. If the message gets | ||
| 70 | * a response then you will regain control immediately, otherwise the system | ||
| 71 | * will give all other Links a chance to respond before returning NULL. | ||
| 72 | *@param pMsgOut The message to broadcast. | ||
| 73 | *@returns The message response, or NULL if no Link understood your message. | ||
| 74 | */ | ||
| 75 | LinkMessage *sendIRM( LinkMessage *pMsgOut ); | ||
| 76 | |||
| 77 | private: | ||
| 78 | /** | ||
| 79 | * Set which chain we're assosiated with. This is how IRM messages make | ||
| 80 | * it out to the rest of the world. | ||
| 81 | *@param pNewChain A pointer to the containing program chain. | ||
| 82 | */ | ||
| 83 | void setChain( class ProgramChain *pNewChain ); | ||
| 84 | |||
| 85 | /** | ||
| 86 | * The pointer to the containing chain. | ||
| 87 | */ | ||
| 88 | class ProgramChain *pChain; | ||
| 89 | /* | ||
| 90 | void postMessage( LinkMessage *pMsg, int nLvl ); | ||
| 91 | LinkMessage *getMessage( int nLvl ); | ||
| 92 | |||
| 93 | enum | ||
| 94 | { | ||
| 95 | msgToChain, | ||
| 96 | msgToLink | ||
| 97 | }; | ||
| 98 | |||
| 99 | private: | ||
| 100 | Queue qMsgToChain; | ||
| 101 | Queue qMsgToLink; | ||
| 102 | */ | ||
| 103 | }; | ||
| 104 | } | ||
| 105 | |||
| 106 | #endif | ||
| @@ -23,7 +23,7 @@ namespace Bu | |||
| 23 | { | 23 | { |
| 24 | public: | 24 | public: |
| 25 | Sha1(); | 25 | Sha1(); |
| 26 | ~Sha1(); | 26 | virtual ~Sha1(); |
| 27 | 27 | ||
| 28 | virtual void reset(); | 28 | virtual void reset(); |
| 29 | virtual void setSalt( const Bu::String &sSalt ); | 29 | virtual void setSalt( const Bu::String &sSalt ); |
diff --git a/src/sio.cpp b/src/sio.cpp index 0fe60d9..5f8e234 100644 --- a/src/sio.cpp +++ b/src/sio.cpp | |||
| @@ -10,3 +10,26 @@ | |||
| 10 | Bu::StdStream Bu::sioRaw; | 10 | Bu::StdStream Bu::sioRaw; |
| 11 | Bu::Formatter Bu::sio( Bu::sioRaw ); | 11 | Bu::Formatter Bu::sio( Bu::sioRaw ); |
| 12 | 12 | ||
| 13 | Bu::size Bu::print( Bu::Stream &s, const Bu::String &str ) | ||
| 14 | { | ||
| 15 | return s.write( str.getStr(), str.getSize() ); | ||
| 16 | } | ||
| 17 | |||
| 18 | Bu::size Bu::print( const Bu::String &str ) | ||
| 19 | { | ||
| 20 | return print( sioRaw, str ); | ||
| 21 | } | ||
| 22 | |||
| 23 | Bu::size Bu::println( Bu::Stream &s, const Bu::String &str ) | ||
| 24 | { | ||
| 25 | Bu::size sRet = s.write( str.getStr(), str.getSize() ); | ||
| 26 | sRet += s.write("\n", 1 ); | ||
| 27 | s.flush(); | ||
| 28 | return sRet; | ||
| 29 | } | ||
| 30 | |||
| 31 | Bu::size Bu::println( const Bu::String &str ) | ||
| 32 | { | ||
| 33 | return println( sioRaw, str ); | ||
| 34 | } | ||
| 35 | |||
| @@ -15,6 +15,12 @@ namespace Bu | |||
| 15 | { | 15 | { |
| 16 | extern Bu::StdStream sioRaw; | 16 | extern Bu::StdStream sioRaw; |
| 17 | extern Bu::Formatter sio; | 17 | extern Bu::Formatter sio; |
| 18 | |||
| 19 | Bu::size print( Bu::Stream &s, const Bu::String &str ); | ||
| 20 | Bu::size print( const Bu::String &str ); | ||
| 21 | |||
| 22 | Bu::size println( Bu::Stream &s, const Bu::String &str ); | ||
| 23 | Bu::size println( const Bu::String &str ); | ||
| 18 | }; | 24 | }; |
| 19 | 25 | ||
| 20 | #endif | 26 | #endif |
diff --git a/src/strfilter.h b/src/strfilter.h new file mode 100644 index 0000000..8da0a3f --- /dev/null +++ b/src/strfilter.h | |||
| @@ -0,0 +1,124 @@ | |||
| 1 | #ifndef STR_FILTER_H | ||
| 2 | #define STR_FILTER_H | ||
| 3 | |||
| 4 | #include "bu/string.h" | ||
| 5 | #include "bu/membuf.h" | ||
| 6 | |||
| 7 | namespace Bu | ||
| 8 | { | ||
| 9 | // | ||
| 10 | // Encoders | ||
| 11 | // | ||
| 12 | template<typename tFilter> | ||
| 13 | Bu::String encodeStr( const Bu::String &sIn ) | ||
| 14 | { | ||
| 15 | Bu::MemBuf mb; | ||
| 16 | { | ||
| 17 | tFilter fEnc( mb ); | ||
| 18 | fEnc.write( sIn.getStr(), sIn.getSize() ); | ||
| 19 | } | ||
| 20 | return mb.getString(); | ||
| 21 | } | ||
| 22 | |||
| 23 | template<typename tFilter, typename p1t> | ||
| 24 | Bu::String encodeStr( const Bu::String &sIn, p1t p1 ) | ||
| 25 | { | ||
| 26 | Bu::MemBuf mb; | ||
| 27 | { | ||
| 28 | tFilter fEnc( mb, p1 ); | ||
| 29 | fEnc.write( sIn.getStr(), sIn.getSize() ); | ||
| 30 | } | ||
| 31 | return mb.getString(); | ||
| 32 | } | ||
| 33 | |||
| 34 | template<typename tFilter, typename p1t, typename p2t> | ||
| 35 | Bu::String encodeStr( const Bu::String &sIn, p1t p1, p2t p2 ) | ||
| 36 | { | ||
| 37 | Bu::MemBuf mb; | ||
| 38 | { | ||
| 39 | tFilter fEnc( mb, p1, p2 ); | ||
| 40 | fEnc.write( sIn.getStr(), sIn.getSize() ); | ||
| 41 | } | ||
| 42 | return mb.getString(); | ||
| 43 | } | ||
| 44 | |||
| 45 | template<typename tFilter, typename p1t, typename p2t, typename p3t> | ||
| 46 | Bu::String encodeStr( const Bu::String &sIn, p1t p1, p2t p2, p3t p3 ) | ||
| 47 | { | ||
| 48 | Bu::MemBuf mb; | ||
| 49 | { | ||
| 50 | tFilter fEnc( mb, p1, p2 ); | ||
| 51 | fEnc.write( sIn.getStr(), sIn.getSize() ); | ||
| 52 | } | ||
| 53 | return mb.getString(); | ||
| 54 | } | ||
| 55 | |||
| 56 | // | ||
| 57 | // Decoders | ||
| 58 | // | ||
| 59 | template<typename tFilter> | ||
| 60 | Bu::String decodeStr( const Bu::String &sIn ) | ||
| 61 | { | ||
| 62 | Bu::MemBuf mb( sIn ); | ||
| 63 | tFilter fDec( mb ); | ||
| 64 | char buf[1024]; | ||
| 65 | String sRet; | ||
| 66 | for(;;) | ||
| 67 | { | ||
| 68 | int iRead = fDec.read( buf, 1024 ); | ||
| 69 | if( iRead == 0 ) | ||
| 70 | return sRet; | ||
| 71 | sRet.append( buf, iRead ); | ||
| 72 | } | ||
| 73 | } | ||
| 74 | |||
| 75 | template<typename tFilter, typename p1t> | ||
| 76 | Bu::String decodeStr( const Bu::String &sIn, p1t p1 ) | ||
| 77 | { | ||
| 78 | Bu::MemBuf mb( sIn ); | ||
| 79 | tFilter fDec( mb, p1 ); | ||
| 80 | char buf[1024]; | ||
| 81 | String sRet; | ||
| 82 | for(;;) | ||
| 83 | { | ||
| 84 | int iRead = fDec.read( buf, 1024 ); | ||
| 85 | if( iRead == 0 ) | ||
| 86 | return sRet; | ||
| 87 | sRet.append( buf, iRead ); | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | template<typename tFilter, typename p1t, typename p2t> | ||
| 92 | Bu::String decodeStr( const Bu::String &sIn, p1t p1, p2t p2 ) | ||
| 93 | { | ||
| 94 | Bu::MemBuf mb( sIn ); | ||
| 95 | tFilter fDec( mb, p1, p2 ); | ||
| 96 | char buf[1024]; | ||
| 97 | String sRet; | ||
| 98 | for(;;) | ||
| 99 | { | ||
| 100 | int iRead = fDec.read( buf, 1024 ); | ||
| 101 | if( iRead == 0 ) | ||
| 102 | return sRet; | ||
| 103 | sRet.append( buf, iRead ); | ||
| 104 | } | ||
| 105 | } | ||
| 106 | |||
| 107 | template<typename tFilter, typename p1t, typename p2t, typename p3t> | ||
| 108 | Bu::String decodeStr( const Bu::String &sIn, p1t p1, p2t p2, p3t p3 ) | ||
| 109 | { | ||
| 110 | Bu::MemBuf mb( sIn ); | ||
| 111 | tFilter fDec( mb, p1, p2, p3 ); | ||
| 112 | char buf[1024]; | ||
| 113 | String sRet; | ||
| 114 | for(;;) | ||
| 115 | { | ||
| 116 | int iRead = fDec.read( buf, 1024 ); | ||
| 117 | if( iRead == 0 ) | ||
| 118 | return sRet; | ||
| 119 | sRet.append( buf, iRead ); | ||
| 120 | } | ||
| 121 | } | ||
| 122 | }; | ||
| 123 | |||
| 124 | #endif | ||
diff --git a/src/string.h b/src/string.h index 2874e37..a9006d1 100644 --- a/src/string.h +++ b/src/string.h | |||
| @@ -18,12 +18,12 @@ | |||
| 18 | #include "bu/list.h" | 18 | #include "bu/list.h" |
| 19 | #include "bu/fmt.h" | 19 | #include "bu/fmt.h" |
| 20 | #include "bu/variant.h" | 20 | #include "bu/variant.h" |
| 21 | |||
| 22 | #include <string.h> | 21 | #include <string.h> |
| 23 | 22 | ||
| 24 | namespace Bu | 23 | namespace Bu |
| 25 | { | 24 | { |
| 26 | class String; | 25 | class String; |
| 26 | class MemBuf; | ||
| 27 | 27 | ||
| 28 | /** @cond DEVEL */ | 28 | /** @cond DEVEL */ |
| 29 | class StringCore | 29 | class StringCore |
diff --git a/src/itoatom.h b/src/synchroatom.h index 3659f4e..fb02054 100644 --- a/src/itoatom.h +++ b/src/synchroatom.h | |||
| @@ -5,13 +5,12 @@ | |||
| 5 | * terms of the license contained in the file LICENSE. | 5 | * terms of the license contained in the file LICENSE. |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | #ifndef BU_ITO_ATOM_H | 8 | #ifndef BU_SYNCHRO_ATOM_H |
| 9 | #define BU_ITO_ATOM_H | 9 | #define BU_SYNCHRO_ATOM_H |
| 10 | 10 | ||
| 11 | #include <pthread.h> | 11 | #include <pthread.h> |
| 12 | 12 | ||
| 13 | #include "itomutex.h" | 13 | #include "bu/mutex.h" |
| 14 | #include "itocondition.h" | ||
| 15 | 14 | ||
| 16 | namespace Bu | 15 | namespace Bu |
| 17 | { | 16 | { |
| @@ -20,22 +19,22 @@ namespace Bu | |||
| 20 | *@ingroup Threading | 19 | *@ingroup Threading |
| 21 | */ | 20 | */ |
| 22 | template <class T> | 21 | template <class T> |
| 23 | class ItoAtom | 22 | class SynchroAtom |
| 24 | { | 23 | { |
| 25 | public: | 24 | public: |
| 26 | /** | 25 | /** |
| 27 | * Construct an empty queue. | 26 | * Construct an empty queue. |
| 28 | */ | 27 | */ |
| 29 | ItoAtom() | 28 | SynchroAtom() |
| 30 | { | 29 | { |
| 31 | } | 30 | } |
| 32 | 31 | ||
| 33 | ItoAtom( const T &src ) : | 32 | SynchroAtom( const T &src ) : |
| 34 | data( src ) | 33 | data( src ) |
| 35 | { | 34 | { |
| 36 | } | 35 | } |
| 37 | 36 | ||
| 38 | ~ItoAtom() | 37 | ~SynchroAtom() |
| 39 | { | 38 | { |
| 40 | } | 39 | } |
| 41 | 40 | ||
| @@ -57,7 +56,7 @@ namespace Bu | |||
| 57 | private: | 56 | private: |
| 58 | T data; | 57 | T data; |
| 59 | 58 | ||
| 60 | ItoMutex mOperate; /**< The master mutex, used on all operations. */ | 59 | Mutex mOperate; /**< The master mutex, used on all operations. */ |
| 61 | }; | 60 | }; |
| 62 | }; | 61 | }; |
| 63 | 62 | ||
diff --git a/src/itocounter.cpp b/src/synchrocounter.cpp index 0c6e06c..48bbe21 100644 --- a/src/itocounter.cpp +++ b/src/synchrocounter.cpp | |||
| @@ -5,4 +5,4 @@ | |||
| 5 | * terms of the license contained in the file LICENSE. | 5 | * terms of the license contained in the file LICENSE. |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | #include "bu/itocounter.h" | 8 | #include "bu/synchrocounter.h" |
diff --git a/src/itocounter.h b/src/synchrocounter.h index 10df467..d201bee 100644 --- a/src/itocounter.h +++ b/src/synchrocounter.h | |||
| @@ -5,10 +5,10 @@ | |||
| 5 | * terms of the license contained in the file LICENSE. | 5 | * terms of the license contained in the file LICENSE. |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | #ifndef BU_ITO_COUNTER_H | 8 | #ifndef BU_SYNCHRO_COUNTER_H |
| 9 | #define BU_ITO_COUNTER_H | 9 | #define BU_SYNCHRO_COUNTER_H |
| 10 | 10 | ||
| 11 | #include "itomutex.h" | 11 | #include "bu/mutex.h" |
| 12 | 12 | ||
| 13 | namespace Bu | 13 | namespace Bu |
| 14 | { | 14 | { |
| @@ -18,15 +18,15 @@ namespace Bu | |||
| 18 | *@ingroup Threading Containers | 18 | *@ingroup Threading Containers |
| 19 | */ | 19 | */ |
| 20 | template <class T> | 20 | template <class T> |
| 21 | class ItoCounter | 21 | class SynchroCounter |
| 22 | { | 22 | { |
| 23 | public: | 23 | public: |
| 24 | ItoCounter() : | 24 | SynchroCounter() : |
| 25 | tCounter( 0 ) | 25 | tCounter( 0 ) |
| 26 | { | 26 | { |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | virtual ~ItoCounter() | 29 | virtual ~SynchroCounter() |
| 30 | { | 30 | { |
| 31 | } | 31 | } |
| 32 | 32 | ||
| @@ -42,7 +42,7 @@ namespace Bu | |||
| 42 | 42 | ||
| 43 | private: | 43 | private: |
| 44 | T tCounter; /**< The counter itself. */ | 44 | T tCounter; /**< The counter itself. */ |
| 45 | ItoMutex mOperate; /**< The master mutex, used on all operations. */ | 45 | Mutex mOperate; /**< The master mutex, used on all operations. */ |
| 46 | }; | 46 | }; |
| 47 | } | 47 | } |
| 48 | 48 | ||
diff --git a/src/itoheap.cpp b/src/synchroheap.cpp index 21ccef8..5dcce33 100644 --- a/src/itoheap.cpp +++ b/src/synchroheap.cpp | |||
| @@ -5,5 +5,5 @@ | |||
| 5 | * terms of the license contained in the file LICENSE. | 5 | * terms of the license contained in the file LICENSE. |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | #include "bu/itoheap.h" | 8 | #include "bu/synchroheap.h" |
| 9 | 9 | ||
diff --git a/src/itoheap.h b/src/synchroheap.h index a5aad05..4dd898d 100644 --- a/src/itoheap.h +++ b/src/synchroheap.h | |||
| @@ -5,28 +5,25 @@ | |||
| 5 | * terms of the license contained in the file LICENSE. | 5 | * terms of the license contained in the file LICENSE. |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | #ifndef BU_ITO_HEAP_H | 8 | #ifndef BU_SYNCHRO_HEAP_H |
| 9 | #define BU_ITO_HEAP_H | 9 | #define BU_SYNCHRO_HEAP_H |
| 10 | 10 | ||
| 11 | #include "bu/heap.h" | 11 | #include "bu/heap.h" |
| 12 | #include "bu/itomutex.h" | 12 | #include "bu/mutex.h" |
| 13 | #include "bu/itocondition.h" | 13 | #include "bu/condition.h" |
| 14 | 14 | ||
| 15 | namespace Bu | 15 | namespace Bu |
| 16 | { | 16 | { |
| 17 | class ItoMutex; | ||
| 18 | class ItoCondition; | ||
| 19 | |||
| 20 | template<typename item, typename cmpfunc=__basicLTCmp<item>, | 17 | template<typename item, typename cmpfunc=__basicLTCmp<item>, |
| 21 | typename itemalloc=std::allocator<item> > | 18 | typename itemalloc=std::allocator<item> > |
| 22 | class ItoHeap | 19 | class SynchroHeap |
| 23 | { | 20 | { |
| 24 | public: | 21 | public: |
| 25 | ItoHeap() | 22 | SynchroHeap() |
| 26 | { | 23 | { |
| 27 | } | 24 | } |
| 28 | 25 | ||
| 29 | virtual ~ItoHeap() | 26 | virtual ~SynchroHeap() |
| 30 | { | 27 | { |
| 31 | } | 28 | } |
| 32 | 29 | ||
| @@ -145,8 +142,8 @@ namespace Bu | |||
| 145 | 142 | ||
| 146 | private: | 143 | private: |
| 147 | Heap< item, cmpfunc, itemalloc > hData; | 144 | Heap< item, cmpfunc, itemalloc > hData; |
| 148 | ItoMutex imData; | 145 | Mutex imData; |
| 149 | ItoCondition icBlock; | 146 | Condition icBlock; |
| 150 | }; | 147 | }; |
| 151 | }; | 148 | }; |
| 152 | 149 | ||
diff --git a/src/itoqueue.h b/src/synchroqueue.h index dc3cadb..79d5e49 100644 --- a/src/itoqueue.h +++ b/src/synchroqueue.h | |||
| @@ -5,19 +5,19 @@ | |||
| 5 | * terms of the license contained in the file LICENSE. | 5 | * terms of the license contained in the file LICENSE. |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | #ifndef BU_ITO_QUEUE_H | 8 | #ifndef BU_SYNCHRO_QUEUE_H |
| 9 | #define BU_ITO_QUEUE_H | 9 | #define BU_SYNCHRO_QUEUE_H |
| 10 | 10 | ||
| 11 | #include <pthread.h> | 11 | #include <pthread.h> |
| 12 | 12 | ||
| 13 | #include "itomutex.h" | 13 | #include "bu/mutex.h" |
| 14 | #include "itocondition.h" | 14 | #include "bu/condition.h" |
| 15 | 15 | ||
| 16 | namespace Bu | 16 | namespace Bu |
| 17 | { | 17 | { |
| 18 | /** | 18 | /** |
| 19 | * A thread-safe queue class. This class is a very simple queue with some | 19 | * A thread-safe queue class. This class is a very simple queue with some |
| 20 | * cool extra functionality for use with the Ito system. The main extra | 20 | * cool extra functionality for use with the Synchro system. The main extra |
| 21 | * that it provides is the option to either dequeue without blocking, with | 21 | * that it provides is the option to either dequeue without blocking, with |
| 22 | * infinite blocking, or with timed blocking, which will return a value if | 22 | * infinite blocking, or with timed blocking, which will return a value if |
| 23 | * something is enqueued within the specified time limit, or NULL if the | 23 | * something is enqueued within the specified time limit, or NULL if the |
| @@ -25,7 +25,7 @@ namespace Bu | |||
| 25 | *@ingroup Threading Containers | 25 | *@ingroup Threading Containers |
| 26 | */ | 26 | */ |
| 27 | template <class T> | 27 | template <class T> |
| 28 | class ItoQueue | 28 | class SynchroQueue |
| 29 | { | 29 | { |
| 30 | private: | 30 | private: |
| 31 | /** | 31 | /** |
| @@ -41,7 +41,7 @@ namespace Bu | |||
| 41 | /** | 41 | /** |
| 42 | * Construct an empty queue. | 42 | * Construct an empty queue. |
| 43 | */ | 43 | */ |
| 44 | ItoQueue() : | 44 | SynchroQueue() : |
| 45 | pStart( NULL ), | 45 | pStart( NULL ), |
| 46 | pEnd( NULL ), | 46 | pEnd( NULL ), |
| 47 | nSize( 0 ) | 47 | nSize( 0 ) |
| @@ -54,7 +54,7 @@ namespace Bu | |||
| 54 | * pointers without cleaning up the memory they pointed to. Make sure | 54 | * pointers without cleaning up the memory they pointed to. Make sure |
| 55 | * you're queue is empty before allowing it to be destroyed! | 55 | * you're queue is empty before allowing it to be destroyed! |
| 56 | */ | 56 | */ |
| 57 | ~ItoQueue() | 57 | ~SynchroQueue() |
| 58 | { | 58 | { |
| 59 | Item *pCur = pStart; | 59 | Item *pCur = pStart; |
| 60 | while( pCur ) | 60 | while( pCur ) |
| @@ -232,8 +232,8 @@ namespace Bu | |||
| 232 | Item *pEnd; /**< The end of the queue, the last element to dequeue. */ | 232 | Item *pEnd; /**< The end of the queue, the last element to dequeue. */ |
| 233 | long nSize; /**< The number of items in the queue. */ | 233 | long nSize; /**< The number of items in the queue. */ |
| 234 | 234 | ||
| 235 | ItoMutex mOperate; /**< The master mutex, used on all operations. */ | 235 | Mutex mOperate; /**< The master mutex, used on all operations. */ |
| 236 | ItoCondition cBlock; /**< The condition for blocking dequeues. */ | 236 | Condition cBlock; /**< The condition for blocking dequeues. */ |
| 237 | }; | 237 | }; |
| 238 | } | 238 | } |
| 239 | 239 | ||
diff --git a/src/tests/deflate.cpp b/src/tests/deflate.cpp new file mode 100644 index 0000000..9796408 --- /dev/null +++ b/src/tests/deflate.cpp | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libbu++ library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include "bu/deflate.h" | ||
| 9 | #include "bu/file.h" | ||
| 10 | |||
| 11 | int main( int argc, char *argv[] ) | ||
| 12 | { | ||
| 13 | if( argc < 3 ) | ||
| 14 | { | ||
| 15 | printf("usage: %s <in> <out>\n", argv[0] ); | ||
| 16 | return -1; | ||
| 17 | } | ||
| 18 | |||
| 19 | char buf[1024]; | ||
| 20 | size_t nRead; | ||
| 21 | |||
| 22 | /* | ||
| 23 | Bu::File fin( argv[1], Bu::File::Read ); | ||
| 24 | fin.seek( 4 ); | ||
| 25 | Bu::Deflate def( fin ); | ||
| 26 | |||
| 27 | Bu::File f( argv[2], Bu::File::WriteNew ); | ||
| 28 | |||
| 29 | for(;;) | ||
| 30 | { | ||
| 31 | nRead = def.read( buf, 1024 ); | ||
| 32 | if( nRead > 0 ) | ||
| 33 | f.write( buf, nRead ); | ||
| 34 | if( def.isEos() ) | ||
| 35 | break; | ||
| 36 | } | ||
| 37 | */ | ||
| 38 | |||
| 39 | Bu::File fin( argv[1], Bu::File::Read ); | ||
| 40 | |||
| 41 | Bu::File f( argv[2], Bu::File::WriteNew ); | ||
| 42 | Bu::Deflate def( f, 9, Bu::Deflate::Gzip ); | ||
| 43 | |||
| 44 | for(;;) | ||
| 45 | { | ||
| 46 | nRead = fin.read( buf, 1024 ); | ||
| 47 | if( nRead > 0 ) | ||
| 48 | def.write( buf, nRead ); | ||
| 49 | if( fin.isEos() ) | ||
| 50 | break; | ||
| 51 | } | ||
| 52 | } | ||
| 53 | |||
diff --git a/src/tests/lzma.cpp b/src/tests/lzma.cpp new file mode 100644 index 0000000..752357a --- /dev/null +++ b/src/tests/lzma.cpp | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libbu++ library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include "bu/lzma.h" | ||
| 9 | #include "bu/file.h" | ||
| 10 | |||
| 11 | int main( int argc, char *argv[] ) | ||
| 12 | { | ||
| 13 | if( argc < 3 ) | ||
| 14 | { | ||
| 15 | printf("usage: %s <in> <out>\n", argv[0] ); | ||
| 16 | return -1; | ||
| 17 | } | ||
| 18 | |||
| 19 | char buf[1024]; | ||
| 20 | size_t nRead; | ||
| 21 | |||
| 22 | /* | ||
| 23 | Bu::File fin( argv[1], Bu::File::Read ); | ||
| 24 | fin.seek( 4 ); | ||
| 25 | Bu::Deflate def( fin ); | ||
| 26 | |||
| 27 | Bu::File f( argv[2], Bu::File::WriteNew ); | ||
| 28 | |||
| 29 | for(;;) | ||
| 30 | { | ||
| 31 | nRead = def.read( buf, 1024 ); | ||
| 32 | if( nRead > 0 ) | ||
| 33 | f.write( buf, nRead ); | ||
| 34 | if( def.isEos() ) | ||
| 35 | break; | ||
| 36 | } | ||
| 37 | */ | ||
| 38 | |||
| 39 | Bu::File fin( argv[1], Bu::File::Read ); | ||
| 40 | |||
| 41 | Bu::File f( argv[2], Bu::File::WriteNew ); | ||
| 42 | Bu::Lzma def( f, 9 ); | ||
| 43 | |||
| 44 | for(;;) | ||
| 45 | { | ||
| 46 | nRead = fin.read( buf, 1024 ); | ||
| 47 | if( nRead > 0 ) | ||
| 48 | def.write( buf, nRead ); | ||
| 49 | if( fin.isEos() ) | ||
| 50 | break; | ||
| 51 | } | ||
| 52 | } | ||
| 53 | |||
diff --git a/src/tests/myriadfs.cpp b/src/tests/myriadfs.cpp index 5946b27..f57f02d 100644 --- a/src/tests/myriadfs.cpp +++ b/src/tests/myriadfs.cpp | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | using namespace Bu; | 7 | using namespace Bu; |
| 8 | 8 | ||
| 9 | int main( int argc, char *argv[] ) | 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 ); |
diff --git a/src/tests/utf.cpp b/src/tests/utf.cpp index 01bac7e..3418e68 100644 --- a/src/tests/utf.cpp +++ b/src/tests/utf.cpp | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | #include <bu/string.h> | 2 | #include <bu/string.h> |
| 3 | #include <bu/utfstring.h> | 3 | #include <bu/utfstring.h> |
| 4 | 4 | ||
| 5 | int main( int argc, char *argv[] ) | 5 | int main() |
| 6 | { | 6 | { |
| 7 | Bu::File fIn("utf8.in", Bu::File::Read ); | 7 | Bu::File fIn("utf8.in", Bu::File::Read ); |
| 8 | Bu::String sUtf8; | 8 | Bu::String sUtf8; |
diff --git a/src/ito.cpp b/src/thread.cpp index aa9a597..e4563a2 100644 --- a/src/ito.cpp +++ b/src/thread.cpp | |||
| @@ -5,51 +5,51 @@ | |||
| 5 | * terms of the license contained in the file LICENSE. | 5 | * terms of the license contained in the file LICENSE. |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | #include "bu/ito.h" | 8 | #include "bu/thread.h" |
| 9 | 9 | ||
| 10 | #include "bu/config.h" | 10 | #include "bu/config.h" |
| 11 | 11 | ||
| 12 | Bu::Ito::Ito() | 12 | Bu::Thread::Thread() |
| 13 | { | 13 | { |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | Bu::Ito::~Ito() | 16 | Bu::Thread::~Thread() |
| 17 | { | 17 | { |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | bool Bu::Ito::start() | 20 | bool Bu::Thread::start() |
| 21 | { | 21 | { |
| 22 | nHandle = pthread_create( &ptHandle, NULL, threadRunner, this ); | 22 | nHandle = pthread_create( &ptHandle, NULL, threadRunner, this ); |
| 23 | 23 | ||
| 24 | return true; | 24 | return true; |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | bool Bu::Ito::stop() | 27 | bool Bu::Thread::stop() |
| 28 | { | 28 | { |
| 29 | pthread_cancel( ptHandle ); | 29 | pthread_cancel( ptHandle ); |
| 30 | 30 | ||
| 31 | return true; | 31 | return true; |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | void *Bu::Ito::threadRunner( void *pThread ) | 34 | void *Bu::Thread::threadRunner( void *pThread ) |
| 35 | { | 35 | { |
| 36 | ((Ito *)pThread)->run(); | 36 | ((Thread *)pThread)->run(); |
| 37 | pthread_exit( NULL ); | 37 | pthread_exit( NULL ); |
| 38 | return NULL; | 38 | return NULL; |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | bool Bu::Ito::join() | 41 | bool Bu::Thread::join() |
| 42 | { | 42 | { |
| 43 | pthread_join( ptHandle, NULL ); | 43 | pthread_join( ptHandle, NULL ); |
| 44 | return true; | 44 | return true; |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | void Bu::Ito::yield() | 47 | void Bu::Thread::yield() |
| 48 | { | 48 | { |
| 49 | #ifndef WIN32 | 49 | #ifndef WIN32 |
| 50 | pthread_yield(); | 50 | pthread_yield(); |
| 51 | #else | 51 | #else |
| 52 | #warning Bu::Ito::yield IS A STUB for WIN32!!!! | 52 | #warning Bu::Thread::yield IS A STUB for WIN32!!!! |
| 53 | #endif | 53 | #endif |
| 54 | } | 54 | } |
| 55 | 55 | ||
| @@ -5,8 +5,8 @@ | |||
| 5 | * terms of the license contained in the file LICENSE. | 5 | * terms of the license contained in the file LICENSE. |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | #ifndef BU_ITO_H | 8 | #ifndef BU_THREAD_H |
| 9 | #define BU_ITO_H | 9 | #define BU_THREAD_H |
| 10 | 10 | ||
| 11 | #include <pthread.h> | 11 | #include <pthread.h> |
| 12 | 12 | ||
| @@ -19,18 +19,18 @@ namespace Bu | |||
| 19 | * run in it's own thread, one per class instance. | 19 | * run in it's own thread, one per class instance. |
| 20 | *@ingroup Threading | 20 | *@ingroup Threading |
| 21 | */ | 21 | */ |
| 22 | class Ito | 22 | class Thread |
| 23 | { | 23 | { |
| 24 | public: | 24 | public: |
| 25 | /** | 25 | /** |
| 26 | * Construct an Ito thread. | 26 | * Construct an Thread thread. |
| 27 | */ | 27 | */ |
| 28 | Ito(); | 28 | Thread(); |
| 29 | 29 | ||
| 30 | /** | 30 | /** |
| 31 | * Destroy an Ito thread. | 31 | * Destroy an Thread thread. |
| 32 | */ | 32 | */ |
| 33 | virtual ~Ito(); | 33 | virtual ~Thread(); |
| 34 | 34 | ||
| 35 | /** | 35 | /** |
| 36 | * Begin thread execution. This will call the overridden run function, | 36 | * Begin thread execution. This will call the overridden run function, |
| @@ -38,7 +38,7 @@ namespace Bu | |||
| 38 | * exits, the thread is killed, or the thread is cancelled (optionally). | 38 | * exits, the thread is killed, or the thread is cancelled (optionally). |
| 39 | * The thread started in this manner has access to all of it's class | 39 | * The thread started in this manner has access to all of it's class |
| 40 | * variables, but be sure to protect possible multiple-access with | 40 | * variables, but be sure to protect possible multiple-access with |
| 41 | * ItoMutex objects. | 41 | * ThreadMutex objects. |
| 42 | * @returns True if starting the thread was successful. False if | 42 | * @returns True if starting the thread was successful. False if |
| 43 | * something went wrong and the thread has not started. | 43 | * something went wrong and the thread has not started. |
| 44 | */ | 44 | */ |
| @@ -63,7 +63,7 @@ namespace Bu | |||
| 63 | /** | 63 | /** |
| 64 | * Join the thread in action. This function performs what is commonly | 64 | * Join the thread in action. This function performs what is commonly |
| 65 | * called a thread join. That is that it effectively makes the calling | 65 | * called a thread join. That is that it effectively makes the calling |
| 66 | * thread an the Ito thread contained in the called object one in the | 66 | * thread an the Thread thread contained in the called object one in the |
| 67 | * same, and pauses the calling thread until the called thread exits. | 67 | * same, and pauses the calling thread until the called thread exits. |
| 68 | * That is, when called from, say, your main(), mythread.join() will | 68 | * That is, when called from, say, your main(), mythread.join() will |
| 69 | * not return until the thread mythread has exited. This is very handy | 69 | * not return until the thread mythread has exited. This is very handy |
| @@ -79,10 +79,10 @@ namespace Bu | |||
| 79 | 79 | ||
| 80 | protected: | 80 | protected: |
| 81 | /** | 81 | /** |
| 82 | * The workhorse of the Ito class. This is the function that will run | 82 | * The workhorse of the Thread class. This is the function that will run |
| 83 | * in the thread, when this function exits the thread dies and is | 83 | * in the thread, when this function exits the thread dies and is |
| 84 | * cleaned up by the system. Make sure to read up on ItoMutex, | 84 | * cleaned up by the system. Make sure to read up on ThreadMutex, |
| 85 | * ItoCondition, and cancel to see how to control and protect | 85 | * ThreadCondition, and cancel to see how to control and protect |
| 86 | * everything you do in a safe way within this function. | 86 | * everything you do in a safe way within this function. |
| 87 | *@returns I'm not sure right now, but this is the posix standard form. | 87 | *@returns I'm not sure right now, but this is the posix standard form. |
| 88 | */ | 88 | */ |
diff --git a/src/tools/bnfcompile.cpp b/src/tools/bnfcompile.cpp index 011ec84..defb16b 100644 --- a/src/tools/bnfcompile.cpp +++ b/src/tools/bnfcompile.cpp | |||
| @@ -390,6 +390,11 @@ private: | |||
| 390 | 390 | ||
| 391 | int main( int argc, char *argv[] ) | 391 | int main( int argc, char *argv[] ) |
| 392 | { | 392 | { |
| 393 | if( argc < 2 ) | ||
| 394 | { | ||
| 395 | println("Provide an input filename as the first parameter."); | ||
| 396 | return 0; | ||
| 397 | } | ||
| 393 | File fIn( argv[1], File::Read ); | 398 | File fIn( argv[1], File::Read ); |
| 394 | 399 | ||
| 395 | BnfLexer bl( fIn ); | 400 | BnfLexer bl( fIn ); |
diff --git a/src/tools/myriad.cpp b/src/tools/myriad.cpp index 128f20c..30b936c 100644 --- a/src/tools/myriad.cpp +++ b/src/tools/myriad.cpp | |||
| @@ -80,7 +80,7 @@ public: | |||
| 80 | Bu::String sDst; | 80 | Bu::String sDst; |
| 81 | }; | 81 | }; |
| 82 | 82 | ||
| 83 | Bu::Formatter &operator>>( Bu::Formatter &f, Mode &e ) | 83 | Bu::Formatter &operator>>( Bu::Formatter &f, Mode & /*e*/ ) |
| 84 | { | 84 | { |
| 85 | sio << "Uh oh, the formatter was called..." << sio.nl; | 85 | sio << "Uh oh, the formatter was called..." << sio.nl; |
| 86 | return f; | 86 | return f; |
diff --git a/src/tools/parser.cpp b/src/tools/parser.cpp index aa9e3e4..7d35f12 100644 --- a/src/tools/parser.cpp +++ b/src/tools/parser.cpp | |||
| @@ -227,6 +227,11 @@ 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 ) | ||
| 231 | { | ||
| 232 | println("Provide an input filename as the first parameter."); | ||
| 233 | return 0; | ||
| 234 | } | ||
| 230 | File fIn( argv[1], File::Read ); | 235 | File fIn( argv[1], File::Read ); |
| 231 | 236 | ||
| 232 | Parser p; | 237 | Parser p; |
diff --git a/src/unit/base64.unit b/src/unit/base64.unit new file mode 100644 index 0000000..e4630c5 --- /dev/null +++ b/src/unit/base64.unit | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | // vim: syntax=cpp | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
| 4 | * | ||
| 5 | * This file is part of the libbu++ library and is released under the | ||
| 6 | * terms of the license contained in the file LICENSE. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include "bu/strfilter.h" | ||
| 10 | #include "bu/base64.h" | ||
| 11 | |||
| 12 | suite MemBuf | ||
| 13 | { | ||
| 14 | test decode01 | ||
| 15 | { | ||
| 16 | unitTest( Bu::decodeStr<Bu::Base64>("RnVu") == "Fun" ); | ||
| 17 | unitTest( Bu::decodeStr<Bu::Base64>("V2hhdA==") == "What" ); | ||
| 18 | unitTest( Bu::decodeStr<Bu::Base64>("SGVsbG8=") == "Hello" ); | ||
| 19 | } | ||
| 20 | |||
| 21 | test encode01 | ||
| 22 | { | ||
| 23 | unitTest( Bu::decodeStr<Bu::Base64>("R n V u") == "Fun" ); | ||
| 24 | unitTest( Bu::decodeStr<Bu::Base64>("V2\n\n\thh dA==") == "What" ); | ||
| 25 | unitTest( Bu::decodeStr<Bu::Base64>("\n\n\t\t SGV\r\ns\tbG8\n=") == "Hello" ); | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
diff --git a/src/utfstring.cpp b/src/utfstring.cpp index 3f57618..19d3ddc 100644 --- a/src/utfstring.cpp +++ b/src/utfstring.cpp | |||
| @@ -121,7 +121,7 @@ void Bu::UtfString::setUtf8( const Bu::String &sInput ) | |||
| 121 | 121 | ||
| 122 | void Bu::UtfString::setUtf16( const Bu::String &sInput ) | 122 | void Bu::UtfString::setUtf16( const Bu::String &sInput ) |
| 123 | { | 123 | { |
| 124 | Bu::String::const_iterator i = sInput.begin(); | 124 | // Bu::String::const_iterator i = sInput.begin(); |
| 125 | if( (uint8_t)*sInput.begin() == 0xFF && | 125 | if( (uint8_t)*sInput.begin() == 0xFF && |
| 126 | (uint8_t)*(sInput.begin()+1) == 0xFE ) | 126 | (uint8_t)*(sInput.begin()+1) == 0xFE ) |
| 127 | { | 127 | { |
| @@ -311,9 +311,9 @@ void Bu::UtfString::writeUtf8( Bu::Stream &sOut ) | |||
| 311 | // 111 111111 111111 111111 | 311 | // 111 111111 111111 111111 |
| 312 | uByte = (chr>>18)|0xF0; | 312 | uByte = (chr>>18)|0xF0; |
| 313 | sOut.write( &uByte, 1 ); | 313 | sOut.write( &uByte, 1 ); |
| 314 | uByte = (chr>>12)&0x3F|0x80; | 314 | uByte = ((chr>>12)&0x3F)|0x80; |
| 315 | sOut.write( &uByte, 1 ); | 315 | sOut.write( &uByte, 1 ); |
| 316 | uByte = (chr>>6)&0x3F|0x80; | 316 | uByte = ((chr>>6)&0x3F)|0x80; |
| 317 | sOut.write( &uByte, 1 ); | 317 | sOut.write( &uByte, 1 ); |
| 318 | uByte = (chr&0x3F)|0x80; | 318 | uByte = (chr&0x3F)|0x80; |
| 319 | sOut.write( &uByte, 1 ); | 319 | sOut.write( &uByte, 1 ); |
| @@ -324,7 +324,7 @@ void Bu::UtfString::writeUtf8( Bu::Stream &sOut ) | |||
| 324 | // 1111 111111 111111 | 324 | // 1111 111111 111111 |
| 325 | uByte = (chr>>12)|0xE0; | 325 | uByte = (chr>>12)|0xE0; |
| 326 | sOut.write( &uByte, 1 ); | 326 | sOut.write( &uByte, 1 ); |
| 327 | uByte = (chr>>6)&0x3F|0x80; | 327 | uByte = ((chr>>6)&0x3F)|0x80; |
| 328 | sOut.write( &uByte, 1 ); | 328 | sOut.write( &uByte, 1 ); |
| 329 | uByte = (chr&0x3F)|0x80; | 329 | uByte = (chr&0x3F)|0x80; |
| 330 | sOut.write( &uByte, 1 ); | 330 | sOut.write( &uByte, 1 ); |
