static int write_config(const char *filename, const game_driver *gamedrv) { file_error filerr; mame_file *f; char buffer[128]; int retval = 1; if (gamedrv != NULL) { sprintf(buffer, "%s.ini", gamedrv->name); filename = buffer; } filerr = mame_fopen(SEARCHPATH_INI, buffer, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &f); if (filerr != FILERR_NONE) goto done; options_output_ini_file(mame_options(), mame_core_file(f)); retval = 0; done: if (f != NULL) mame_fclose(f); return retval; }
static int execute_commands(core_options *options, const char *exename, const game_driver *driver) { static const struct { const char *option; int (*function)(core_options *options, const char *gamename); } info_commands[] = { { CLIOPTION_LISTXML, cli_info_listxml }, { CLIOPTION_LISTFULL, cli_info_listfull }, { CLIOPTION_LISTSOURCE, cli_info_listsource }, { CLIOPTION_LISTCLONES, cli_info_listclones }, { CLIOPTION_LISTCRC, cli_info_listcrc }, #ifdef MESS { CLIOPTION_LISTDEVICES, info_listdevices }, #endif { CLIOPTION_LISTROMS, cli_info_listroms }, { CLIOPTION_LISTSAMPLES, cli_info_listsamples }, { CLIOPTION_VERIFYROMS, info_verifyroms }, { CLIOPTION_VERIFYSAMPLES, info_verifysamples }, { CLIOPTION_ROMIDENT, info_romident } }; int i; /* createconfig? */ if (options_get_bool(options, CLIOPTION_CREATECONFIG)) { file_error filerr; mame_file *file; /* parse any relevant INI files before proceeding */ mame_parse_ini_files(options, driver); /* make the output filename */ filerr = mame_fopen_options(options, NULL, CONFIGNAME ".ini", OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file); /* error if unable to create the file */ if (filerr != FILERR_NONE) { fprintf(stderr, "Unable to create file " CONFIGNAME ".ini\n"); return MAMERR_FATALERROR; } /* output the configuration and exit cleanly */ options_output_ini_file(options, mame_core_file(file)); mame_fclose(file); return MAMERR_NONE; } /* showconfig? */ if (options_get_bool(options, CLIOPTION_SHOWCONFIG)) { /* parse any relevant INI files before proceeding */ mame_parse_ini_files(options, driver); options_output_ini_stdfile(options, stdout); return MAMERR_NONE; } /* informational commands? */ for (i = 0; i < ARRAY_LENGTH(info_commands); i++) if (options_get_bool(options, info_commands[i].option)) { const char *gamename = options_get_string(options, OPTION_GAMENAME); /* parse any relevant INI files before proceeding */ mame_parse_ini_files(options, driver); return (*info_commands[i].function)(options, (gamename[0] == 0) ? "*" : gamename); } return -1; }