2001-12-10 01:13:39 +01:00
|
|
|
/* vi: set ts=2:
|
|
|
|
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
|
|
|
|
| | Enno Rehling <enno@eressea-pbem.de>
|
|
|
|
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
|
2003-07-29 11:48:03 +02:00
|
|
|
| (c) 1998 - 2003 | Henning Peters <faroul@beyond.kn-bremen.de>
|
2001-12-10 01:13:39 +01:00
|
|
|
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
|
|
|
|
+-------------------+ Stefan Reich <reich@halbling.de>
|
|
|
|
|
|
|
|
This program may not be used, modified or distributed
|
|
|
|
without prior permission by the authors of Eressea.
|
|
|
|
*/
|
2001-03-25 09:42:34 +02:00
|
|
|
#include <config.h>
|
|
|
|
#include "xml.h"
|
|
|
|
|
2001-12-10 01:13:39 +01:00
|
|
|
/* util includes */
|
|
|
|
#include "log.h"
|
|
|
|
|
2001-03-25 09:42:34 +02:00
|
|
|
/* libc includes */
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
2002-01-05 17:14:38 +01:00
|
|
|
typedef struct xml_hierarchy {
|
|
|
|
const char * name;
|
|
|
|
unsigned int flags;
|
|
|
|
struct xml_callbacks * functions;
|
|
|
|
struct xml_hierarchy * next;
|
|
|
|
struct xml_hierarchy * children;
|
|
|
|
struct xml_hierarchy * parent;
|
|
|
|
} xml_hierarchy;
|
|
|
|
|
2001-03-25 09:42:34 +02:00
|
|
|
static int
|
2003-07-29 11:48:03 +02:00
|
|
|
__cberror(struct xml_stack * stack, const char* parsed, unsigned int line, const char *filename, int error)
|
2001-03-25 09:42:34 +02:00
|
|
|
{
|
2001-12-10 01:13:39 +01:00
|
|
|
struct xml_stack * s = stack;
|
2003-07-29 11:48:03 +02:00
|
|
|
log_error(("Error #%d in %s:%u while parsing element \"%s\"\n",
|
|
|
|
error, filename, line, parsed));
|
2001-12-10 01:13:39 +01:00
|
|
|
|
2002-01-05 17:14:38 +01:00
|
|
|
log_printf("XML stacktrace:\n");
|
2001-12-10 01:13:39 +01:00
|
|
|
while (s) {
|
2002-01-05 17:14:38 +01:00
|
|
|
if (s->tag && s->tag->name) log_printf("\t%s\n", s->tag->name);
|
|
|
|
else log_printf("\t<unknown>\n");
|
2001-12-10 01:13:39 +01:00
|
|
|
s = s->next;
|
|
|
|
}
|
2001-03-25 09:42:34 +02:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static xml_tag *
|
|
|
|
make_tag(const char * name)
|
|
|
|
{
|
|
|
|
xml_tag * tag = calloc(sizeof(xml_tag), 1);
|
|
|
|
tag->name = strdup(name);
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-01-05 17:14:38 +01:00
|
|
|
push_tag(xml_stack ** ostack, xml_tag * tag)
|
2001-03-25 09:42:34 +02:00
|
|
|
{
|
|
|
|
xml_stack * stack = calloc(sizeof(xml_stack), 1);
|
|
|
|
stack->next = *ostack;
|
|
|
|
stack->tag = tag;
|
2002-01-05 17:14:38 +01:00
|
|
|
if (*ostack) {
|
|
|
|
stack->stream = (*ostack)->stream;
|
|
|
|
stack->callbacks = (*ostack)->callbacks;
|
|
|
|
stack->state = (*ostack)->state;
|
|
|
|
}
|
2001-03-25 09:42:34 +02:00
|
|
|
*ostack = stack;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_attribs(xml_attrib * xa)
|
|
|
|
{
|
|
|
|
free(xa->name);
|
2002-03-31 15:34:02 +02:00
|
|
|
if(xa->value) free(xa->value);
|
2001-03-25 09:42:34 +02:00
|
|
|
free(xa);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_tag(xml_tag * tag)
|
|
|
|
{
|
|
|
|
while (tag->attribs) {
|
|
|
|
xml_attrib * p = tag->attribs;
|
|
|
|
tag->attribs = tag->attribs->next;
|
|
|
|
free_attribs(p);
|
|
|
|
}
|
|
|
|
free(tag->name);
|
|
|
|
free(tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
static xml_attrib *
|
|
|
|
make_attrib(xml_tag * tag, const char * name)
|
|
|
|
{
|
|
|
|
xml_attrib * xa = calloc(sizeof(xml_attrib), 1);
|
|
|
|
xa->name = strdup(name);
|
|
|
|
xa->next = tag->attribs;
|
|
|
|
return tag->attribs = xa;
|
|
|
|
}
|
|
|
|
|
|
|
|
static xml_tag *
|
|
|
|
pop_tag(xml_stack ** ostack)
|
|
|
|
{
|
|
|
|
xml_stack * stack = *ostack;
|
|
|
|
xml_tag * tag = stack->tag;
|
|
|
|
*ostack = stack->next;
|
|
|
|
free(stack);
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
|
2002-01-05 17:14:38 +01:00
|
|
|
static xml_hierarchy * callbacks;
|
|
|
|
|
|
|
|
void
|
|
|
|
xml_register(struct xml_callbacks * cb, const char * path, unsigned int flags)
|
2001-03-25 09:42:34 +02:00
|
|
|
{
|
2002-01-05 17:14:38 +01:00
|
|
|
xml_hierarchy ** node=&callbacks;
|
|
|
|
xml_hierarchy * parent = NULL;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
const char * nextspace = path;
|
|
|
|
while (*nextspace && !isspace(*nextspace)) ++nextspace;
|
|
|
|
if (*nextspace == '\0') {
|
|
|
|
/* advance to the last child: */
|
|
|
|
while (*node && strcmp((*node)->name, path)!=0) node=&(*node)->next;
|
|
|
|
if (*node == NULL) {
|
|
|
|
*node = calloc(sizeof(xml_hierarchy), 1);
|
|
|
|
(*node)->name = strdup(path);
|
|
|
|
(*node)->parent = parent;
|
|
|
|
}
|
|
|
|
(*node)->flags = flags;
|
|
|
|
(*node)->functions = cb;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
size_t lpath = nextspace-path;
|
|
|
|
if (*node == NULL) {
|
|
|
|
/* adding path into graph */
|
|
|
|
*node = calloc(sizeof(xml_hierarchy), 1);
|
|
|
|
(*node)->name = strncpy(calloc(sizeof(char), 1+lpath), path, lpath);
|
|
|
|
(*node)->parent = parent;
|
|
|
|
(*node)->functions = NULL;
|
|
|
|
path = nextspace+1;
|
|
|
|
while (isspace(*path)) ++path;
|
|
|
|
assert(*path || !"trailing blanks in path");
|
|
|
|
parent = *node;
|
|
|
|
node=&parent->children;
|
|
|
|
} else if (strlen((*node)->name)==lpath && strncmp((*node)->name, path, lpath)==0) {
|
|
|
|
path = nextspace+1;
|
|
|
|
while (isspace(*path)) ++path;
|
|
|
|
assert(*path || !"trailing blanks in path");
|
|
|
|
parent = *node;
|
|
|
|
node=&parent->children;
|
|
|
|
} else {
|
|
|
|
node=&(*node)->next;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2003-07-29 11:48:03 +02:00
|
|
|
xml_parse(xml_stack * stack, const char *filename)
|
2002-01-05 17:14:38 +01:00
|
|
|
{
|
|
|
|
FILE * stream = stack->stream;
|
2001-12-10 01:13:39 +01:00
|
|
|
xml_stack * start = stack;
|
2001-03-25 09:42:34 +02:00
|
|
|
enum { TAG, ENDTAG, ATNAME, ATVALUE, PLAIN } state = PLAIN;
|
2002-01-01 21:51:18 +01:00
|
|
|
boolean startline = true;
|
2001-03-25 09:42:34 +02:00
|
|
|
char tokbuffer[1024];
|
|
|
|
char * pos = tokbuffer;
|
|
|
|
int quoted = 0;
|
|
|
|
unsigned int line = 0;
|
|
|
|
xml_tag * tag = NULL;
|
|
|
|
xml_attrib * attrib = NULL;
|
2003-07-29 11:48:03 +02:00
|
|
|
int (*cb_error)(struct xml_stack*, const char*, unsigned int, const char *, int) = __cberror;
|
2001-12-10 01:13:39 +01:00
|
|
|
|
2001-03-25 09:42:34 +02:00
|
|
|
for (;;) {
|
|
|
|
int reparse;
|
|
|
|
int c = fgetc(stream);
|
|
|
|
if (c=='\n') {
|
|
|
|
++line;
|
|
|
|
} else if (c==EOF) {
|
|
|
|
if (state==PLAIN) {
|
2002-01-05 17:14:38 +01:00
|
|
|
const xml_hierarchy * cb = stack->callbacks;
|
2001-03-25 09:42:34 +02:00
|
|
|
*pos='\0';
|
2002-01-05 17:14:38 +01:00
|
|
|
if (cb && cb->functions->plaintext && pos!=tokbuffer) {
|
|
|
|
cb->functions->plaintext(stack, tokbuffer);
|
|
|
|
}
|
2001-03-25 09:42:34 +02:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
*pos='\0';
|
2003-07-29 11:48:03 +02:00
|
|
|
return cb_error(stack, tokbuffer, line, filename, XML_BROKENSTREAM);
|
2001-03-25 09:42:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
reparse = 0;
|
|
|
|
switch (state) {
|
|
|
|
case ATVALUE:
|
|
|
|
switch (c) {
|
|
|
|
case '<':
|
|
|
|
*pos='\0';
|
2003-07-29 11:48:03 +02:00
|
|
|
return cb_error(stack, tokbuffer, line, filename, XML_INVALIDCHAR);
|
2001-03-25 09:42:34 +02:00
|
|
|
case '"':
|
|
|
|
quoted = !quoted;
|
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
if (quoted) {
|
|
|
|
*pos='\0';
|
2003-07-29 11:48:03 +02:00
|
|
|
return cb_error(stack, tokbuffer, line, filename, XML_INVALIDCHAR);
|
2001-03-25 09:42:34 +02:00
|
|
|
}
|
|
|
|
state = TAG;
|
|
|
|
/* intentional fallthrough */
|
|
|
|
default:
|
|
|
|
if (quoted) *pos++ = (char)c;
|
|
|
|
else {
|
|
|
|
if (isspace(c) || c=='>') {
|
|
|
|
assert(attrib || !"internal error");
|
|
|
|
*pos='\0';
|
|
|
|
attrib->value = strdup(tokbuffer);
|
|
|
|
state = TAG;
|
|
|
|
pos = tokbuffer;
|
|
|
|
if (c=='>') reparse = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break; /* case ATVALUE */
|
|
|
|
case ATNAME:
|
|
|
|
switch (c) {
|
|
|
|
case '=':
|
|
|
|
*pos='\0';
|
|
|
|
assert(tag || !"internal error");
|
|
|
|
attrib = make_attrib(tag, tokbuffer);
|
|
|
|
state = ATVALUE;
|
|
|
|
pos = tokbuffer;
|
|
|
|
break;
|
|
|
|
case '<':
|
2001-12-10 01:13:39 +01:00
|
|
|
case '"':
|
2001-03-25 09:42:34 +02:00
|
|
|
case '/':
|
|
|
|
*pos='\0';
|
2003-07-29 11:48:03 +02:00
|
|
|
return cb_error(stack, tokbuffer, line, filename, XML_INVALIDCHAR);
|
2001-03-25 09:42:34 +02:00
|
|
|
default:
|
2001-12-10 01:13:39 +01:00
|
|
|
if (isspace(c) || c == '>') {
|
|
|
|
*pos++='\0';
|
|
|
|
attrib = make_attrib(tag, tokbuffer);
|
|
|
|
attrib->value = NULL;
|
|
|
|
state = TAG;
|
|
|
|
pos = tokbuffer;
|
|
|
|
if (c=='>') reparse = 1;
|
|
|
|
break;
|
2001-03-25 09:42:34 +02:00
|
|
|
}
|
|
|
|
*pos++ = (char)c;
|
|
|
|
}
|
|
|
|
break; /* case ATNAME */
|
|
|
|
case PLAIN:
|
|
|
|
switch (c) {
|
|
|
|
case '<':
|
2002-01-05 17:14:38 +01:00
|
|
|
if (pos!=tokbuffer) {
|
|
|
|
const xml_hierarchy * cb = stack->callbacks;
|
|
|
|
if (cb && cb->functions->plaintext) {
|
|
|
|
*pos = '\0';
|
|
|
|
cb->functions->plaintext(stack, tokbuffer);
|
|
|
|
}
|
2001-03-25 09:42:34 +02:00
|
|
|
}
|
|
|
|
state = TAG;
|
|
|
|
tag = NULL;
|
|
|
|
pos = tokbuffer;
|
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
*pos='\0';
|
2003-07-29 11:48:03 +02:00
|
|
|
return cb_error(stack, tokbuffer, line, filename, XML_INVALIDCHAR);
|
2002-01-01 21:51:18 +01:00
|
|
|
case '\n':
|
|
|
|
/* ignore */
|
|
|
|
if (!startline) *pos++ = ' ';
|
|
|
|
startline = true;
|
|
|
|
break;
|
|
|
|
case ' ':
|
|
|
|
case '\t':
|
|
|
|
if (!startline) {
|
|
|
|
*pos++ = (char)c;
|
|
|
|
}
|
|
|
|
break;
|
2001-03-25 09:42:34 +02:00
|
|
|
default:
|
|
|
|
*pos++ = (char)c;
|
2002-01-01 21:51:18 +01:00
|
|
|
startline = false;
|
2001-03-25 09:42:34 +02:00
|
|
|
}
|
|
|
|
break; /* case PLAIN */
|
|
|
|
case TAG:
|
|
|
|
switch (c) {
|
|
|
|
case '/':
|
|
|
|
if (pos==tokbuffer) state = ENDTAG;
|
|
|
|
else {
|
|
|
|
*pos='\0';
|
2003-07-29 11:48:03 +02:00
|
|
|
return cb_error(stack, tokbuffer, line, filename, XML_INVALIDCHAR);
|
2001-03-25 09:42:34 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
if (tag==NULL) {
|
|
|
|
*pos='\0';
|
2002-01-05 17:14:38 +01:00
|
|
|
push_tag(&stack, tag = make_tag(tokbuffer));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const xml_hierarchy * cnext = stack->callbacks?stack->callbacks->children:callbacks;
|
|
|
|
while (cnext && strcmp(cnext->name, tag->name)!=0) cnext=cnext->next;
|
|
|
|
if (cnext==NULL) {
|
|
|
|
/* unknown tag. assume same handler again: */
|
|
|
|
cnext = stack->callbacks;
|
|
|
|
} else if ((cnext->flags & XML_CB_IGNORE) == 0) {
|
|
|
|
stack->callbacks = cnext;
|
|
|
|
}
|
|
|
|
if (cnext->functions->tagbegin) {
|
|
|
|
cnext->functions->tagbegin(stack);
|
|
|
|
}
|
2001-03-25 09:42:34 +02:00
|
|
|
}
|
|
|
|
state = PLAIN;
|
2002-01-01 21:51:18 +01:00
|
|
|
startline = true;
|
2001-03-25 09:42:34 +02:00
|
|
|
pos = tokbuffer;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (isspace(c)) {
|
|
|
|
if (tag==NULL) {
|
|
|
|
*pos='\0';
|
2002-01-05 17:14:38 +01:00
|
|
|
push_tag(&stack, tag = make_tag(tokbuffer));
|
2001-03-25 09:42:34 +02:00
|
|
|
state = ATNAME;
|
|
|
|
pos = tokbuffer;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (tag!=NULL) {
|
|
|
|
state = ATNAME;
|
|
|
|
pos = tokbuffer;
|
|
|
|
reparse = 1;
|
|
|
|
}
|
|
|
|
else *pos++ = (char)c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break; /* case TAG */
|
|
|
|
case ENDTAG:
|
|
|
|
switch (c) {
|
|
|
|
case '>':
|
|
|
|
*pos = '\0';
|
2002-01-05 17:14:38 +01:00
|
|
|
/* might be an unknown tag: */
|
|
|
|
if (stack->callbacks) {
|
|
|
|
/* && strcmp(stack->callbacks->name, stack->tag->name)==0 */
|
|
|
|
const xml_hierarchy * cb = stack->callbacks;
|
|
|
|
if (strcmp(stack->tag->name, tokbuffer)!=0) {
|
|
|
|
xml_stack * top = stack;
|
2003-07-29 11:48:03 +02:00
|
|
|
cb_error(stack, tokbuffer, line, filename, XML_NESTINGERROR);
|
|
|
|
while (top && top->tag && strcmp(top->tag->name, tokbuffer)!=0) top = top->next;
|
|
|
|
if (top==NULL || top->tag==NULL) return XML_NESTINGERROR;
|
2002-01-05 17:14:38 +01:00
|
|
|
while (stack && stack!=top) {
|
|
|
|
if (cb->functions->tagend) {
|
|
|
|
cb->functions->tagend(stack);
|
|
|
|
}
|
|
|
|
free_tag(pop_tag(&stack));
|
|
|
|
cb = stack->callbacks;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cb->functions->tagend) {
|
|
|
|
cb->functions->tagend(stack);
|
|
|
|
}
|
|
|
|
cb = cb->parent;
|
|
|
|
}
|
|
|
|
if (strcmp(stack->tag->name, tokbuffer)!=0) {
|
|
|
|
return XML_NESTINGERROR;
|
|
|
|
}
|
|
|
|
free_tag(pop_tag(&stack));
|
2001-12-10 01:13:39 +01:00
|
|
|
if (stack==start) {
|
|
|
|
return XML_OK;
|
|
|
|
}
|
2001-03-25 09:42:34 +02:00
|
|
|
state = PLAIN;
|
|
|
|
pos = tokbuffer;
|
|
|
|
break;
|
|
|
|
case '<':
|
|
|
|
case ' ':
|
|
|
|
case '=':
|
|
|
|
case '/':
|
|
|
|
*pos='\0';
|
2003-07-29 11:48:03 +02:00
|
|
|
return cb_error(stack, tokbuffer, line, filename, XML_INVALIDCHAR);
|
2001-03-25 09:42:34 +02:00
|
|
|
default:
|
|
|
|
*pos++ = (char)c;
|
|
|
|
}
|
|
|
|
break; /* case ENDTAG */
|
|
|
|
} /* switch(state) */
|
|
|
|
} while (reparse);
|
|
|
|
} /* for(;;) */
|
|
|
|
return XML_OK; /* SUCCESS */
|
|
|
|
}
|
- Neue Messages fertig
Messages werden jetzt in einem anderen Meta-Format (message* of
message_type*) gespeichert, das man in beliebige Formate (CR oder NR)
rendern kann. crmessage.c und nrmessage.c sind die render-engines dafür.
Die Messagetypen werden in res/{de,en}/messages.xml gesammelt, ultimativ
kann das aber durchaus eine einzelne Datei sein. Die ist derzeit nicht
wirklich xml (Umlaute drin, keine Definitionsdatei), aber gut lesbar.
- make_message
Diese Funktion ersetzt new_message, und ist etwas einfacher in der Syntax:
make_message("dumb_mistake", "unit region command", u, r, cmd) erzeugt
eine neue Nachricht, die dann einfach mit add_message wie bisher an die
Nachrichtenliste gehängt werden kann.
TODO: Messages könnte man durchaus reference-counten, und in mehrere Listen
einfügen, solang sie a) mehrfachverwendet (Kampf!) und b) vom Betrachter
unabhängig sind. Das spart einigen Speicher.
- CR Version erhöht.
Weil die MESSAGETYPES Blocks anders sind als früher
- OFFENSIVE_DELAY
Verbietet Einheiten, deren Partei eine Reigon niht bewachen, den
Angriff in der Region, wenn sie sich in der Runde zuvor bewegt haben.
Status der letzten Runde wird in neuem Attribut at_moved gespeichert.
- SHORT_ATTACKS
ein define, das angibt ob Kämpfen grundsätzlich keine lange Aktion ist.
- XML Parser
xml.[hc] enthält einen XML-Parser, dem man ein plugin mit callbacks
übergibt, die nach dem Parsen eines tokens aufgerufen werden.
2001-04-12 19:21:57 +02:00
|
|
|
|
2002-01-05 17:14:38 +01:00
|
|
|
int
|
2003-07-29 11:48:03 +02:00
|
|
|
xml_read(FILE * stream, const char *filename, xml_stack * stack)
|
2002-01-05 17:14:38 +01:00
|
|
|
{
|
|
|
|
xml_stack root;
|
|
|
|
FILE * save;
|
|
|
|
if (!stack) {
|
|
|
|
stack = &root;
|
|
|
|
memset(stack, 0, sizeof(xml_stack));
|
|
|
|
}
|
|
|
|
save = stack->stream;
|
|
|
|
stack->stream = stream;
|
|
|
|
while (!feof(stream)) {
|
2003-07-29 11:48:03 +02:00
|
|
|
int i = xml_parse(stack, filename);
|
2002-01-05 17:14:38 +01:00
|
|
|
if (i!=0) return i;
|
|
|
|
}
|
|
|
|
stack->stream = save;
|
|
|
|
return XML_OK;
|
|
|
|
}
|
|
|
|
|
- Neue Messages fertig
Messages werden jetzt in einem anderen Meta-Format (message* of
message_type*) gespeichert, das man in beliebige Formate (CR oder NR)
rendern kann. crmessage.c und nrmessage.c sind die render-engines dafür.
Die Messagetypen werden in res/{de,en}/messages.xml gesammelt, ultimativ
kann das aber durchaus eine einzelne Datei sein. Die ist derzeit nicht
wirklich xml (Umlaute drin, keine Definitionsdatei), aber gut lesbar.
- make_message
Diese Funktion ersetzt new_message, und ist etwas einfacher in der Syntax:
make_message("dumb_mistake", "unit region command", u, r, cmd) erzeugt
eine neue Nachricht, die dann einfach mit add_message wie bisher an die
Nachrichtenliste gehängt werden kann.
TODO: Messages könnte man durchaus reference-counten, und in mehrere Listen
einfügen, solang sie a) mehrfachverwendet (Kampf!) und b) vom Betrachter
unabhängig sind. Das spart einigen Speicher.
- CR Version erhöht.
Weil die MESSAGETYPES Blocks anders sind als früher
- OFFENSIVE_DELAY
Verbietet Einheiten, deren Partei eine Reigon niht bewachen, den
Angriff in der Region, wenn sie sich in der Runde zuvor bewegt haben.
Status der letzten Runde wird in neuem Attribut at_moved gespeichert.
- SHORT_ATTACKS
ein define, das angibt ob Kämpfen grundsätzlich keine lange Aktion ist.
- XML Parser
xml.[hc] enthält einen XML-Parser, dem man ein plugin mit callbacks
übergibt, die nach dem Parsen eines tokens aufgerufen werden.
2001-04-12 19:21:57 +02:00
|
|
|
const char *
|
|
|
|
xml_value(const xml_tag * tag, const char * name)
|
|
|
|
{
|
|
|
|
const xml_attrib * xa = tag->attribs;
|
|
|
|
while (xa && strcmp(name, xa->name)!=0) xa = xa->next;
|
|
|
|
if (xa) return xa->value;
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-12-10 01:13:39 +01:00
|
|
|
|
|
|
|
int
|
|
|
|
xml_ivalue(const xml_tag * tag, const char * name)
|
|
|
|
{
|
|
|
|
const xml_attrib * xa = tag->attribs;
|
|
|
|
while (xa && strcmp(name, xa->name)!=0) xa = xa->next;
|
|
|
|
if (xa) return atoi(xa->value);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean
|
|
|
|
xml_bvalue(const xml_tag * tag, const char * name)
|
|
|
|
{
|
|
|
|
const xml_attrib * xa = tag->attribs;
|
|
|
|
while (xa && strcmp(name, xa->name)!=0) xa = xa->next;
|
|
|
|
if (xa) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
xml_fvalue(const xml_tag * tag, const char * name)
|
|
|
|
{
|
|
|
|
const xml_attrib * xa = tag->attribs;
|
|
|
|
while (xa && strcmp(name, xa->name)!=0) xa = xa->next;
|
|
|
|
if (xa) return atof(xa->value);
|
|
|
|
return 0.0;
|
|
|
|
}
|