annotate lcdtest/dispatch.c @ 16:1e94c7d4af03

lcdtest: raw FTDI command fc added
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 07 Apr 2018 17:52:53 +0000
parents 5a602e512b12
children 43cc53581975
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include <ctype.h>
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <stdio.h>
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <string.h>
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 #include <strings.h>
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <stdlib.h>
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
16
1e94c7d4af03 lcdtest: raw FTDI command fc added
Mychaela Falconia <falcon@freecalypso.org>
parents: 14
diff changeset
7 extern int cmd_fc();
14
5a602e512b12 lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
8 extern int cmd_fr();
13
238a77db4134 lcdtest: read operations implemented, but don't work
Mychaela Falconia <falcon@freecalypso.org>
parents: 12
diff changeset
9 extern int cmd_rd();
238a77db4134 lcdtest: read operations implemented, but don't work
Mychaela Falconia <falcon@freecalypso.org>
parents: 12
diff changeset
10 extern int cmd_ri();
12
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 extern int cmd_wd();
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 extern int cmd_wi();
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 extern int cmd_wr();
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 extern int reset_pulse();
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 cmd_exit()
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 {
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 exit(0);
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 }
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 static struct cmdtab {
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 char *cmd;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 int minargs;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 int maxargs;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 int (*func)();
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 } cmdtab[] = {
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 {"exit", 0, 0, cmd_exit},
16
1e94c7d4af03 lcdtest: raw FTDI command fc added
Mychaela Falconia <falcon@freecalypso.org>
parents: 14
diff changeset
29 {"fc", 1, 16, cmd_fc},
14
5a602e512b12 lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
30 {"fr", 1, 1, cmd_fr},
12
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 {"quit", 0, 0, cmd_exit},
13
238a77db4134 lcdtest: read operations implemented, but don't work
Mychaela Falconia <falcon@freecalypso.org>
parents: 12
diff changeset
32 {"rd", 0, 0, cmd_rd},
12
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 {"reset", 0, 0, reset_pulse},
13
238a77db4134 lcdtest: read operations implemented, but don't work
Mychaela Falconia <falcon@freecalypso.org>
parents: 12
diff changeset
34 {"ri", 0, 0, cmd_ri},
12
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 {"wd", 1, 1, cmd_wd},
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 {"wi", 1, 1, cmd_wi},
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 {"wr", 2, 2, cmd_wr},
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 {0, 0, 0, 0}
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 };
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 dispatch_cmd(cmd)
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 char *cmd;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 {
16
1e94c7d4af03 lcdtest: raw FTDI command fc added
Mychaela Falconia <falcon@freecalypso.org>
parents: 14
diff changeset
44 char *argv[18];
12
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 char *cp, **ap;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 struct cmdtab *tp;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 for (cp = cmd; isspace(*cp); cp++)
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 ;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 if (!*cp || *cp == '#')
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 return(0);
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 argv[0] = cp;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 while (*cp && !isspace(*cp))
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 cp++;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 if (*cp)
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 *cp++ = '\0';
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 for (tp = cmdtab; tp->cmd; tp++)
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 if (!strcmp(tp->cmd, argv[0]))
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 break;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 if (!tp->func) {
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 fprintf(stderr, "error: no such command\n");
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 return(-1);
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 }
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 for (ap = argv + 1; ; ) {
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 while (isspace(*cp))
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 cp++;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 if (!*cp || *cp == '#')
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 break;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 if (ap - argv - 1 >= tp->maxargs) {
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 fprintf(stderr, "error: too many arguments\n");
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 return(-1);
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 }
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 *ap++ = cp;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 while (*cp && !isspace(*cp))
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 cp++;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 if (*cp)
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 *cp++ = '\0';
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 }
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 if (ap - argv - 1 < tp->minargs) {
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 fprintf(stderr, "error: too few arguments\n");
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 return(-1);
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 }
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 *ap = 0;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 return tp->func(ap - argv, argv);
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 }