annotate lcdtest/dispatch.c @ 22:e9df47110181

lcdtest: added ability to specify chdir on the command line
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 14 Apr 2018 06:15:24 +0000
parents 2e4f27ea7067
children 94521a02c33d
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
19
f3671d3ad953 lcdtest: added cd command to avoid typing long pathnames for show
Mychaela Falconia <falcon@freecalypso.org>
parents: 17
diff changeset
7 extern int cmd_cd();
16
1e94c7d4af03 lcdtest: raw FTDI command fc added
Mychaela Falconia <falcon@freecalypso.org>
parents: 14
diff changeset
8 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
9 extern int cmd_fr();
20
2e4f27ea7067 lcdtest: init-st command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 19
diff changeset
10 extern int cmd_init_st();
13
238a77db4134 lcdtest: read operations implemented, but don't work
Mychaela Falconia <falcon@freecalypso.org>
parents: 12
diff changeset
11 extern int cmd_rd();
238a77db4134 lcdtest: read operations implemented, but don't work
Mychaela Falconia <falcon@freecalypso.org>
parents: 12
diff changeset
12 extern int cmd_ri();
17
43cc53581975 lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
13 extern int cmd_show();
12
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 extern int cmd_wd();
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 extern int cmd_wi();
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 extern int cmd_wr();
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 extern int reset_pulse();
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 cmd_exit()
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 exit(0);
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 }
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 static struct cmdtab {
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 char *cmd;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 int minargs;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 int maxargs;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 int (*func)();
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 } cmdtab[] = {
19
f3671d3ad953 lcdtest: added cd command to avoid typing long pathnames for show
Mychaela Falconia <falcon@freecalypso.org>
parents: 17
diff changeset
31 {"cd", 1, 1, cmd_cd},
12
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 {"exit", 0, 0, cmd_exit},
16
1e94c7d4af03 lcdtest: raw FTDI command fc added
Mychaela Falconia <falcon@freecalypso.org>
parents: 14
diff changeset
33 {"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
34 {"fr", 1, 1, cmd_fr},
20
2e4f27ea7067 lcdtest: init-st command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 19
diff changeset
35 {"init-st", 0, 0, cmd_init_st},
12
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 {"quit", 0, 0, cmd_exit},
13
238a77db4134 lcdtest: read operations implemented, but don't work
Mychaela Falconia <falcon@freecalypso.org>
parents: 12
diff changeset
37 {"rd", 0, 0, cmd_rd},
12
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 {"reset", 0, 0, reset_pulse},
13
238a77db4134 lcdtest: read operations implemented, but don't work
Mychaela Falconia <falcon@freecalypso.org>
parents: 12
diff changeset
39 {"ri", 0, 0, cmd_ri},
17
43cc53581975 lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
40 {"show", 1, 1, cmd_show},
12
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 {"wd", 1, 1, cmd_wd},
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 {"wi", 1, 1, cmd_wi},
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 {"wr", 2, 2, cmd_wr},
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 {0, 0, 0, 0}
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 };
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 dispatch_cmd(cmd)
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 char *cmd;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 {
16
1e94c7d4af03 lcdtest: raw FTDI command fc added
Mychaela Falconia <falcon@freecalypso.org>
parents: 14
diff changeset
50 char *argv[18];
12
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 char *cp, **ap;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 struct cmdtab *tp;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 for (cp = cmd; isspace(*cp); cp++)
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 ;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 if (!*cp || *cp == '#')
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 return(0);
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 argv[0] = cp;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 while (*cp && !isspace(*cp))
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 cp++;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 if (*cp)
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 *cp++ = '\0';
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 for (tp = cmdtab; tp->cmd; tp++)
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 if (!strcmp(tp->cmd, argv[0]))
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 break;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 if (!tp->func) {
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 fprintf(stderr, "error: no such command\n");
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 return(-1);
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 }
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 for (ap = argv + 1; ; ) {
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 while (isspace(*cp))
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 cp++;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 if (!*cp || *cp == '#')
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 break;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 if (ap - argv - 1 >= tp->maxargs) {
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 fprintf(stderr, "error: too many arguments\n");
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 return(-1);
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 *ap++ = cp;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 while (*cp && !isspace(*cp))
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 cp++;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 if (*cp)
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 *cp++ = '\0';
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 }
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 if (ap - argv - 1 < tp->minargs) {
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 fprintf(stderr, "error: too few arguments\n");
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 return(-1);
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 }
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 *ap = 0;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 return tp->func(ap - argv, argv);
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 }