forked from github/server
read game configuration data from .ini file
This commit is contained in:
parent
b51349df6b
commit
e511bf76b5
|
@ -712,6 +712,40 @@ bool config_changed(int *cache_key) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define MAXKEYS 16
|
||||||
|
void config_set_from(const dictionary *d)
|
||||||
|
{
|
||||||
|
int s, nsec = iniparser_getnsec(d);
|
||||||
|
for (s=0;s!=nsec;++s) {
|
||||||
|
char key[128];
|
||||||
|
const char *sec = iniparser_getsecname(d, s);
|
||||||
|
int k, nkeys = iniparser_getsecnkeys(d, sec);
|
||||||
|
const char *akeys[MAXKEYS];
|
||||||
|
const char ** keys = akeys;
|
||||||
|
size_t slen = strlen(sec);
|
||||||
|
assert(slen<sizeof(key));
|
||||||
|
memcpy(key, sec, slen);
|
||||||
|
key[slen] = ':';
|
||||||
|
if (nkeys>MAXKEYS) {
|
||||||
|
keys = malloc(sizeof(const char *) * nkeys);
|
||||||
|
}
|
||||||
|
iniparser_getseckeys(d, sec, keys);
|
||||||
|
for (k=0;k!=nkeys;++k) {
|
||||||
|
const char *val;
|
||||||
|
size_t klen = strlen(keys[k]);
|
||||||
|
assert(klen+slen+1<sizeof(key));
|
||||||
|
memcpy(key+slen+1, keys[k], klen+1);
|
||||||
|
val = iniparser_getstring(d, key, NULL);
|
||||||
|
if (val) {
|
||||||
|
config_set(key, val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (keys!=akeys) {
|
||||||
|
free(keys);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void config_set(const char *key, const char *value) {
|
void config_set(const char *key, const char *value) {
|
||||||
++config_cache_key;
|
++config_cache_key;
|
||||||
set_param(&configuration, key, value);
|
set_param(&configuration, key, value);
|
||||||
|
|
|
@ -123,6 +123,7 @@ struct param;
|
||||||
void free_params(struct param **pp);
|
void free_params(struct param **pp);
|
||||||
|
|
||||||
void config_set(const char *key, const char *value);
|
void config_set(const char *key, const char *value);
|
||||||
|
void config_set_from(const struct _dictionary_ *d);
|
||||||
const char *config_get(const char *key);
|
const char *config_get(const char *key);
|
||||||
int config_get_int(const char *key, int def);
|
int config_get_int(const char *key, int def);
|
||||||
double config_get_flt(const char *key, double def);
|
double config_get_flt(const char *key, double def);
|
||||||
|
|
|
@ -83,6 +83,7 @@ static void parse_config(const char *filename)
|
||||||
if (d) {
|
if (d) {
|
||||||
load_inifile(d);
|
load_inifile(d);
|
||||||
log_debug("reading from configuration file %s\n", filename);
|
log_debug("reading from configuration file %s\n", filename);
|
||||||
|
config_set_from(d);
|
||||||
|
|
||||||
memdebug = iniparser_getint(d, "game:memcheck", memdebug);
|
memdebug = iniparser_getint(d, "game:memcheck", memdebug);
|
||||||
#ifdef USE_CURSES
|
#ifdef USE_CURSES
|
||||||
|
|
Loading…
Reference in New Issue