annotate sw/mcsi-rxtx/usercmd.c @ 12:23555b9a1c20

fc-mcsi-rxtx: implement pcm-fill command
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 28 Oct 2024 06:52:33 +0000
parents c1d9b5d128f5
children 315428573a25
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
12
23555b9a1c20 fc-mcsi-rxtx: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
14 extern void cmd_pcm_fill();
10
c1d9b5d128f5 fc-mcsi-rxtx: implement print-rx command
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
15 extern void cmd_print_rx();
c1d9b5d128f5 fc-mcsi-rxtx: implement print-rx command
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
16
7
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 static void
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 cmd_exit()
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 {
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 tty_cleanup();
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 exit(0);
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
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 static struct cmdtab {
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 char *cmd;
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 int minargs;
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 int maxargs;
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 void (*func)();
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 } cmdtab[] = {
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 {"exit", 0, 0, cmd_exit},
12
23555b9a1c20 fc-mcsi-rxtx: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
31 {"pcm-fill", 0, 1, cmd_pcm_fill},
10
c1d9b5d128f5 fc-mcsi-rxtx: implement print-rx command
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
32 {"print-rx", 0, 0, cmd_print_rx},
7
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 {"quit", 0, 0, cmd_exit},
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 {0, 0, 0, 0}
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 };
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 void
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 dispatch_user_cmd()
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 {
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 char *argv[10];
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 char *cp, **ap;
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 struct cmdtab *tp;
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 for (cp = usercmd; isspace(*cp); cp++)
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 ;
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 if (!*cp || *cp == '#')
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 return;
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 argv[0] = cp;
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 while (*cp && !isspace(*cp))
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 cp++;
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 if (*cp)
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 *cp++ = '\0';
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 for (tp = cmdtab; tp->cmd; tp++)
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 if (!strcmp(tp->cmd, argv[0]))
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 break;
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 if (!tp->func) {
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 printf("error: no such command\n");
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 return;
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 }
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 for (ap = argv + 1; ; ) {
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 while (isspace(*cp))
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 cp++;
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 if (!*cp || *cp == '#')
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 break;
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 if (ap - argv - 1 >= tp->maxargs) {
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 printf("error: too many arguments\n");
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 return;
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 }
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 if (*cp == '"') {
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 *ap++ = ++cp;
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 while (*cp && *cp != '"')
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 cp++;
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 if (*cp != '"') {
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 printf("error: unterminated quoted string\n");
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 return;
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 }
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 *cp++ = '\0';
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 } else {
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 *ap++ = cp;
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 while (*cp && !isspace(*cp))
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 cp++;
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 if (*cp)
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 *cp++ = '\0';
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 }
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 }
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 if (ap - argv - 1 < tp->minargs) {
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 printf("error: too few arguments\n");
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 return;
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 }
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 *ap = 0;
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 tp->func(ap - argv, argv);
8a386263dd51 fc-mcsi-rxtx skeleton put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 }