///////////////////////////////////////// readconfig void readConfig() { FILE *file; // Init all user vars with the default value int count = 0; for (; count < VARS_TOTAL; count++) seth.value[count] = seth.vars[count].defaultValue; if ((file = fopen(getConfigFilename(), "rb")) == NULL) return; // Get config file line by line char line[32]; while (fgets(line, sizeof(line) - 1, file) != 0) { char *sep = strrchr(line, '='); *sep = '\0'; // Separate name from value // Search this var int count = 0; if( !strcmp(line,"ksFormat") ){ strncpy(ksFormat, sep+1, sizeof(ksFormat)); } else if( !strcmp(line,"dieFormat") ) { strncpy(dieFormat, sep+1, sizeof(ksFormat)); } else if( !strcmp(line,"bnFormat") ) { strncpy(bnFormat, sep+1, sizeof(ksFormat)); } else if( !strcmp(line,"skFormat") ) { strncpy(skFormat, sep+1, sizeof(ksFormat)); } else { for (; count < VARS_TOTAL; count++) { if (!seth.vars[count].cvarName) { ethLog("readConfig: error: VAR_%i undefine", count); } else if (!strcmp(line, seth.vars[count].cvarName)) { seth.value[count] = atof(sep + 1); break; } else if ((count + 1) == VARS_TOTAL) { ethLog("readConfig: don't know this var: [%s]", line); } if (count == VAR_CHUD) if (atoi(sep + 1)) syscall_CG_SendConsoleCommand(va("cg_draw2d %s\n", seth.value[count] ? "0" : "1")); } } } fclose(file); } ///////////////////////////////////////////////// writeconfig void writeConfig() { FILE *file; if ((file = fopen(getConfigFilename(), "w")) == NULL) { ethLog("eth: can't write config file."); return; } int count = 0; for (; count < VARS_TOTAL; count++) { if (!seth.vars[count].cvarName) ethLog("writeConfig: error: VAR_%i undefine", count); else if (seth.value[count] == (float)(int)seth.value[count]) fprintf(file, "%s=%i\n", seth.vars[count].cvarName, (int)seth.value[count]); else fprintf(file, "%s=%.2f\n", seth.vars[count].cvarName, seth.value[count]); } fprintf(file, "ksFormat=%s\n",ksFormat); fprintf(file, "dieFormat=%s\n",dieFormat); fprintf(file, "bnFormat=%s\n",bnFormat); fprintf(file, "skFormat=%s\n",skFormat); fclose(file); }