typedef struct _command COMMAND; struct _command { char * name; int argc; char * argv[5]; COMMAND * next; }; |
next
member, of course, is to allow commands to be strung together into a linked
list. Note that this "command language" is really simple, because the "commands" are really
notifications from the task manager that something has happened which the engine needs to act
upon. Maybe "messages" would be a better terminology -- but nope, they're commands now.
Live with it.
Well, so the other thing we want to define here is a handy little function to tack a command
onto a list of commands.
COMMAND * command_add (COMMAND * list, char * name, int argc, ...) { COMMAND * cmd; int i; va_list argv; va_start(argv, argc); cmd = (COMMAND *) malloc (sizeof (struct _command)); cmd->name = name; cmd->argc = argc; for (i=0; i < argc; i++) { cmd->argv[i] = va_arg(argv, char *); } va_end(argv); cmd->next = NULL; if (!list) return (cmd); while (list->next != NULL) list = list->next; list->next = cmd; return cmd; } |
void command_freelist (COMMAND * list) { COMMAND * cmd; while (list) { cmd = list; list = list->next; free ((void *) cmd); } } |
void command_load (COMMAND * list, FILE * file) { } |
This code and documentation are released under the terms of the GNU license. They are additionally copyright (c) 2000, Vivtek. All rights reserved except those explicitly granted under the terms of the GNU license. |