10
#include <io/log/stdlog.h>
11
#include <main/wrapped_main.h>
13
10
#include "../src/trie.h"
14
11
#include "../src/writepng.h"
15
12
#include "../src/writeraw.h"
17
14
using namespace std;
20
16
//choose which locale we are producing
21
17
#include "../src/locale/en.cc"
36
void checkLoaded( const _uint8* loaded, const _uint8* packed, unsigned len );
32
void checkLoaded( const uint8_t* loaded, const uint8_t* packed, unsigned len );
39
35
* Produces the packed form of a word list. This has built in test code -- at each
58
54
unsigned totalSize = 0;
59
55
unsigned skipped = 0;
61
for( unsigned arg=1; arg < args.size(); arg++ )
57
for( unsigned arg=1; arg < argc; arg++ )
63
if( args.at(arg) == "--outpng" )
65
outpng = args.at(++arg);
68
else if( args.at(arg) == "--outraw" )
70
outraw = args.at(++arg);
73
else if( args.at(arg) == "--in" )
75
unsigned rank = atoi( args.at(++arg).c_str() );
59
if( args[arg] == "--outpng" )
64
else if( args[arg] == "--outraw" )
69
else if( args[arg] == "--in" )
71
unsigned rank = atoi( args[++arg] );
77
while( (arg+1) < args.size() && args.at(arg+1)[0] != '-' )
73
while( (arg+1) < argc && args[arg+1][0] != '-' )
79
string file = args.at(++arg);
80
logProgressHigh << "Loading " << file << " @" << rank << "..." << endl;
75
string file = args[++arg];
76
cout << "Loading " << file << " @" << rank << "..." << endl;
81
77
ifstream in( file.c_str() );
83
79
unsigned localSkipped = 0;
106
102
if( asSet.find( orig ) == asSet.end() )
107
logError << "Failed to add: " << orig << endl;
103
cerr << "Failed to add: " << orig << endl;
111
logInfo << "Added + Skipped: " << localAdded << " + " << localSkipped << endl;
107
cout << "Added + Skipped: " << localAdded << " + " << localSkipped << endl;
112
108
skipped += localSkipped;
118
logError << "Unrecognized option: " << args.at(arg++) << endl;
114
cerr << "Unrecognized option: " << args[arg++] << endl;
122
logInfo << "Total Input Size: " << totalSize << endl;
123
logInfo << "Total Skipped: " << skipped << endl;
118
cout << "Total Input Size: " << totalSize << endl;
119
cout << "Total Skipped: " << skipped << endl;
126
122
for( set<string>::iterator iter = asSet.begin(); iter != asSet.end(); iter++ )
133
129
//dump the items (or at least count them)
135
logProgressHigh << "Dumping..." << endl;
131
cout << "Dumping..." << endl;
136
132
unsigned count = trie.walk( dumpString );
137
logInfo << "Node Count: " << count << endl;
138
logInfo << "Dumped: " << dumped << endl;
133
cout << "Node Count: " << count << endl;
134
cout << "Dumped: " << dumped << endl;
139
135
assert( dumped == asSet.size() );
142
logProgressHigh << "Packing..." << endl;
143
vector<_uint8> packedV = trie.packToVector();
144
logInfo << "Packed Size: " << packedV.size() << endl;
138
cout << "Packing..." << endl;
139
vector<uint8_t> packedV = trie.packToVector();
140
cout << "Packed Size: " << packedV.size() << endl;
146
_uint8 packed[packedV.size()];
142
uint8_t packed[packedV.size()];
147
143
for( unsigned i=0; i < packedV.size(); i++ )
148
144
packed[i] = packedV[i];
150
146
//further dump for testing/counting
152
148
packedWalk( dumpString, packed );
153
logInfo << "Dumped: " << dumped << endl;
149
cout << "Dumped: " << dumped << endl;
154
150
assert( dumped == asSet.size() );
156
152
//write the image
157
153
if( outpng.size() )
159
logProgressHigh << "Writing PNG " << outpng << endl;
155
cout << "Writing PNG " << outpng << endl;
160
156
writePNG( outpng, packed, packedV.size() );
162
158
//load and check again
163
_uint8* loaded = loadPNG( outpng );
159
uint8_t* loaded = loadPNG( outpng );
164
160
checkLoaded( loaded, packed, packedV.size() );
168
164
//write the raw output
169
165
if( outraw.size() )
171
logProgressHigh << "Writing RAW" << outraw << endl;
167
cout << "Writing RAW" << outraw << endl;
172
168
writeRAW( outraw, packed, packedV.size() );
173
_uint8* loaded = loadRAW( outraw );
169
uint8_t* loaded = loadRAW( outraw );
174
170
checkLoaded( loaded, packed, packedV.size() );
179
logProgressHigh << "Done." << endl;
175
cout << "Done." << endl;
184
void checkLoaded( const _uint8* loaded, const _uint8* packed, unsigned len )
180
void checkLoaded( const uint8_t* loaded, const uint8_t* packed, unsigned len )
186
182
for( unsigned i=0; i < len; i++ )
187
183
if( loaded[i] != packed[i] )