int main(int argc, char *argv[]) { #if (!PSTANDALONE) track_memory(true); { #endif nlwav_options_t opts; int ret; if ((ret = opts.parse(argc, argv)) != argc) { fprintf(stderr, "Error parsing %s\n", argv[ret]); usage(opts); return 1; } if (opts.opt_help()) { usage(opts); return 1; } convert(opts); #if (!PSTANDALONE) } dump_unfreed_mem(); #endif return 0; }
int main(int argc, char *argv[]) { #if (!PSTANDALONE) track_memory(true); { #endif tool_options_t opts; int ret; fprintf(stderr, "%s", "WARNING: This is Work In Progress! - It may fail anytime\n"); fprintf(stderr, "Update dispatching using method %s\n", pmf_verbose[NL_PMF_TYPE]); if ((ret = opts.parse(argc, argv)) != argc) { fprintf(stderr, "Error parsing %s\n", argv[ret]); usage(opts); return 1; } if (opts.opt_help()) { usage(opts); return 1; } pstring cmd = opts.opt_cmd(); if (cmd == "listdevices") listdevices(); else if (cmd == "run") run(opts); else if (cmd == "convert") { pstring contents = filetobuf(opts.opt_file()); nl_convert_base_t *converter = NULL; if (opts.opt_type().equals("spice")) converter = palloc(nl_convert_spice_t); else converter = palloc(nl_convert_eagle_t); converter->convert(contents); /* present result */ printf("%s\n", converter->result().cstr()); pfree(converter); } else { fprintf(stderr, "Unknown command %s\n", cmd.cstr()); usage(opts); return 1; } #if (!PSTANDALONE) } dump_unfreed_mem(); #endif return 0; }
int cli_execute(int argc, char **argv, const options_entry *osd_options) { core_options *options = NULL; const char *gamename_option; const game_driver *driver; int result = MAMERR_FATALERROR; astring gamename; astring exename; try { /* initialize the options manager and add the CLI-specific options */ options = mame_options_init(osd_options); options_add_entries(options, cli_options); /* parse the command line first; if we fail here, we're screwed */ if (options_parse_command_line(options, argc, argv, OPTION_PRIORITY_CMDLINE)) { result = MAMERR_INVALID_CONFIG; goto error; } /* parse the simple commmands before we go any further */ core_filename_extract_base(&exename, argv[0], TRUE); result = execute_simple_commands(options, exename); if (result != -1) goto error; /* find out what game we might be referring to */ gamename_option = options_get_string(options, OPTION_GAMENAME); core_filename_extract_base(&gamename, gamename_option, TRUE); driver = driver_get_name(gamename); /* execute any commands specified */ result = execute_commands(options, exename, driver); if (result != -1) goto error; /* if we don't have a valid driver selected, offer some suggestions */ if (strlen(gamename_option) > 0 && driver == NULL) { const game_driver *matches[10]; int drvnum; /* get the top 10 approximate matches */ driver_list_get_approx_matches(drivers, gamename_option, ARRAY_LENGTH(matches), matches); /* print them out */ fprintf(stderr, "\n\"%s\" approximately matches the following\n" "supported " GAMESNOUN " (best match first):\n\n", gamename_option); for (drvnum = 0; drvnum < ARRAY_LENGTH(matches); drvnum++) if (matches[drvnum] != NULL) fprintf(stderr, "%-18s%s\n", matches[drvnum]->name, matches[drvnum]->description); /* exit with an error */ result = MAMERR_NO_SUCH_GAME; goto error; } /* run the game */ result = mame_execute(options); } catch (emu_fatalerror &fatal) { fprintf(stderr, "%s\n", fatal.string()); if (fatal.exitcode() != 0) result = fatal.exitcode(); } catch (emu_exception &) { fprintf(stderr, "Caught unhandled emulator exception\n"); } catch (std::bad_alloc &) { fprintf(stderr, "Out of memory!\n"); } catch (...) { fprintf(stderr, "Caught unhandled exception\n"); } error: /* free our options and exit */ if (options != NULL) options_free(options); /* report any unfreed memory */ dump_unfreed_mem(); return result; }