Fix datatypes to use platform independent values, Add command line switch scaffolding
Allow users to chose which bink/channelid they'd like to generate with Add rudimentary help system, Sanitize user input
This commit is contained in:
51
src/cli.cpp
51
src/cli.cpp
@@ -4,14 +4,61 @@
|
||||
|
||||
#include "header.h"
|
||||
|
||||
void print_product_id(ul32 *pid)
|
||||
void showHelp(char *argv[]) {
|
||||
std::cout << "usage: " << argv[0] << std::endl << std::endl
|
||||
<< "\t-h --help\tshow this message" << std::endl
|
||||
<< "\t-v --verbose\tenable verbose output" << std::endl
|
||||
<< "\t-b --binkid\tspecify which BINK identifier to load (defaults to 2E)" << std::endl
|
||||
<< "\t-l --list\tshow which products/binks can be loaded" << std::endl
|
||||
<< "\t-c --channelid\tspecify which Channel Identifier to use (defaults to 640)" << std::endl
|
||||
<< std::endl << std::endl;
|
||||
}
|
||||
|
||||
Options parseCommandLine(int argc, char* argv[]) {
|
||||
Options options = {
|
||||
"2E",
|
||||
640,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
};
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
std::string arg = argv[i];
|
||||
|
||||
if (arg == "-v" || arg == "--verbose") {
|
||||
options.verbose = true;
|
||||
} else if (arg == "-h" || arg == "--help") {
|
||||
options.help = true;
|
||||
} else if (arg == "-b" || arg == "--bink") {
|
||||
options.binkid = argv[i+1];
|
||||
i++;
|
||||
} else if (arg == "-l" || arg == "--list") {
|
||||
options.list = true;
|
||||
} else if (arg == "-c" || arg == "--channelid") {
|
||||
int siteID;
|
||||
if (!sscanf(argv[i+1], "%d", &siteID)) {
|
||||
options.error = true;
|
||||
} else {
|
||||
options.channelID = siteID;
|
||||
}
|
||||
i++;
|
||||
} else {
|
||||
options.error = true;
|
||||
}
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
void print_product_id(uint32_t *pid)
|
||||
{
|
||||
char raw[12];
|
||||
char b[6], c[8];
|
||||
int i, digit = 0;
|
||||
|
||||
// Cut a away last bit of pid and convert it to an accii-number (=raw)
|
||||
sprintf(raw, "%lu", pid[0] >> 1);
|
||||
sprintf(raw, "%iu", pid[0] >> 1);
|
||||
|
||||
// Make b-part {640-....}
|
||||
strncpy(b, raw, 3);
|
||||
|
||||
Reference in New Issue
Block a user