diff --git a/src/config.c b/src/config.c
index 885a0e4b8aeee0b998c6d0e270c114b38939235a..86b6d227c96893cbc7cde91cdc83ca5c31a7f406 100644 (file)
--- a/src/config.c
+++ b/src/config.c
-/*
- Copyright (C) Prikol Software 1996-1997
- Copyright (C) Aleksey Volynskov 1996-1997
- Copyright (C) <ARembo@gmail.com> 2011
-
- This file is part of the Doom2D:Rembo project.
-
- Doom2D:Rembo is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License version 2 as
- published by the Free Software Foundation.
-
- Doom2D:Rembo is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/> or
- write to the Free Software Foundation, Inc.,
- 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+/* Copyright (C) 2020 SovietPony
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License ONLY.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
#include "glob.h"
#include <stdio.h>
#include "glob.h"
#include <stdio.h>
#include "files.h"
#include "input.h"
#include "files.h"
#include "input.h"
+#include "common/cp866.h"
+
static FILE *f;
static int ch;
const cfg_t *CFG_find_entry (const char *key, const cfg_t *cfg) {
assert(key != NULL);
static FILE *f;
static int ch;
const cfg_t *CFG_find_entry (const char *key, const cfg_t *cfg) {
assert(key != NULL);
- assert(cfg != NULL);
- int i = 0;
- while (cfg[i].cfg && strcasecmp(cfg[i].cfg, key) != 0) {
- i++;
+ if (cfg != NULL) {
+ int i = 0;
+ while (cfg[i].cfg && cp866_strcasecmp(cfg[i].cfg, key) != 0) {
+ i++;
+ }
+ return cfg[i].cfg ? &cfg[i] : NULL;
+ } else {
+ return NULL;
}
}
- return cfg[i].cfg ? &cfg[i] : NULL;
}
int CFG_update_key (const char *key, const char *value, const cfg_t *cfg) {
}
int CFG_update_key (const char *key, const char *value, const cfg_t *cfg) {
+ assert(key != NULL);
+ assert(value != NULL);
const cfg_t *entry = CFG_find_entry(key, cfg);
if (entry != NULL) {
void *p = entry->p;
const cfg_t *entry = CFG_find_entry(key, cfg);
if (entry != NULL) {
void *p = entry->p;
case Y_WORD: *(word*)p = atoi(value); break;
case Y_DWORD: *(dword*)p = atoi(value); break;
case Y_STRING: strcpy(p, value); break; // TODO fix this security problem
case Y_WORD: *(word*)p = atoi(value); break;
case Y_DWORD: *(dword*)p = atoi(value); break;
case Y_STRING: strcpy(p, value); break; // TODO fix this security problem
- case Y_SW_ON: *(byte*)p = strcasecmp(value, "on") == 0 ? 1 : 0; break;
- case Y_SW_OFF: *(byte*)p = strcasecmp(value, "off") == 0 ? 0 : 1; break;
+ case Y_SW_ON: *(byte*)p = cp866_strcasecmp(value, "on") == 0 ? 1 : 0; break;
+ case Y_SW_OFF: *(byte*)p = cp866_strcasecmp(value, "off") == 0 ? 1 : 0; break;
case Y_FILES: F_addwad(value); break;
case Y_KEY: *(int*)p = I_string_to_key(value); break;
default: assert(0); // unknown type -> something broken
}
case Y_FILES: F_addwad(value); break;
case Y_KEY: *(int*)p = I_string_to_key(value); break;
default: assert(0); // unknown type -> something broken
}
+ //logo("CFG_update_key: [%s] = [%s]\n", key, value);
return 1;
} else {
return 0;
return 1;
} else {
return 0;
/* --- reader --- */
/* --- reader --- */
-int CFG_read_config (const char *name, const cfg_t *cfg) {
+int CFG_read_config (const char *name, int n, const cfg_t **cfg) {
+ assert(name != NULL);
+ assert(n >= 0);
+ assert(cfg != NULL);
+ int i;
char key[64];
char value[64];
assert(name != NULL);
if (CFG_open_iterator(name)) {
while (CFG_scan_iterator(key, 64, value, 64)) {
char key[64];
char value[64];
assert(name != NULL);
if (CFG_open_iterator(name)) {
while (CFG_scan_iterator(key, 64, value, 64)) {
- CFG_update_key(key, value, cfg);
+ i = 0;
+ while (i < n && CFG_update_key(key, value, cfg[i]) == 0) {
+ i++;
+ }
}
CFG_close_iterator();
return 1;
}
CFG_close_iterator();
return 1;
@@ -172,21 +180,21 @@ static void CFG_write_key_value (FILE *f, const char *key, const char *value) {
static int CFG_write_entry (FILE *f, const cfg_t *entry) {
assert(f != NULL);
assert(entry != NULL);
static int CFG_write_entry (FILE *f, const cfg_t *entry) {
assert(f != NULL);
assert(entry != NULL);
- char buf[64];
+ char buf[16];
const char *str;
const char *key = entry->cfg;
if (key != NULL) {
switch (entry->t) {
case Y_BYTE:
const char *str;
const char *key = entry->cfg;
if (key != NULL) {
switch (entry->t) {
case Y_BYTE:
- snprintf(buf, 64, "%i", *(byte*)entry->p);
+ snprintf(buf, 16, "%i", *(byte*)entry->p);
CFG_write_key_value(f, key, buf);
break;
case Y_WORD:
CFG_write_key_value(f, key, buf);
break;
case Y_WORD:
- snprintf(buf, 64, "%i", *(word*)entry->p);
+ snprintf(buf, 16, "%i", *(word*)entry->p);
CFG_write_key_value(f, key, buf);
break;
case Y_DWORD:
CFG_write_key_value(f, key, buf);
break;
case Y_DWORD:
- snprintf(buf, 64, "%i", *(dword*)entry->p);
+ snprintf(buf, 16, "%i", *(dword*)entry->p);
CFG_write_key_value(f, key, buf);
break;
case Y_STRING:
CFG_write_key_value(f, key, buf);
break;
case Y_STRING:
return entry->t == 0 ? 0 : 1;
}
return entry->t == 0 ? 0 : 1;
}
-int CFG_update_config (const char *old, const char *new, const cfg_t *cfg, const char *msg) {
+int CFG_update_config (const char *old, const char *new, int n, const cfg_t **cfg, const char *msg) {
assert(old != NULL);
assert(new != NULL);
assert(old != NULL);
assert(new != NULL);
+ assert(n >= 0);
assert(cfg != NULL);
assert(cfg != NULL);
+ int i, j;
char key[64];
char value[64];
FILE *nf = fopen(new, "wb");
char key[64];
char value[64];
FILE *nf = fopen(new, "wb");
@@ -224,15 +234,23 @@ int CFG_update_config (const char *old, const char *new, const cfg_t *cfg, const
}
if (CFG_open_iterator(old)) {
while (CFG_scan_iterator(key, 64, value, 64)) {
}
if (CFG_open_iterator(old)) {
while (CFG_scan_iterator(key, 64, value, 64)) {
- if (CFG_find_entry(key, cfg) == NULL) {
+ i = 0;
+ while (i < n && CFG_find_entry(key, cfg[i]) == NULL) {
+ i++;
+ }
+ if (i >= n) {
CFG_write_key_value(nf, key, value);
}
}
CFG_close_iterator();
}
CFG_write_key_value(nf, key, value);
}
}
CFG_close_iterator();
}
- int i = 0;
- while (CFG_write_entry(nf, &cfg[i])) {
- i++;
+ for (j = 0; j < n; j++) {
+ if (cfg[j] != NULL) {
+ i = 0;
+ while (CFG_write_entry(nf, &cfg[j][i])) {
+ i++;
+ }
+ }
}
fclose(nf);
}
}
fclose(nf);
}