diff options
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/myriad.cpp | 66 |
1 files changed, 44 insertions, 22 deletions
diff --git a/src/tools/myriad.cpp b/src/tools/myriad.cpp index 73ceba1..b6e435d 100644 --- a/src/tools/myriad.cpp +++ b/src/tools/myriad.cpp | |||
@@ -22,6 +22,7 @@ enum Mode | |||
22 | modeStreamNew, | 22 | modeStreamNew, |
23 | modeStreamDump, | 23 | modeStreamDump, |
24 | modeStreamPut, | 24 | modeStreamPut, |
25 | modeStreamGet, | ||
25 | 26 | ||
26 | modeNone | 27 | modeNone |
27 | }; | 28 | }; |
@@ -43,9 +44,11 @@ public: | |||
43 | addOption( eMode, 'n', "new", | 44 | addOption( eMode, 'n', "new", |
44 | "Create a new sub-stream in a Myriad file."); | 45 | "Create a new sub-stream in a Myriad file."); |
45 | addOption( eMode, 'd', "dump", | 46 | addOption( eMode, 'd', "dump", |
46 | "Read a stream from a Myriad file."); | 47 | "Display a hexdump of a stream from a Myriad file."); |
48 | addOption( eMode, "get", | ||
49 | "Get a file out of a Myriad stream (use --dst)."); | ||
47 | addOption( eMode, "put", | 50 | addOption( eMode, "put", |
48 | "Put a file into a Myriad stream."); | 51 | "Put a file into a Myriad stream (usr --src)."); |
49 | addHelpOption(); | 52 | addHelpOption(); |
50 | 53 | ||
51 | addHelpBanner("\nGeneral options:"); | 54 | addHelpBanner("\nGeneral options:"); |
@@ -55,12 +58,15 @@ public: | |||
55 | addOption( sFile, 'f', "file", "Set the Myriad filename." ); | 58 | addOption( sFile, 'f', "file", "Set the Myriad filename." ); |
56 | addOption( iStream, 's', "stream", "Substream to work with."); | 59 | addOption( iStream, 's', "stream", "Substream to work with."); |
57 | 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", | ||
62 | "Destination file for copying out of a Myriad file."); | ||
58 | 63 | ||
59 | setOverride( "create", "create" ); | 64 | setOverride( "create", modeCreate ); |
60 | setOverride( "info", "info" ); | 65 | setOverride( "info", modeInfo ); |
61 | setOverride( "new", "new" ); | 66 | setOverride( "new", modeStreamNew ); |
62 | setOverride( "dump", "dump" ); | 67 | setOverride( "dump", modeStreamDump ); |
63 | setOverride( "put", "put" ); | 68 | setOverride( "put", modeStreamPut ); |
69 | setOverride( "get", modeStreamGet ); | ||
64 | 70 | ||
65 | parse( argc, argv ); | 71 | parse( argc, argv ); |
66 | } | 72 | } |
@@ -71,23 +77,12 @@ public: | |||
71 | int iStream; | 77 | int iStream; |
72 | Bu::FString sFile; | 78 | Bu::FString sFile; |
73 | Bu::FString sSrc; | 79 | Bu::FString sSrc; |
80 | Bu::FString sDst; | ||
74 | }; | 81 | }; |
75 | 82 | ||
76 | Bu::Formatter &operator>>( Bu::Formatter &f, Mode &m ) | 83 | Bu::Formatter &operator>>( Bu::Formatter &f, Mode &e ) |
77 | { | 84 | { |
78 | Bu::FString sTok = f.readToken(); | 85 | sio << "Uh oh, the formatter was called..." << sio.nl; |
79 | if( sTok == "create" ) | ||
80 | m = modeCreate; | ||
81 | else if( sTok == "info" ) | ||
82 | m = modeInfo; | ||
83 | else if( sTok == "new" ) | ||
84 | m = modeStreamNew; | ||
85 | else if( sTok == "dump" ) | ||
86 | m = modeStreamDump; | ||
87 | else if( sTok == "put" ) | ||
88 | m = modeStreamPut; | ||
89 | else | ||
90 | m = modeNone; | ||
91 | return f; | 86 | return f; |
92 | } | 87 | } |
93 | 88 | ||
@@ -126,7 +121,10 @@ int main( int argc, char *argv[] ) | |||
126 | << " Blocks used: " << m.getNumUsedBlocks() << " (" | 121 | << " Blocks used: " << m.getNumUsedBlocks() << " (" |
127 | << m.getNumUsedBlocks()*100/m.getNumBlocks() << "%)" | 122 | << m.getNumUsedBlocks()*100/m.getNumBlocks() << "%)" |
128 | << sio.nl | 123 | << sio.nl |
129 | << " Stream count: " << m.getNumStreams() << sio.nl; | 124 | << " Stream count: " << m.getNumStreams() << sio.nl |
125 | << " Used space: " << m.getTotalUsedBytes() << 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; | ||
130 | Bu::Array<int> aStreams = m.getStreamIds(); | 128 | Bu::Array<int> aStreams = m.getStreamIds(); |
131 | sio << " Stream info:" << sio.nl; | 129 | sio << " Stream info:" << sio.nl; |
132 | for( Bu::Array<int>::iterator i = aStreams.begin(); i; i++ ) | 130 | for( Bu::Array<int>::iterator i = aStreams.begin(); i; i++ ) |
@@ -220,6 +218,30 @@ int main( int argc, char *argv[] ) | |||
220 | } | 218 | } |
221 | break; | 219 | break; |
222 | 220 | ||
221 | case modeStreamGet: | ||
222 | if( !opts.sFile.isSet() ) | ||
223 | { | ||
224 | sio << "Please specify a file manipulate." << sio.nl; | ||
225 | return 0; | ||
226 | } | ||
227 | else if( !opts.sDst.isSet() ) | ||
228 | { | ||
229 | sio << "Please specify a destination file to write." << sio.nl; | ||
230 | } | ||
231 | else | ||
232 | { | ||
233 | File fIn( opts.sFile, File::Write|File::Read ); | ||
234 | Myriad m( fIn ); | ||
235 | MyriadStream sIn = m.openStream( opts.iStream ); | ||
236 | File fOut( opts.sDst, File::Write|File::Create|File::Truncate ); | ||
237 | char buf[1024]; | ||
238 | while( !sIn.isEos() ) | ||
239 | { | ||
240 | fOut.write( buf, sIn.read( buf, 1024 ) ); | ||
241 | } | ||
242 | } | ||
243 | break; | ||
244 | |||
223 | case modeNone: | 245 | case modeNone: |
224 | sio << "Please select a mode, for more info, try --help." | 246 | sio << "Please select a mode, for more info, try --help." |
225 | << sio.nl << sio.nl; | 247 | << sio.nl << sio.nl; |