minor features

This commit is contained in:
David Rose 2003-09-29 18:39:44 +00:00
parent 426164d9dc
commit 4ae797fc86
2 changed files with 19 additions and 5 deletions

View File

@ -43,12 +43,17 @@ BinToC() :
"for portably importing binary data into a library or executable."); "for portably importing binary data into a library or executable.");
add_option add_option
("n", "name", 50, ("n", "name", 0,
"Specify the name of the table that is generated.", "Specify the name of the table that is generated.",
&BinToC::dispatch_string, NULL, &_table_name); &BinToC::dispatch_string, NULL, &_table_name);
add_option 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. " "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 " "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 " "name of the output file, or standard output is used if there are no "
@ -72,15 +77,20 @@ run() {
} }
ostream &out = get_output(); ostream &out = get_output();
string static_keyword;
if (_static_table) {
static_keyword = "static ";
}
out << "\n" out << "\n"
<< "/*\n" << "/*\n"
<< " * This file was generated by the command:\n" << " * This table was generated by the command:\n"
<< " *\n" << " *\n"
<< " * " << get_exec_command() << "\n" << " * " << get_exec_command() << "\n"
<< " */\n\n" << " */\n\n"
<< "const unsigned char " << _table_name << "[] = {"; << static_keyword << "const unsigned char " << _table_name << "[] = {";
out << hex << setfill('0'); out << hex << setfill('0');
int count = 0;
int col = 0; int col = 0;
unsigned int ch; unsigned int ch;
ch = in.get(); ch = in.get();
@ -95,9 +105,12 @@ run() {
} }
out << "0x" << setw(2) << ch; out << "0x" << setw(2) << ch;
col++; col++;
count++;
ch = in.get(); ch = in.get();
} }
out << "\n};\n\n"; out << "\n};\n\n"
<< static_keyword << "const int " << _table_name << "_len = "
<< dec << count << ";\n\n";
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////

View File

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