int scriptfile_getstring(scriptfile *sf, char **retst) { (*retst) = scriptfile_gettoken(sf); if (*retst == NULL) { initprintf("Error on line %s:%d: unexpected eof\n",sf->filename,scriptfile_getlinum(sf,sf->textptr)); return(-2); } return(0); }
int32_t getatoken(scriptfile *sf, const tokenlist *tl, int32_t ntokens) { char *tok; int32_t i; if (!sf) return T_ERROR; tok = scriptfile_gettoken(sf); if (!tok) return T_EOF; for (i=ntokens-1; i>=0; i--) { if (!Bstrcasecmp(tok, tl[i].text)) return tl[i].tokenid; } return T_ERROR; }
static int getatoken(scriptfile *sf, tokenlist *tl, int ntokens) { char *tok; int i; if (!sf) return T_ERROR; tok = scriptfile_gettoken(sf); if (!tok) return T_EOF; for(i=0;i<ntokens;i++) { if (!Bstrcasecmp(tok, tl[i].text)) return tl[i].tokenid; } return T_ERROR; }
int scriptfile_getsymbol(scriptfile *sf, int *num) { char *t, *e; int v; t = scriptfile_gettoken(sf); if (!t) return -1; v = Bstrtol(t, &e, 10); if (*e) { // looks like a string, so find it in the symbol table if (scriptfile_getsymbolvalue(t, num)) return 0; initprintf("Error on line %s:%d: expecting symbol, got \"%s\"\n",sf->filename,scriptfile_getlinum(sf,sf->ltextptr),t); return -2; // not found } *num = v; return 0; }
int loadsetup(const char *fn) { scriptfile *cfg; char *token; int item; cfg = scriptfile_fromfile(fn); if (!cfg) { return -1; } scriptfile_clearsymbols(); option[0] = 1; // vesa all the way... option[1] = 1; // sound all the way... option[4] = 0; // no multiplayer option[5] = 0; while (1) { token = scriptfile_gettoken(cfg); if (!token) break; //EOF for (item = 0; configspec[item].name; item++) { if (!Bstrcasecmp(token, configspec[item].name)) { // Seek past any = symbol. token = scriptfile_peektoken(cfg); if (!Bstrcasecmp("=", token)) { scriptfile_gettoken(cfg); } switch (configspec[item].type) { case type_bool: { int value = 0; if (scriptfile_getnumber(cfg, &value)) break; *(int*)configspec[item].store = (value != 0); break; } case type_int: { int value = 0; if (scriptfile_getnumber(cfg, &value)) break; *(int*)configspec[item].store = value; break; } case type_hex: { int value = 0; if (scriptfile_gethex(cfg, &value)) break; *(int*)configspec[item].store = value; break; } case type_double: { double value = 0.0; if (scriptfile_getdouble(cfg, &value)) break; *(double*)configspec[item].store = value; break; } default: { buildputs("loadsetup: unhandled value type\n"); break; } } break; } } if (!configspec[item].name) { buildprintf("loadsetup: error on line %d\n", scriptfile_getlinum(cfg, cfg->ltextptr)); continue; } } #if USE_POLYMOST if (tmprenderer >= 0) { setrendermode(tmprenderer); } #endif if (tmpbrightness >= 0) { brightness = min(max(tmpbrightness,0),15); } OSD_CaptureKey(keys[19]); scriptfile_close(cfg); scriptfile_clearsymbols(); return 0; }