diff options
Diffstat (limited to '')
| -rw-r--r-- | src/tools/myriad.cpp | 438 |
1 files changed, 219 insertions, 219 deletions
diff --git a/src/tools/myriad.cpp b/src/tools/myriad.cpp index 7cab628..8a288b0 100644 --- a/src/tools/myriad.cpp +++ b/src/tools/myriad.cpp | |||
| @@ -17,237 +17,237 @@ using namespace Bu; | |||
| 17 | 17 | ||
| 18 | enum Mode | 18 | enum Mode |
| 19 | { | 19 | { |
| 20 | modeCreate, | 20 | modeCreate, |
| 21 | modeInfo, | 21 | modeInfo, |
| 22 | modeStreamNew, | 22 | modeStreamNew, |
| 23 | modeStreamDump, | 23 | modeStreamDump, |
| 24 | modeStreamPut, | 24 | modeStreamPut, |
| 25 | modeStreamGet, | 25 | modeStreamGet, |
| 26 | 26 | ||
| 27 | modeNone | 27 | modeNone |
| 28 | }; | 28 | }; |
| 29 | 29 | ||
| 30 | class Options : public OptParser | 30 | class Options : public OptParser |
| 31 | { | 31 | { |
| 32 | public: | 32 | public: |
| 33 | Options( int argc, char *argv[] ) : | 33 | Options( int argc, char *argv[] ) : |
| 34 | eMode( modeNone ), | 34 | eMode( modeNone ), |
| 35 | iBlockSize( 64 ), | 35 | iBlockSize( 64 ), |
| 36 | iPreallocate( 0 ), | 36 | iPreallocate( 0 ), |
| 37 | iStream( 0 ) | 37 | iStream( 0 ) |
| 38 | { | 38 | { |
| 39 | addHelpBanner("Mode of operation:"); | 39 | addHelpBanner("Mode of operation:"); |
| 40 | addOption( eMode, 'c', "create", | 40 | addOption( eMode, 'c', "create", |
| 41 | "Create a new Myriad file." ); | 41 | "Create a new Myriad file." ); |
| 42 | addOption( eMode, 'i', "info", | 42 | addOption( eMode, 'i', "info", |
| 43 | "Display some info about a Myriad file." ); | 43 | "Display some info about a Myriad file." ); |
| 44 | addOption( eMode, 'n', "new", | 44 | addOption( eMode, 'n', "new", |
| 45 | "Create a new sub-stream in a Myriad file."); | 45 | "Create a new sub-stream in a Myriad file."); |
| 46 | addOption( eMode, 'd', "dump", | 46 | addOption( eMode, 'd', "dump", |
| 47 | "Display a hexdump of a stream from a Myriad file."); | 47 | "Display a hexdump of a stream from a Myriad file."); |
| 48 | addOption( eMode, "get", | 48 | addOption( eMode, "get", |
| 49 | "Get a file out of a Myriad stream (use --dst)."); | 49 | "Get a file out of a Myriad stream (use --dst)."); |
| 50 | addOption( eMode, "put", | 50 | addOption( eMode, "put", |
| 51 | "Put a file into a Myriad stream (usr --src)."); | 51 | "Put a file into a Myriad stream (usr --src)."); |
| 52 | addHelpOption(); | 52 | addHelpOption(); |
| 53 | 53 | ||
| 54 | addHelpBanner("\nGeneral options:"); | 54 | addHelpBanner("\nGeneral options:"); |
| 55 | addOption( iBlockSize, 'b', "block-size", "Set the block size." ); | 55 | addOption( iBlockSize, 'b', "block-size", "Set the block size." ); |
| 56 | addOption( iPreallocate, 'p', "preallocate", | 56 | addOption( iPreallocate, 'p', "preallocate", |
| 57 | "Number of blocks to preallocate." ); | 57 | "Number of blocks to preallocate." ); |
| 58 | addOption( sFile, 'f', "file", "Set the Myriad filename." ); | 58 | addOption( sFile, 'f', "file", "Set the Myriad filename." ); |
| 59 | addOption( iStream, 's', "stream", "Substream to work with."); | 59 | addOption( iStream, 's', "stream", "Substream to work with."); |
| 60 | addOption( sSrc, "src", "Source file for copying into a Myriad file."); | 60 | addOption( sSrc, "src", "Source file for copying into a Myriad file."); |
| 61 | addOption( sDst, "dst", | 61 | addOption( sDst, "dst", |
| 62 | "Destination file for copying out of a Myriad file."); | 62 | "Destination file for copying out of a Myriad file."); |
| 63 | 63 | ||
| 64 | setOverride( "create", modeCreate ); | 64 | setOverride( "create", modeCreate ); |
| 65 | setOverride( "info", modeInfo ); | 65 | setOverride( "info", modeInfo ); |
| 66 | setOverride( "new", modeStreamNew ); | 66 | setOverride( "new", modeStreamNew ); |
| 67 | setOverride( "dump", modeStreamDump ); | 67 | setOverride( "dump", modeStreamDump ); |
| 68 | setOverride( "put", modeStreamPut ); | 68 | setOverride( "put", modeStreamPut ); |
| 69 | setOverride( "get", modeStreamGet ); | 69 | setOverride( "get", modeStreamGet ); |
| 70 | 70 | ||
| 71 | parse( argc, argv ); | 71 | parse( argc, argv ); |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | Mode eMode; | 74 | Mode eMode; |
| 75 | int iBlockSize; | 75 | int iBlockSize; |
| 76 | int iPreallocate; | 76 | int iPreallocate; |
| 77 | int iStream; | 77 | int iStream; |
| 78 | Bu::String sFile; | 78 | Bu::String sFile; |
| 79 | Bu::String sSrc; | 79 | Bu::String sSrc; |
| 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; |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | int main( int argc, char *argv[] ) | 89 | int main( int argc, char *argv[] ) |
| 90 | { | 90 | { |
| 91 | Options opts( argc, argv ); | 91 | Options opts( argc, argv ); |
| 92 | 92 | ||
| 93 | switch( opts.eMode ) | 93 | switch( opts.eMode ) |
| 94 | { | 94 | { |
| 95 | case modeCreate: | 95 | case modeCreate: |
| 96 | if( !opts.sFile.isSet() ) | 96 | if( !opts.sFile.isSet() ) |
| 97 | { | 97 | { |
| 98 | sio << "Please specify a file to create." << sio.nl; | 98 | sio << "Please specify a file to create." << sio.nl; |
| 99 | return 0; | 99 | return 0; |
| 100 | } | 100 | } |
| 101 | else | 101 | else |
| 102 | { | 102 | { |
| 103 | File fOut( opts.sFile, File::WriteNew|File::Read ); | 103 | File fOut( opts.sFile, File::WriteNew|File::Read ); |
| 104 | Myriad m( fOut, opts.iBlockSize, opts.iPreallocate ); | 104 | Myriad m( fOut, opts.iBlockSize, opts.iPreallocate ); |
| 105 | } | 105 | } |
| 106 | break; | 106 | break; |
| 107 | 107 | ||
| 108 | case modeInfo: | 108 | case modeInfo: |
| 109 | if( !opts.sFile.isSet() ) | 109 | if( !opts.sFile.isSet() ) |
| 110 | { | 110 | { |
| 111 | sio << "Please specify a file to display info about." << sio.nl; | 111 | sio << "Please specify a file to display info about." << sio.nl; |
| 112 | return 0; | 112 | return 0; |
| 113 | } | 113 | } |
| 114 | else | 114 | else |
| 115 | { | 115 | { |
| 116 | File fIn( opts.sFile, File::Read ); | 116 | File fIn( opts.sFile, File::Read ); |
| 117 | Myriad m( fIn ); | 117 | Myriad m( fIn ); |
| 118 | sio << "Myriad info:" << sio.nl | 118 | sio << "Myriad info:" << sio.nl |
| 119 | << " Block size: " << m.getBlockSize() << sio.nl | 119 | << " Block size: " << m.getBlockSize() << sio.nl |
| 120 | << " Block count: " << m.getNumBlocks() << sio.nl | 120 | << " Block count: " << m.getNumBlocks() << sio.nl |
| 121 | << " Blocks used: " << m.getNumUsedBlocks() << " (" | 121 | << " Blocks used: " << m.getNumUsedBlocks() << " (" |
| 122 | << m.getNumUsedBlocks()*100/m.getNumBlocks() << "%)" | 122 | << m.getNumUsedBlocks()*100/m.getNumBlocks() << "%)" |
| 123 | << sio.nl | 123 | << sio.nl |
| 124 | << " Stream count: " << m.getNumStreams() << sio.nl | 124 | << " Stream count: " << m.getNumStreams() << sio.nl |
| 125 | << " Used space: " << m.getTotalUsedBytes() << sio.nl | 125 | << " Used space: " << m.getTotalUsedBytes() << sio.nl |
| 126 | << " Unused space: " << m.getTotalUnusedBytes() << sio.nl | 126 | << " Unused space: " << m.getTotalUnusedBytes() << sio.nl |
| 127 | << " % of files: " << (double)(m.getNumBlocks()*m.getBlockSize())/(double)(m.getTotalUsedBytes() + m.getTotalUnusedBytes( 4096 ))*100.0 << sio.nl; | 127 | << " % of files: " << (double)(m.getNumBlocks()*m.getBlockSize())/(double)(m.getTotalUsedBytes() + m.getTotalUnusedBytes( 4096 ))*100.0 << sio.nl; |
| 128 | /* Bu::Array<int> aStreams = m.getStreamIds(); | 128 | /* Bu::Array<int> aStreams = m.getStreamIds(); |
| 129 | sio << " Stream info:" << sio.nl; | 129 | sio << " Stream info:" << sio.nl; |
| 130 | for( Bu::Array<int>::iterator i = aStreams.begin(); i; i++ ) | 130 | for( Bu::Array<int>::iterator i = aStreams.begin(); i; i++ ) |
| 131 | { | 131 | { |
| 132 | sio << " " << Fmt(4) << *i << ") " | 132 | sio << " " << Fmt(4) << *i << ") " |
| 133 | << m.getStreamSize( *i ) << "b" << sio.nl; | 133 | << m.getStreamSize( *i ) << "b" << sio.nl; |
| 134 | } */ | 134 | } */ |
| 135 | } | 135 | } |
| 136 | break; | 136 | break; |
| 137 | 137 | ||
| 138 | case modeStreamNew: | 138 | case modeStreamNew: |
| 139 | if( !opts.sFile.isSet() ) | 139 | if( !opts.sFile.isSet() ) |
| 140 | { | 140 | { |
| 141 | sio << "Please specify a file manipulate." << sio.nl; | 141 | sio << "Please specify a file manipulate." << sio.nl; |
| 142 | return 0; | 142 | return 0; |
| 143 | } | 143 | } |
| 144 | else | 144 | else |
| 145 | { | 145 | { |
| 146 | File fOut( opts.sFile, File::Write|File::Read ); | 146 | File fOut( opts.sFile, File::Write|File::Read ); |
| 147 | Myriad m( fOut ); | 147 | Myriad m( fOut ); |
| 148 | m.createStream( opts.iPreallocate ); | 148 | m.createStream( opts.iPreallocate ); |
| 149 | } | 149 | } |
| 150 | break; | 150 | break; |
| 151 | 151 | ||
| 152 | case modeStreamDump: | 152 | case modeStreamDump: |
| 153 | if( !opts.sFile.isSet() ) | 153 | if( !opts.sFile.isSet() ) |
| 154 | { | 154 | { |
| 155 | sio << "Please specify a file to manipulate." << sio.nl; | 155 | sio << "Please specify a file to manipulate." << sio.nl; |
| 156 | return 0; | 156 | return 0; |
| 157 | } | 157 | } |
| 158 | else | 158 | else |
| 159 | { | 159 | { |
| 160 | File fOut( opts.sFile, File::Read ); | 160 | File fOut( opts.sFile, File::Read ); |
| 161 | Myriad m( fOut ); | 161 | Myriad m( fOut ); |
| 162 | MyriadStream s = m.openStream( opts.iStream ); | 162 | MyriadStream s = m.openStream( opts.iStream ); |
| 163 | sio << "Stream " << opts.iStream << ":" << sio.nl; | 163 | sio << "Stream " << opts.iStream << ":" << sio.nl; |
| 164 | char buf[8]; | 164 | char buf[8]; |
| 165 | int iPos = 0; | 165 | int iPos = 0; |
| 166 | while( !s.isEos() ) | 166 | while( !s.isEos() ) |
| 167 | { | 167 | { |
| 168 | size_t sAmnt = s.read( buf, 8 ); | 168 | size_t sAmnt = s.read( buf, 8 ); |
| 169 | sio << Fmt(5) << iPos << ": "; | 169 | sio << Fmt(5) << iPos << ": "; |
| 170 | iPos += sAmnt; | 170 | iPos += sAmnt; |
| 171 | for( size_t j = 0; j < sAmnt; j++ ) | 171 | for( size_t j = 0; j < sAmnt; j++ ) |
| 172 | { | 172 | { |
| 173 | sio << Fmt::hex(2) << (int)((unsigned char)buf[j]) | 173 | sio << Fmt::hex(2) << (int)((unsigned char)buf[j]) |
| 174 | << " "; | 174 | << " "; |
| 175 | } | 175 | } |
| 176 | for( size_t j = sAmnt; j < 8; j++ ) | 176 | for( size_t j = sAmnt; j < 8; j++ ) |
| 177 | { | 177 | { |
| 178 | sio << "-- "; | 178 | sio << "-- "; |
| 179 | } | 179 | } |
| 180 | sio << "| "; | 180 | sio << "| "; |
| 181 | for( size_t j = 0; j < sAmnt; j++ ) | 181 | for( size_t j = 0; j < sAmnt; j++ ) |
| 182 | { | 182 | { |
| 183 | if( buf[j] >= 32 && buf[j] <= 126 ) | 183 | if( buf[j] >= 32 && buf[j] <= 126 ) |
| 184 | sio << buf[j] << " "; | 184 | sio << buf[j] << " "; |
| 185 | else | 185 | else |
| 186 | sio << " "; | 186 | sio << " "; |
| 187 | } | 187 | } |
| 188 | sio << sio.nl; | 188 | sio << sio.nl; |
| 189 | } | 189 | } |
| 190 | sio << "Position: " << s.tell() << ", isEos()=" << s.isEos() | 190 | sio << "Position: " << s.tell() << ", isEos()=" << s.isEos() |
| 191 | << sio.nl; | 191 | << sio.nl; |
| 192 | } | 192 | } |
| 193 | break; | 193 | break; |
| 194 | 194 | ||
| 195 | case modeStreamPut: | 195 | case modeStreamPut: |
| 196 | if( !opts.sFile.isSet() ) | 196 | if( !opts.sFile.isSet() ) |
| 197 | { | 197 | { |
| 198 | sio << "Please specify a file manipulate." << sio.nl; | 198 | sio << "Please specify a file manipulate." << sio.nl; |
| 199 | return 0; | 199 | return 0; |
| 200 | } | 200 | } |
| 201 | else if( !opts.sSrc.isSet() ) | 201 | else if( !opts.sSrc.isSet() ) |
| 202 | { | 202 | { |
| 203 | sio << "Please specify a source file to read." << sio.nl; | 203 | sio << "Please specify a source file to read." << sio.nl; |
| 204 | } | 204 | } |
| 205 | else | 205 | else |
| 206 | { | 206 | { |
| 207 | File fOut( opts.sFile, File::Write|File::Read ); | 207 | File fOut( opts.sFile, File::Write|File::Read ); |
| 208 | Myriad m( fOut ); | 208 | Myriad m( fOut ); |
| 209 | MyriadStream sOut = m.openStream( | 209 | MyriadStream sOut = m.openStream( |
| 210 | m.createStream( opts.iPreallocate ) | 210 | m.createStream( opts.iPreallocate ) |
| 211 | ); | 211 | ); |
| 212 | File fIn( opts.sSrc, File::Read ); | 212 | File fIn( opts.sSrc, File::Read ); |
| 213 | char buf[1024]; | 213 | char buf[1024]; |
| 214 | while( !fIn.isEos() ) | 214 | while( !fIn.isEos() ) |
| 215 | { | 215 | { |
| 216 | sOut.write( buf, fIn.read( buf, 1024 ) ); | 216 | sOut.write( buf, fIn.read( buf, 1024 ) ); |
| 217 | } | 217 | } |
| 218 | } | 218 | } |
| 219 | break; | 219 | break; |
| 220 | 220 | ||
| 221 | case modeStreamGet: | 221 | case modeStreamGet: |
| 222 | if( !opts.sFile.isSet() ) | 222 | if( !opts.sFile.isSet() ) |
| 223 | { | 223 | { |
| 224 | sio << "Please specify a file manipulate." << sio.nl; | 224 | sio << "Please specify a file manipulate." << sio.nl; |
| 225 | return 0; | 225 | return 0; |
| 226 | } | 226 | } |
| 227 | else if( !opts.sDst.isSet() ) | 227 | else if( !opts.sDst.isSet() ) |
| 228 | { | 228 | { |
| 229 | sio << "Please specify a destination file to write." << sio.nl; | 229 | sio << "Please specify a destination file to write." << sio.nl; |
| 230 | } | 230 | } |
| 231 | else | 231 | else |
| 232 | { | 232 | { |
| 233 | File fIn( opts.sFile, File::Write|File::Read ); | 233 | File fIn( opts.sFile, File::Write|File::Read ); |
| 234 | Myriad m( fIn ); | 234 | Myriad m( fIn ); |
| 235 | MyriadStream sIn = m.openStream( opts.iStream ); | 235 | MyriadStream sIn = m.openStream( opts.iStream ); |
| 236 | File fOut( opts.sDst, File::Write|File::Create|File::Truncate ); | 236 | File fOut( opts.sDst, File::Write|File::Create|File::Truncate ); |
| 237 | char buf[1024]; | 237 | char buf[1024]; |
| 238 | while( !sIn.isEos() ) | 238 | while( !sIn.isEos() ) |
| 239 | { | 239 | { |
| 240 | fOut.write( buf, sIn.read( buf, 1024 ) ); | 240 | fOut.write( buf, sIn.read( buf, 1024 ) ); |
| 241 | } | 241 | } |
| 242 | } | 242 | } |
| 243 | break; | 243 | break; |
| 244 | 244 | ||
| 245 | case modeNone: | 245 | case modeNone: |
| 246 | sio << "Please select a mode, for more info, try --help." | 246 | sio << "Please select a mode, for more info, try --help." |
| 247 | << sio.nl << sio.nl; | 247 | << sio.nl << sio.nl; |
| 248 | break; | 248 | break; |
| 249 | } | 249 | } |
| 250 | 250 | ||
| 251 | return 0; | 251 | return 0; |
| 252 | } | 252 | } |
| 253 | 253 | ||
