FreeCalypso > hg > fc-pcm-if
annotate sw/mcsi-rxtx/usercmd.c @ 11:e93a11f44e6f
fc-mcsi-rxtx: implement basic Tx
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 28 Oct 2024 06:34:42 +0000 |
parents | c1d9b5d128f5 |
children | 23555b9a1c20 |
rev | line source |
---|---|
7
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements fc-mcsi-rxtx user command dispatch. |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <ctype.h> |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <string.h> |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <strings.h> |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdlib.h> |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 extern char usercmd[]; |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
10
c1d9b5d128f5
fc-mcsi-rxtx: implement print-rx command
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
14 extern void cmd_print_rx(); |
c1d9b5d128f5
fc-mcsi-rxtx: implement print-rx command
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
15 |
7
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 static void |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 cmd_exit() |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 { |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 tty_cleanup(); |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 exit(0); |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 } |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 static struct cmdtab { |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 char *cmd; |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 int minargs; |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 int maxargs; |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 void (*func)(); |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 } cmdtab[] = { |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 {"exit", 0, 0, cmd_exit}, |
10
c1d9b5d128f5
fc-mcsi-rxtx: implement print-rx command
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
30 {"print-rx", 0, 0, cmd_print_rx}, |
7
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 {"quit", 0, 0, cmd_exit}, |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 {0, 0, 0, 0} |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 }; |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 void |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 dispatch_user_cmd() |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 { |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 char *argv[10]; |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 char *cp, **ap; |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 struct cmdtab *tp; |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 for (cp = usercmd; isspace(*cp); cp++) |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 ; |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 if (!*cp || *cp == '#') |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 return; |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 argv[0] = cp; |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 while (*cp && !isspace(*cp)) |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 cp++; |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 if (*cp) |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 *cp++ = '\0'; |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 for (tp = cmdtab; tp->cmd; tp++) |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 if (!strcmp(tp->cmd, argv[0])) |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 break; |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 if (!tp->func) { |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 printf("error: no such command\n"); |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 return; |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 } |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 for (ap = argv + 1; ; ) { |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 while (isspace(*cp)) |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 cp++; |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 if (!*cp || *cp == '#') |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 break; |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 if (ap - argv - 1 >= tp->maxargs) { |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 printf("error: too many arguments\n"); |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 return; |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 } |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 if (*cp == '"') { |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 *ap++ = ++cp; |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 while (*cp && *cp != '"') |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 cp++; |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 if (*cp != '"') { |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 printf("error: unterminated quoted string\n"); |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 return; |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 } |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 *cp++ = '\0'; |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 } else { |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 *ap++ = cp; |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 while (*cp && !isspace(*cp)) |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 cp++; |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 if (*cp) |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 *cp++ = '\0'; |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 } |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 } |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 if (ap - argv - 1 < tp->minargs) { |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 printf("error: too few arguments\n"); |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 return; |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 } |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 *ap = 0; |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 tp->func(ap - argv, argv); |
8a386263dd51
fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 } |