FreeCalypso > hg > freecalypso-sw
annotate rvinterf/asyncshell/usercmd.c @ 1034:405b5469abc4 default tip
top README: repository change notice
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 12 Jun 2016 19:06:34 +0000 |
parents | 1178befeda76 |
children |
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 |
874
72d64c172d85
fc-shell: Rx control implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
872
diff
changeset
|
14 extern void cmd_disable(); |
72d64c172d85
fc-shell: Rx control implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
872
diff
changeset
|
15 extern void cmd_enable(); |
889
1b1683cda154
fc-shell: implemented poweroff and tgtreset commands
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
879
diff
changeset
|
16 extern void cmd_poweroff(); |
879
4661b84260a0
fc-shell: AT-over-RVTMUX command sending implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
875
diff
changeset
|
17 extern void cmd_sendat(); |
1013
6eee1e547778
fc-shell: arbitrary send command implemented in interactive mode
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
965
diff
changeset
|
18 extern void cmd_send_interactive(); |
965
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
889
diff
changeset
|
19 extern void cmd_sp_interactive(); |
1027
1178befeda76
fc-shell: tch command framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
1014
diff
changeset
|
20 extern void cmd_tch_dispatch(); |
1014
0511507bf6e7
fc-shell: tch-dl control command implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
1013
diff
changeset
|
21 extern void cmd_tchdl_interactive(); |
889
1b1683cda154
fc-shell: implemented poweroff and tgtreset commands
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
879
diff
changeset
|
22 extern void cmd_tgtreset(); |
874
72d64c172d85
fc-shell: Rx control implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
872
diff
changeset
|
23 |
872
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 void |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 cmd_exit() |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 { |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 tty_cleanup(); |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 exit(0); |
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 |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 static struct cmdtab { |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 char *cmd; |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 void (*func)(); |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 } cmdtab[] = { |
874
72d64c172d85
fc-shell: Rx control implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
872
diff
changeset
|
35 {"disable", cmd_disable}, |
72d64c172d85
fc-shell: Rx control implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
872
diff
changeset
|
36 {"enable", cmd_enable}, |
872
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 {"exit", cmd_exit}, |
889
1b1683cda154
fc-shell: implemented poweroff and tgtreset commands
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
879
diff
changeset
|
38 {"poweroff", cmd_poweroff}, |
872
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 {"quit", cmd_exit}, |
1013
6eee1e547778
fc-shell: arbitrary send command implemented in interactive mode
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
965
diff
changeset
|
40 {"send", cmd_send_interactive}, |
965
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
889
diff
changeset
|
41 {"sp", cmd_sp_interactive}, |
879
4661b84260a0
fc-shell: AT-over-RVTMUX command sending implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
875
diff
changeset
|
42 {"str", cmd_sendat}, |
1027
1178befeda76
fc-shell: tch command framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
1014
diff
changeset
|
43 {"tch", cmd_tch_dispatch}, |
1014
0511507bf6e7
fc-shell: tch-dl control command implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
1013
diff
changeset
|
44 {"tch-dl", cmd_tchdl_interactive}, |
889
1b1683cda154
fc-shell: implemented poweroff and tgtreset commands
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
879
diff
changeset
|
45 {"tgtreset", cmd_tgtreset}, |
872
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 {0, 0} |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 }; |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 void |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 dispatch_user_cmd() |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 { |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 char *cp, *np; |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 struct cmdtab *tp; |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 for (cp = usercmd; isspace(*cp); cp++) |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 ; |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 if (!*cp || *cp == '#') |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 return; |
879
4661b84260a0
fc-shell: AT-over-RVTMUX command sending implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
875
diff
changeset
|
59 if (!strncmp(cp, "AT", 2) || !strncmp(cp, "at", 2)) { |
4661b84260a0
fc-shell: AT-over-RVTMUX command sending implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
875
diff
changeset
|
60 cmd_sendat(cp); |
4661b84260a0
fc-shell: AT-over-RVTMUX command sending implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
875
diff
changeset
|
61 return; |
4661b84260a0
fc-shell: AT-over-RVTMUX command sending implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
875
diff
changeset
|
62 } |
872
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 for (np = cp; *cp && !isspace(*cp); cp++) |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 ; |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 if (*cp) |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 *cp++ = '\0'; |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 for (tp = cmdtab; tp->cmd; tp++) |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 if (!strcmp(tp->cmd, np)) |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 break; |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
70 if (tp->func) |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
71 tp->func(cp); |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
72 else |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
73 printf("error: no such command\n"); |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
74 } |