From 41c9581b48f055f6559335ffc0316f27ed1b3657 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 12 Apr 2010 07:37:09 +0000 Subject: Myriad is getting pretty close, just have to finish the writing code and probably tweak the header init. --- src/tools/myriad.cpp | 112 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 92 insertions(+), 20 deletions(-) (limited to 'src/tools/myriad.cpp') diff --git a/src/tools/myriad.cpp b/src/tools/myriad.cpp index b3067d2..95b4503 100644 --- a/src/tools/myriad.cpp +++ b/src/tools/myriad.cpp @@ -19,6 +19,8 @@ enum Mode { modeCreate, modeInfo, + modeStreamNew, + modeStreamRead, modeNone }; @@ -29,22 +31,32 @@ public: Options( int argc, char *argv[] ) : eMode( modeNone ), iBlockSize( 64 ), - iPreallocate( 0 ) + iPreallocate( 0 ), + iStream( 0 ) { addHelpBanner("Mode of operation:"); - addOption( eMode, 'c', "create", "Create a new NIDS file." ); - addOption( eMode, "info", "Display some info about a NIDS file." ); + addOption( eMode, 'c', "create", + "Create a new Myriad file." ); + addOption( eMode, 'i', "info", + "Display some info about a Myriad file." ); + addOption( eMode, 'n', "new", + "Create a new sub-stream in a Myriad file."); + addOption( eMode, 'r', "read", + "Read a stream from a Myriad file."); addHelpOption(); addHelpBanner("\nGeneral options:"); addOption( iBlockSize, 'b', "block-size", "Set the block size." ); addOption( iPreallocate, 'p', "preallocate", "Number of blocks to preallocate." ); - addOption( sOutput, 'o', "output", "Set the output filename." ); - addOption( sInput, 'i', "input", "Set the input filename." ); + 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."); setOverride( "create", "create" ); setOverride( "info", "info" ); + setOverride( "new", "new" ); + setOverride( "read", "read" ); parse( argc, argv ); } @@ -52,17 +64,22 @@ public: Mode eMode; int iBlockSize; int iPreallocate; - Bu::FString sOutput; - Bu::FString sInput; + int iStream; + Bu::FString sFile; + Bu::FString sSrc; }; Bu::Formatter &operator>>( Bu::Formatter &f, Mode &m ) { Bu::FString sTok = f.readToken(); - if( sTok == "create" || sTok == "c" ) + if( sTok == "create" ) m = modeCreate; else if( sTok == "info" ) m = modeInfo; + else if( sTok == "new" ) + m = modeStreamNew; + else if( sTok == "read" ) + m = modeStreamRead; else m = modeNone; return f; @@ -75,32 +92,87 @@ int main( int argc, char *argv[] ) switch( opts.eMode ) { case modeCreate: - if( !opts.sOutput.isSet() ) + if( !opts.sFile.isSet() ) { - sio << "Please specify an output file to create a stream for." - << sio.nl; + sio << "Please specify a file to create." << sio.nl; return 0; } else { - File fOut( opts.sOutput, File::WriteNew ); - Myriad n( fOut ); - n.initialize( opts.iBlockSize, opts.iPreallocate ); + File fOut( opts.sFile, File::WriteNew ); + Myriad m( fOut ); + m.initialize( opts.iBlockSize, opts.iPreallocate ); } break; case modeInfo: - if( !opts.sInput.isSet() ) + if( !opts.sFile.isSet() ) { - sio << "Please specify an input file to display info about." - << sio.nl; + sio << "Please specify a file to display info about." << sio.nl; return 0; } else { - File fIn( opts.sInput, File::Read ); - Myriad n( fIn ); - n.initialize(); + File fIn( opts.sFile, File::Read ); + Myriad m( fIn ); + m.initialize(); + } + break; + + case modeStreamNew: + if( !opts.sFile.isSet() ) + { + sio << "Please specify a file manipulate." << sio.nl; + return 0; + } + else + { + File fOut( opts.sFile, File::Write|File::Read ); + Myriad m( fOut ); + m.initialize(); + m.createStream( opts.iPreallocate ); + } + break; + + case modeStreamRead: + if( !opts.sFile.isSet() ) + { + sio << "Please specify a file manipulate." << sio.nl; + return 0; + } + else + { + File fOut( opts.sFile, File::Read ); + Myriad m( fOut ); + m.initialize(); + MyriadStream s = m.openStream( opts.iStream ); + sio << "Stream " << opts.iStream << ":" << sio.nl; + char buf[8]; + int iPos = 0; + while( !s.isEos() ) + { + size_t sAmnt = s.read( buf, 8 ); + sio << Fmt(5) << iPos << ": "; + iPos += sAmnt; + for( size_t j = 0; j < sAmnt; j++ ) + { + sio << Fmt::hex(2) << (int)((unsigned char)buf[j]) + << " "; + } + for( size_t j = sAmnt; j < 8; j++ ) + { + sio << "-- "; + } + sio << "| "; + for( size_t j = 0; j < sAmnt; j++ ) + { + if( buf[j] >= 32 && buf[j] <= 126 ) + sio << buf[j] << " "; + else + sio << " "; + } + sio << sio.nl; + } } break; -- cgit v1.2.3