From 839325922d0ff84a05324b17464ef86d20eebec8 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 26 Nov 2004 19:34:31 +0000 Subject: [PATCH] add -string --- pandatool/src/miscprogs/binToC.cxx | 16 ++++++++++++++-- pandatool/src/miscprogs/binToC.h | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pandatool/src/miscprogs/binToC.cxx b/pandatool/src/miscprogs/binToC.cxx index 71b1d23278..4e8a09c138 100644 --- a/pandatool/src/miscprogs/binToC.cxx +++ b/pandatool/src/miscprogs/binToC.cxx @@ -52,6 +52,11 @@ BinToC() : "Flag the table with the keyword 'static'.", &BinToC::dispatch_none, &_static_table); + add_option + ("string", "", 0, + "Define the table suitablly to pass to a string constructor.", + &BinToC::dispatch_none, &_for_string); + add_option ("o", "filename", 0, "Specify the filename to which the resulting C code will be written. " @@ -82,13 +87,20 @@ run() { static_keyword = "static "; } + string table_type = "const unsigned char "; + string length_type = "const int "; + if (_for_string) { + table_type = "const char "; + length_type = "const size_t "; + } + out << "\n" << "/*\n" << " * This table was generated by the command:\n" << " *\n" << " * " << get_exec_command() << "\n" << " */\n\n" - << static_keyword << "const unsigned char " << _table_name << "[] = {"; + << static_keyword << table_type << _table_name << "[] = {"; out << hex << setfill('0'); int count = 0; int col = 0; @@ -109,7 +121,7 @@ run() { ch = in.get(); } out << "\n};\n\n" - << static_keyword << "const int " << _table_name << "_len = " + << static_keyword << length_type << _table_name << "_len = " << dec << count << ";\n\n"; } diff --git a/pandatool/src/miscprogs/binToC.h b/pandatool/src/miscprogs/binToC.h index f729c23a22..7ce4d25c88 100644 --- a/pandatool/src/miscprogs/binToC.h +++ b/pandatool/src/miscprogs/binToC.h @@ -43,6 +43,7 @@ protected: Filename _input_filename; string _table_name; bool _static_table; + bool _for_string; }; #endif