diff options
author | Mike Buland <eichlan@xagasoft.com> | 2010-05-15 07:44:10 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2010-05-15 07:44:10 +0000 |
commit | 306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68 (patch) | |
tree | 32c35f8507edb4ea403f4ebc4b625c1096f6f384 /src/tools/nidstool.cpp | |
parent | 11413d228bae2919fe69c83b74c7ff49209dd65a (diff) | |
download | libbu++-306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68.tar.gz libbu++-306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68.tar.bz2 libbu++-306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68.tar.xz libbu++-306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68.zip |
mkunit.sh was a little dumb, it didn't handle a number of things correctly.
I've written a new program that basically does the same thing, only it's much
more clever, and does many more of the translations and conversions better,
including the #line directives. Also, I dropped nids, we don't need it anymore.
But now I'm ready to write some serious tests for myriad.
Diffstat (limited to '')
-rw-r--r-- | src/tools/nidstool.cpp | 248 |
1 files changed, 0 insertions, 248 deletions
diff --git a/src/tools/nidstool.cpp b/src/tools/nidstool.cpp deleted file mode 100644 index 41179f9..0000000 --- a/src/tools/nidstool.cpp +++ /dev/null | |||
@@ -1,248 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2010 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/file.h" | ||
9 | #include "bu/nids.h" | ||
10 | #include "bu/nidsstream.h" | ||
11 | #include "bu/paramproc.h" | ||
12 | |||
13 | #include <stdlib.h> | ||
14 | |||
15 | typedef struct Block | ||
16 | { | ||
17 | uint32_t uFirstBlock; | ||
18 | uint32_t uNextBlock; | ||
19 | uint32_t uBytesUsed; | ||
20 | } Block; | ||
21 | |||
22 | class Param : public Bu::ParamProc | ||
23 | { | ||
24 | public: | ||
25 | Param( int argc, char *argv[] ) | ||
26 | { | ||
27 | addHelpBanner("nidstool - Do stuff with nids files.\n\n"); | ||
28 | addParam("info", 'i', mkproc(Param::procInfo), | ||
29 | "Print some info about the file."); | ||
30 | addParam("dump", 'd', mkproc(Param::procDump), | ||
31 | "Dump a stream to a file."); | ||
32 | addParam("analyze", 'a', mkproc(Param::procAnalyze), | ||
33 | "Analyze a nids file."); | ||
34 | addParam("copy", 'c', mkproc(Param::procCopy), | ||
35 | "Copy a nids file, changing settings."); | ||
36 | addParam("help", 'h', mkproc(Bu::ParamProc::help), "This help."); | ||
37 | process( argc, argv ); | ||
38 | } | ||
39 | |||
40 | virtual ~Param() | ||
41 | { | ||
42 | } | ||
43 | |||
44 | void printInfo( Bu::Nids &n ) | ||
45 | { | ||
46 | printf("File info:\n"); | ||
47 | printf(" Header overhead: %db\n", n.getBlockStart() ); | ||
48 | printf(" Block size: %db\n", n.getBlockSize() ); | ||
49 | printf(" Block count: %d\n", n.getNumBlocks() ); | ||
50 | printf(" Blocks used: %d (%d%%)\n", n.getNumUsedBlocks(), | ||
51 | n.getNumUsedBlocks()*100/n.getNumBlocks() ); | ||
52 | printf(" Block overhead: %db\n", n.getBlockOverhead() ); | ||
53 | printf(" Block storage: %db (%d%%)\n", | ||
54 | n.getBlockSize()-n.getBlockOverhead(), | ||
55 | (n.getBlockSize()-n.getBlockOverhead())*100/n.getBlockSize() ); | ||
56 | } | ||
57 | |||
58 | int procInfo( int argc, char *argv[] ) | ||
59 | { | ||
60 | if( argc < 1 ) | ||
61 | { | ||
62 | printf("You must provide a file name.\n"); | ||
63 | exit( 1 ); | ||
64 | } | ||
65 | |||
66 | Bu::File fIn( argv[0], Bu::File::Read ); | ||
67 | Bu::Nids n( fIn ); | ||
68 | n.initialize(); | ||
69 | |||
70 | printInfo( n ); | ||
71 | |||
72 | if( argc >= 2 ) | ||
73 | { | ||
74 | uint32_t uStream = strtoul( argv[1], NULL, 0 ); | ||
75 | uint32_t uBlock = uStream; | ||
76 | |||
77 | Block b; | ||
78 | |||
79 | for(;;) | ||
80 | { | ||
81 | fIn.setPos( n.getBlockStart()+n.getBlockSize()*uBlock ); | ||
82 | fIn.read( &b, sizeof(Block) ); | ||
83 | printf("Stream %u: block %u, next %u, %ub used.\n", | ||
84 | uStream, uBlock, b.uNextBlock, b.uBytesUsed | ||
85 | ); | ||
86 | if( b.uNextBlock == 0xFFFFFFFFUL ) | ||
87 | break; | ||
88 | uBlock = b.uNextBlock; | ||
89 | } | ||
90 | printf("Stream End.\n"); | ||
91 | |||
92 | return 2; | ||
93 | } | ||
94 | |||
95 | return 1; | ||
96 | } | ||
97 | |||
98 | int procDump( int argc, char *argv[] ) | ||
99 | { | ||
100 | if( argc < 3 ) | ||
101 | { | ||
102 | printf("You must provide a nids file, a stream id, and an output " | ||
103 | "file.\n"); | ||
104 | exit( 1 ); | ||
105 | } | ||
106 | |||
107 | Bu::File fIn( argv[0], Bu::File::Read ); | ||
108 | Bu::Nids n( fIn ); | ||
109 | n.initialize(); | ||
110 | |||
111 | int iStream = strtol( argv[1], NULL, 0 ); | ||
112 | Bu::NidsStream sIn = n.openStream( iStream ); | ||
113 | |||
114 | Bu::File fOut( argv[2], Bu::File::Write|Bu::File::Create ); | ||
115 | int iTotal = 0; | ||
116 | char buf[100]; | ||
117 | for(;;) | ||
118 | { | ||
119 | int iRead = sIn.read( buf, 100 ); | ||
120 | iTotal += fOut.write( buf, iRead ); | ||
121 | if( iRead < 100 ) | ||
122 | break; | ||
123 | } | ||
124 | |||
125 | printf("Wrote %db from stream %d in %s to %s.\n", | ||
126 | iTotal, iStream, argv[0], argv[2] ); | ||
127 | return 3; | ||
128 | } | ||
129 | |||
130 | int procAnalyze( int argc, char *argv[] ) | ||
131 | { | ||
132 | if( argc < 1 ) | ||
133 | { | ||
134 | printf("You must provide a file name.\n"); | ||
135 | exit( 1 ); | ||
136 | } | ||
137 | |||
138 | Bu::File fIn( argv[0], Bu::File::Read ); | ||
139 | Bu::Nids n( fIn ); | ||
140 | n.initialize(); | ||
141 | |||
142 | printInfo( n ); | ||
143 | |||
144 | int iStreamCnt = 0; | ||
145 | int iStreamTotal = 0; | ||
146 | int iOneBlock = 0; | ||
147 | uint32_t iLargest = 0; | ||
148 | uint32_t iSmallest = 0; | ||
149 | int iWaste = 0; | ||
150 | int iUsable = n.getBlockSize()-n.getBlockOverhead(); | ||
151 | Block b; | ||
152 | for( int j = 0; j < n.getNumBlocks(); j++ ) | ||
153 | { | ||
154 | fIn.setPos( n.getBlockStart()+n.getBlockSize()*j ); | ||
155 | fIn.read( &b, sizeof(Block) ); | ||
156 | if( b.uFirstBlock != (uint32_t)j ) | ||
157 | continue; | ||
158 | |||
159 | iStreamCnt++; | ||
160 | iStreamTotal += b.uBytesUsed; | ||
161 | |||
162 | if( b.uNextBlock == 0xFFFFFFFFUL ) | ||
163 | { | ||
164 | iOneBlock++; | ||
165 | iWaste += iUsable - b.uBytesUsed; | ||
166 | } | ||
167 | else | ||
168 | { | ||
169 | iWaste += iUsable - (b.uBytesUsed%iUsable); | ||
170 | } | ||
171 | |||
172 | if( j == 0 ) | ||
173 | { | ||
174 | iSmallest = iLargest = b.uBytesUsed; | ||
175 | } | ||
176 | else | ||
177 | { | ||
178 | if( iLargest < b.uBytesUsed ) | ||
179 | iLargest = b.uBytesUsed; | ||
180 | if( iSmallest > b.uBytesUsed ) | ||
181 | iSmallest = b.uBytesUsed; | ||
182 | } | ||
183 | } | ||
184 | printf("Steam analysis:\n"); | ||
185 | printf(" Stream count: %d\n", iStreamCnt ); | ||
186 | printf(" Stream size: %db/%db/%db (min/avr/max)\n", | ||
187 | iSmallest, iStreamTotal/iStreamCnt, iLargest ); | ||
188 | printf(" One-block streams: %d (%d%%)\n", | ||
189 | iOneBlock, iOneBlock*100/iStreamCnt ); | ||
190 | printf(" Total wasted space: %db (%d%%)\n", | ||
191 | iWaste, iWaste*100/iStreamTotal ); | ||
192 | printf(" Avr blocks-per-stream: %f%%\n", | ||
193 | (float)n.getNumBlocks()/(float)iStreamCnt ); | ||
194 | |||
195 | return 1; | ||
196 | } | ||
197 | |||
198 | int procCopy( int argc, char *argv[] ) | ||
199 | { | ||
200 | if( argc < 3 ) | ||
201 | { | ||
202 | printf("You must provide source stream, blocksize, destination.\n"); | ||
203 | exit( 1 ); | ||
204 | } | ||
205 | |||
206 | Bu::File fIn( argv[0], Bu::File::Read ); | ||
207 | Bu::Nids nIn( fIn ); | ||
208 | nIn.initialize(); | ||
209 | |||
210 | Bu::File fOut( argv[2], Bu::File::Read|Bu::File::Write|Bu::File::Create| | ||
211 | Bu::File::Truncate ); | ||
212 | Bu::Nids nOut( fOut ); | ||
213 | nOut.initialize( strtol( argv[1], 0, NULL ) ); | ||
214 | |||
215 | Block b; | ||
216 | for( int j = 0; j < nIn.getNumBlocks(); j++ ) | ||
217 | { | ||
218 | fIn.setPos( nIn.getBlockStart()+nIn.getBlockSize()*j ); | ||
219 | fIn.read( &b, sizeof(Block) ); | ||
220 | if( b.uFirstBlock != (uint32_t)j ) | ||
221 | continue; | ||
222 | |||
223 | Bu::NidsStream sIn = nIn.openStream( j ); | ||
224 | int iNew = nOut.createStream(); | ||
225 | Bu::NidsStream sOut = nOut.openStream( iNew ); | ||
226 | |||
227 | char buf[1024]; | ||
228 | for(;;) | ||
229 | { | ||
230 | int iRead = sIn.read( buf, 1024 ); | ||
231 | sOut.write( buf, iRead ); | ||
232 | if( iRead < 1024 ) | ||
233 | break; | ||
234 | } | ||
235 | } | ||
236 | |||
237 | return 3; | ||
238 | } | ||
239 | }; | ||
240 | |||
241 | |||
242 | int main( int argc, char *argv[] ) | ||
243 | { | ||
244 | Param p( argc, argv ); | ||
245 | |||
246 | return 0; | ||
247 | } | ||
248 | |||