FreeCalypso > hg > freecalypso-tools
annotate rvinterf/tmsh/usercmd.c @ 85:c5766d12360d
fc-buzplay started
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 27 Oct 2016 05:28:30 +0000 |
parents | 27c41e4b21ae |
children | 2825d79bb151 |
rev | line source |
---|---|
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements fc-tmsh user command dispatch. |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <ctype.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <string.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <strings.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdlib.h> |
71
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
69
diff
changeset
|
11 #include "exitcodes.h" |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 extern char usercmd[]; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
69
2159f260ed13
fc-tmsh: all commands internally return values
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
15 extern int cmd_abbr(); |
2159f260ed13
fc-tmsh: all commands internally return values
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
16 extern int cmd_abbw(); |
2159f260ed13
fc-tmsh: all commands internally return values
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
17 extern int cmd_audio(); |
2159f260ed13
fc-tmsh: all commands internally return values
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
18 extern int cmd_check_ffs1(); |
2159f260ed13
fc-tmsh: all commands internally return values
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
19 extern int cmd_dieid(); |
2159f260ed13
fc-tmsh: all commands internally return values
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
20 extern int cmd_ffs2(); |
2159f260ed13
fc-tmsh: all commands internally return values
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
21 extern int cmd_omr(); |
2159f260ed13
fc-tmsh: all commands internally return values
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
22 extern int cmd_ping(); |
2159f260ed13
fc-tmsh: all commands internally return values
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
23 extern int cmd_r8(); |
2159f260ed13
fc-tmsh: all commands internally return values
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
24 extern int cmd_r16(); |
2159f260ed13
fc-tmsh: all commands internally return values
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
25 extern int cmd_r32(); |
2159f260ed13
fc-tmsh: all commands internally return values
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
26 extern int cmd_tgtreset(); |
2159f260ed13
fc-tmsh: all commands internally return values
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
27 extern int cmd_tmpkt(); |
2159f260ed13
fc-tmsh: all commands internally return values
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
28 extern int cmd_version(); |
2159f260ed13
fc-tmsh: all commands internally return values
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
29 extern int cmd_w8(); |
2159f260ed13
fc-tmsh: all commands internally return values
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
30 extern int cmd_w16(); |
2159f260ed13
fc-tmsh: all commands internally return values
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
31 extern int cmd_w32(); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 cmd_exit() |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 tty_cleanup(); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 exit(0); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 static struct cmdtab { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 char *cmd; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 int minargs; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 int maxargs; |
69
2159f260ed13
fc-tmsh: all commands internally return values
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
43 int (*func)(); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 } cmdtab[] = { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 {"abbr", 2, 2, cmd_abbr}, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 {"abbw", 3, 3, cmd_abbw}, |
32
ea061975c883
fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
47 {"audio", 2, 2, cmd_audio}, |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 {"check-ffs1", 0, 0, cmd_check_ffs1}, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 {"dieid", 0, 0, cmd_dieid}, |
68
585f63e5bca6
fc-tmsh: etmpkt command renamed to tmpkt, etmpkt retained as alias
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
50 {"etmpkt", 1, 253, cmd_tmpkt}, |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 {"exit", 0, 0, cmd_exit}, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 {"ffs2", 1, 3, cmd_ffs2}, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 {"omr", 2, 2, cmd_omr}, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 {"ping", 0, 2, cmd_ping}, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 {"quit", 0, 0, cmd_exit}, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 {"r8", 1, 2, cmd_r8}, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 {"r16", 1, 2, cmd_r16}, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 {"r32", 1, 2, cmd_r32}, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 {"tgtreset", 0, 0, cmd_tgtreset}, |
68
585f63e5bca6
fc-tmsh: etmpkt command renamed to tmpkt, etmpkt retained as alias
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
60 {"tmpkt", 1, 253, cmd_tmpkt}, |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 {"version", 1, 1, cmd_version}, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 {"w8", 2, 246, cmd_w8}, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 {"w16", 2, 123, cmd_w16}, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 {"w32", 2, 62, cmd_w32}, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 {0, 0, 0, 0} |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 }; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 void |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 dispatch_user_cmd() |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 char *argv[257]; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 char *cp, **ap; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 struct cmdtab *tp; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 for (cp = usercmd; isspace(*cp); cp++) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 ; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 if (!*cp || *cp == '#') |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 return; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 argv[0] = cp; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 while (*cp && !isspace(*cp)) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 cp++; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 if (*cp) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 *cp++ = '\0'; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 for (tp = cmdtab; tp->cmd; tp++) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 if (!strcmp(tp->cmd, argv[0])) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 break; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 if (!tp->func) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 printf("error: no such command\n"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 return; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 for (ap = argv + 1; ; ) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 while (isspace(*cp)) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 cp++; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 if (!*cp || *cp == '#') |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 break; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 if (ap - argv - 1 >= tp->maxargs) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 printf("error: too many arguments\n"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 return; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 if (*cp == '"') { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 *ap++ = ++cp; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 while (*cp && *cp != '"') |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 cp++; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 if (*cp != '"') { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 printf("error: unterminated quoted string\n"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 return; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 *cp++ = '\0'; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 } else { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 *ap++ = cp; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 while (*cp && !isspace(*cp)) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 cp++; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 if (*cp) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 *cp++ = '\0'; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 if (ap - argv - 1 < tp->minargs) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 printf("error: too few arguments\n"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 return; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 *ap = 0; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 tp->func(ap - argv, argv); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 } |
71
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
69
diff
changeset
|
124 |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
69
diff
changeset
|
125 dispatch_oneshot_cmd(argc, argv) |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
69
diff
changeset
|
126 char **argv; |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
69
diff
changeset
|
127 { |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
69
diff
changeset
|
128 struct cmdtab *tp; |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
69
diff
changeset
|
129 |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
69
diff
changeset
|
130 for (tp = cmdtab; tp->cmd; tp++) |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
69
diff
changeset
|
131 if (!strcmp(tp->cmd, argv[0])) |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
69
diff
changeset
|
132 break; |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
69
diff
changeset
|
133 if (!tp->func) { |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
69
diff
changeset
|
134 fprintf(stderr, |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
69
diff
changeset
|
135 "error: \"%s\" is not a valid command\n", argv[0]); |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
69
diff
changeset
|
136 exit(ERROR_USAGE); |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
69
diff
changeset
|
137 } |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
69
diff
changeset
|
138 if (argc - 1 > tp->maxargs) { |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
69
diff
changeset
|
139 fprintf(stderr, "%s: too many arguments\n", tp->cmd); |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
69
diff
changeset
|
140 exit(ERROR_USAGE); |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
69
diff
changeset
|
141 } |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
69
diff
changeset
|
142 if (argc - 1 < tp->minargs) { |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
69
diff
changeset
|
143 fprintf(stderr, "%s: too few arguments\n", tp->cmd); |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
69
diff
changeset
|
144 exit(ERROR_USAGE); |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
69
diff
changeset
|
145 } |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
69
diff
changeset
|
146 return tp->func(argc, argv); |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
69
diff
changeset
|
147 } |