begin expat message parsing

This commit is contained in:
Enno Rehling 2018-05-18 18:50:13 +02:00
parent 6608f1b1ab
commit f8b8a5284c
3 changed files with 32 additions and 16 deletions

View File

@ -16,6 +16,7 @@
#include "util/functions.h"
#include "util/log.h"
#include "util/message.h"
#include "util/strings.h"
#include <expat.h>
@ -47,7 +48,6 @@ enum {
EXP_SHIPS,
EXP_RACES,
EXP_MESSAGES,
EXP_STRINGS,
EXP_SPELLS,
EXP_SPELLBOOKS,
};
@ -285,6 +285,25 @@ static void handle_weapon(parseinfo *pi, const XML_Char *el, const XML_Char **at
wtype->flags = flags;
}
static void XMLCALL start_messages(parseinfo *pi, const XML_Char *el, const XML_Char **attr) {
if (xml_strcmp(el, "message") == 0) {
const XML_Char *name = NULL, *section = NULL;
int i;
for (i = 0; attr[i]; i += 2) {
const XML_Char *key = attr[i], *val = attr[i + 1];
if (xml_strcmp(key, "name") == 0) {
name = val;
}
else if (xml_strcmp(key, "section") == 0) {
section = val;
}
}
if (name) {
pi->object = mt_new(name, NULL);
}
}
}
#define MAX_COMPONENTS 8
static spell_component components[MAX_COMPONENTS];
static int ncomponents;
@ -1192,9 +1211,6 @@ static void XMLCALL handle_start(void *data, const XML_Char *el, const XML_Char
else if (xml_strcmp(el, "messages") == 0) {
pi->type = EXP_MESSAGES;
}
else if (xml_strcmp(el, "strings") == 0) {
pi->type = EXP_STRINGS;
}
else if (xml_strcmp(el, "spells") == 0) {
pi->type = EXP_SPELLS;
}
@ -1232,6 +1248,9 @@ static void XMLCALL handle_start(void *data, const XML_Char *el, const XML_Char
case EXP_SPELLS:
start_spells(pi, el, attr);
break;
case EXP_MESSAGES:
start_messages(pi, el, attr);
break;
case EXP_UNKNOWN:
handle_bad_input(pi, el, NULL);
break;

View File

@ -79,16 +79,9 @@ message_type *mt_new(const char *name, const char *args[])
mtype->name = str_strdup(name);
mtype->nparameters = nparameters;
if (nparameters > 0) {
int i;
mtype->pnames = (char **)malloc(sizeof(char *) * nparameters);
mtype->types = (arg_type **)malloc(sizeof(arg_type *) * nparameters);
}
else {
mtype->pnames = NULL;
mtype->types = NULL;
}
if (args != NULL) {
int i;
for (i = 0; args[i]; ++i) {
const char *x = args[i];
const char *spos = strchr(x, ':');
@ -110,6 +103,10 @@ message_type *mt_new(const char *name, const char *args[])
}
}
}
else {
mtype->pnames = NULL;
mtype->types = NULL;
}
return mtype;
}

View File

@ -27,10 +27,10 @@
#include <stdlib.h>
typedef struct nrmessage_type {
const struct message_type *mtype;
char *vars;
struct nrmessage_type *next;
const char *section;
const struct message_type *mtype;
char *vars;
struct nrmessage_type *next;
const char *section;
} nrmessage_type;
#define NRT_MAXHASH 1021