aboutsummaryrefslogtreecommitdiff
path: root/src/tools/myriad.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-04-12 07:37:09 +0000
committerMike Buland <eichlan@xagasoft.com>2010-04-12 07:37:09 +0000
commit41c9581b48f055f6559335ffc0316f27ed1b3657 (patch)
tree22c6737ff5e6fd7732597dcd83a190ae917f0079 /src/tools/myriad.cpp
parent943cf16f5661357086532b2241e6f85bfe43565a (diff)
downloadlibbu++-41c9581b48f055f6559335ffc0316f27ed1b3657.tar.gz
libbu++-41c9581b48f055f6559335ffc0316f27ed1b3657.tar.bz2
libbu++-41c9581b48f055f6559335ffc0316f27ed1b3657.tar.xz
libbu++-41c9581b48f055f6559335ffc0316f27ed1b3657.zip
Myriad is getting pretty close, just have to finish the writing code and
probably tweak the header init.
Diffstat (limited to '')
-rw-r--r--src/tools/myriad.cpp112
1 files changed, 92 insertions, 20 deletions
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
19{ 19{
20 modeCreate, 20 modeCreate,
21 modeInfo, 21 modeInfo,
22 modeStreamNew,
23 modeStreamRead,
22 24
23 modeNone 25 modeNone
24}; 26};
@@ -29,22 +31,32 @@ public:
29 Options( int argc, char *argv[] ) : 31 Options( int argc, char *argv[] ) :
30 eMode( modeNone ), 32 eMode( modeNone ),
31 iBlockSize( 64 ), 33 iBlockSize( 64 ),
32 iPreallocate( 0 ) 34 iPreallocate( 0 ),
35 iStream( 0 )
33 { 36 {
34 addHelpBanner("Mode of operation:"); 37 addHelpBanner("Mode of operation:");
35 addOption( eMode, 'c', "create", "Create a new NIDS file." ); 38 addOption( eMode, 'c', "create",
36 addOption( eMode, "info", "Display some info about a NIDS file." ); 39 "Create a new Myriad file." );
40 addOption( eMode, 'i', "info",
41 "Display some info about a Myriad file." );
42 addOption( eMode, 'n', "new",
43 "Create a new sub-stream in a Myriad file.");
44 addOption( eMode, 'r', "read",
45 "Read a stream from a Myriad file.");
37 addHelpOption(); 46 addHelpOption();
38 47
39 addHelpBanner("\nGeneral options:"); 48 addHelpBanner("\nGeneral options:");
40 addOption( iBlockSize, 'b', "block-size", "Set the block size." ); 49 addOption( iBlockSize, 'b', "block-size", "Set the block size." );
41 addOption( iPreallocate, 'p', "preallocate", 50 addOption( iPreallocate, 'p', "preallocate",
42 "Number of blocks to preallocate." ); 51 "Number of blocks to preallocate." );
43 addOption( sOutput, 'o', "output", "Set the output filename." ); 52 addOption( sFile, 'f', "file", "Set the Myriad filename." );
44 addOption( sInput, 'i', "input", "Set the input filename." ); 53 addOption( iStream, 's', "stream", "Substream to work with.");
54 addOption( sSrc, "src", "Source file for copying into a Myriad file.");
45 55
46 setOverride( "create", "create" ); 56 setOverride( "create", "create" );
47 setOverride( "info", "info" ); 57 setOverride( "info", "info" );
58 setOverride( "new", "new" );
59 setOverride( "read", "read" );
48 60
49 parse( argc, argv ); 61 parse( argc, argv );
50 } 62 }
@@ -52,17 +64,22 @@ public:
52 Mode eMode; 64 Mode eMode;
53 int iBlockSize; 65 int iBlockSize;
54 int iPreallocate; 66 int iPreallocate;
55 Bu::FString sOutput; 67 int iStream;
56 Bu::FString sInput; 68 Bu::FString sFile;
69 Bu::FString sSrc;
57}; 70};
58 71
59Bu::Formatter &operator>>( Bu::Formatter &f, Mode &m ) 72Bu::Formatter &operator>>( Bu::Formatter &f, Mode &m )
60{ 73{
61 Bu::FString sTok = f.readToken(); 74 Bu::FString sTok = f.readToken();
62 if( sTok == "create" || sTok == "c" ) 75 if( sTok == "create" )
63 m = modeCreate; 76 m = modeCreate;
64 else if( sTok == "info" ) 77 else if( sTok == "info" )
65 m = modeInfo; 78 m = modeInfo;
79 else if( sTok == "new" )
80 m = modeStreamNew;
81 else if( sTok == "read" )
82 m = modeStreamRead;
66 else 83 else
67 m = modeNone; 84 m = modeNone;
68 return f; 85 return f;
@@ -75,32 +92,87 @@ int main( int argc, char *argv[] )
75 switch( opts.eMode ) 92 switch( opts.eMode )
76 { 93 {
77 case modeCreate: 94 case modeCreate:
78 if( !opts.sOutput.isSet() ) 95 if( !opts.sFile.isSet() )
79 { 96 {
80 sio << "Please specify an output file to create a stream for." 97 sio << "Please specify a file to create." << sio.nl;
81 << sio.nl;
82 return 0; 98 return 0;
83 } 99 }
84 else 100 else
85 { 101 {
86 File fOut( opts.sOutput, File::WriteNew ); 102 File fOut( opts.sFile, File::WriteNew );
87 Myriad n( fOut ); 103 Myriad m( fOut );
88 n.initialize( opts.iBlockSize, opts.iPreallocate ); 104 m.initialize( opts.iBlockSize, opts.iPreallocate );
89 } 105 }
90 break; 106 break;
91 107
92 case modeInfo: 108 case modeInfo:
93 if( !opts.sInput.isSet() ) 109 if( !opts.sFile.isSet() )
94 { 110 {
95 sio << "Please specify an input file to display info about." 111 sio << "Please specify a file to display info about." << sio.nl;
96 << sio.nl;
97 return 0; 112 return 0;
98 } 113 }
99 else 114 else
100 { 115 {
101 File fIn( opts.sInput, File::Read ); 116 File fIn( opts.sFile, File::Read );
102 Myriad n( fIn ); 117 Myriad m( fIn );
103 n.initialize(); 118 m.initialize();
119 }
120 break;
121
122 case modeStreamNew:
123 if( !opts.sFile.isSet() )
124 {
125 sio << "Please specify a file manipulate." << sio.nl;
126 return 0;
127 }
128 else
129 {
130 File fOut( opts.sFile, File::Write|File::Read );
131 Myriad m( fOut );
132 m.initialize();
133 m.createStream( opts.iPreallocate );
134 }
135 break;
136
137 case modeStreamRead:
138 if( !opts.sFile.isSet() )
139 {
140 sio << "Please specify a file manipulate." << sio.nl;
141 return 0;
142 }
143 else
144 {
145 File fOut( opts.sFile, File::Read );
146 Myriad m( fOut );
147 m.initialize();
148 MyriadStream s = m.openStream( opts.iStream );
149 sio << "Stream " << opts.iStream << ":" << sio.nl;
150 char buf[8];
151 int iPos = 0;
152 while( !s.isEos() )
153 {
154 size_t sAmnt = s.read( buf, 8 );
155 sio << Fmt(5) << iPos << ": ";
156 iPos += sAmnt;
157 for( size_t j = 0; j < sAmnt; j++ )
158 {
159 sio << Fmt::hex(2) << (int)((unsigned char)buf[j])
160 << " ";
161 }
162 for( size_t j = sAmnt; j < 8; j++ )
163 {
164 sio << "-- ";
165 }
166 sio << "| ";
167 for( size_t j = 0; j < sAmnt; j++ )
168 {
169 if( buf[j] >= 32 && buf[j] <= 126 )
170 sio << buf[j] << " ";
171 else
172 sio << " ";
173 }
174 sio << sio.nl;
175 }
104 } 176 }
105 break; 177 break;
106 178