aboutsummaryrefslogtreecommitdiff
path: root/src/tools/myriad.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-11-10 21:18:58 +0000
committerMike Buland <eichlan@xagasoft.com>2010-11-10 21:18:58 +0000
commitaefab051dd21df0123ffa45a5a28d594bfecf82d (patch)
tree790ed55144c6114cb59f7d7280a79e020a14d031 /src/tools/myriad.cpp
parent31b0ab27116519ecc441c96166ac36dcd637f68d (diff)
downloadlibbu++-aefab051dd21df0123ffa45a5a28d594bfecf82d.tar.gz
libbu++-aefab051dd21df0123ffa45a5a28d594bfecf82d.tar.bz2
libbu++-aefab051dd21df0123ffa45a5a28d594bfecf82d.tar.xz
libbu++-aefab051dd21df0123ffa45a5a28d594bfecf82d.zip
Added a couple more debugging functions to Bu::Myriad, and exposed them in the
cli tool.
Diffstat (limited to 'src/tools/myriad.cpp')
-rw-r--r--src/tools/myriad.cpp40
1 files changed, 37 insertions, 3 deletions
diff --git a/src/tools/myriad.cpp b/src/tools/myriad.cpp
index c6a3a4d..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", modeCreate ); 64 setOverride( "create", modeCreate );
60 setOverride( "info", modeInfo ); 65 setOverride( "info", modeInfo );
61 setOverride( "new", modeStreamNew ); 66 setOverride( "new", modeStreamNew );
62 setOverride( "dump", modeStreamDump ); 67 setOverride( "dump", modeStreamDump );
63 setOverride( "put", modeStreamPut ); 68 setOverride( "put", modeStreamPut );
69 setOverride( "get", modeStreamGet );
64 70
65 parse( argc, argv ); 71 parse( argc, argv );
66 } 72 }
@@ -71,6 +77,7 @@ 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
76Bu::Formatter &operator>>( Bu::Formatter &f, Mode &e ) 83Bu::Formatter &operator>>( Bu::Formatter &f, Mode &e )
@@ -114,7 +121,10 @@ int main( int argc, char *argv[] )
114 << " Blocks used: " << m.getNumUsedBlocks() << " (" 121 << " Blocks used: " << m.getNumUsedBlocks() << " ("
115 << m.getNumUsedBlocks()*100/m.getNumBlocks() << "%)" 122 << m.getNumUsedBlocks()*100/m.getNumBlocks() << "%)"
116 << sio.nl 123 << sio.nl
117 << " 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;
118 Bu::Array<int> aStreams = m.getStreamIds(); 128 Bu::Array<int> aStreams = m.getStreamIds();
119 sio << " Stream info:" << sio.nl; 129 sio << " Stream info:" << sio.nl;
120 for( Bu::Array<int>::iterator i = aStreams.begin(); i; i++ ) 130 for( Bu::Array<int>::iterator i = aStreams.begin(); i; i++ )
@@ -208,6 +218,30 @@ int main( int argc, char *argv[] )
208 } 218 }
209 break; 219 break;
210 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
211 case modeNone: 245 case modeNone:
212 sio << "Please select a mode, for more info, try --help." 246 sio << "Please select a mode, for more info, try --help."
213 << sio.nl << sio.nl; 247 << sio.nl << sio.nl;