comparison 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
comparison
equal deleted inserted replaced
259:35113b1964d3 260:c146f38d2b5f
1 /*
2 * This module implements fc-tmsh user command dispatch.
3 */
4
5 #include <sys/types.h>
6 #include <ctype.h>
7 #include <stdio.h>
8 #include <string.h>
9 #include <strings.h>
10 #include <stdlib.h>
11
12 extern char usercmd[];
13
14 extern void cmd_abbr();
15 extern void cmd_abbw();
16 extern void cmd_check_ffs1();
17 extern void cmd_dieid();
18 extern void cmd_etmpkt();
19 extern void cmd_ffs2();
20 extern void cmd_ping();
21 extern void cmd_r8();
22 extern void cmd_r16();
23 extern void cmd_r32();
24 extern void cmd_tgtreset();
25 extern void cmd_version();
26 extern void cmd_w8();
27 extern void cmd_w16();
28 extern void cmd_w32();
29
30 void
31 cmd_exit()
32 {
33 tty_cleanup();
34 exit(0);
35 }
36
37 static struct cmdtab {
38 char *cmd;
39 int minargs;
40 int maxargs;
41 void (*func)();
42 } cmdtab[] = {
43 {"abbr", 2, 2, cmd_abbr},
44 {"abbw", 3, 3, cmd_abbw},
45 {"check-ffs1", 0, 0, cmd_check_ffs1},
46 {"dieid", 0, 0, cmd_dieid},
47 {"etmpkt", 1, 253, cmd_etmpkt},
48 {"exit", 0, 0, cmd_exit},
49 {"ffs2", 1, 3, cmd_ffs2},
50 {"ping", 0, 2, cmd_ping},
51 {"quit", 0, 0, cmd_exit},
52 {"r8", 1, 2, cmd_r8},
53 {"r16", 1, 2, cmd_r16},
54 {"r32", 1, 2, cmd_r32},
55 {"tgtreset", 0, 0, cmd_tgtreset},
56 {"version", 1, 1, cmd_version},
57 {"w8", 2, 246, cmd_w8},
58 {"w16", 2, 123, cmd_w16},
59 {"w32", 2, 62, cmd_w32},
60 {0, 0, 0, 0}
61 };
62
63 void
64 dispatch_user_cmd()
65 {
66 char *argv[257];
67 char *cp, **ap;
68 struct cmdtab *tp;
69
70 for (cp = usercmd; isspace(*cp); cp++)
71 ;
72 if (!*cp || *cp == '#')
73 return;
74 argv[0] = cp;
75 while (*cp && !isspace(*cp))
76 cp++;
77 if (*cp)
78 *cp++ = '\0';
79 for (tp = cmdtab; tp->cmd; tp++)
80 if (!strcmp(tp->cmd, argv[0]))
81 break;
82 if (!tp->func) {
83 printf("error: no such command\n");
84 return;
85 }
86 for (ap = argv + 1; ; ) {
87 while (isspace(*cp))
88 cp++;
89 if (!*cp || *cp == '#')
90 break;
91 if (ap - argv - 1 >= tp->maxargs) {
92 printf("error: too many arguments\n");
93 return;
94 }
95 *ap++ = cp;
96 while (*cp && !isspace(*cp))
97 cp++;
98 if (*cp)
99 *cp++ = '\0';
100 }
101 if (ap - argv - 1 < tp->minargs) {
102 printf("error: too few arguments\n");
103 return;
104 }
105 *ap = 0;
106 tp->func(ap - argv, argv);
107 }