/* get_config_string: * Reads a string from the configuration file. */ char *get_config_string(char *section, char *name, char *def) { CONFIG_ENTRY *p; init_config(TRUE); p = find_config_string(config_override, section, name, NULL); if (!p) p = find_config_string(config[0], section, name, NULL); if (p) return (p->data ? p->data : ""); else return def; }
/* get_config_string: * Reads a string from the configuration file. */ char *get_config_string(char *section, char *name, char *def) { char section_name[256]; CONFIG_HOOK *hook; CONFIG_ENTRY *p; init_config(TRUE); prettify_section_name(section, section_name); /* check for hooked sections */ hook = config_hook; while (hook) { if (stricmp(section_name, hook->section) == 0) { if (hook->stringgetter) return hook->stringgetter(name, def); else return def; } hook = hook->next; } /* find the string */ p = find_config_string(config_override, section_name, name, NULL); if (!p) { if ((name[0] == '#') || ((section_name[0] == '[') && (section_name[1] == '#'))) p = find_config_string(system_config, section_name, name, NULL); else p = find_config_string(config[0], section_name, name, NULL); } if (p) return (p->data ? p->data : ""); else return def; }
/* set_config_string: * Writes a string to the configuration file. */ void set_config_string(char *section, char *name, char *val) { CONFIG *the_config; CONFIG_HOOK *hook; CONFIG_ENTRY *p, *prev; char section_name[256]; init_config(TRUE); prettify_section_name(section, section_name); /* check for hooked sections */ hook = config_hook; while (hook) { if (stricmp(section_name, hook->section) == 0) { if (hook->stringsetter) hook->stringsetter(name, val); return; } hook = hook->next; } /* decide which config file to use */ if ((name[0] == '#') || ((section_name[0] == '[') && (section_name[1] == '#'))) the_config = system_config; else the_config = config[0]; if (the_config) { p = find_config_string(the_config, section_name, name, &prev); if (p) { if ((val) && (*val)) { /* modify existing variable */ if (p->data) free(p->data); p->data = malloc(strlen(val)+1); if (p->data) strcpy(p->data, val); } else { /* delete variable */ if (p->name) free(p->name); if (p->data) free(p->data); if (prev) prev->next = p->next; else the_config->head = p->next; free(p); } } else { if ((val) && (*val)) { /* add a new variable */ if (section_name[0]) { p = find_config_string(the_config, NULL, section_name, &prev); if (!p) { /* create a new section */ p = the_config->head; while ((p) && (p->next)) p = p->next; if ((p) && (p->data) && (*p->data)) p = insert_variable(the_config, p, NULL, NULL); p = insert_variable(the_config, p, section_name, NULL); } /* append to the end of the section */ while ((p) && (p->next) && (((p->next->name) && (*p->next->name)) || ((p->next->data) && (*p->next->data)))) p = p->next; p = insert_variable(the_config, p, name, val); } else { /* global variable */ p = the_config->head; insert_variable(the_config, NULL, name, val); the_config->head->next = p; } } } the_config->dirty = TRUE; } }
/* set_config_string: * Writes a string to the configuration file. */ void set_config_string(char *section, char *name, char *val) { CONFIG_ENTRY *p, *prev; char section_name[256]; init_config(TRUE); if (config[0]) { p = find_config_string(config[0], section, name, &prev); if (p) { if ((val) && (*val)) { /* modify existing variable */ if (p->data) free(p->data); p->data = (char *) malloc(strlen(val)+1); strcpy(p->data, val); } else { /* delete variable */ if (p->name) free(p->name); if (p->data) free(p->data); if (prev) prev->next = p->next; else config[0]->head = p->next; free(p); } } else { if ((val) && (*val)) { /* add a new variable */ prettify_section_name(section, section_name); if (section_name[0]) { p = find_config_string(config[0], NULL, section_name, &prev); if (!p) { /* create a new section */ p = config[0]->head; while ((p) && (p->next)) p = p->next; if ((p) && (p->data) && (*p->data)) p = insert_variable(p, NULL, NULL); p = insert_variable(p, section_name, NULL); } /* append to the end of the section */ while ((p) && (p->next) && (((p->next->name) && (*p->next->name)) || ((p->next->data) && (*p->next->data)))) p = p->next; p = insert_variable(p, name, val); } else { /* global variable */ p = config[0]->head; insert_variable(NULL, name, val); config[0]->head->next = p; } } } config[0]->dirty = TRUE; } }