From aefab051dd21df0123ffa45a5a28d594bfecf82d Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 10 Nov 2010 21:18:58 +0000 Subject: Added a couple more debugging functions to Bu::Myriad, and exposed them in the cli tool. --- src/tools/myriad.cpp | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'src/tools') 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 modeStreamNew, modeStreamDump, modeStreamPut, + modeStreamGet, modeNone }; @@ -43,9 +44,11 @@ public: addOption( eMode, 'n', "new", "Create a new sub-stream in a Myriad file."); addOption( eMode, 'd', "dump", - "Read a stream from a Myriad file."); + "Display a hexdump of a stream from a Myriad file."); + addOption( eMode, "get", + "Get a file out of a Myriad stream (use --dst)."); addOption( eMode, "put", - "Put a file into a Myriad stream."); + "Put a file into a Myriad stream (usr --src)."); addHelpOption(); addHelpBanner("\nGeneral options:"); @@ -55,12 +58,15 @@ public: addOption( sFile, 'f', "file", "Set the Myriad filename." ); addOption( iStream, 's', "stream", "Substream to work with."); addOption( sSrc, "src", "Source file for copying into a Myriad file."); + addOption( sDst, "dst", + "Destination file for copying out of a Myriad file."); setOverride( "create", modeCreate ); setOverride( "info", modeInfo ); setOverride( "new", modeStreamNew ); setOverride( "dump", modeStreamDump ); setOverride( "put", modeStreamPut ); + setOverride( "get", modeStreamGet ); parse( argc, argv ); } @@ -71,6 +77,7 @@ public: int iStream; Bu::FString sFile; Bu::FString sSrc; + Bu::FString sDst; }; Bu::Formatter &operator>>( Bu::Formatter &f, Mode &e ) @@ -114,7 +121,10 @@ int main( int argc, char *argv[] ) << " Blocks used: " << m.getNumUsedBlocks() << " (" << m.getNumUsedBlocks()*100/m.getNumBlocks() << "%)" << sio.nl - << " Stream count: " << m.getNumStreams() << sio.nl; + << " Stream count: " << m.getNumStreams() << sio.nl + << " Used space: " << m.getTotalUsedBytes() << sio.nl + << " Unused space: " << m.getTotalUnusedBytes() << sio.nl + << " % of files: " << (double)(m.getNumBlocks()*m.getBlockSize())/(double)(m.getTotalUsedBytes() + m.getTotalUnusedBytes( 4096 ))*100.0 << sio.nl; Bu::Array aStreams = m.getStreamIds(); sio << " Stream info:" << sio.nl; for( Bu::Array::iterator i = aStreams.begin(); i; i++ ) @@ -208,6 +218,30 @@ int main( int argc, char *argv[] ) } break; + case modeStreamGet: + if( !opts.sFile.isSet() ) + { + sio << "Please specify a file manipulate." << sio.nl; + return 0; + } + else if( !opts.sDst.isSet() ) + { + sio << "Please specify a destination file to write." << sio.nl; + } + else + { + File fIn( opts.sFile, File::Write|File::Read ); + Myriad m( fIn ); + MyriadStream sIn = m.openStream( opts.iStream ); + File fOut( opts.sDst, File::Write|File::Create|File::Truncate ); + char buf[1024]; + while( !sIn.isEos() ) + { + fOut.write( buf, sIn.read( buf, 1024 ) ); + } + } + break; + case modeNone: sio << "Please select a mode, for more info, try --help." << sio.nl << sio.nl; -- cgit v1.2.3