add -string

This commit is contained in:
David Rose 2004-11-26 19:34:31 +00:00
parent d636bc832f
commit 839325922d
2 changed files with 15 additions and 2 deletions

View File

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

View File

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