summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2014-11-28 17:38:56 +0000
committerMike Buland <eichlan@xagasoft.com>2014-11-28 17:38:56 +0000
commit8bbf908ab1afd341e361dd5ad0c37f3c1b9a6635 (patch)
tree6dadb4930707e541a4ed86ac5ddb4d8af9f48dfc /src
parent2698c84576447535f397fafcb9f5f06290c3596a (diff)
downloadlibbu++-8bbf908ab1afd341e361dd5ad0c37f3c1b9a6635.tar.gz
libbu++-8bbf908ab1afd341e361dd5ad0c37f3c1b9a6635.tar.bz2
libbu++-8bbf908ab1afd341e361dd5ad0c37f3c1b9a6635.tar.xz
libbu++-8bbf908ab1afd341e361dd5ad0c37f3c1b9a6635.zip
Autoconfig now detects libraries that libbu++ can use and generates the
appropriate headers. bin2cpp now uses those headers to compile correctly despite having missing filters.
Diffstat (limited to 'src')
-rw-r--r--src/tools/bin2cpp.cpp53
1 files changed, 42 insertions, 11 deletions
diff --git a/src/tools/bin2cpp.cpp b/src/tools/bin2cpp.cpp
index cd57086..e0eab28 100644
--- a/src/tools/bin2cpp.cpp
+++ b/src/tools/bin2cpp.cpp
@@ -5,9 +5,16 @@
5#include <bu/strfilter.h> 5#include <bu/strfilter.h>
6#include <bu/taf.h> 6#include <bu/taf.h>
7 7
8#ifdef BU_HAS_DEFLATE
8#include <bu/deflate.h> 9#include <bu/deflate.h>
10#endif
11#ifdef BU_HAS_BZIP2
9#include <bu/bzip2.h> 12#include <bu/bzip2.h>
13#endif
14#ifdef BU_HAS_LZMA
10#include <bu/lzma.h> 15#include <bu/lzma.h>
16#endif
17
11#include <bu/base64.h> 18#include <bu/base64.h>
12#include <bu/hex.h> 19#include <bu/hex.h>
13 20
@@ -26,7 +33,17 @@ public:
26 addOption( sClass, 'c', "Class name [default=\"Datafiles\"]"); 33 addOption( sClass, 'c', "Class name [default=\"Datafiles\"]");
27 addOption( sOutBase, 'o', "Output base filename [defaults to classname]"); 34 addOption( sOutBase, 'o', "Output base filename [defaults to classname]");
28 addOption( sOutDir, 'd', "Output directory [defaults to current dir]"); 35 addOption( sOutDir, 'd', "Output directory [defaults to current dir]");
29 addOption( slot(this, &Options::addFilter), 'f', "Add filter: deflate, bzip2, lzma, base64, hex"); 36 addOption( slot(this, &Options::addFilter), 'f', "Add filter: "
37#ifdef BU_HAS_DEFLATE
38 "deflate, "
39#endif
40#ifdef BU_HAS_BZIP2
41 "bzip2, "
42#endif
43#ifdef BU_HAS_LZMA
44 "lzma, "
45#endif
46 "base64, hex");
30 addOption( sSpecFile, 's', "Use the specified spec file instead of providing options on the command line. If you use this option all others are ignored."); 47 addOption( sSpecFile, 's', "Use the specified spec file instead of providing options on the command line. If you use this option all others are ignored.");
31 setNonOption( slot(this, &Options::addInput) ); 48 setNonOption( slot(this, &Options::addInput) );
32 addHelpOption(); 49 addHelpOption();
@@ -115,15 +132,22 @@ int main( int argc, char *argv[] )
115 << "};" << fHdr.nl << fHdr.nl; 132 << "};" << fHdr.nl << fHdr.nl;
116 fHdr << "#endif"; 133 fHdr << "#endif";
117 134
118 fSrc << "#include \"" << opt.sOutBase << ".h\"" << fSrc.nl 135 fSrc << "#include \"" << opt.sOutBase << ".h\"" << fSrc.nl;
119 << "#include <bu/deflate.h>" << fSrc.nl 136#ifdef BU_HAS_DEFLATE
120 << "#include <bu/bzip2.h>" << fSrc.nl 137 fSrc << "#include <bu/deflate.h>" << fSrc.nl;
121 << "#include <bu/base64.h>" << fSrc.nl 138#endif
122 << "#include <bu/lzma.h>" << fSrc.nl 139#ifdef BU_HAS_BZIP2
123 << "#include <bu/hex.h>" << fSrc.nl 140 fSrc << "#include <bu/bzip2.h>" << fSrc.nl;
124 << "#include <bu/strfilter.h>" << fSrc.nl 141#endif
125 << "#include <bu/staticmembuf.h>" << fSrc.nl << fSrc.nl 142#ifdef BU_HAS_LZMA
126 << "const " << opt.sClass << "::File " << opt.sClass << "::aFile[] = {" << fSrc.nl; 143 fSrc << "#include <bu/lzma.h>" << fSrc.nl;
144#endif
145 fSrc << "#include <bu/base64.h>" << fSrc.nl;
146 fSrc << "#include <bu/hex.h>" << fSrc.nl;
147 fSrc << "#include <bu/strfilter.h>" << fSrc.nl;
148 fSrc << "#include <bu/staticmembuf.h>" << fSrc.nl;
149 fSrc << fSrc.nl;
150 fSrc << "const " << opt.sClass << "::File " << opt.sClass << "::aFile[] = {" << fSrc.nl;
127 151
128 for( Bu::StringList::iterator i = opt.slInput.begin(); i; i++ ) 152 for( Bu::StringList::iterator i = opt.slInput.begin(); i; i++ )
129 { 153 {
@@ -138,24 +162,31 @@ int main( int argc, char *argv[] )
138 Bu::String sFltDesc; 162 Bu::String sFltDesc;
139 for( Bu::StringList::iterator f = opt.slFilter.begin(); f; f++ ) 163 for( Bu::StringList::iterator f = opt.slFilter.begin(); f; f++ )
140 { 164 {
141 if( *f == "deflate" ) 165 if( false ) { } // should optomize out
166#ifdef BU_HAS_DEFLATE
167 else if( *f == "deflate" )
142 { 168 {
143 sDat = encodeStr<Deflate>( sDat ); 169 sDat = encodeStr<Deflate>( sDat );
144 sFltDesc.prepend("d"); 170 sFltDesc.prepend("d");
145 hFilters.insert('d', true ); 171 hFilters.insert('d', true );
146 } 172 }
173#endif
174#ifdef BU_HAS_BZIP2
147 else if( *f == "bzip2" ) 175 else if( *f == "bzip2" )
148 { 176 {
149 sDat = encodeStr<BZip2>( sDat ); 177 sDat = encodeStr<BZip2>( sDat );
150 sFltDesc.prepend("b"); 178 sFltDesc.prepend("b");
151 hFilters.insert('b', true ); 179 hFilters.insert('b', true );
152 } 180 }
181#endif
182#ifdef BU_HAS_LZMA
153 else if( *f == "lzma" ) 183 else if( *f == "lzma" )
154 { 184 {
155 sDat = encodeStr<Lzma>( sDat ); 185 sDat = encodeStr<Lzma>( sDat );
156 sFltDesc.prepend("l"); 186 sFltDesc.prepend("l");
157 hFilters.insert('l', true ); 187 hFilters.insert('l', true );
158 } 188 }
189#endif
159 else if( *f == "base64" ) 190 else if( *f == "base64" )
160 { 191 {
161 sDat = encodeStr<Base64>( sDat ); 192 sDat = encodeStr<Base64>( sDat );