X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fconfig.c;h=78664aafcbd529d4d6c3f2eec6fbdcb66c2e72be;hb=HEAD;hp=1980bc61ec2986f13e9d82bfe4100a47abecfa9e;hpb=4a99fe51561ca331df54512eb25c502d0fcd2b55;p=flatwaifu.git diff --git a/src/config.c b/src/config.c index 1980bc6..78664aa 100644 --- a/src/config.c +++ b/src/config.c @@ -1,24 +1,17 @@ -/* - Copyright (C) Prikol Software 1996-1997 - Copyright (C) Aleksey Volynskov 1996-1997 - Copyright (C) 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 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 . + */ #include "glob.h" #include @@ -30,6 +23,8 @@ #include "files.h" #include "input.h" +#include "common/cp866.h" + static FILE *f; static int ch; @@ -37,7 +32,7 @@ const cfg_t *CFG_find_entry (const char *key, const cfg_t *cfg) { assert(key != NULL); if (cfg != NULL) { int i = 0; - while (cfg[i].cfg && strcasecmp(cfg[i].cfg, key) != 0) { + while (cfg[i].cfg && cp866_strcasecmp(cfg[i].cfg, key) != 0) { i++; } return cfg[i].cfg ? &cfg[i] : NULL; @@ -47,9 +42,10 @@ const cfg_t *CFG_find_entry (const char *key, const cfg_t *cfg) { } int CFG_update_key (const char *key, const char *value, const cfg_t *cfg) { + const cfg_t *entry; assert(key != NULL); assert(value != NULL); - const cfg_t *entry = CFG_find_entry(key, cfg); + entry = CFG_find_entry(key, cfg); if (entry != NULL) { void *p = entry->p; switch (entry->t) { @@ -57,8 +53,8 @@ int CFG_update_key (const char *key, const char *value, const cfg_t *cfg) { 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 ? 1 : 0; 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 @@ -97,12 +93,12 @@ static void CFG_skip_line (void) { } int CFG_scan_iterator (char *key, int keylen, char *value, int valuelen) { + int i; + int found = 0; assert(key != NULL); assert(keylen > 0); assert(value != NULL); assert(valuelen > 0); - int i; - int found = 0; while (feof(f) == 0 && found == 0) { CFG_skip_space(); if (ch == ';') { @@ -147,13 +143,13 @@ void CFG_close_iterator (void) { /* --- reader --- */ 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); + assert(n >= 0); + assert(cfg != NULL); + assert(name != NULL); if (CFG_open_iterator(name)) { while (CFG_scan_iterator(key, 64, value, 64)) { i = 0; @@ -183,11 +179,12 @@ 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); char buf[16]; const char *str; - const char *key = entry->cfg; + const char *key; + assert(f != NULL); + assert(entry != NULL); + key = entry->cfg; if (key != NULL) { switch (entry->t) { case Y_BYTE: @@ -223,14 +220,15 @@ static int CFG_write_entry (FILE *f, const cfg_t *entry) { } int CFG_update_config (const char *old, const char *new, int n, const cfg_t **cfg, const char *msg) { + int i, j; + char key[64]; + char value[64]; + FILE *nf; assert(old != NULL); assert(new != NULL); assert(n >= 0); assert(cfg != NULL); - int i, j; - char key[64]; - char value[64]; - FILE *nf = fopen(new, "wb"); + nf = fopen(new, "wb"); if (nf != NULL) { if (msg != NULL) { fwrite("; ", 2, 1, nf);