forked from github/server
implement JSON prefixes. fix free_prefixes not resetting size (TODO: quicklist).
This commit is contained in:
parent
f0e255924f
commit
47c95aee35
|
@ -31,6 +31,9 @@ without prior permission by the authors of Eressea.
|
|||
#include "spellbook.h"
|
||||
#include "calendar.h"
|
||||
|
||||
/* game modules */
|
||||
#include "prefix.h"
|
||||
|
||||
/* util includes */
|
||||
#include <util/attrib.h>
|
||||
#include <util/bsdstring.h>
|
||||
|
@ -487,6 +490,17 @@ static void json_race(cJSON *json, race *rc) {
|
|||
}
|
||||
}
|
||||
|
||||
static void json_prefixes(cJSON *json) {
|
||||
cJSON *child;
|
||||
if (json->type != cJSON_Array) {
|
||||
log_error("prefixes is not a json array: %d", json->type);
|
||||
return;
|
||||
}
|
||||
for (child = json->child; child; child = child->next) {
|
||||
add_raceprefix(child->valuestring);
|
||||
}
|
||||
}
|
||||
|
||||
static void json_terrains(cJSON *json) {
|
||||
cJSON *child;
|
||||
if (json->type != cJSON_Object) {
|
||||
|
@ -837,6 +851,9 @@ void json_config(cJSON *json) {
|
|||
else if (strcmp(child->string, "spells") == 0) {
|
||||
json_spells(child);
|
||||
}
|
||||
else if (strcmp(child->string, "prefixes") == 0) {
|
||||
json_prefixes(child);
|
||||
}
|
||||
else if (strcmp(child->string, "terrains") == 0) {
|
||||
json_terrains(child);
|
||||
init_terrains();
|
||||
|
|
11
src/prefix.c
11
src/prefix.c
|
@ -1,18 +1,23 @@
|
|||
#include <platform.h>
|
||||
#include "prefix.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char **race_prefixes = NULL;
|
||||
static size_t size = 4;
|
||||
static unsigned int next = 0;
|
||||
|
||||
void add_raceprefix(const char *prefix)
|
||||
{
|
||||
static size_t size = 4;
|
||||
static unsigned int next = 0;
|
||||
if (race_prefixes == NULL)
|
||||
assert(prefix);
|
||||
if (race_prefixes == NULL) {
|
||||
next = 0;
|
||||
size = 4;
|
||||
race_prefixes = malloc(size * sizeof(char *));
|
||||
}
|
||||
if (next + 1 == size) {
|
||||
size *= 2;
|
||||
race_prefixes = realloc(race_prefixes, size * sizeof(char *));
|
||||
|
|
Loading…
Reference in New Issue