bool Config::Init(const char* filename_) { FILE* fp; char buffer[1024]; char token[1024]; char name[1024]; char* p; int nline; ConfigVar* var; filename = filename_; fp = fopen(filename, "r"); if (!fp) return false; nline = 0; while (fgets(buffer, sizeof(buffer) - 1, fp)) { buffer[sizeof(buffer) - 1] = '\0'; nline++; p = ParseToken(buffer, token, sizeof(token)); if (!p) { // empty or commented line continue; } strncpy(name, token, strlen(token)); name[strlen(token)] = '\0'; p = ParseToken(p, token, sizeof(token)); if (!p || token[0] != '=') { // syntax error Log_Message("syntax error at %s, line %d", filename, nline); fclose(fp); return false; } var = new ConfigVar(name); vars.Enqueue(var); while (true) { p = ParseToken(p, token, sizeof(token)); if (!p) break; if (token[0] == ',') continue; var->Append(token); } } fclose(fp); return true; }
void Config::AppendListValue(const char* name, const char* value) { ConfigVar* var; var = GetVar(name); if (!var) { var = new ConfigVar(name); vars.Enqueue(var); } var->Append(value); }
void Config::SetValue(const char* name, const char *value) { ConfigVar* var; var = GetVar(name); if (!var) { var = new ConfigVar(name); vars.Enqueue(var); } else var->ClearValue(); var->Append(value); }