FreeCalypso > hg > freecalypso-tools
comparison rvinterf/tmsh/usercmd.c @ 0:e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 11 Jun 2016 00:13:35 +0000 |
parents | |
children | ea061975c883 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e7502631a0f9 |
---|---|
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_omr(); | |
21 extern void cmd_ping(); | |
22 extern void cmd_r8(); | |
23 extern void cmd_r16(); | |
24 extern void cmd_r32(); | |
25 extern void cmd_set_imeisv(); | |
26 extern void cmd_set_pcm_string(); | |
27 extern void cmd_set_rfcap(); | |
28 extern void cmd_tgtreset(); | |
29 extern void cmd_version(); | |
30 extern void cmd_w8(); | |
31 extern void cmd_w16(); | |
32 extern void cmd_w32(); | |
33 | |
34 void | |
35 cmd_exit() | |
36 { | |
37 tty_cleanup(); | |
38 exit(0); | |
39 } | |
40 | |
41 static struct cmdtab { | |
42 char *cmd; | |
43 int minargs; | |
44 int maxargs; | |
45 void (*func)(); | |
46 } cmdtab[] = { | |
47 {"abbr", 2, 2, cmd_abbr}, | |
48 {"abbw", 3, 3, cmd_abbw}, | |
49 {"check-ffs1", 0, 0, cmd_check_ffs1}, | |
50 {"dieid", 0, 0, cmd_dieid}, | |
51 {"etmpkt", 1, 253, cmd_etmpkt}, | |
52 {"exit", 0, 0, cmd_exit}, | |
53 {"ffs2", 1, 3, cmd_ffs2}, | |
54 {"omr", 2, 2, cmd_omr}, | |
55 {"ping", 0, 2, cmd_ping}, | |
56 {"quit", 0, 0, cmd_exit}, | |
57 {"r8", 1, 2, cmd_r8}, | |
58 {"r16", 1, 2, cmd_r16}, | |
59 {"r32", 1, 2, cmd_r32}, | |
60 {"set-imeisv", 2, 2, cmd_set_imeisv}, | |
61 {"set-pcm-string", 2, 2, cmd_set_pcm_string}, | |
62 {"set-rfcap", 16, 16, cmd_set_rfcap}, | |
63 {"tgtreset", 0, 0, cmd_tgtreset}, | |
64 {"version", 1, 1, cmd_version}, | |
65 {"w8", 2, 246, cmd_w8}, | |
66 {"w16", 2, 123, cmd_w16}, | |
67 {"w32", 2, 62, cmd_w32}, | |
68 {0, 0, 0, 0} | |
69 }; | |
70 | |
71 void | |
72 dispatch_user_cmd() | |
73 { | |
74 char *argv[257]; | |
75 char *cp, **ap; | |
76 struct cmdtab *tp; | |
77 | |
78 for (cp = usercmd; isspace(*cp); cp++) | |
79 ; | |
80 if (!*cp || *cp == '#') | |
81 return; | |
82 argv[0] = cp; | |
83 while (*cp && !isspace(*cp)) | |
84 cp++; | |
85 if (*cp) | |
86 *cp++ = '\0'; | |
87 for (tp = cmdtab; tp->cmd; tp++) | |
88 if (!strcmp(tp->cmd, argv[0])) | |
89 break; | |
90 if (!tp->func) { | |
91 printf("error: no such command\n"); | |
92 return; | |
93 } | |
94 for (ap = argv + 1; ; ) { | |
95 while (isspace(*cp)) | |
96 cp++; | |
97 if (!*cp || *cp == '#') | |
98 break; | |
99 if (ap - argv - 1 >= tp->maxargs) { | |
100 printf("error: too many arguments\n"); | |
101 return; | |
102 } | |
103 if (*cp == '"') { | |
104 *ap++ = ++cp; | |
105 while (*cp && *cp != '"') | |
106 cp++; | |
107 if (*cp != '"') { | |
108 printf("error: unterminated quoted string\n"); | |
109 return; | |
110 } | |
111 *cp++ = '\0'; | |
112 } else { | |
113 *ap++ = cp; | |
114 while (*cp && !isspace(*cp)) | |
115 cp++; | |
116 if (*cp) | |
117 *cp++ = '\0'; | |
118 } | |
119 } | |
120 if (ap - argv - 1 < tp->minargs) { | |
121 printf("error: too few arguments\n"); | |
122 return; | |
123 } | |
124 *ap = 0; | |
125 tp->func(ap - argv, argv); | |
126 } |