aboutsummaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-10-04 03:12:01 +0000
committerMike Buland <eichlan@xagasoft.com>2012-10-04 03:12:01 +0000
commit955e3b8885397f394b72b57ccc0e0e0284fac77d (patch)
treed0f42b4419d800bcd01fdb3750f11d5200e4dadd /src/tools
parent46542b4d64565fcf46a4d92f63e1bcd4e4b9ccd8 (diff)
downloadlibbu++-955e3b8885397f394b72b57ccc0e0e0284fac77d.tar.gz
libbu++-955e3b8885397f394b72b57ccc0e0e0284fac77d.tar.bz2
libbu++-955e3b8885397f394b72b57ccc0e0e0284fac77d.tar.xz
libbu++-955e3b8885397f394b72b57ccc0e0e0284fac77d.zip
Adding new config-file support to the bin2cpp program. I should probably call
it bu-bin2cpp or something to make it more unique.
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/bin2cpp.cpp34
1 files changed, 31 insertions, 3 deletions
diff --git a/src/tools/bin2cpp.cpp b/src/tools/bin2cpp.cpp
index 15ef73d..0b822f0 100644
--- a/src/tools/bin2cpp.cpp
+++ b/src/tools/bin2cpp.cpp
@@ -1,14 +1,15 @@
1#include <bu/sio.h> 1#include <bu/sio.h>
2#include <bu/optparser.h> 2#include <bu/optparser.h>
3#include <bu/file.h> 3#include <bu/file.h>
4#include <bu/streamstack.h>
5#include <bu/strfilter.h>
6#include <bu/taf.h>
7
4#include <bu/deflate.h> 8#include <bu/deflate.h>
5#include <bu/bzip2.h> 9#include <bu/bzip2.h>
6#include <bu/lzma.h> 10#include <bu/lzma.h>
7#include <bu/base64.h> 11#include <bu/base64.h>
8#include <bu/hex.h> 12#include <bu/hex.h>
9#include <bu/streamstack.h>
10
11#include <bu/strfilter.h>
12 13
13using namespace Bu; 14using namespace Bu;
14 15
@@ -18,10 +19,15 @@ public:
18 Options( int argc, char *argv[] ) : 19 Options( int argc, char *argv[] ) :
19 sClass("Datafiles") 20 sClass("Datafiles")
20 { 21 {
22 addHelpBanner("bin2cpp - convert files into executable-embeddable C++ code.\n");
23 addHelpBanner("Each file in the input is loaded, filtered according to your options, and written as stack allocated, static variables in a generated class. You can then access the files as though they were on disk through that class.");
24 addHelpBanner("\nUsage: bin2cpp [options] [input1] [input2] [...] [inputN]");
25 addHelpBanner( " Or: bin2cpp -s <taf spec file>\n");
21 addOption( sClass, 'c', "Class name [default=\"Datafiles\"]"); 26 addOption( sClass, 'c', "Class name [default=\"Datafiles\"]");
22 addOption( sOutBase, 'o', "Output base filename [defaults to classname]"); 27 addOption( sOutBase, 'o', "Output base filename [defaults to classname]");
23 addOption( sOutDir, 'd', "Output directory [defaults to current dir]"); 28 addOption( sOutDir, 'd', "Output directory [defaults to current dir]");
24 addOption( slot(this, &Options::addFilter), 'f', "Add filter: deflate, bzip2, lzma, base64, hex"); 29 addOption( slot(this, &Options::addFilter), 'f', "Add filter: deflate, bzip2, lzma, 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.");
25 setNonOption( slot(this, &Options::addInput) ); 31 setNonOption( slot(this, &Options::addInput) );
26 addHelpOption(); 32 addHelpOption();
27 33
@@ -54,12 +60,34 @@ public:
54 Bu::String sOutDir; 60 Bu::String sOutDir;
55 Bu::StringList slInput; 61 Bu::StringList slInput;
56 Bu::StringList slFilter; 62 Bu::StringList slFilter;
63 Bu::String sSpecFile;
57}; 64};
58 65
59int main( int argc, char *argv[] ) 66int main( int argc, char *argv[] )
60{ 67{
61 Options opt( argc, argv ); 68 Options opt( argc, argv );
62 69
70 if( !opt.sSpecFile.isEmpty() )
71 {
72 Bu::File fTaf( opt.sSpecFile, Bu::File::Read );
73 Bu::TafReader rTaf( fTaf );
74 Bu::TafGroup *pRoot = rTaf.readGroup();
75
76 if( pRoot == NULL || pRoot->getName() != "bin2cpp" )
77 {
78 sio << "Specfied spec file does not appear to be a bin2cpp taf "
79 "specifications file." << sio.nl;
80 return 5;
81 }
82
83 opt.sOutBase = opt.sClass = pRoot->getProperty("class");
84 if( pRoot->hasProperty("output") )
85 opt.sOutBase = pRoot->getProperty("output");
86 opt.sOutDir = pRoot->getProperty("dir", ".") + "/";
87
88 delete pRoot;
89 }
90
63 File fHdrOut( opt.sOutDir + opt.sOutBase + ".h", File::WriteNew ); 91 File fHdrOut( opt.sOutDir + opt.sOutBase + ".h", File::WriteNew );
64 File fSrcOut( opt.sOutDir + opt.sOutBase + ".cpp", File::WriteNew ); 92 File fSrcOut( opt.sOutDir + opt.sOutBase + ".cpp", File::WriteNew );
65 93