VStr Info_ValueForKey(const VStr& s, const VStr& key) { guard(Info_ValueForKey); if (s.IsEmpty() || key.IsEmpty()) { return VStr(); } if (s.Length() >= MAX_INFO_STRING) { Host_Error("Info_ValueForKey: oversize infostring"); } int i = 0; if (s[i] == '\\') i++; while (1) { int Start = i; while (s[i] != '\\') { if (!s[i]) return VStr(); i++; } VStr pkey(s, Start, i - Start); i++; Start = i; while (s[i] != '\\' && s[i]) { i++; } if (!key.ICmp(pkey)) return VStr(s, Start, i - Start); if (!s[i]) return VStr(); i++; } unguard; }
void Info_RemoveKey(VStr& s, const VStr& key) { guard(Info_RemoveKey); if (s.IsEmpty()) { return; } if (s.Length() >= MAX_INFO_STRING) { Host_Error("Info_RemoveKey: oversize infostring"); } if (strchr(*key, '\\')) { GCon->Log("Can't use a key with a \\"); return; } int i = 0; while (1) { int start = i; if (s[i] == '\\') i++; int KeyStart = i; while (s[i] != '\\') { if (!s[i]) return; i++; } VStr pkey(s, KeyStart, i - KeyStart); i++; int ValStart = i; while (s[i] != '\\' && s[i]) { i++; } VStr value(s, ValStart, i - ValStart); if (!key.Cmp(pkey)) { s = VStr(s, 0, start) + VStr(s, i, s.Length() - i); // remove this part return; } if (!s[i]) return; } unguard; }
void Info_SetValueForKey(VStr& s, const VStr& key, const VStr& value) { guard(Info_SetValueForKey); if (s.Length() >= MAX_INFO_STRING) { Host_Error("Info_SetValueForKey: oversize infostring"); } if (strchr(*key, '\\') || strchr(*value, '\\')) { GCon->Log("Can't use keys or values with a \\"); return; } if (strchr(*key, '\"') || strchr(*value, '\"')) { GCon->Log("Can't use keys or values with a \""); return; } // this next line is kinda trippy VStr v = Info_ValueForKey(s, key); if (v.IsNotEmpty()) { // Key exists, make sure we have enough room for new value, if we // don't, don't change it! if (value.Length() - v.Length() + s.Length() > MAX_INFO_STRING) { GCon->Log("Info string length exceeded"); return; } } Info_RemoveKey(s, key); if (value.IsEmpty()) return; VStr newi = VStr("\\") + key + "\\" + value; if (newi.Length() + s.Length() > MAX_INFO_STRING) { GCon->Log("Info string length exceeded"); return; } s = s + newi; unguard; }
static void ParseBase(const VStr& name) { guard(ParseBase); TArray<version_t> games; bool select_game; VStr UseName; if (fl_savedir.IsNotEmpty() && Sys_FileExists(fl_savedir + "/" + name)) { UseName = fl_savedir + "/" + name; } else if (Sys_FileExists(fl_basedir + "/" + name)) { UseName = fl_basedir + "/" + name; } else { return; } select_game = false; VScriptParser* sc = new VScriptParser(UseName, FL_OpenSysFileRead(UseName)); while (!sc->AtEnd()) { version_t &dst = games.Alloc(); dst.ParmFound = 0; dst.FixVoices = false; sc->Expect("game"); sc->ExpectString(); dst.GameDir = sc->String; if (sc->Check("iwad")) { sc->ExpectString(); dst.MainWad = sc->String; } while (sc->Check("addfile")) { sc->ExpectString(); dst.AddFiles.Append(sc->String); } if (sc->Check("param")) { sc->ExpectString(); dst.ParmFound = GArgs.CheckParm(*sc->String); if (dst.ParmFound) { select_game = true; } } if (sc->Check("fixvoices")) { dst.FixVoices = true; } sc->Expect("end"); } delete sc; sc = NULL; for (int gi = games.Num() - 1; gi >= 0; gi--) { version_t& G = games[gi]; if (select_game && !G.ParmFound) { continue; } if (fl_mainwad.IsNotEmpty()) { if (G.MainWad.IsEmpty() || G.MainWad == fl_mainwad || select_game) { if (!bIwadAdded) { IWadIndex = SearchPaths.Num(); VStr MainWadPath = FindMainWad(fl_mainwad); W_AddFile(MainWadPath, fl_savedir, G.FixVoices); bIwadAdded = true; } for (int j = 0; j < G.AddFiles.Num(); j++) { W_AddFile(fl_basedir + "/" + G.AddFiles[j], fl_savedir, false); } SetupGameDir(G.GameDir); return; } continue; } if (G.MainWad.IsEmpty()) { continue; } // Look for the main wad file. VStr MainWadPath = FindMainWad(G.MainWad); if (MainWadPath.IsNotEmpty()) { fl_mainwad = G.MainWad; if (!bIwadAdded) { IWadIndex = SearchPaths.Num(); W_AddFile(MainWadPath, fl_savedir, G.FixVoices); bIwadAdded = true; } for (int j = 0; j < G.AddFiles.Num(); j++) { VStr FName = FindMainWad(G.AddFiles[j]); if (FName.IsEmpty()) { Sys_Error("Required file %s not found", *G.AddFiles[j]); } W_AddFile(FName, fl_savedir, false); } SetupGameDir(G.GameDir); return; } } if (select_game) Sys_Error("Main wad file not found."); else Sys_Error("Game mode indeterminate."); unguard; }