FreeCalypso > hg > freecalypso-sw
diff rvinterf/tmsh/usercmd.c @ 260:c146f38d2b5f
rvinterf subdir structure made a little more sensible
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Wed, 05 Feb 2014 04:02:13 +0000 |
parents | rvinterf/etm/usercmd.c@35113b1964d3 |
children | b5b54feb111a |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rvinterf/tmsh/usercmd.c Wed Feb 05 04:02:13 2014 +0000 @@ -0,0 +1,107 @@ +/* + * This module implements fc-tmsh user command dispatch. + */ + +#include <sys/types.h> +#include <ctype.h> +#include <stdio.h> +#include <string.h> +#include <strings.h> +#include <stdlib.h> + +extern char usercmd[]; + +extern void cmd_abbr(); +extern void cmd_abbw(); +extern void cmd_check_ffs1(); +extern void cmd_dieid(); +extern void cmd_etmpkt(); +extern void cmd_ffs2(); +extern void cmd_ping(); +extern void cmd_r8(); +extern void cmd_r16(); +extern void cmd_r32(); +extern void cmd_tgtreset(); +extern void cmd_version(); +extern void cmd_w8(); +extern void cmd_w16(); +extern void cmd_w32(); + +void +cmd_exit() +{ + tty_cleanup(); + exit(0); +} + +static struct cmdtab { + char *cmd; + int minargs; + int maxargs; + void (*func)(); +} cmdtab[] = { + {"abbr", 2, 2, cmd_abbr}, + {"abbw", 3, 3, cmd_abbw}, + {"check-ffs1", 0, 0, cmd_check_ffs1}, + {"dieid", 0, 0, cmd_dieid}, + {"etmpkt", 1, 253, cmd_etmpkt}, + {"exit", 0, 0, cmd_exit}, + {"ffs2", 1, 3, cmd_ffs2}, + {"ping", 0, 2, cmd_ping}, + {"quit", 0, 0, cmd_exit}, + {"r8", 1, 2, cmd_r8}, + {"r16", 1, 2, cmd_r16}, + {"r32", 1, 2, cmd_r32}, + {"tgtreset", 0, 0, cmd_tgtreset}, + {"version", 1, 1, cmd_version}, + {"w8", 2, 246, cmd_w8}, + {"w16", 2, 123, cmd_w16}, + {"w32", 2, 62, cmd_w32}, + {0, 0, 0, 0} +}; + +void +dispatch_user_cmd() +{ + char *argv[257]; + char *cp, **ap; + struct cmdtab *tp; + + for (cp = usercmd; isspace(*cp); cp++) + ; + if (!*cp || *cp == '#') + return; + argv[0] = cp; + while (*cp && !isspace(*cp)) + cp++; + if (*cp) + *cp++ = '\0'; + for (tp = cmdtab; tp->cmd; tp++) + if (!strcmp(tp->cmd, argv[0])) + break; + if (!tp->func) { + printf("error: no such command\n"); + return; + } + for (ap = argv + 1; ; ) { + while (isspace(*cp)) + cp++; + if (!*cp || *cp == '#') + break; + if (ap - argv - 1 >= tp->maxargs) { + printf("error: too many arguments\n"); + return; + } + *ap++ = cp; + while (*cp && !isspace(*cp)) + cp++; + if (*cp) + *cp++ = '\0'; + } + if (ap - argv - 1 < tp->minargs) { + printf("error: too few arguments\n"); + return; + } + *ap = 0; + tp->func(ap - argv, argv); +}