int uistring_init (void *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 (osd_fgets (curline, 255, langfile) != NULL) { /* Ignore commented and blank lines */ if (curline[0] == ';') continue; if (curline[0] == '\n') 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"); sscanf (ptr, "%d", &lang.version); } else if (strcmp (ptr, "Language") == 0) { ptr = strtok (NULL, "\n"); strcpy (lang.langname, ptr); } else if (strcmp (ptr, "Author") == 0) { ptr = strtok (NULL, "\n"); strcpy (lang.author, ptr); } else if (strcmp (ptr, "Font") == 0) { ptr = strtok (NULL, "\n"); 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"); /* 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 */ osd_fgets (transline, 255, langfile); /* Get all text up to the first line ending */ ptr = strtok (transline, "\n"); /* Allocate storage and copy the string */ trans_text[i] = (char*) 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) { void *f = osd_fopen (NULL, db_filename, OSD_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 (osd_fgets (buffer, MAX_CONFIG_LINE_SIZE, f)) { if (mode==FIND_NAME) { if (strlen(buffer) == 0) break; 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 = (struct mem_range*)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; } } osd_fclose (f); } }