diff options
Diffstat (limited to '')
| -rw-r--r-- | src/tools/myriad.cpp | 115 |
1 files changed, 115 insertions, 0 deletions
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2008 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libbu++ library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include "bu/sio.h" | ||
| 9 | #include "bu/file.h" | ||
| 10 | #include "bu/myriad.h" | ||
| 11 | #include "bu/myriadstream.h" | ||
| 12 | #include "bu/optparser.h" | ||
| 13 | |||
| 14 | #include <stdlib.h> | ||
| 15 | |||
| 16 | using namespace Bu; | ||
| 17 | |||
| 18 | enum Mode | ||
| 19 | { | ||
| 20 | modeCreate, | ||
| 21 | modeInfo, | ||
| 22 | |||
| 23 | modeNone | ||
| 24 | }; | ||
| 25 | |||
| 26 | class Options : public OptParser | ||
| 27 | { | ||
| 28 | public: | ||
| 29 | Options( int argc, char *argv[] ) : | ||
| 30 | eMode( modeNone ), | ||
| 31 | iBlockSize( 64 ), | ||
| 32 | iPreallocate( 0 ) | ||
| 33 | { | ||
| 34 | addHelpBanner("Mode of operation:"); | ||
| 35 | addOption( eMode, 'c', "create", "Create a new NIDS file." ); | ||
| 36 | addOption( eMode, "info", "Display some info about a NIDS file." ); | ||
| 37 | addHelpOption(); | ||
| 38 | |||
| 39 | addHelpBanner("\nGeneral options:"); | ||
| 40 | addOption( iBlockSize, 'b', "block-size", "Set the block size." ); | ||
| 41 | addOption( iPreallocate, 'p', "preallocate", | ||
| 42 | "Number of blocks to preallocate." ); | ||
| 43 | addOption( sOutput, 'o', "output", "Set the output filename." ); | ||
| 44 | addOption( sInput, 'i', "input", "Set the input filename." ); | ||
| 45 | |||
| 46 | setOverride( "create", "create" ); | ||
| 47 | setOverride( "info", "info" ); | ||
| 48 | |||
| 49 | parse( argc, argv ); | ||
| 50 | } | ||
| 51 | |||
| 52 | Mode eMode; | ||
| 53 | int iBlockSize; | ||
| 54 | int iPreallocate; | ||
| 55 | Bu::FString sOutput; | ||
| 56 | Bu::FString sInput; | ||
| 57 | }; | ||
| 58 | |||
| 59 | Bu::Formatter &operator>>( Bu::Formatter &f, Mode &m ) | ||
| 60 | { | ||
| 61 | Bu::FString sTok = f.readToken(); | ||
| 62 | if( sTok == "create" || sTok == "c" ) | ||
| 63 | m = modeCreate; | ||
| 64 | else if( sTok == "info" ) | ||
| 65 | m = modeInfo; | ||
| 66 | else | ||
| 67 | m = modeNone; | ||
| 68 | return f; | ||
| 69 | } | ||
| 70 | |||
| 71 | int main( int argc, char *argv[] ) | ||
| 72 | { | ||
| 73 | Options opts( argc, argv ); | ||
| 74 | |||
| 75 | switch( opts.eMode ) | ||
| 76 | { | ||
| 77 | case modeCreate: | ||
| 78 | if( !opts.sOutput ) | ||
| 79 | { | ||
| 80 | sio << "Please specify an output file to create a stream for." | ||
| 81 | << sio.nl; | ||
| 82 | return 0; | ||
| 83 | } | ||
| 84 | else | ||
| 85 | { | ||
| 86 | File fOut( opts.sOutput, File::WriteNew ); | ||
| 87 | Myriad n( fOut ); | ||
| 88 | n.initialize( opts.iBlockSize, opts.iPreallocate ); | ||
| 89 | } | ||
| 90 | break; | ||
| 91 | |||
| 92 | case modeInfo: | ||
| 93 | if( !opts.sInput ) | ||
| 94 | { | ||
| 95 | sio << "Please specify an input file to display info about." | ||
| 96 | << sio.nl; | ||
| 97 | return 0; | ||
| 98 | } | ||
| 99 | else | ||
| 100 | { | ||
| 101 | File fIn( opts.sInput, File::Read ); | ||
| 102 | Myriad n( fIn ); | ||
| 103 | n.initialize(); | ||
| 104 | } | ||
| 105 | break; | ||
| 106 | |||
| 107 | case modeNone: | ||
| 108 | sio << "Please select a mode, for more info, try --help." | ||
| 109 | << sio.nl << sio.nl; | ||
| 110 | break; | ||
| 111 | } | ||
| 112 | |||
| 113 | return 0; | ||
| 114 | } | ||
| 115 | |||
