diff options
author | Mike Buland <eichlan@xagasoft.com> | 2007-06-10 21:28:14 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2007-06-10 21:28:14 +0000 |
commit | 5f39066a4f561e9a94a6cc9293ab9b978ebf1f81 (patch) | |
tree | a25698caf9594feecae8b71f032a11f81ba6cc3c | |
parent | f5352edf3dc23c044a91f1d1537fa0dc0f0babc7 (diff) | |
download | libbu++-5f39066a4f561e9a94a6cc9293ab9b978ebf1f81.tar.gz libbu++-5f39066a4f561e9a94a6cc9293ab9b978ebf1f81.tar.bz2 libbu++-5f39066a4f561e9a94a6cc9293ab9b978ebf1f81.tar.xz libbu++-5f39066a4f561e9a94a6cc9293ab9b978ebf1f81.zip |
Bunch of maintenence type things. Minor tweaks and the like. The file class
has a lot more helper functions and the like, the filters give more info back
to the caller, minor updates to taf.
-rw-r--r-- | src/bzip2.cpp | 41 | ||||
-rw-r--r-- | src/bzip2.h | 2 | ||||
-rw-r--r-- | src/file.cpp | 31 | ||||
-rw-r--r-- | src/file.h | 17 | ||||
-rw-r--r-- | src/filter.cpp | 7 | ||||
-rw-r--r-- | src/filter.h | 4 | ||||
-rw-r--r-- | src/socket.cpp | 4 | ||||
-rw-r--r-- | src/socket.h | 2 | ||||
-rw-r--r-- | src/stream.h | 2 | ||||
-rw-r--r-- | src/tafnode.cpp | 6 | ||||
-rw-r--r-- | src/tafnode.h | 4 | ||||
-rw-r--r-- | src/tests/taf.cpp | 2 |
12 files changed, 105 insertions, 17 deletions
diff --git a/src/bzip2.cpp b/src/bzip2.cpp index 433fc91..5423a10 100644 --- a/src/bzip2.cpp +++ b/src/bzip2.cpp | |||
@@ -26,16 +26,18 @@ void Bu::BZip2::start() | |||
26 | pBuf = new char[nBufSize]; | 26 | pBuf = new char[nBufSize]; |
27 | } | 27 | } |
28 | 28 | ||
29 | void Bu::BZip2::stop() | 29 | size_t Bu::BZip2::stop() |
30 | { | 30 | { |
31 | if( bzState.state ) | 31 | if( bzState.state ) |
32 | { | 32 | { |
33 | if( bReading ) | 33 | if( bReading ) |
34 | { | 34 | { |
35 | BZ2_bzDecompressEnd( &bzState ); | 35 | BZ2_bzDecompressEnd( &bzState ); |
36 | return 0; | ||
36 | } | 37 | } |
37 | else | 38 | else |
38 | { | 39 | { |
40 | size_t sTotal = 0; | ||
39 | for(;;) | 41 | for(;;) |
40 | { | 42 | { |
41 | bzState.next_in = NULL; | 43 | bzState.next_in = NULL; |
@@ -45,14 +47,16 @@ void Bu::BZip2::stop() | |||
45 | int res = BZ2_bzCompress( &bzState, BZ_FINISH ); | 47 | int res = BZ2_bzCompress( &bzState, BZ_FINISH ); |
46 | if( bzState.avail_out < nBufSize ) | 48 | if( bzState.avail_out < nBufSize ) |
47 | { | 49 | { |
48 | rNext.write( pBuf, nBufSize-bzState.avail_out ); | 50 | sTotal += rNext.write( pBuf, nBufSize-bzState.avail_out ); |
49 | } | 51 | } |
50 | if( res == BZ_STREAM_END ) | 52 | if( res == BZ_STREAM_END ) |
51 | break; | 53 | break; |
52 | } | 54 | } |
53 | BZ2_bzCompressEnd( &bzState ); | 55 | BZ2_bzCompressEnd( &bzState ); |
56 | return sTotal; | ||
54 | } | 57 | } |
55 | } | 58 | } |
59 | return 0; | ||
56 | } | 60 | } |
57 | 61 | ||
58 | void Bu::BZip2::bzError( int code ) | 62 | void Bu::BZip2::bzError( int code ) |
@@ -63,13 +67,35 @@ void Bu::BZip2::bzError( int code ) | |||
63 | return; | 67 | return; |
64 | 68 | ||
65 | case BZ_CONFIG_ERROR: | 69 | case BZ_CONFIG_ERROR: |
66 | throw ExceptionBase("The bzip2 library has been miscompiled."); | 70 | throw ExceptionBase("BZip2: Library configured improperly, reinstall."); |
71 | |||
72 | case BZ_SEQUENCE_ERROR: | ||
73 | throw ExceptionBase("BZip2: Functions were called in an invalid sequence."); | ||
67 | 74 | ||
68 | case BZ_PARAM_ERROR: | 75 | case BZ_PARAM_ERROR: |
69 | throw ExceptionBase("bzip2 parameter error."); | 76 | throw ExceptionBase("BZip2: Invalid parameter was passed into a function."); |
70 | 77 | ||
71 | case BZ_MEM_ERROR: | 78 | case BZ_MEM_ERROR: |
72 | throw ExceptionBase("Not enough memory available for bzip2."); | 79 | throw ExceptionBase("BZip2: Couldn't allocate sufficient memory."); |
80 | |||
81 | case BZ_DATA_ERROR: | ||
82 | throw ExceptionBase("BZip2: Data was corrupted before decompression."); | ||
83 | |||
84 | case BZ_DATA_ERROR_MAGIC: | ||
85 | throw ExceptionBase("BZip2: Stream does not appear to be bzip2 data."); | ||
86 | |||
87 | case BZ_IO_ERROR: | ||
88 | throw ExceptionBase("BZip2: File couldn't be read from / written to."); | ||
89 | |||
90 | case BZ_UNEXPECTED_EOF: | ||
91 | throw ExceptionBase("BZip2: End of file encountered before end of stream."); | ||
92 | |||
93 | case BZ_OUTBUFF_FULL: | ||
94 | throw ExceptionBase("BZip2: Buffer not large enough to accomidate data."); | ||
95 | |||
96 | default: | ||
97 | throw ExceptionBase("BZip2: Unknown error encountered."); | ||
98 | |||
73 | } | 99 | } |
74 | } | 100 | } |
75 | 101 | ||
@@ -124,6 +150,7 @@ size_t Bu::BZip2::write( const void *pData, size_t nBytes ) | |||
124 | if( bReading == true ) | 150 | if( bReading == true ) |
125 | throw ExceptionBase("This bzip2 filter is in reading mode, you can't write."); | 151 | throw ExceptionBase("This bzip2 filter is in reading mode, you can't write."); |
126 | 152 | ||
153 | size_t sTotalOut = 0; | ||
127 | bzState.next_in = (char *)pData; | 154 | bzState.next_in = (char *)pData; |
128 | bzState.avail_in = nBytes; | 155 | bzState.avail_in = nBytes; |
129 | for(;;) | 156 | for(;;) |
@@ -135,12 +162,12 @@ size_t Bu::BZip2::write( const void *pData, size_t nBytes ) | |||
135 | 162 | ||
136 | if( bzState.avail_out < nBufSize ) | 163 | if( bzState.avail_out < nBufSize ) |
137 | { | 164 | { |
138 | rNext.write( pBuf, nBufSize-bzState.avail_out ); | 165 | sTotalOut += rNext.write( pBuf, nBufSize-bzState.avail_out ); |
139 | } | 166 | } |
140 | if( bzState.avail_in == 0 ) | 167 | if( bzState.avail_in == 0 ) |
141 | break; | 168 | break; |
142 | } | 169 | } |
143 | 170 | ||
144 | return 0; | 171 | return sTotalOut; |
145 | } | 172 | } |
146 | 173 | ||
diff --git a/src/bzip2.h b/src/bzip2.h index 056f336..a23f07a 100644 --- a/src/bzip2.h +++ b/src/bzip2.h | |||
@@ -18,7 +18,7 @@ namespace Bu | |||
18 | virtual ~BZip2(); | 18 | virtual ~BZip2(); |
19 | 19 | ||
20 | virtual void start(); | 20 | virtual void start(); |
21 | virtual void stop(); | 21 | virtual size_t stop(); |
22 | virtual size_t read( void *pBuf, size_t nBytes ); | 22 | virtual size_t read( void *pBuf, size_t nBytes ); |
23 | virtual size_t write( const void *pBuf, size_t nBytes ); | 23 | virtual size_t write( const void *pBuf, size_t nBytes ); |
24 | 24 | ||
diff --git a/src/file.cpp b/src/file.cpp index 26986a5..14b6e54 100644 --- a/src/file.cpp +++ b/src/file.cpp | |||
@@ -1,6 +1,8 @@ | |||
1 | #include "file.h" | 1 | #include "file.h" |
2 | #include "exceptions.h" | 2 | #include "exceptions.h" |
3 | #include <errno.h> | 3 | #include <errno.h> |
4 | #include <sys/types.h> | ||
5 | #include <sys/stat.h> | ||
4 | 6 | ||
5 | Bu::File::File( const char *sName, const char *sFlags ) | 7 | Bu::File::File( const char *sName, const char *sFlags ) |
6 | { | 8 | { |
@@ -11,6 +13,20 @@ Bu::File::File( const char *sName, const char *sFlags ) | |||
11 | } | 13 | } |
12 | } | 14 | } |
13 | 15 | ||
16 | Bu::File::File( const Bu::FString &sName, const char *sFlags ) | ||
17 | { | ||
18 | fh = fopen( sName.getStr(), sFlags ); | ||
19 | if( fh == NULL ) | ||
20 | { | ||
21 | throw Bu::FileException( errno, strerror(errno) ); | ||
22 | } | ||
23 | } | ||
24 | |||
25 | Bu::File::File( int fd, const char *sFlags ) | ||
26 | { | ||
27 | fh = fdopen( fd, sFlags ); | ||
28 | } | ||
29 | |||
14 | Bu::File::~File() | 30 | Bu::File::~File() |
15 | { | 31 | { |
16 | close(); | 32 | close(); |
@@ -108,3 +124,18 @@ void Bu::File::setBlocking( bool bBlocking ) | |||
108 | return; | 124 | return; |
109 | } | 125 | } |
110 | 126 | ||
127 | void Bu::File::truncate( long nSize ) | ||
128 | { | ||
129 | ftruncate( fileno( fh ), nSize ); | ||
130 | } | ||
131 | |||
132 | void Bu::File::flush() | ||
133 | { | ||
134 | fflush( fh ); | ||
135 | } | ||
136 | |||
137 | void Bu::File::chmod( mode_t t ) | ||
138 | { | ||
139 | fchmod( fileno( fh ), t ); | ||
140 | } | ||
141 | |||
@@ -3,7 +3,8 @@ | |||
3 | 3 | ||
4 | #include <stdint.h> | 4 | #include <stdint.h> |
5 | 5 | ||
6 | #include "stream.h" | 6 | #include "bu/stream.h" |
7 | #include "bu/fstring.h" | ||
7 | 8 | ||
8 | namespace Bu | 9 | namespace Bu |
9 | { | 10 | { |
@@ -11,6 +12,8 @@ namespace Bu | |||
11 | { | 12 | { |
12 | public: | 13 | public: |
13 | File( const char *sName, const char *sFlags ); | 14 | File( const char *sName, const char *sFlags ); |
15 | File( const Bu::FString &sName, const char *sFlags ); | ||
16 | File( int fd, const char *sFlags ); | ||
14 | virtual ~File(); | 17 | virtual ~File(); |
15 | 18 | ||
16 | virtual void close(); | 19 | virtual void close(); |
@@ -23,6 +26,8 @@ namespace Bu | |||
23 | virtual void setPosEnd( long pos ); | 26 | virtual void setPosEnd( long pos ); |
24 | virtual bool isEOS(); | 27 | virtual bool isEOS(); |
25 | 28 | ||
29 | virtual void flush(); | ||
30 | |||
26 | virtual bool canRead(); | 31 | virtual bool canRead(); |
27 | virtual bool canWrite(); | 32 | virtual bool canWrite(); |
28 | virtual bool canSeek(); | 33 | virtual bool canSeek(); |
@@ -30,6 +35,16 @@ namespace Bu | |||
30 | virtual bool isBlocking(); | 35 | virtual bool isBlocking(); |
31 | virtual void setBlocking( bool bBlocking=true ); | 36 | virtual void setBlocking( bool bBlocking=true ); |
32 | 37 | ||
38 | inline static Bu::File tempFile( Bu::FString &sName, const char *sFlags ) | ||
39 | { | ||
40 | int afh_d = mkstemp( sName.getStr() ); | ||
41 | |||
42 | return Bu::File( afh_d, sFlags ); | ||
43 | } | ||
44 | |||
45 | void truncate( long nSize ); | ||
46 | void chmod( mode_t t ); | ||
47 | |||
33 | private: | 48 | private: |
34 | FILE *fh; | 49 | FILE *fh; |
35 | 50 | ||
diff --git a/src/filter.cpp b/src/filter.cpp index d3faa00..693fb9f 100644 --- a/src/filter.cpp +++ b/src/filter.cpp | |||
@@ -7,7 +7,7 @@ Bu::Filter::Filter( Bu::Stream &rNext ) : | |||
7 | 7 | ||
8 | Bu::Filter::~Filter() | 8 | Bu::Filter::~Filter() |
9 | { | 9 | { |
10 | printf("-> Bu::Filter::~Filter()\n"); | 10 | //printf("-> Bu::Filter::~Filter()\n"); |
11 | } | 11 | } |
12 | /* | 12 | /* |
13 | void Bu::Filter::start() | 13 | void Bu::Filter::start() |
@@ -75,3 +75,8 @@ void Bu::Filter::setBlocking( bool bBlocking ) | |||
75 | rNext.setBlocking( bBlocking ); | 75 | rNext.setBlocking( bBlocking ); |
76 | } | 76 | } |
77 | 77 | ||
78 | void Bu::Filter::flush() | ||
79 | { | ||
80 | rNext.flush(); | ||
81 | } | ||
82 | |||
diff --git a/src/filter.h b/src/filter.h index b068206..088d46e 100644 --- a/src/filter.h +++ b/src/filter.h | |||
@@ -33,7 +33,7 @@ namespace Bu | |||
33 | virtual ~Filter(); | 33 | virtual ~Filter(); |
34 | 34 | ||
35 | virtual void start()=0; | 35 | virtual void start()=0; |
36 | virtual void stop()=0; | 36 | virtual size_t stop()=0; |
37 | virtual void close(); | 37 | virtual void close(); |
38 | virtual long tell(); | 38 | virtual long tell(); |
39 | virtual void seek( long offset ); | 39 | virtual void seek( long offset ); |
@@ -41,6 +41,8 @@ namespace Bu | |||
41 | virtual void setPosEnd( long pos ); | 41 | virtual void setPosEnd( long pos ); |
42 | virtual bool isEOS(); | 42 | virtual bool isEOS(); |
43 | 43 | ||
44 | virtual void flush(); | ||
45 | |||
44 | virtual bool canRead(); | 46 | virtual bool canRead(); |
45 | virtual bool canWrite(); | 47 | virtual bool canWrite(); |
46 | virtual bool canSeek(); | 48 | virtual bool canSeek(); |
diff --git a/src/socket.cpp b/src/socket.cpp index 441678a..1832898 100644 --- a/src/socket.cpp +++ b/src/socket.cpp | |||
@@ -240,3 +240,7 @@ void Bu::Socket::setBlocking( bool bBlocking ) | |||
240 | { | 240 | { |
241 | } | 241 | } |
242 | 242 | ||
243 | void Bu::Socket::flush() | ||
244 | { | ||
245 | } | ||
246 | |||
diff --git a/src/socket.h b/src/socket.h index e65eb74..30a43fb 100644 --- a/src/socket.h +++ b/src/socket.h | |||
@@ -29,6 +29,8 @@ namespace Bu | |||
29 | virtual void setPosEnd( long pos ); | 29 | virtual void setPosEnd( long pos ); |
30 | virtual bool isEOS(); | 30 | virtual bool isEOS(); |
31 | 31 | ||
32 | virtual void flush(); | ||
33 | |||
32 | virtual bool canRead(); | 34 | virtual bool canRead(); |
33 | virtual bool canWrite(); | 35 | virtual bool canWrite(); |
34 | virtual bool canSeek(); | 36 | virtual bool canSeek(); |
diff --git a/src/stream.h b/src/stream.h index fa0a606..a80586b 100644 --- a/src/stream.h +++ b/src/stream.h | |||
@@ -32,6 +32,8 @@ namespace Bu | |||
32 | virtual void setPosEnd( long pos ) = 0; | 32 | virtual void setPosEnd( long pos ) = 0; |
33 | virtual bool isEOS() = 0; | 33 | virtual bool isEOS() = 0; |
34 | 34 | ||
35 | virtual void flush() = 0; | ||
36 | |||
35 | virtual bool canRead() = 0; | 37 | virtual bool canRead() = 0; |
36 | virtual bool canWrite() = 0; | 38 | virtual bool canWrite() = 0; |
37 | virtual bool canSeek() = 0; | 39 | virtual bool canSeek() = 0; |
diff --git a/src/tafnode.cpp b/src/tafnode.cpp index 3060606..b9a4a24 100644 --- a/src/tafnode.cpp +++ b/src/tafnode.cpp | |||
@@ -45,7 +45,7 @@ const Bu::TafNode::PropList &Bu::TafNode::getProperties( const Bu::FString &sNam | |||
45 | return hProp.get( sName ); | 45 | return hProp.get( sName ); |
46 | } | 46 | } |
47 | 47 | ||
48 | const Bu::TafNode::NodeList &Bu::TafNode::getNodes( const Bu::FString &sName ) const | 48 | const Bu::TafNode::NodeList &Bu::TafNode::getChildren( const Bu::FString &sName ) const |
49 | { | 49 | { |
50 | return hChildren.get( sName ); | 50 | return hChildren.get( sName ); |
51 | } | 51 | } |
@@ -55,9 +55,9 @@ const Bu::FString &Bu::TafNode::getProperty( const Bu::FString &sName ) const | |||
55 | return getProperties( sName ).first(); | 55 | return getProperties( sName ).first(); |
56 | } | 56 | } |
57 | 57 | ||
58 | const Bu::TafNode *Bu::TafNode::getNode( const Bu::FString &sName ) const | 58 | const Bu::TafNode *Bu::TafNode::getChild( const Bu::FString &sName ) const |
59 | { | 59 | { |
60 | return getNodes( sName ).first(); | 60 | return getChildren( sName ).first(); |
61 | } | 61 | } |
62 | 62 | ||
63 | void Bu::TafNode::setName( const Bu::FString &sName ) | 63 | void Bu::TafNode::setName( const Bu::FString &sName ) |
diff --git a/src/tafnode.h b/src/tafnode.h index 10232d2..08f78e8 100644 --- a/src/tafnode.h +++ b/src/tafnode.h | |||
@@ -28,9 +28,9 @@ namespace Bu | |||
28 | 28 | ||
29 | void setProperty( Bu::FString sName, Bu::FString sValue ); | 29 | void setProperty( Bu::FString sName, Bu::FString sValue ); |
30 | const Bu::FString &getProperty( const Bu::FString &sName ) const; | 30 | const Bu::FString &getProperty( const Bu::FString &sName ) const; |
31 | const TafNode *getNode( const Bu::FString &sName ) const; | ||
32 | const PropList &getProperties( const Bu::FString &sName ) const; | 31 | const PropList &getProperties( const Bu::FString &sName ) const; |
33 | const NodeList &getNodes( const Bu::FString &sName ) const; | 32 | const TafNode *getChild( const Bu::FString &sName ) const; |
33 | const NodeList &getChildren( const Bu::FString &sName ) const; | ||
34 | void addChild( TafNode *pNode ); | 34 | void addChild( TafNode *pNode ); |
35 | 35 | ||
36 | private: | 36 | private: |
diff --git a/src/tests/taf.cpp b/src/tests/taf.cpp index e7bad52..d135e78 100644 --- a/src/tests/taf.cpp +++ b/src/tests/taf.cpp | |||
@@ -8,7 +8,7 @@ int main() | |||
8 | 8 | ||
9 | Bu::TafNode *pNode = tr.getNode(); | 9 | Bu::TafNode *pNode = tr.getNode(); |
10 | 10 | ||
11 | const Bu::TafNode *pStats = pNode->getNode("stats"); | 11 | const Bu::TafNode *pStats = pNode->getChild("stats"); |
12 | printf("%s\n", pStats->getName().getStr() ); | 12 | printf("%s\n", pStats->getName().getStr() ); |
13 | printf(" str = %s\n", pStats->getProperty("str").getStr() ); | 13 | printf(" str = %s\n", pStats->getProperty("str").getStr() ); |
14 | 14 | ||