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/stable/bzip2.cpp | 3 +++ src/stable/bzip2.h | 5 +++++ src/stable/condition.cpp | 4 ++-- src/stable/lzma.cpp | 4 ++++ src/stable/lzma.h | 5 +++++ src/tools/bin2cpp.cpp | 43 ++++++++++++++++++++++++++++++++++++++----- 6 files changed, 57 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/stable/bzip2.cpp b/src/stable/bzip2.cpp index b48af37..b634a2c 100644 --- a/src/stable/bzip2.cpp +++ b/src/stable/bzip2.cpp @@ -8,6 +8,7 @@ #include "bu/bzip2.h" #include "bu/trace.h" +#ifdef BU_HAS_BZIP2 #include #define pState ((bz_stream *)prState) @@ -234,3 +235,5 @@ Bu::size Bu::BZip2::getCompressedSize() return sTotalOut; } +#endif + diff --git a/src/stable/bzip2.h b/src/stable/bzip2.h index e2c2753..6b5d9a9 100644 --- a/src/stable/bzip2.h +++ b/src/stable/bzip2.h @@ -11,6 +11,9 @@ #include #include "bu/filter.h" +#include "bu/autoconfig.h" + +#ifdef BU_HAS_BZIP2 namespace Bu { @@ -47,3 +50,5 @@ namespace Bu } #endif + +#endif diff --git a/src/stable/condition.cpp b/src/stable/condition.cpp index 7719d7b..b82626d 100644 --- a/src/stable/condition.cpp +++ b/src/stable/condition.cpp @@ -5,10 +5,10 @@ * terms of the license contained in the file LICENSE. */ -#include - #include "bu/condition.h" +#include + Bu::Condition::Condition() { pthread_cond_init( &cond, NULL ); diff --git a/src/stable/lzma.cpp b/src/stable/lzma.cpp index d05c79f..c8e8960 100644 --- a/src/stable/lzma.cpp +++ b/src/stable/lzma.cpp @@ -8,6 +8,8 @@ #include "bu/lzma.h" #include "bu/trace.h" +#ifdef BU_HAS_LZMA + #include #define pState ((lzma_stream *)prState) @@ -246,3 +248,5 @@ Bu::size Bu::Lzma::getCompressedSize() return sTotalOut; } +#endif + diff --git a/src/stable/lzma.h b/src/stable/lzma.h index f4a6e28..3685546 100644 --- a/src/stable/lzma.h +++ b/src/stable/lzma.h @@ -11,6 +11,9 @@ #include #include "bu/filter.h" +#include "bu/autoconfig.h" + +#ifdef BU_HAS_LZMA namespace Bu { @@ -57,3 +60,5 @@ namespace Bu } #endif + +#endif 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