X-Git-Url: http://git.tdb.fi/?p=libs%2Fdatafile.git;a=blobdiff_plain;f=tool%2Ftool.cpp;h=d58853eef5cbf519228e1fa7a0401811173db6df;hp=59c5cbcb1df30f33a6263697e216a2fb26719e38;hb=0bf1684c1ae0f5ecc23b7c64f0a0fec79a8c2082;hpb=06fe7b7a0c0af0bab3df79cebe87f8ff93b31b00 diff --git a/tool/tool.cpp b/tool/tool.cpp index 59c5cbc..d58853e 100644 --- a/tool/tool.cpp +++ b/tool/tool.cpp @@ -5,6 +5,7 @@ #include #include #include "compiler.h" +#include "packer.h" #include "tool.h" using namespace std; @@ -15,24 +16,33 @@ DataTool::DataTool(int argc, char **argv): binary(false), compile(false), float_size(0), - compress(false) + compress(false), + pack(false), + debug(false) { GetOpt getopt; - getopt.add_option('b', "binary", binary, GetOpt::NO_ARG); - getopt.add_option('c', "compile", compile, GetOpt::NO_ARG); - getopt.add_option('f', "float-size", float_size, GetOpt::REQUIRED_ARG); - getopt.add_option('o', "output", out_fn, GetOpt::REQUIRED_ARG); - getopt.add_option('z', "compress", compress, GetOpt::NO_ARG); + getopt.add_option('b', "binary", binary, GetOpt::NO_ARG).set_help("Produce a binary datafile"); + getopt.add_option('c', "compile", compile, GetOpt::NO_ARG).set_help("Create a collection based on a template file"); + getopt.add_option('f', "float-size", float_size, GetOpt::REQUIRED_ARG).set_help("Floating-point precision", "BITS"); + getopt.add_option('g', "debug", debug, GetOpt::NO_ARG).set_help("Display control statements"); + getopt.add_option('o', "output", out_fn, GetOpt::REQUIRED_ARG).set_help("Output to a file instead of stdout", "FILE"); + getopt.add_option('p', "pack", pack, GetOpt::NO_ARG).set_help("Create a pack from multiple files"); + getopt.add_option('z', "compress", compress, GetOpt::NO_ARG).set_help("Produce a compressed datafile"); + getopt.add_argument("infile", in_fns, GetOpt::OPTIONAL_ARG).set_help("Files to process"); getopt(argc, argv); - in_fns = getopt.get_args(); if(in_fns.empty()) in_fns.push_back("-"); + + if(pack && out_fn=="-") + throw usage_error("Can't write pack to stdout"); } int DataTool::main() { - if(compile) + if(pack) + do_pack(); + else if(compile) do_compile(); else do_transfer(); @@ -45,15 +55,15 @@ void DataTool::do_transfer() IO::Base *out = open_output(out_fn); DataFile::Writer *writer = create_writer(*out); - for(vector::const_iterator i=in_fns.begin(); i!=in_fns.end(); ++i) + for(list::const_iterator i=in_fns.begin(); i!=in_fns.end(); ++i) { IO::Base *in = open_input(*i); DataFile::Parser parser(*in, *i); while(parser) { - DataFile::Statement st = parser.parse(); - if(st.valid) + DataFile::Statement st = parser.parse(true); + if(st.valid && (!st.control || st.keyword=="__src" || debug)) writer->write(st); } @@ -70,7 +80,7 @@ void DataTool::do_compile() DataFile::Writer *writer = create_writer(*out); Compiler compiler(*writer); - for(vector::const_iterator i=in_fns.begin(); i!=in_fns.end(); ++i) + for(list::const_iterator i=in_fns.begin(); i!=in_fns.end(); ++i) { IO::Base *in = open_input(*i); DataFile::Parser parser(*in, *i); @@ -82,6 +92,14 @@ void DataTool::do_compile() delete out; } +void DataTool::do_pack() +{ + Packer packer(*this); + for(list::const_iterator i=in_fns.begin(); i!=in_fns.end(); ++i) + packer.pack_file(*i); + packer.create_pack(out_fn); +} + IO::Base *DataTool::open_output(const string &fn) { if(fn=="-")