2014-06-13 02:34:57 +02:00
|
|
|
#include "bind_config.h"
|
|
|
|
|
|
|
|
#include <platform.h>
|
|
|
|
#include <kernel/types.h>
|
|
|
|
#include <kernel/jsonconf.h>
|
2014-06-13 17:04:06 +02:00
|
|
|
#include <util/log.h>
|
2014-06-17 17:46:22 +02:00
|
|
|
#include <util/language.h>
|
2014-06-13 02:34:57 +02:00
|
|
|
#include <cJSON.h>
|
2014-06-13 22:02:03 +02:00
|
|
|
#include <string.h>
|
2014-06-13 02:34:57 +02:00
|
|
|
|
2014-06-17 17:46:22 +02:00
|
|
|
#include "kernel/building.h"
|
|
|
|
#include "kernel/race.h"
|
|
|
|
#include "kernel/ship.h"
|
|
|
|
#include "kernel/spell.h"
|
|
|
|
#include "kernel/spellbook.h"
|
|
|
|
#include "kernel/terrain.h"
|
|
|
|
|
|
|
|
void config_reset(void) {
|
|
|
|
default_locale = 0;
|
|
|
|
free_locales();
|
|
|
|
free_spells();
|
|
|
|
free_buildingtypes();
|
|
|
|
free_shiptypes();
|
|
|
|
free_races();
|
|
|
|
free_spellbooks();
|
|
|
|
}
|
|
|
|
|
2014-06-13 22:02:03 +02:00
|
|
|
int config_parse(const char *json)
|
2014-06-13 02:34:57 +02:00
|
|
|
{
|
|
|
|
cJSON * conf = cJSON_Parse(json);
|
|
|
|
if (conf) {
|
|
|
|
json_config(conf);
|
|
|
|
cJSON_Delete(conf);
|
2014-06-13 22:02:03 +02:00
|
|
|
return 0;
|
2014-06-13 17:04:06 +02:00
|
|
|
} else {
|
2014-06-13 22:02:03 +02:00
|
|
|
int line;
|
|
|
|
char buffer[10];
|
|
|
|
const char *xp = json, *lp, *ep = cJSON_GetErrorPtr();
|
2014-07-03 06:17:31 +02:00
|
|
|
for (line=1,lp=xp;xp && xp<ep;++line,lp=xp+1) {
|
2014-06-18 06:33:42 +02:00
|
|
|
xp = strchr(lp, '\n');
|
2014-07-03 06:17:31 +02:00
|
|
|
if (xp>=ep) break;
|
2014-06-13 22:02:03 +02:00
|
|
|
}
|
|
|
|
xp = (ep > json + 10) ? ep - 10 : json;
|
|
|
|
strncpy(buffer, xp, sizeof(buffer));
|
|
|
|
buffer[9] = 0;
|
|
|
|
log_error("json parse error in line %d, position %d, near `%s`\n", line, ep-lp, buffer);
|
2014-06-13 02:34:57 +02:00
|
|
|
}
|
2014-06-17 17:46:22 +02:00
|
|
|
return 1;
|
2014-06-13 02:34:57 +02:00
|
|
|
}
|
|
|
|
|
2014-06-13 22:02:03 +02:00
|
|
|
int config_read(const char *filename)
|
2014-06-13 02:34:57 +02:00
|
|
|
{
|
2014-06-13 22:02:03 +02:00
|
|
|
return 1;
|
2014-06-13 02:34:57 +02:00
|
|
|
}
|
2014-06-13 22:02:03 +02:00
|
|
|
|