void parse_options(int argc, char ** argv){ static struct option longopts[] = { { "help", 0, NULL, 'h'}, { "debug", 0, NULL, 'd'}, { "device", 0, NULL, 'D'}, { "export-cfg", 0, NULL, 'e'}, { "info", 0, NULL, 'I'}, { "records", 0, NULL, 'R'}, { "input-file", 0, NULL, 'i'}, { NULL, 0, NULL, 0} }; int c; for (;;) { c = getopt_long(argc, argv, "dhei:Io:RD:", longopts, (int *) 0); if (c == -1) break; switch (c) { case 'h': /* --help */ dispHelp(); break; case 'I': global_wich_action=0; break; case 'i': global_input = optarg; break; case 'R': global_wich_action=1; break; case 'd': global_debug=1; break; case 'o': global_output=optarg; break; case 'e': global_export_cfgs=1; break; case 'D': global_device=optarg; break; default: dispHelp(); } } }
static int findhelp( VTAB *tab ) { help_file *fileinfo; int ret; fileinfo = help_open( helpInBuf ); if( fileinfo == NULL ) { return( HELP_NO_SUBJECT ); } helpFileHdl = fileinfo->f; helpSearchHdl = fileinfo->searchhdl; ret = dispHelp( helpStack->word, tab ); /* if a new help file name exists, then link to the new file */ if( helpTab != NULL && helpCur->key2_len != 0 ) { curEvent = EV_ESCAPE; } return( ret ); }
int main(int argc, char** argv) { int res = 0; if (argc < 2) { dispHelp(); return 1; } #ifdef WIN32 if (UTIL::FS::isValidFolder("bin")) SetDllDir(".\\bin"); #endif InitFactory(); std::vector<UtilFunction*> list; GetFunctionList(list); std::vector<std::string> args; UtilFunction* funct = NULL; for (size_t x=2; x<(size_t)argc; x++) { if (argv[x]) args.push_back(argv[x]); else break; } size_t len = strlen(argv[1]); if (len == 2 && argv[1][0] == '-') { for (size_t x=0; x<list.size(); x++) { if (list[x]->getShortArg() == argv[1][1]) { funct = list[x]; break; } } } if (len > 2 && argv[1][0] == '-' && argv[1][1] == '-') { std::string arg(argv[1]+2, len-2); for (size_t x=0; x<list.size(); x++) { if (arg == list[x]->getFullArg()) { funct = list[x]; break; } } } if (funct) { if (funct->getNumArgs() > args.size()) { printf("Not enought arguments. Expected:"); for (size_t y=0; y<funct->getNumArgs(); y++) { printf(" [%s] ", funct->getArgDesc(y)); } printf("\n"); res = -1; } else { printf("Running %s...\n", funct->getFullArg()); try { res = funct->performAction(args); funct->checkException(); } catch (gcException &e) { printf("%s Failed %s [%d.%d]\n", funct->getFullArg(), e.getErrMsg(), e.getErrId(), e.getSecErrId()); res = (e.getErrId()&0x0000FFFF) + (e.getSecErrId()<<16); } catch (std::exception &e) { printf("%s Failed %s\n", funct->getFullArg(), e.what()); res = -1; } catch (...) { printf("%s Failed: Failed to catch exception. :(\n", funct->getFullArg()); res = -1; } } } else { printf("Unknown Command Line Arg: %s. (no args for help)\n", argv[1]); } printf("--- Done ---\n"); return res; }