forked from github/server
begin expat message parsing
This commit is contained in:
parent
6608f1b1ab
commit
f8b8a5284c
3 changed files with 32 additions and 16 deletions
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
#include "util/functions.h"
|
#include "util/functions.h"
|
||||||
#include "util/log.h"
|
#include "util/log.h"
|
||||||
|
#include "util/message.h"
|
||||||
#include "util/strings.h"
|
#include "util/strings.h"
|
||||||
|
|
||||||
#include <expat.h>
|
#include <expat.h>
|
||||||
|
@ -47,7 +48,6 @@ enum {
|
||||||
EXP_SHIPS,
|
EXP_SHIPS,
|
||||||
EXP_RACES,
|
EXP_RACES,
|
||||||
EXP_MESSAGES,
|
EXP_MESSAGES,
|
||||||
EXP_STRINGS,
|
|
||||||
EXP_SPELLS,
|
EXP_SPELLS,
|
||||||
EXP_SPELLBOOKS,
|
EXP_SPELLBOOKS,
|
||||||
};
|
};
|
||||||
|
@ -285,6 +285,25 @@ static void handle_weapon(parseinfo *pi, const XML_Char *el, const XML_Char **at
|
||||||
wtype->flags = flags;
|
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
|
#define MAX_COMPONENTS 8
|
||||||
static spell_component components[MAX_COMPONENTS];
|
static spell_component components[MAX_COMPONENTS];
|
||||||
static int ncomponents;
|
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) {
|
else if (xml_strcmp(el, "messages") == 0) {
|
||||||
pi->type = EXP_MESSAGES;
|
pi->type = EXP_MESSAGES;
|
||||||
}
|
}
|
||||||
else if (xml_strcmp(el, "strings") == 0) {
|
|
||||||
pi->type = EXP_STRINGS;
|
|
||||||
}
|
|
||||||
else if (xml_strcmp(el, "spells") == 0) {
|
else if (xml_strcmp(el, "spells") == 0) {
|
||||||
pi->type = EXP_SPELLS;
|
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:
|
case EXP_SPELLS:
|
||||||
start_spells(pi, el, attr);
|
start_spells(pi, el, attr);
|
||||||
break;
|
break;
|
||||||
|
case EXP_MESSAGES:
|
||||||
|
start_messages(pi, el, attr);
|
||||||
|
break;
|
||||||
case EXP_UNKNOWN:
|
case EXP_UNKNOWN:
|
||||||
handle_bad_input(pi, el, NULL);
|
handle_bad_input(pi, el, NULL);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -79,16 +79,9 @@ message_type *mt_new(const char *name, const char *args[])
|
||||||
mtype->name = str_strdup(name);
|
mtype->name = str_strdup(name);
|
||||||
mtype->nparameters = nparameters;
|
mtype->nparameters = nparameters;
|
||||||
if (nparameters > 0) {
|
if (nparameters > 0) {
|
||||||
|
int i;
|
||||||
mtype->pnames = (char **)malloc(sizeof(char *) * nparameters);
|
mtype->pnames = (char **)malloc(sizeof(char *) * nparameters);
|
||||||
mtype->types = (arg_type **)malloc(sizeof(arg_type *) * 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) {
|
for (i = 0; args[i]; ++i) {
|
||||||
const char *x = args[i];
|
const char *x = args[i];
|
||||||
const char *spos = strchr(x, ':');
|
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;
|
return mtype;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,10 +27,10 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
typedef struct nrmessage_type {
|
typedef struct nrmessage_type {
|
||||||
const struct message_type *mtype;
|
const struct message_type *mtype;
|
||||||
char *vars;
|
char *vars;
|
||||||
struct nrmessage_type *next;
|
struct nrmessage_type *next;
|
||||||
const char *section;
|
const char *section;
|
||||||
} nrmessage_type;
|
} nrmessage_type;
|
||||||
|
|
||||||
#define NRT_MAXHASH 1021
|
#define NRT_MAXHASH 1021
|
||||||
|
|
Loading…
Reference in a new issue