annotate rvinterf/asyncshell/usercmd.c @ 872:5e46679bdb6a

fc-shell skeleton created
author Space Falcon <falcon@ivan.Harhan.ORG>
date Sat, 30 May 2015 06:42:32 +0000
parents
children 72d64c172d85
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
872
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
2 * This module implements interactive fc-shell command dispatch.
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
3 */
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
4
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <sys/types.h>
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <ctype.h>
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdio.h>
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <string.h>
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <strings.h>
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <stdlib.h>
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
11
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
12 extern char usercmd[];
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
13
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
14 void
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
15 cmd_exit()
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
16 {
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
17 tty_cleanup();
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
18 exit(0);
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
19 }
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
20
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
21 static struct cmdtab {
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
22 char *cmd;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
23 void (*func)();
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
24 } cmdtab[] = {
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
25 {"exit", cmd_exit},
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
26 {"quit", cmd_exit},
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
27 {0, 0}
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
28 };
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
29
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
30 void
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
31 dispatch_user_cmd()
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
32 {
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
33 char *cp, *np;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
34 struct cmdtab *tp;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
35
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
36 for (cp = usercmd; isspace(*cp); cp++)
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
37 ;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
38 if (!*cp || *cp == '#')
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
39 return;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
40 for (np = cp; *cp && !isspace(*cp); cp++)
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
41 ;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
42 if (*cp)
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
43 *cp++ = '\0';
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
44 for (tp = cmdtab; tp->cmd; tp++)
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
45 if (!strcmp(tp->cmd, np))
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
46 break;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
47 if (tp->func)
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
48 tp->func(cp);
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
49 else
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
50 printf("error: no such command\n");
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
51 }