|
|
@@ -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";
|
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|