~extremepopcorn/dhlib/dhlib_ep

« back to all changes in this revision

Viewing changes to restricted/wordlib/app/packwords.cc

  • Committer: edA-qa mort-ora-y
  • Date: 2010-02-16 06:02:38 UTC
  • Revision ID: eda-qa@disemia.com-20100216060238-90h405qfmmyeu729
decouple

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
#include <iomanip>
8
8
#include <cstdlib>
9
9
 
10
 
#include <io/log/stdlog.h>
11
 
#include <main/wrapped_main.h>
12
 
 
13
10
#include "../src/trie.h"
14
11
#include "../src/writepng.h"
15
12
#include "../src/writeraw.h"
16
13
 
17
14
using namespace std;
18
 
using namespace io;
19
15
 
20
16
//choose which locale we are producing
21
17
#include "../src/locale/en.cc"
33
29
        dumped++;
34
30
}
35
31
 
36
 
void checkLoaded( const _uint8* loaded, const _uint8* packed, unsigned len );
 
32
void checkLoaded( const uint8_t* loaded, const uint8_t* packed, unsigned len );
37
33
 
38
34
/**
39
35
 * Produces the packed form of a word list.  This has built in test code -- at each
50
46
 *
51
47
 * --out where to write the HX data array.
52
48
 */
53
 
int wrapped_main( const Args& args )
 
49
int main( int argc, char** args )
54
50
{
55
51
        string outpng;
56
52
        string outraw;
58
54
        unsigned totalSize = 0;
59
55
        unsigned skipped = 0;
60
56
        
61
 
        for( unsigned arg=1; arg < args.size(); arg++ )
 
57
        for( unsigned arg=1; arg < argc; arg++ )
62
58
        {
63
 
                if( args.at(arg) == "--outpng" )
64
 
                {
65
 
                        outpng = args.at(++arg);
66
 
                }
67
 
                
68
 
                else if( args.at(arg) == "--outraw" )
69
 
                {
70
 
                        outraw = args.at(++arg);
71
 
                }
72
 
                
73
 
                else if( args.at(arg) == "--in" )
74
 
                {
75
 
                        unsigned rank = atoi( args.at(++arg).c_str() );
 
59
                if( args[arg] == "--outpng" )
 
60
                {
 
61
                        outpng = args[++arg];
 
62
                }
 
63
                
 
64
                else if( args[arg] == "--outraw" )
 
65
                {
 
66
                        outraw = args[++arg];
 
67
                }
 
68
                
 
69
                else if( args[arg] == "--in" )
 
70
                {
 
71
                        unsigned rank = atoi( args[++arg] );
76
72
                        
77
 
                        while( (arg+1) < args.size() && args.at(arg+1)[0] != '-' )
 
73
                        while( (arg+1) < argc && args[arg+1][0] != '-' )
78
74
                        {
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() );
82
78
                                
83
79
                                unsigned localSkipped = 0;
104
100
                                        else
105
101
                                        {
106
102
                                                if( asSet.find( orig ) == asSet.end() )
107
 
                                                        logError << "Failed to add: " << orig << endl;
 
103
                                                        cerr << "Failed to add: " << orig << endl;
108
104
                                        }
109
105
                                }
110
106
                                
111
 
                                logInfo << "Added + Skipped: " << localAdded << " + " << localSkipped << endl;
 
107
                                cout << "Added + Skipped: " << localAdded << " + " << localSkipped << endl;
112
108
                                skipped += localSkipped;
113
109
                        }
114
110
                }
115
111
                
116
112
                else
117
113
                {
118
 
                        logError << "Unrecognized option: " << args.at(arg++) << endl;
 
114
                        cerr << "Unrecognized option: " << args[arg++] << endl;
119
115
                }
120
116
        }//end of args
121
117
        
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;
124
120
        
125
121
        //sanity check
126
122
        for( set<string>::iterator iter = asSet.begin(); iter != asSet.end(); iter++ )
132
128
                
133
129
        //dump the items (or at least count them)
134
130
        dumped = 0;
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() );
140
136
                
141
137
        //pack them
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;
145
141
        
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];
149
145
        
150
146
        //further dump for testing/counting
151
147
        dumped = 0;
152
148
        packedWalk( dumpString, packed );
153
 
        logInfo << "Dumped: " << dumped << endl;
 
149
        cout << "Dumped: " << dumped << endl;
154
150
        assert( dumped == asSet.size() );
155
151
        
156
152
        //write the image
157
153
        if( outpng.size() )
158
154
        {
159
 
                logProgressHigh << "Writing PNG " << outpng << endl;
 
155
                cout << "Writing PNG " << outpng << endl;
160
156
                writePNG( outpng, packed, packedV.size() );
161
157
                
162
158
                //load and check again
163
 
                _uint8* loaded = loadPNG( outpng );
 
159
                uint8_t* loaded = loadPNG( outpng );
164
160
                checkLoaded( loaded, packed, packedV.size() );
165
161
                delete[] loaded;
166
162
        }
168
164
        //write the raw output
169
165
        if( outraw.size() )
170
166
        {
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() );
175
171
                delete[] loaded;
176
172
        }
177
173
        
178
174
        // done
179
 
        logProgressHigh << "Done." << endl;
 
175
        cout << "Done." << endl;
180
176
        
181
177
        return 0;
182
178
}
183
179
 
184
 
void checkLoaded( const _uint8* loaded, const _uint8* packed, unsigned len )
 
180
void checkLoaded( const uint8_t* loaded, const uint8_t* packed, unsigned len )
185
181
{
186
182
        for( unsigned i=0; i < len; i++ )
187
183
                if( loaded[i] != packed[i] )