From a612205584558c52ae2fedd616d7eb735d5ba84a Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 21 Sep 2016 12:54:23 -0600 Subject: Tweaks to make building on windows easier. Also, just building without bzip2 or lzma easier. --- src/tools/bin2cpp.cpp | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) (limited to 'src/tools') 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 @@ #include #include #include +#include #ifdef BU_HAS_DEFLATE #include @@ -18,6 +19,16 @@ #include #include +Bu::String cescape( const Bu::String &sIn ) +{ + Bu::String sOut; + for( Bu::String::const_iterator i = sIn.begin(); i; i++ ) + { + sOut += Bu::String("\\x%1").arg( (int)*i, Bu::Fmt(2).hex() ); + } + return sOut; +} + using namespace Bu; class Options : public OptParser @@ -223,12 +234,34 @@ int main( int argc, char *argv[] ) << "\t{" << fSrc.nl; int idx = 0; - for( Bu::StringList::iterator i = opt.slInput.begin(); i; i++ ) { - fSrc << "\t\tcase " << Bu::__calcHashCode( *i ) << "UL: // \"" - << *i << "\"" << fSrc.nl - << "\t\t\treturn aFile[" << idx << "];" << fSrc.nl; - idx++; + typedef Bu::List IterList; + typedef Bu::Hash IterHashList; + typedef Bu::Hash IdxHash; + + IdxHash hIdx; + IterHashList hCodes; + for( Bu::StringList::iterator i = opt.slInput.begin(); i; i++ ) + { + uint32_t uc = Bu::__calcHashCode( *i ); + if( !hCodes.has( uc ) ) + { + hCodes.insert( uc, IterList() ); + } + hCodes.get( uc ).append( i ); + hIdx.insert( *i, idx++ ); + } + for( IterHashList::iterator r = hCodes.begin(); r; r++ ) + { + fSrc << "\t\tcase " << r.getKey() << "UL:" << fSrc.nl; + for( IterList::iterator i = r.getValue().begin(); i; i++ ) + { + fSrc << "\t\t\tif( sName == \"" << cescape(*(*i)) << "\" ) // " + << *(*i) << fSrc.nl + << "\t\t\t\treturn aFile[" << hIdx.get(*(*i)) << "];" << fSrc.nl; + } + fSrc << "\t\t\tbreak;" << fSrc.nl; + } } fSrc << "\t}" << fSrc.nl << "\tthrow Bu::ExceptionBase(\"No file matching \\\"%s\\\" found.\", sName.getStr() );" << fSrc.nl -- cgit v1.2.3