From 4f59dec6bad120b72f1bc075715d79bfbe881f7e Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 28 Jan 2009 07:12:35 +0000 Subject: The nids tool now has a re-write and cleanup option, it can also change the block size. Isn't that nifty? --- src/tests/nidstool.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/tests') diff --git a/src/tests/nidstool.cpp b/src/tests/nidstool.cpp index 1becba5..d1465ce 100644 --- a/src/tests/nidstool.cpp +++ b/src/tests/nidstool.cpp @@ -24,6 +24,8 @@ public: "Dump a stream to a file."); addParam("analyze", 'a', mkproc(Param::procAnalyze), "Analyze a nids file."); + addParam("copy", 'c', mkproc(Param::procCopy), + "Copy a nids file, changing settings."); addParam("help", 'h', mkproc(Bu::ParamProc::help), "This help."); process( argc, argv ); } @@ -185,6 +187,48 @@ public: return 1; } + + int procCopy( int argc, char *argv[] ) + { + if( argc < 3 ) + { + printf("You must provide source stream, blocksize, destination.\n"); + exit( 1 ); + } + + Bu::File fIn( argv[0], Bu::File::Read ); + Bu::Nids nIn( fIn ); + nIn.initialize(); + + Bu::File fOut( argv[2], Bu::File::Read|Bu::File::Write|Bu::File::Create| + Bu::File::Truncate ); + Bu::Nids nOut( fOut ); + nOut.initialize( strtol( argv[1], 0, NULL ) ); + + Block b; + for( int j = 0; j < nIn.getNumBlocks(); j++ ) + { + fIn.setPos( nIn.getBlockStart()+nIn.getBlockSize()*j ); + fIn.read( &b, sizeof(Block) ); + if( b.uFirstBlock != (uint32_t)j ) + continue; + + Bu::NidsStream sIn = nIn.openStream( j ); + int iNew = nOut.createStream(); + Bu::NidsStream sOut = nOut.openStream( iNew ); + + char buf[1024]; + for(;;) + { + int iRead = sIn.read( buf, 1024 ); + sOut.write( buf, iRead ); + if( iRead < 1024 ) + break; + } + } + + return 3; + } }; -- cgit v1.2.3