annotate rvinterf/asyncshell/oneshot.c @ 1005:908566db1538

gsm-fw feature tch-reroute: init and config fleshed out
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Sun, 20 Mar 2016 18:50:54 +0000
parents bd873572ef2c
children 93f4fc26b204
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
965
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
2 * This module implements the one-shot command mode of fc-shell.
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
3 */
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
4
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <stdio.h>
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <string.h>
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <strings.h>
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <stdlib.h>
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
9
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
10 extern int cmd_poweroff();
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
11 extern int cmd_sp_oneshot();
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
12 extern int cmd_tgtreset();
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
13
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
14 static struct cmdtab {
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
15 char *cmd;
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
16 int minargs;
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
17 int maxargs;
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
18 int (*func)();
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
19 } cmdtab[] = {
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
20 {"poweroff", 0, 0, cmd_poweroff},
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
21 {"sp", 2, 2, cmd_sp_oneshot},
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
22 {"tgtreset", 0, 0, cmd_tgtreset},
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
23 {0, 0, 0, 0}
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
24 };
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
25
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
26 oneshot_command(argc, argv)
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
27 char **argv;
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
28 {
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
29 struct cmdtab *tp;
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
30
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
31 for (tp = cmdtab; tp->cmd; tp++)
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
32 if (!strcmp(tp->cmd, argv[0]))
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
33 break;
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
34 if (!tp->func) {
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
35 fprintf(stderr,
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
36 "error: \"%s\" is not a valid one-shot command\n",
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
37 argv[0]);
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
38 exit(1);
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
39 }
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
40 if (argc - 1 > tp->maxargs) {
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
41 fprintf(stderr, "%s: too many arguments\n", tp->cmd);
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
42 exit(1);
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
43 }
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
44 if (argc - 1 < tp->minargs) {
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
45 fprintf(stderr, "%s: too few arguments\n", tp->cmd);
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
46 exit(1);
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
47 }
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
48 return tp->func(argc, argv);
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
49 }