From 955e3b8885397f394b72b57ccc0e0e0284fac77d Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 4 Oct 2012 03:12:01 +0000 Subject: Adding new config-file support to the bin2cpp program. I should probably call it bu-bin2cpp or something to make it more unique. --- src/tools/bin2cpp.cpp | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'src/tools/bin2cpp.cpp') 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 @@ #include #include #include +#include +#include +#include + #include #include #include #include #include -#include - -#include using namespace Bu; @@ -18,10 +19,15 @@ public: Options( int argc, char *argv[] ) : sClass("Datafiles") { + addHelpBanner("bin2cpp - convert files into executable-embeddable C++ code.\n"); + 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."); + addHelpBanner("\nUsage: bin2cpp [options] [input1] [input2] [...] [inputN]"); + addHelpBanner( " Or: bin2cpp -s \n"); addOption( sClass, 'c', "Class name [default=\"Datafiles\"]"); addOption( sOutBase, 'o', "Output base filename [defaults to classname]"); addOption( sOutDir, 'd', "Output directory [defaults to current dir]"); addOption( slot(this, &Options::addFilter), 'f', "Add filter: deflate, bzip2, lzma, base64, hex"); + 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."); setNonOption( slot(this, &Options::addInput) ); addHelpOption(); @@ -54,12 +60,34 @@ public: Bu::String sOutDir; Bu::StringList slInput; Bu::StringList slFilter; + Bu::String sSpecFile; }; int main( int argc, char *argv[] ) { Options opt( argc, argv ); + if( !opt.sSpecFile.isEmpty() ) + { + Bu::File fTaf( opt.sSpecFile, Bu::File::Read ); + Bu::TafReader rTaf( fTaf ); + Bu::TafGroup *pRoot = rTaf.readGroup(); + + if( pRoot == NULL || pRoot->getName() != "bin2cpp" ) + { + sio << "Specfied spec file does not appear to be a bin2cpp taf " + "specifications file." << sio.nl; + return 5; + } + + opt.sOutBase = opt.sClass = pRoot->getProperty("class"); + if( pRoot->hasProperty("output") ) + opt.sOutBase = pRoot->getProperty("output"); + opt.sOutDir = pRoot->getProperty("dir", ".") + "/"; + + delete pRoot; + } + File fHdrOut( opt.sOutDir + opt.sOutBase + ".h", File::WriteNew ); File fSrcOut( opt.sOutDir + opt.sOutBase + ".cpp", File::WriteNew ); -- cgit v1.2.3