summaryrefslogtreecommitdiff
path: root/src/tools/bin2cpp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/bin2cpp.cpp')
-rw-r--r--src/tools/bin2cpp.cpp43
1 files changed, 38 insertions, 5 deletions
diff --git a/src/tools/bin2cpp.cpp b/src/tools/bin2cpp.cpp
index e0eab28..65e48ed 100644
--- a/src/tools/bin2cpp.cpp
+++ b/src/tools/bin2cpp.cpp
@@ -4,6 +4,7 @@
4#include <bu/streamstack.h> 4#include <bu/streamstack.h>
5#include <bu/strfilter.h> 5#include <bu/strfilter.h>
6#include <bu/taf.h> 6#include <bu/taf.h>
7#include <bu/autoconfig.h>
7 8
8#ifdef BU_HAS_DEFLATE 9#ifdef BU_HAS_DEFLATE
9#include <bu/deflate.h> 10#include <bu/deflate.h>
@@ -18,6 +19,16 @@
18#include <bu/base64.h> 19#include <bu/base64.h>
19#include <bu/hex.h> 20#include <bu/hex.h>
20 21
22Bu::String cescape( const Bu::String &sIn )
23{
24 Bu::String sOut;
25 for( Bu::String::const_iterator i = sIn.begin(); i; i++ )
26 {
27 sOut += Bu::String("\\x%1").arg( (int)*i, Bu::Fmt(2).hex() );
28 }
29 return sOut;
30}
31
21using namespace Bu; 32using namespace Bu;
22 33
23class Options : public OptParser 34class Options : public OptParser
@@ -223,12 +234,34 @@ int main( int argc, char *argv[] )
223 << "\t{" << fSrc.nl; 234 << "\t{" << fSrc.nl;
224 235
225 int idx = 0; 236 int idx = 0;
226 for( Bu::StringList::iterator i = opt.slInput.begin(); i; i++ )
227 { 237 {
228 fSrc << "\t\tcase " << Bu::__calcHashCode( *i ) << "UL: // \"" 238 typedef Bu::List<Bu::StringList::iterator> IterList;
229 << *i << "\"" << fSrc.nl 239 typedef Bu::Hash<uint32_t, IterList> IterHashList;
230 << "\t\t\treturn aFile[" << idx << "];" << fSrc.nl; 240 typedef Bu::Hash<Bu::String, int> IdxHash;
231 idx++; 241
242 IdxHash hIdx;
243 IterHashList hCodes;
244 for( Bu::StringList::iterator i = opt.slInput.begin(); i; i++ )
245 {
246 uint32_t uc = Bu::__calcHashCode( *i );
247 if( !hCodes.has( uc ) )
248 {
249 hCodes.insert( uc, IterList() );
250 }
251 hCodes.get( uc ).append( i );
252 hIdx.insert( *i, idx++ );
253 }
254 for( IterHashList::iterator r = hCodes.begin(); r; r++ )
255 {
256 fSrc << "\t\tcase " << r.getKey() << "UL:" << fSrc.nl;
257 for( IterList::iterator i = r.getValue().begin(); i; i++ )
258 {
259 fSrc << "\t\t\tif( sName == \"" << cescape(*(*i)) << "\" ) // "
260 << *(*i) << fSrc.nl
261 << "\t\t\t\treturn aFile[" << hIdx.get(*(*i)) << "];" << fSrc.nl;
262 }
263 fSrc << "\t\t\tbreak;" << fSrc.nl;
264 }
232 } 265 }
233 fSrc << "\t}" << fSrc.nl 266 fSrc << "\t}" << fSrc.nl
234 << "\tthrow Bu::ExceptionBase(\"No file matching \\\"%s\\\" found.\", sName.getStr() );" << fSrc.nl 267 << "\tthrow Bu::ExceptionBase(\"No file matching \\\"%s\\\" found.\", sName.getStr() );" << fSrc.nl