From 4ae797fc86aff4dcb1f50b874d72e03f596270c6 Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 29 Sep 2003 18:39:44 +0000 Subject: [PATCH] minor features --- pandatool/src/miscprogs/binToC.cxx | 23 ++++++++++++++++++----- pandatool/src/miscprogs/binToC.h | 1 + 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/pandatool/src/miscprogs/binToC.cxx b/pandatool/src/miscprogs/binToC.cxx index e191659256..61d3a6b3d0 100644 --- a/pandatool/src/miscprogs/binToC.cxx +++ b/pandatool/src/miscprogs/binToC.cxx @@ -43,12 +43,17 @@ BinToC() : "for portably importing binary data into a library or executable."); add_option - ("n", "name", 50, + ("n", "name", 0, "Specify the name of the table that is generated.", &BinToC::dispatch_string, NULL, &_table_name); add_option - ("o", "filename", 50, + ("static", "", 0, + "Flag the table with the keyword 'static'.", + &BinToC::dispatch_none, &_static_table); + + add_option + ("o", "filename", 0, "Specify the filename to which the resulting C code will be written. " "If this option is omitted, the last parameter name is taken to be the " "name of the output file, or standard output is used if there are no " @@ -72,15 +77,20 @@ run() { } ostream &out = get_output(); + string static_keyword; + if (_static_table) { + static_keyword = "static "; + } out << "\n" << "/*\n" - << " * This file was generated by the command:\n" + << " * This table was generated by the command:\n" << " *\n" << " * " << get_exec_command() << "\n" << " */\n\n" - << "const unsigned char " << _table_name << "[] = {"; + << static_keyword << "const unsigned char " << _table_name << "[] = {"; out << hex << setfill('0'); + int count = 0; int col = 0; unsigned int ch; ch = in.get(); @@ -95,9 +105,12 @@ run() { } out << "0x" << setw(2) << ch; col++; + count++; ch = in.get(); } - out << "\n};\n\n"; + out << "\n};\n\n" + << static_keyword << "const int " << _table_name << "_len = " + << dec << count << ";\n\n"; } //////////////////////////////////////////////////////////////////// diff --git a/pandatool/src/miscprogs/binToC.h b/pandatool/src/miscprogs/binToC.h index 311844b411..bc5bd1c5b0 100644 --- a/pandatool/src/miscprogs/binToC.h +++ b/pandatool/src/miscprogs/binToC.h @@ -42,6 +42,7 @@ protected: Filename _input_filename; string _table_name; + bool _static_table; }; #endif