Define operation functions
static void cmd_capture (char *par) {}static void cmd_fill (char *par) {}static void cmd_type (char *par) {}static void cmd_rename (char *par) {}static void cmd_copy (char *par) {}static void cmd_delete (char *par) {}static void cmd_dir (char *par) {}static void cmd_format (char *par) {}static void cmd_help (char *par) {}
Type Definition
typedef struct scmd { char val[8]; void (*func)(char *par);} SCMD;
Definition of matching commands and functions
Static const SCMD cmd [] = {"CAP", 1__capture, "TYPE", 1__type, "REN", 1__rename, "COPY", 1__copy, "DEL", 1__delete, "DIR", 1__dir, "FORMAT", 1__format, "HELP", 1__help, "FILL", 1__fill ,"? ", Cmd_help };
#define CMD_COUNT (sizeof (cmd) / sizeof (cmd[0]))
for (i = 0; i < CMD_COUNT; i++) { if (strcmp (sp, (const char *)&cmd[i].val)) { continue; } cmd[i].func (next); /* execute command function */ break; } if (i == CMD_COUNT) { printf ("\nCommand error\n"); }
For example, strings and corresponding functions can be matched.