int commands(&b,c);
commands returns 0 when it reaches end of file. It returns -1, setting errno appropriately, if it runs out of memory or has trouble reading b.
Each command is terminated by \n. Partial final lines are ignored. If a command ends with \r, the \r is removed.
Each command contains a verb, consisting of zero or more non-space characters, followed optionally by one or more spaces and an argument.
Recognized verbs are listed in c. c is an array of one or more struct commands. Each struct has three components: char *verb; void *action(); and void *flush().
verb points to a \0-terminated string, interpreted without regard to case. If the command verb matches this string, commands calls action(arg), followed by flush() if flush is not the zero pointer. Here arg is a pointer to a \0-terminated string containing the argument (with any \0 inside the argument replaced by \n), or the empty string if there is no argument.
Exception: In the last struct in c, verb is the 0 pointer. commands uses this action for all unrecognized verbs.
This does not mean it is a good format. It violates basic engineering principles. It has produced a continuing string of interoperability problems.
See http://pobox.com/~djb/proto/design.html for further comments.
{ { "help", usage, empty }
, { "do", doit, 0 }
, { 0, syntax, empty }
}
and commands receives the input
Do this
undo that
HELP
then commands will call doit(this), syntax(that), empty(), usage(), and empty().