forked from github/server
read json config file if available.
missed an include, broke the build.
This commit is contained in:
parent
0aec5592a0
commit
f9c5d58f41
|
@ -6,3 +6,4 @@ if config.install then
|
||||||
confdir = config.install .. '/' .. confdir
|
confdir = config.install .. '/' .. confdir
|
||||||
end
|
end
|
||||||
read_xml(confdir .. 'config.xml', confdir .. 'catalog.xml')
|
read_xml(confdir .. 'config.xml', confdir .. 'catalog.xml')
|
||||||
|
eressea.config.read(confdir .. 'config.json')
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
#include <util/language.h>
|
#include <util/language.h>
|
||||||
#include <cJSON.h>
|
#include <cJSON.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "kernel/building.h"
|
#include "kernel/building.h"
|
||||||
#include "kernel/race.h"
|
#include "kernel/race.h"
|
||||||
|
@ -50,6 +52,22 @@ int config_parse(const char *json)
|
||||||
|
|
||||||
int config_read(const char *filename)
|
int config_read(const char *filename)
|
||||||
{
|
{
|
||||||
|
FILE *F = fopen(filename, "rt");
|
||||||
|
if (F) {
|
||||||
|
int result;
|
||||||
|
char *data;
|
||||||
|
size_t sz;
|
||||||
|
|
||||||
|
fseek(F, 0, SEEK_END);
|
||||||
|
sz = ftell(F);
|
||||||
|
rewind(F);
|
||||||
|
data = malloc(sz);
|
||||||
|
fread(data, 1, sz, F);
|
||||||
|
fclose(F);
|
||||||
|
result = config_parse(data);
|
||||||
|
free(data);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -643,10 +643,10 @@ static void json_configs(cJSON *json) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (child = json->child; child; child = child->next) {
|
for (child = json->child; child; child = child->next) {
|
||||||
cJSON *config;
|
|
||||||
char *data;
|
|
||||||
FILE *F = fopen(child->valuestring, "rt");
|
FILE *F = fopen(child->valuestring, "rt");
|
||||||
if (F) {
|
if (F) {
|
||||||
|
cJSON *config;
|
||||||
|
char *data;
|
||||||
size_t sz;
|
size_t sz;
|
||||||
fseek(F, 0, SEEK_END);
|
fseek(F, 0, SEEK_END);
|
||||||
sz = ftell(F);
|
sz = ftell(F);
|
||||||
|
@ -657,6 +657,7 @@ static void json_configs(cJSON *json) {
|
||||||
config = cJSON_Parse(data);
|
config = cJSON_Parse(data);
|
||||||
free(data);
|
free(data);
|
||||||
json_config(config);
|
json_config(config);
|
||||||
|
cJSON_Delete(config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include <CuTest.h>
|
#include <CuTest.h>
|
||||||
#include <cJSON.h>
|
#include <cJSON.h>
|
||||||
#include <tests.h>
|
#include <tests.h>
|
||||||
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
static const struct race * race_with_flag(const char * name) {
|
static const struct race * race_with_flag(const char * name) {
|
||||||
|
@ -393,6 +394,7 @@ static void test_keywords(CuTest * tc)
|
||||||
CuAssertIntEquals(tc, K_MOVE, get_keyword("nach", lang));
|
CuAssertIntEquals(tc, K_MOVE, get_keyword("nach", lang));
|
||||||
|
|
||||||
CuAssertStrEquals(tc, "LERNEN", locale_string(lang, "keyword::study"));
|
CuAssertStrEquals(tc, "LERNEN", locale_string(lang, "keyword::study"));
|
||||||
|
CuAssertStrEquals(tc, "NACH", locale_string(lang, "keyword::move"));
|
||||||
|
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue