/* vi: set ts=2: +-------------------+ Christian Schlittchen | | Enno Rehling | Eressea PBEM host | Katja Zedel | (c) 1998 - 2001 | Henning Peters | | Ingo Wilken +-------------------+ Stefan Reich This program may not be used, modified or distributed without prior permission by the authors of Eressea. */ #include #include "command.h" #include "umlaut.h" #include "language.h" /* libc includes */ #include #include #include #include typedef struct command { parser fun; struct tnode * nodes; } command; tnode * stree_find(const syntaxtree * stree, const struct locale * lang) { while (stree) { if (stree->lang==lang) return stree->root; stree = stree->next; } return NULL; } syntaxtree * stree_create(void) { syntaxtree * sroot = NULL; const struct locale * lang = locales; while (lang) { syntaxtree * stree = malloc(sizeof(syntaxtree)); stree->lang = lang; stree->next = sroot; sroot=stree; lang=nextlocale(lang); } return sroot; } void add_command(struct tnode * keys, struct tnode * tnext, const char * str, parser fun) { command * cmd = malloc(sizeof(command)); cmd->fun = fun; cmd->nodes = tnext; addtoken(keys, str, (void*)cmd); } void do_command(const struct tnode * keys, void * u, const char * str) { int i; char zText[16]; const char * c; command * cmd; while (isspace(*str)) ++str; c = str; while (isalnum(*c)) ++c; i = min(16, c-str); strncpy(zText, str, i); zText[i]=0; if (findtoken(keys, zText, (void**)&cmd)==E_TOK_SUCCESS) { if (cmd->nodes) { assert(!cmd->fun); do_command(cmd->nodes, u, ++c); return; } assert(cmd->fun); cmd->fun(cmd->nodes, ++c, u, str); } return; }