Laurent Vivier wrote:
Le lundi 11 août 2008 à 14:22 -0500, Anthony Liguori a écrit :
but using "void (*handler)(int argc, char** argv)" avoids the switch:
switch(nb_args) {
case 0:
cmd->handler();
break;
case 1:
cmd->handler(args[0]);
break;
...
}
becomes
cmd->handler(nb_args, args);
And then every monitor command changes from:
void do_eject(int force, char *device)
{
...
}
to:
void do_eject(int argc, char **argv)
{
char *device;
int force = 0;
if (argc == 2) {
if (strcmp(argv[0], "-f") == 0) {
force = 1;
device = argv[1];
} else {
term_printf("bad option %s\n", argv[0]);
return;
}
} else if (argc == 1) {
device = argv[0];
} else {
term_printf("bad number of options\n");
return;
}
...
}
Consider multiplying that by all of the possible monitor commands, and
it's totally not worth it.