/* 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" /* libc includes */ #include #include #include typedef struct command { struct command * next; const char * key; void (*perform)(const char *, void *, const char *); } command; void add_command(struct tnode * keys, command ** cmds, const char * str, void(*fun)(const char*, void *, const char*)) { command * nc = calloc(sizeof(command), 1); nc->key = str; nc->perform = fun; nc->next = *cmds; *cmds = nc; addtoken(keys, str, (void*)nc); } void do_command(const struct tnode * keys, void * u, const char * str) { int i; char zText[16]; const char * c; command * cm; 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**)&cm)==E_TOK_SUCCESS && cm->perform) cm->perform(++c, u, str); }