annotate rvinterf/etm/usercmd.c @ 189:a95d253ef952

fc-tmsh: some basic tmcore commands implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 25 Nov 2013 03:10:41 +0000
parents 13a0348ffce4
children 707aa640b2dc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
182
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This module implements fc-tmsh user command dispatch.
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 */
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <sys/types.h>
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <ctype.h>
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdio.h>
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <string.h>
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <strings.h>
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <stdlib.h>
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 extern char usercmd[];
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13
189
a95d253ef952 fc-tmsh: some basic tmcore commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
14 extern void cmd_dieid();
182
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 extern void cmd_etmpkt();
189
a95d253ef952 fc-tmsh: some basic tmcore commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
16 extern void cmd_ping();
a95d253ef952 fc-tmsh: some basic tmcore commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
17 extern void cmd_r8();
a95d253ef952 fc-tmsh: some basic tmcore commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
18 extern void cmd_r16();
a95d253ef952 fc-tmsh: some basic tmcore commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
19 extern void cmd_r32();
a95d253ef952 fc-tmsh: some basic tmcore commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
20 extern void cmd_tgtreset();
a95d253ef952 fc-tmsh: some basic tmcore commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
21 extern void cmd_version();
182
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 void
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 cmd_exit()
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 {
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 tty_cleanup();
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 exit(0);
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 }
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 static struct cmdtab {
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 char *cmd;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 int minargs;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 int maxargs;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 void (*func)();
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 } cmdtab[] = {
189
a95d253ef952 fc-tmsh: some basic tmcore commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
36 {"dieid", 0, 0, cmd_dieid},
182
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 {"etmpkt", 1, 253, cmd_etmpkt},
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 {"exit", 0, 0, cmd_exit},
189
a95d253ef952 fc-tmsh: some basic tmcore commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
39 {"ping", 0, 2, cmd_ping},
182
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 {"quit", 0, 0, cmd_exit},
189
a95d253ef952 fc-tmsh: some basic tmcore commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
41 {"r8", 1, 2, cmd_r8},
a95d253ef952 fc-tmsh: some basic tmcore commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
42 {"r16", 1, 2, cmd_r16},
a95d253ef952 fc-tmsh: some basic tmcore commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
43 {"r32", 1, 2, cmd_r32},
a95d253ef952 fc-tmsh: some basic tmcore commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
44 {"tgtreset", 0, 0, cmd_tgtreset},
a95d253ef952 fc-tmsh: some basic tmcore commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
45 {"version", 1, 1, cmd_version},
182
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 {0, 0, 0, 0}
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 };
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 void
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 dispatch_user_cmd()
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 {
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 char *argv[257];
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 char *cp, **ap;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 struct cmdtab *tp;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 for (cp = usercmd; isspace(*cp); cp++)
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 ;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 if (!*cp || *cp == '#')
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 return;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 argv[0] = cp;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 while (*cp && !isspace(*cp))
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 cp++;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 if (*cp)
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 *cp++ = '\0';
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 for (tp = cmdtab; tp->cmd; tp++)
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 if (!strcmp(tp->cmd, argv[0]))
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 break;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 if (!tp->func) {
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 printf("error: no such command\n");
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 return;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 }
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 for (ap = argv + 1; ; ) {
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 while (isspace(*cp))
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 cp++;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 if (!*cp || *cp == '#')
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 break;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 if (ap - argv - 1 >= tp->maxargs) {
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 printf("error: too many arguments\n");
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 return;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 }
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81 *ap++ = cp;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 while (*cp && !isspace(*cp))
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83 cp++;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 if (*cp)
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 *cp++ = '\0';
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 }
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87 if (ap - argv - 1 < tp->minargs) {
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 printf("error: too few arguments\n");
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89 return;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
90 }
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
91 *ap = 0;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92 tp->func(ap - argv, argv);
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
93 }