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(n >= 0);
assert(cfg != NULL);
+ int i, j;
char key[64];
char value[64];
FILE *nf = fopen(new, "wb");
}
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();
}
- int i = 0;
- while (CFG_write_entry(nf, &cfg[i])) {
- i++;
+ for (j = 0; j < n; j++) {
+ i = 0;
+ while (CFG_write_entry(nf, &cfg[j][i])) {
+ i++;
+ }
}
fclose(nf);
}
void CFG_close_iterator (void);
int CFG_read_config (const char *name, const cfg_t *cfg);
-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);
#endif /* CONFIG_H_INCLUDED */
}
static void CFG_save (void) {
- CFG_update_config("doom2d.cfg", "doom2d.cfg", cfg, "generated by doom2d, do not modify");
+ const cfg_t *list[] = { &cfg, NULL };
+ CFG_update_config("doom2d.cfg", "doom2d.cfg", 1, list, "generated by doom2d, do not modify");
//CFG_update_config("doom2d.cfg", "doom2d.tmp", cfg, "temporary file");
//CFG_update_config("doom2d.tmp", "doom2d.cfg", cfg, "generated by doom2d, do not modify");
//remove("doom2d.tmp");
}
static void CFG_save (void) {
- CFG_update_config("doom2d.cfg", "doom2d.cfg", cfg, "generated by doom2d, do not modify");
+ const cfg_t *list[] = { &cfg, NULL };
+ CFG_update_config("doom2d.cfg", "doom2d.cfg", 1, list, "generated by doom2d, do not modify");
//CFG_update_config("doom2d.cfg", "doom2d.tmp", cfg, "temporary file");
//CFG_update_config("doom2d.tmp", "doom2d.cfg", cfg, "generated by doom2d, do not modify");
//remove("doom2d.tmp");