From 3f1c8998166466245aee2860197fb4908e55f1a2 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 8 Oct 2008 16:17:26 +0000 Subject: Ok...corrected a problem with new block allocation in nids, and it no longer goes into an infinite loop while doing certain kinds of read. Also, it zeros out new blocks to make things easier to cope with in the hex editor, it'll probably also compress better. I also fixed Bu::MemBuf so that you can now write to arbitrary places mid-stream. --- src/tests/nids.cpp | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) (limited to 'src/tests') diff --git a/src/tests/nids.cpp b/src/tests/nids.cpp index f50fde5..d531280 100644 --- a/src/tests/nids.cpp +++ b/src/tests/nids.cpp @@ -4,22 +4,44 @@ int main( int argc, char *argv[] ) { - if( argc < 2 ) + if( argc < 3 ) { - printf("usage: %s \n\n", argv[0] ); + printf("usage: %s [r|w] \n\n", argv[0] ); return 1; } - Bu::File fOut( argv[1], Bu::File::ReadWrite ); - Bu::Nids n( fOut ); + if( argv[1][0] == 'w' ) + { + Bu::File fOut( argv[2], + Bu::File::ReadWrite|Bu::File::Create|Bu::File::Truncate ); + Bu::Nids n( fOut ); -// n.initialize( 120, 5 ); + n.initialize( 120, 1 ); + Bu::NidsStream s = n.openStream( n.createStream() ); - Bu::NidsStream s = n.openStream( n.createStream() ); + Bu::FString sBuf( 350 ); + memset( sBuf.getStr(), 'a', 350 ); + s.write( sBuf ); + } + else if( argv[1][0] == 'r' ) + { + Bu::File fOut( argv[2], Bu::File::Read ); + Bu::Nids n( fOut ); -// Bu::FString sBuf( 350 ); -// memset( sBuf.getStr(), 'a', 350 ); -// s.write( sBuf ); + Bu::NidsStream s = n.openStream( 0 ); + char buf[75]; + for( int j = 0; j < 3; j++ ) + { + int iRead = s.read( buf, 75 ); + fwrite( buf, 1, iRead, stdout ); + printf("\n(read %d chars)\n", iRead ); + } + printf("Position: %ld\n", s.tell() ); + } + else + { + printf("r or w, those are your choices.\n"); + } return 0; } -- cgit v1.2.3