comparison rvinterf/asyncshell/oneshot.c @ 965:bd873572ef2c

fc-shell: one-shot command mode implemented
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Sat, 07 Nov 2015 00:00:46 +0000
parents
children 93f4fc26b204
comparison
equal deleted inserted replaced
964:373af5f74e39 965:bd873572ef2c
1 /*
2 * This module implements the one-shot command mode of fc-shell.
3 */
4
5 #include <stdio.h>
6 #include <string.h>
7 #include <strings.h>
8 #include <stdlib.h>
9
10 extern int cmd_poweroff();
11 extern int cmd_sp_oneshot();
12 extern int cmd_tgtreset();
13
14 static struct cmdtab {
15 char *cmd;
16 int minargs;
17 int maxargs;
18 int (*func)();
19 } cmdtab[] = {
20 {"poweroff", 0, 0, cmd_poweroff},
21 {"sp", 2, 2, cmd_sp_oneshot},
22 {"tgtreset", 0, 0, cmd_tgtreset},
23 {0, 0, 0, 0}
24 };
25
26 oneshot_command(argc, argv)
27 char **argv;
28 {
29 struct cmdtab *tp;
30
31 for (tp = cmdtab; tp->cmd; tp++)
32 if (!strcmp(tp->cmd, argv[0]))
33 break;
34 if (!tp->func) {
35 fprintf(stderr,
36 "error: \"%s\" is not a valid one-shot command\n",
37 argv[0]);
38 exit(1);
39 }
40 if (argc - 1 > tp->maxargs) {
41 fprintf(stderr, "%s: too many arguments\n", tp->cmd);
42 exit(1);
43 }
44 if (argc - 1 < tp->minargs) {
45 fprintf(stderr, "%s: too few arguments\n", tp->cmd);
46 exit(1);
47 }
48 return tp->func(argc, argv);
49 }