static void parse_cmdline_and_init_file (int argc, char **argv) { char *home; strcpy (optionsfile, ""); #ifdef OPTIONS_IN_HOME home = getenv ("HOME"); if (home != NULL && strlen (home) < 240) { strcpy (optionsfile, home); strcat (optionsfile, "/"); } #endif strcat (optionsfile, OPTIONSFILENAME); if (! cfgfile_load (&currprefs, optionsfile)) { #ifdef OPTIONS_IN_HOME /* If not found in $HOME then look in current directory. However, * don't use the optionsfile variable, so that we will save changes * to the home directory. */ char pwd_optionsfile[256]; strcpy (optionsfile, OPTIONSFILENAME); cfgfile_load (&currprefs, optionsfile); #endif } parse_cmdline (argc, argv); }
void parse_cmdline (int argc, char **argv) { int i; for (i = 1; i < argc; i++) { if (strncmp (argv[i], "-config=", 8) == 0) cfgfile_load (&currprefs, argv[i] + 8); /* Check for new-style "-f xxx" argument, where xxx is config-file */ else if (strcmp (argv[i], "-f") == 0) { if (i + 1 == argc) write_log ("Missing argument for '-f' option.\n"); else cfgfile_load (&currprefs, argv[++i]); } else if (strcmp (argv[i], "-s") == 0) { if (i + 1 == argc) write_log ("Missing argument for '-s' option.\n"); else cfgfile_parse_line (&currprefs, argv[++i]); } else if (strcmp (argv[i], "-h") == 0 || strcmp (argv[i], "-help") == 0) { usage (); exit (0); } else { if (argv[i][0] == '-' && argv[i][1] != '\0') { const char *arg = argv[i] + 2; int extra_arg = *arg == '\0'; if (extra_arg) arg = i + 1 < argc ? argv[i + 1] : 0; if (parse_cmdline_option (&currprefs, argv[i][1], arg) && extra_arg) i++; } } } }
int target_cfgfile_load (struct uae_prefs *p, const TCHAR *filename, int type, int isdefault) { int v, i, type2; int ct, ct2 = 0;//, size; char tmp1[MAX_DPATH], tmp2[MAX_DPATH]; char fname[MAX_DPATH]; _tcscpy (fname, filename); if (!zfile_exists (fname)) { fetch_configurationpath (fname, sizeof (fname) / sizeof (TCHAR)); if (_tcsncmp (fname, filename, _tcslen (fname))) _tcscat (fname, filename); else _tcscpy (fname, filename); } if (!isdefault) qs_override = 1; if (type < 0) { type = 0; cfgfile_get_description (fname, NULL, NULL, NULL, &type); } if (type == 0 || type == 1) { discard_prefs (p, 0); } type2 = type; if (type == 0) { default_prefs (p, type); } //regqueryint (NULL, "ConfigFile_NoAuto", &ct2); v = cfgfile_load (p, fname, &type2, ct2, isdefault ? 0 : 1); if (!v) return v; if (type > 0) return v; for (i = 1; i <= 2; i++) { if (type != i) { // size = sizeof (ct); ct = 0; //regqueryint (NULL, configreg2[i], &ct); if (ct && ((i == 1 && p->config_hardware_path[0] == 0) || (i == 2 && p->config_host_path[0] == 0) || ct2)) { // size = sizeof (tmp1) / sizeof (TCHAR); //regquerystr (NULL, configreg[i], tmp1, &size); fetch_path ("ConfigurationPath", tmp2, sizeof (tmp2) / sizeof (TCHAR)); _tcscat (tmp2, tmp1); v = i; cfgfile_load (p, tmp2, &v, 1, 0); } } } v = 1; return v; }
static void parse_cmdline (int argc, char **argv) { int i; for (i = 1; i < argc; i++) { if (strcmp (argv[i], "-cfgparam") == 0) { if (i + 1 < argc) i++; } else if (strncmp (argv[i], "-config=", 8) == 0) { #ifdef FILESYS free_mountinfo (currprefs.mountinfo); currprefs.mountinfo = alloc_mountinfo (); #endif if (cfgfile_load (&currprefs, argv[i] + 8, 0)) strcpy (optionsfile, argv[i] + 8); } /* Check for new-style "-f xxx" argument, where xxx is config-file */ else if (strcmp (argv[i], "-f") == 0) { if (i + 1 == argc) { write_log ("Missing argument for '-f' option.\n"); } else { #ifdef FILESYS free_mountinfo (currprefs.mountinfo); currprefs.mountinfo = alloc_mountinfo (); #endif if (cfgfile_load (&currprefs, argv[++i], 0)) strcpy (optionsfile, argv[i]); } } else if (strcmp (argv[i], "-s") == 0) { if (i + 1 == argc) write_log ("Missing argument for '-s' option.\n"); else cfgfile_parse_line (&currprefs, argv[++i], 0); } else if (strcmp (argv[i], "-h") == 0 || strcmp (argv[i], "-help") == 0) { usage (); exit (0); } else if (strcmp (argv[i], "-version") == 0) { show_version_full (); exit (0); } else if (strcmp (argv[i], "-scsilog") == 0) { log_scsi = 1; } else { if (argv[i][0] == '-' && argv[i][1] != '\0') { const char *arg = argv[i] + 2; int extra_arg = *arg == '\0'; if (extra_arg) arg = i + 1 < argc ? argv[i + 1] : 0; if (parse_cmdline_option (&currprefs, argv[i][1], (char*)arg) && extra_arg) i++; } } } }
static void parse_cmdline_and_init_file (int argc, char **argv) { char *home; #ifdef _WIN32 extern char *start_path; #endif strcpy (optionsfile, ""); #ifdef OPTIONS_IN_HOME home = getenv ("HOME"); if (home != NULL && strlen (home) < 240) { strcpy (optionsfile, home); strcat (optionsfile, "/"); } #endif #ifdef _WIN32 sprintf( optionsfile, "%s\\Configurations\\", start_path ); #endif strcat (optionsfile, OPTIONSFILENAME); if (! cfgfile_load (&currprefs, optionsfile, 0)) { write_log ("failed to load config '%s'\n", optionsfile); #ifdef OPTIONS_IN_HOME /* sam: if not found in $HOME then look in current directory */ char *saved_path = strdup (optionsfile); strcpy (optionsfile, OPTIONSFILENAME); if (! cfgfile_load (&currprefs, optionsfile, 0) ) { /* If not in current dir either, change path back to home * directory - so that a GUI can save a new config file there */ strcpy (optionsfile, saved_path); } free (saved_path); #endif } cfgfile_load (&currprefs, SAVEDFILENAME, 0); cfgfile_load (&currprefs, USERFILENAME, 0); parse_cmdline (argc, argv); fix_options (); }
VEXTERN MIDIMOD VEXPORT midimod_create(UINT samprate) { UINT size; MIDIMOD ret; BRESULT r; size = sizeof(_MIDIMOD); size += sizeof(INSTRUMENT) * 128 * 2; size += sizeof(_TONECFG) * 128 * 2; ret = (MIDIMOD)_MALLOC(size, "MIDIMOD"); if (ret == NULL) { goto mmcre_err1; } ZeroMemory(ret, size); ret->samprate = samprate; ret->tone[0] = (INSTRUMENT *)(ret + 1); ret->tone[1] = ret->tone[0] + 128; ret->tonecfg[0] = (TONECFG)(ret->tone[1] + 128); ret->tonecfg[1] = ret->tonecfg[0] + 128; ret->pathtbl = listarray_new(sizeof(_PATHLIST), 16); pathadd(ret, NULL); pathadd(ret, file_getcd(str_null)); ret->namelist = listarray_new(MAX_NAME, 128); r = cfgfile_load(ret, file_timiditycfg, 0); #if defined(TIMIDITY_CFGFILE) if (r != SUCCESS) { r = cfgfile_load(ret, TIMIDITY_CFGFILE, 0); } #endif if (r != SUCCESS) { goto mmcre_err2; } midimod_lock(ret); return(ret); mmcre_err2: listarray_destroy(ret->namelist); listarray_destroy(ret->pathtbl); _MFREE(ret); mmcre_err1: return(NULL); }
void uade_option(int argc, char **argv) { int i, j, no_more_opts; char **s_argv; int s_argc; int cfg_loaded = 0; char optionsfile[PATH_MAX]; int ret; char *input = NULL; char *output = NULL; /* network byte order is the big endian order */ uade_big_endian = (htonl(0x1234) == 0x1234); memset(&song, 0, sizeof(song)); no_more_opts = 0; s_argv = malloc(sizeof(argv[0]) * (argc + 1)); if (!s_argv) { fprintf (stderr, "uadecore: Out of memory for command line parsing.\n"); exit(-1); } s_argc = 0; s_argv[s_argc++] = argv[0]; for (i = 1; i < argc;) { j = i; /* if argv[i] begins with '-', see if it is a switch that we should handle here. */ if (argv[i][0] == '-') { if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h") || !strcmp(argv[i], "-help")) { uade_print_help(OPTION_HELP, argv[0]); exit(0); } else if (!strcmp(argv[i], "-i")) { if ((i + 1) >= argc) { fprintf(stderr, "uadecore: %s parameter missing\n", argv[i]); uade_print_help(OPTION_ILLEGAL_PARAMETERS, argv[0]); exit(-1); } input = argv[i + 1]; i += 2; } else if (!strcmp(argv[i], "-o")) { if ((i + 1) >= argc) { fprintf(stderr, "uadecore: %s parameter missing\n", argv[i]); uade_print_help(OPTION_ILLEGAL_PARAMETERS, argv[0]); exit(-1); } output = argv[i + 1]; i += 2; } else if (!strcmp(argv[i], "--")) { for (i = i + 1; i < argc ; i++) s_argv[s_argc++] = argv[i]; break; } } if (i == j) { s_argv[s_argc++] = argv[i]; i++; } } s_argv[s_argc] = NULL; uade_set_peer(&uadeipc, 0, input, output); ret = uade_receive_string(optionsfile, UADE_COMMAND_CONFIG, sizeof(optionsfile), &uadeipc); if (ret == 0) { fprintf(stderr, "uadecore: No config file passed as a message.\n"); exit(-1); } else if (ret < 0) { fprintf(stderr, "uadecore: Invalid input. Expected a config file.\n"); exit(-1); } // printf("got config : %s\n",optionsfile); /* use the config file provided with a message, if '-config' option was not given */ if (!cfg_loaded) { if (cfgfile_load (&currprefs, optionsfile) == 0) { fprintf(stderr, "uadecore: Could not load uaerc (%s).\n", optionsfile); exit(-1); } } free(s_argv); uade_portable_initializations(); uade_reboot = 1; }
VEXTERN BRESULT VEXPORT midimod_cfgload(MIDIMOD mod, const OEMCHAR *filename) { return(cfgfile_load(mod, filename, 0)); }
static BRESULT VERMOUTHCL cfgfile_load(MIDIMOD mod, const OEMCHAR *filename, int depth) { TEXTFILEH tfh; OEMCHAR buf[1024]; int bank; int i; int argc; OEMCHAR *argv[16]; int val; UINT cfg; bank = -1; if ((depth >= 16) || (midimod_getfile(mod, filename, buf, NELEMENTS(buf)) != SUCCESS)) { goto cfl_err; } // TRACEOUT(("open: %s", buf)); tfh = textfile_open(buf, 0x1000); if (tfh == NULL) { goto cfl_err; } while(textfile_read(tfh, buf, NELEMENTS(buf)) == SUCCESS) { argc = cfggetarg(buf, argv, NELEMENTS(argv)); if (argc < 2) { continue; } cfg = 0; while(cfg < NELEMENTS(cfgstr)) { if (!milstr_cmp(argv[0], cfgstr[cfg])) { break; } cfg++; } switch(cfg) { case CFG_DIR: for (i=1; i<argc; i++) { pathaddex(mod, argv[i]); } break; case CFG_SOURCE: for (i=1; i<argc; i++) { depth++; cfgfile_load(mod, argv[i], depth); depth--; } break; case CFG_DEFAULT: break; case CFG_BANK: case CFG_DRUM: if ((cfggetval(argv[1], &val) == SUCCESS) && (val >= 0) && (val < 128)) { val <<= 1; if (cfg == CFG_DRUM) { val++; } bank = val; } break; default: settone(mod, bank, argc, argv); break; } } textfile_close(tfh); return(SUCCESS); cfl_err: return(FAILURE); }
/** * This functions sets up the actual font and then displays the main dialog. */ int Dialog_MainDlg(bool *bReset, bool *bLoadedSnapshot) { int retbut=0; bool bOldMouseVisibility; int nOldMouseX, nOldMouseY; char *psNewCfg; *bReset = false; *bLoadedSnapshot = false; if (SDLGui_SetScreen(/*sdlscrn*/)) return false; SDLGui_CenterDlg(maindlg); maindlg[MAINDLG_NORESET].state |= SG_SELECTED; maindlg[MAINDLG_RESET].state &= ~SG_SELECTED; do { retbut = SDLGui_DoDialog(maindlg, NULL); switch (retbut) { case MAINDLG_ABOUT: Dialog_AboutDlg(); break; case MAINDLG_FLOPPYS: DlgFloppy_Main(); break; case MAINDLG_HARDDISK: DlgHardDisk_Main(); break; case MAINDLG_ROM: DlgRom_Main(); break; case MAINDLG_VIDEO: Dialog_VideoDlg(); break; case MAINDLG_SYSTEM: Dialog_SystemDlg(); break; case MAINDLG_MEMORY: if (Dialog_MemDlg()) { /* Memory snapshot has been loaded - leave GUI immediately */ *bLoadedSnapshot = true; //Main_WarpMouse(nOldMouseX, nOldMouseY); return true; } break; case MAINDLG_MISC: Dialog_MiscDlg(); break; case MAINDLG_JOYSTICK: Dialog_JoyDlg(); break; case MAINDLG_SOUND: Dialog_SoundDlg(); break; case MAINDLG_LOADCFG: strcpy(sConfigFileName, ".uaerc"); psNewCfg = SDLGui_FileSelect(sConfigFileName, NULL, false); if (psNewCfg) { default_prefs(& changed_prefs, 0); changed_prefs.chipmem_size = 0; changed_prefs.bogomem_size = 0; unmount_all_hdfs(); int ret = cfgfile_load (& changed_prefs, psNewCfg, NULL,1,0); if (ret) { check_prefs_changed_cpu(); check_prefs_changed_audio(); check_prefs_changed_custom(); MUSTRESET_CFG=1; } strcpy(sConfigFileName, psNewCfg); } break; case MAINDLG_QUIT: bQuitProgram = true; break; } gui_poll_events(); } while (retbut != MAINDLG_OK && retbut != MAINDLG_CANCEL && retbut != SDLGUI_QUIT && retbut != SDLGUI_ERROR && !bQuitProgram); if (maindlg[MAINDLG_RESET].state & SG_SELECTED) *bReset = true; return (retbut == MAINDLG_OK); }
static void scan_configs (const char *path) { DIR *dir; int pathlen = strlen (path); int bufsz = pathlen + 256; char *buffer; uae_u8 *data; predef_configs_space = 20; predef_configs = malloc (sizeof (struct config_list) * 20); n_predef_configs = 0; dir = opendir (path); if (!dir) return; buffer = malloc (bufsz); if (!buffer) goto out; data = malloc (1024 * 1024); if (!data) goto out1; strcpy (buffer, path); buffer[pathlen++] = '/'; buffer[pathlen] = '\0'; for (;;) { struct uae_prefs p; struct zfile *f; struct dirent *ent = readdir (dir); int len; struct romdata *rd; long size; if (!ent) break; len = strlen (ent->d_name); if (len + pathlen + 1 >= bufsz) { bufsz = len + pathlen + 200; buffer = realloc (buffer, bufsz); if (!buffer) { free (data); goto out; } } strcpy (buffer + pathlen, ent->d_name); if (n_predef_configs >= predef_configs_space) { predef_configs_space += 20; predef_configs = realloc (predef_configs, sizeof (struct config_list) * predef_configs_space); } default_prefs (&p); strcpy (p.description, ""); strcpy (p.sortstr, ""); cfgfile_load (&p, buffer); if (strlen (p.description) > 0) { predef_configs[n_predef_configs].filename = strdup (buffer); predef_configs[n_predef_configs].description = strdup (p.description); predef_configs[n_predef_configs++].sortstr = strdup (p.sortstr); } } qsort (predef_configs, n_predef_configs, sizeof *predef_configs, sortfn); free (data); out1: free (buffer); out: closedir (dir); }
int main (int argc, char **argv) { #ifdef GEKKO printf("\x1b[2;0H"); //initialize libfat library if (fatInitDefault()) printf("FAT subsytem initialized\n\n"); else { printf("Couldn't initialize FAT subsytem\n\n"); sleep(3); exit(0); } DIR *dp; dp = opendir ("sd:/"); if (dp) sdismount = 1; else sdismount = 0; if (sdismount) printf("SD FAT subsytem initialized\n\n"); else printf("Couldn't initialize SD fat subsytem\n\n"); if (sdismount) closedir (dp); usbismount = InitUSB(); default_prefs (&currprefs, 0); cfgfile_load (&currprefs, SMBFILENAME, 0); printf("\n"); if (currprefs.smb_enable) networkisinit = InitNetwork(); if (networkisinit && currprefs.smb_enable) ConnectShare(); sleep(2); if (!(log_quiet = !currprefs.write_logfile)) set_logfile("/uae/uae.log"); #endif write_log("main started\n"); init_sdl (); write_log("sdl inited\n"); gui_init (argc, argv); write_log("Starting real main\n"); real_main (argc, argv); #ifdef GEKKO if (smbismount) CloseShare (); DeInitUSB(); fatUnmount(0); #endif return 0; }