int options_parse_ini_file(mame_file *inifile) { /* loop over data */ while (mame_fgets(giant_string_buffer, GIANT_STRING_BUFFER_SIZE, inifile) != NULL) { char *optionname, *optiondata, *temp; options_data *data; int inquotes = FALSE; /* find the name */ for (optionname = giant_string_buffer; *optionname != 0; optionname++) if (!isspace(*optionname)) break; /* skip comments */ if (*optionname == 0 || *optionname == '#') continue; /* scan forward to find the first space */ for (temp = optionname; *temp != 0; temp++) if (isspace(*temp)) break; /* if we hit the end early, print a warning and continue */ if (*temp == 0) { mame_printf_warning("Warning: invalid line in INI: %s", giant_string_buffer); continue; } /* NULL-terminate */ *temp++ = 0; optiondata = temp; /* scan the data, stopping when we hit a comment */ for (temp = optiondata; *temp != 0; temp++) { if (*temp == '"') inquotes = !inquotes; if (*temp == '#' && !inquotes) break; } *temp = 0; /* find our entry */ data = find_entry_data(optionname, FALSE); if (data == NULL) { mame_printf_warning("Warning: unknown option in INI: %s\n", optionname); continue; } if ((data->flags & (OPTION_DEPRECATED | OPTION_INTERNAL)) != 0) continue; /* allocate a new copy of data for this */ update_data(data, optiondata); } return 0; }
int uistring_init (mame_file *langfile) { /* TODO: This routine needs to do several things: - load an external font if needed - determine the number of characters in the font - deal with multibyte languages */ int i, j, str; char curline[255]; char section[255] = "\0"; char *ptr; int string_count; /* count the total amount of strings */ string_count = 0; for (i = 0; default_text[i]; i++) { for (j = 0; default_text[i][j]; j++) string_count++; } /* allocate the translated text array, and set defaults */ trans_text = auto_malloc(sizeof(const char *) * string_count); /* copy in references to all of the strings */ str = 0; for (i = 0; default_text[i]; i++) { for (j = 0; default_text[i][j]; j++) trans_text[str++] = default_text[i][j]; } memset(&lang, 0, sizeof(lang)); /* if no language file, exit */ if (!langfile) return 0; while (mame_fgets (curline, sizeof(curline) / sizeof(curline[0]), langfile) != NULL) { /* Ignore commented and blank lines */ if (curline[0] == ';') continue; if (curline[0] == '\n') continue; if (curline[0] == '\r') continue; if (curline[0] == '[') { ptr = strtok (&curline[1], "]"); /* Found a section, indicate as such */ strcpy (section, ptr); /* Skip to the next line */ continue; } /* Parse the LangInfo section */ if (strcmp (section, "LangInfo") == 0) { ptr = strtok (curline, "="); if (strcmp (ptr, "Version") == 0) { ptr = strtok (NULL, "\n\r"); sscanf (ptr, "%d", &lang.version); } else if (strcmp (ptr, "Language") == 0) { ptr = strtok (NULL, "\n\r"); strcpy (lang.langname, ptr); } else if (strcmp (ptr, "Author") == 0) { ptr = strtok (NULL, "\n\r"); strcpy (lang.author, ptr); } else if (strcmp (ptr, "Font") == 0) { ptr = strtok (NULL, "\n\r"); strcpy (lang.fontname, ptr); } } /* Parse the Strings section */ if (strcmp (section, "Strings") == 0) { /* Get all text up to the first line ending */ ptr = strtok (curline, "\n\r"); /* Find a matching default string */ str = 0; for (i = 0; default_text[i]; i++) { for (j = 0; default_text[i][j]; j++) { if (strcmp (curline, default_text[i][j]) == 0) { char transline[255]; /* Found a match, read next line as the translation */ mame_fgets (transline, 255, langfile); /* Get all text up to the first line ending */ ptr = strtok (transline, "\n\r"); /* Allocate storage and copy the string */ trans_text[str] = auto_strdup(transline); if (!trans_text[str]) return 1; } str++; } } } } /* indicate success */ return 0; }
int uistring_init (mame_file *langfile) { /* TODO: This routine needs to do several things: - load an external font if needed - determine the number of characters in the font - deal with multibyte languages */ int i; char curline[255]; char section[255] = "\0"; char *ptr; /* Clear out any default strings */ for (i = 0; i <= UI_last_entry; i ++) { trans_text[i] = NULL; } memset(&lang, 0, sizeof(lang)); if (!langfile) return 0; while (mame_fgets (curline, 255, langfile) != NULL) { /* Ignore commented and blank lines */ if (curline[0] == ';') continue; if (curline[0] == '\n') continue; if (curline[0] == '\r') continue; if (curline[0] == '[') { ptr = strtok (&curline[1], "]"); /* Found a section, indicate as such */ strcpy (section, ptr); /* Skip to the next line */ continue; } /* Parse the LangInfo section */ if (strcmp (section, "LangInfo") == 0) { ptr = strtok (curline, "="); if (strcmp (ptr, "Version") == 0) { ptr = strtok (NULL, "\n\r"); sscanf (ptr, "%d", &lang.version); } else if (strcmp (ptr, "Language") == 0) { ptr = strtok (NULL, "\n\r"); strcpy (lang.langname, ptr); } else if (strcmp (ptr, "Author") == 0) { ptr = strtok (NULL, "\n\r"); strcpy (lang.author, ptr); } else if (strcmp (ptr, "Font") == 0) { ptr = strtok (NULL, "\n\r"); strcpy (lang.fontname, ptr); } } /* Parse the Strings section */ if (strcmp (section, "Strings") == 0) { /* Get all text up to the first line ending */ ptr = strtok (curline, "\n\r"); /* Find a matching default string */ for (i = 0; i < UI_last_entry; i ++) { if (strcmp (curline, default_text[i]) == 0) { char transline[255]; /* Found a match, read next line as the translation */ mame_fgets (transline, 255, langfile); /* Get all text up to the first line ending */ ptr = strtok (transline, "\n\r"); /* Allocate storage and copy the string */ trans_text[i] = malloc (strlen(transline)+1); strcpy (trans_text[i], transline); /* Done searching */ break; } } } } /* indicate success */ return 0; }
/* call hs_open once after loading a game */ void hs_open (const char *name) { mame_file *f = mame_fopen (NULL, db_filename, FILETYPE_HIGHSCORE_DB, 0); state.mem_range = NULL; LOG(("hs_open: '%s'\n", name)); if (f) { char buffer[MAX_CONFIG_LINE_SIZE]; enum { FIND_NAME, FIND_DATA, FETCH_DATA } mode; mode = FIND_NAME; while (mame_fgets (buffer, MAX_CONFIG_LINE_SIZE, f)) { if (mode==FIND_NAME) { if (matching_game_name (buffer, name)) { mode = FIND_DATA; LOG(("hs config found!\n")); } } else if (is_mem_range (buffer)) { const char *pBuf = buffer; struct mem_range *mem_range = osd_malloc(sizeof(struct mem_range)); if (mem_range) { mem_range->cpu = hexstr2num (&pBuf); mem_range->addr = hexstr2num (&pBuf); mem_range->num_bytes = hexstr2num (&pBuf); mem_range->start_value = hexstr2num (&pBuf); mem_range->end_value = hexstr2num (&pBuf); mem_range->next = NULL; { struct mem_range *last = state.mem_range; while (last && last->next) last = last->next; if (last == NULL) { state.mem_range = mem_range; } else { last->next = mem_range; } } mode = FETCH_DATA; } else { hs_free(); break; } } else { /* line is a game name */ if (mode == FETCH_DATA) break; } } mame_fclose (f); } }