annotate lcdtest/dispatch.c @ 12:5eaf832d57d0

lcdtest program started, skeleton compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 06 Apr 2018 06:15:11 +0000
parents
children 238a77db4134
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
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 extern int cmd_wd();
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 extern int cmd_wi();
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 extern int cmd_wr();
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 extern int reset_pulse();
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 cmd_exit()
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 exit(0);
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
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 static struct cmdtab {
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 char *cmd;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 int minargs;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 int maxargs;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 int (*func)();
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 } cmdtab[] = {
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 {"exit", 0, 0, cmd_exit},
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 {"quit", 0, 0, cmd_exit},
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 {"reset", 0, 0, reset_pulse},
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 {"wd", 1, 1, cmd_wd},
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 {"wi", 1, 1, cmd_wi},
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 {"wr", 2, 2, cmd_wr},
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 {0, 0, 0, 0}
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 };
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 dispatch_cmd(cmd)
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 char *cmd;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 {
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 char *argv[10];
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 char *cp, **ap;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 struct cmdtab *tp;
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 for (cp = cmd; isspace(*cp); cp++)
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 ;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 if (!*cp || *cp == '#')
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 return(0);
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 argv[0] = cp;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 while (*cp && !isspace(*cp))
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 cp++;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 if (*cp)
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 *cp++ = '\0';
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 for (tp = cmdtab; tp->cmd; tp++)
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 if (!strcmp(tp->cmd, argv[0]))
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 break;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 if (!tp->func) {
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 fprintf(stderr, "error: no such command\n");
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 return(-1);
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 for (ap = argv + 1; ; ) {
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 while (isspace(*cp))
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 cp++;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 if (!*cp || *cp == '#')
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 break;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 if (ap - argv - 1 >= tp->maxargs) {
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 fprintf(stderr, "error: too many arguments\n");
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 return(-1);
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 *ap++ = cp;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 while (*cp && !isspace(*cp))
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 cp++;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 if (*cp)
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 *cp++ = '\0';
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 }
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 if (ap - argv - 1 < tp->minargs) {
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 fprintf(stderr, "error: too few arguments\n");
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 return(-1);
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 }
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 *ap = 0;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 return tp->func(ap - argv, argv);
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 }