Am Montag, 4. Juni 2007 03:40 schrieb chromatic:
> > > #define c_b 25245
> >
> > Another WTF from code history.
> >
> > leo - please remove this - kthx.
>
> We have to replace it with something; any ideas?
Well, just the "normal" way of parsing commands. Chained ifs:
if (!memcmp(cmd, "foo", 3))
do_foo_cmd(cmd + 3);
else if (!memcmp(cmd, "bar", 3))
do_bar_cmd(cmd + 3);
...
Or a dispatch table:
typedef int (*cmd_func_t)(Interp *, char *cmd);
static int do_foo_cmd(Interp* interp, char *cmd) {...}
...
static const struct debug_cmds {
const char *name;
cmd_func_t func;
} cmds[] = {
{ "bar", do_bar_cmd, }, /* plz keep sorted */
{ "foo", do_foo_cmd, },
...
};
Then bsearch the command name, exec the func with the cmd pointer advanced to
the rest of the command line.
leo