Kaynağa Gözat

add -string

David Rose 21 yıl önce
ebeveyn
işleme
839325922d

+ 14 - 2
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";
 }
 

+ 1 - 0
pandatool/src/miscprogs/binToC.h

@@ -43,6 +43,7 @@ protected:
   Filename _input_filename;
   string _table_name;
   bool _static_table;
+  bool _for_string;
 };
 
 #endif