On Jan 8, 2004, at 6:56 PM, Rick Widmer wrote:
1. Does switch/case work with strings?

No. Only with byte/int/long/word datatypes.


It might be possible to build some sort of table of the commands and the functions to call:

typedef struct {
        char    *command,
        void (*function)(),
} functableentry;

const functableentry functable[] = {
        { "showusers", &show_users },
        { "showaliases", &show_aliases }
}

notfound = 1;
for (i = 0; notfound && i < (sizeof(functable) / sizeof(functable[0])); i++) {
if (strcmp (functable[i].command, command) == 0) {
notfound = 0;
functable[i].function();
}
}
if (notfound) {
printf ("invalid command: %s\n", command);
}


Note that with this system, you need to come up with a standard function call (identical parameters and return value) to use for each function in the table. Something like this could really clean up command.c.

2. How much trouble is it to add or remove .c source files? Say all the code in alias.c is obsolete except for a function or two and I want to move those functions to a different file and remove it.

Not much trouble at all. We can just add or remove it from CVS and Makefile.am.


--
Tom Collins  -  [EMAIL PROTECTED]
QmailAdmin: http://qmailadmin.sf.net/  Vpopmail: http://vpopmail.sf.net/
Info on the Sniffter hand-held Network Tester: http://sniffter.com/



Reply via email to