From 79b7b631750b69cbe06daedb0453306595dea6ad Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 10 Feb 2010 18:20:40 +0000 Subject: Changed the name of nids to Myriad, I like it, but I'm not getting rid of nids until I can safely migrate to Myriad. --- src/tools/myriad.cpp | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 src/tools/myriad.cpp (limited to 'src/tools') diff --git a/src/tools/myriad.cpp b/src/tools/myriad.cpp new file mode 100644 index 0000000..e951882 --- /dev/null +++ b/src/tools/myriad.cpp @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2007-2008 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#include "bu/sio.h" +#include "bu/file.h" +#include "bu/myriad.h" +#include "bu/myriadstream.h" +#include "bu/optparser.h" + +#include + +using namespace Bu; + +enum Mode +{ + modeCreate, + modeInfo, + + modeNone +}; + +class Options : public OptParser +{ +public: + Options( int argc, char *argv[] ) : + eMode( modeNone ), + iBlockSize( 64 ), + iPreallocate( 0 ) + { + addHelpBanner("Mode of operation:"); + addOption( eMode, 'c', "create", "Create a new NIDS file." ); + addOption( eMode, "info", "Display some info about a NIDS 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." ); + + setOverride( "create", "create" ); + setOverride( "info", "info" ); + + parse( argc, argv ); + } + + Mode eMode; + int iBlockSize; + int iPreallocate; + Bu::FString sOutput; + Bu::FString sInput; +}; + +Bu::Formatter &operator>>( Bu::Formatter &f, Mode &m ) +{ + Bu::FString sTok = f.readToken(); + if( sTok == "create" || sTok == "c" ) + m = modeCreate; + else if( sTok == "info" ) + m = modeInfo; + else + m = modeNone; + return f; +} + +int main( int argc, char *argv[] ) +{ + Options opts( argc, argv ); + + switch( opts.eMode ) + { + case modeCreate: + if( !opts.sOutput ) + { + sio << "Please specify an output file to create a stream for." + << sio.nl; + return 0; + } + else + { + File fOut( opts.sOutput, File::WriteNew ); + Myriad n( fOut ); + n.initialize( opts.iBlockSize, opts.iPreallocate ); + } + break; + + case modeInfo: + if( !opts.sInput ) + { + sio << "Please specify an input file to display info about." + << sio.nl; + return 0; + } + else + { + File fIn( opts.sInput, File::Read ); + Myriad n( fIn ); + n.initialize(); + } + break; + + case modeNone: + sio << "Please select a mode, for more info, try --help." + << sio.nl << sio.nl; + break; + } + + return 0; +} + -- cgit v1.2.3