Browse Source

minor features

David Rose 22 years ago
parent
commit
4ae797fc86
2 changed files with 19 additions and 5 deletions
  1. 18 5
      pandatool/src/miscprogs/binToC.cxx
  2. 1 0
      pandatool/src/miscprogs/binToC.h

+ 18 - 5
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";
 }
 
 ////////////////////////////////////////////////////////////////////

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

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