comparison rvinterf/asyncshell/oneshot.c @ 0:e7502631a0f9

initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 Jun 2016 00:13:35 +0000
parents
children d43d82cbfb85
comparison
equal deleted inserted replaced
-1:000000000000 0:e7502631a0f9
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 #include "limits.h"
10
11 extern int cmd_poweroff();
12 extern int cmd_send_oneshot();
13 extern int cmd_sp_oneshot();
14 extern int cmd_tchdl_oneshot();
15 extern int cmd_tgtreset();
16
17 static struct cmdtab {
18 char *cmd;
19 int minargs;
20 int maxargs;
21 int (*func)();
22 } cmdtab[] = {
23 {"poweroff", 0, 0, cmd_poweroff},
24 {"send", 1, MAX_PKT_TO_TARGET, cmd_send_oneshot},
25 {"sp", 2, 2, cmd_sp_oneshot},
26 {"tch-dl", 1, 1, cmd_tchdl_oneshot},
27 {"tgtreset", 0, 0, cmd_tgtreset},
28 {0, 0, 0, 0}
29 };
30
31 oneshot_command(argc, argv)
32 char **argv;
33 {
34 struct cmdtab *tp;
35
36 for (tp = cmdtab; tp->cmd; tp++)
37 if (!strcmp(tp->cmd, argv[0]))
38 break;
39 if (!tp->func) {
40 fprintf(stderr,
41 "error: \"%s\" is not a valid one-shot command\n",
42 argv[0]);
43 exit(1);
44 }
45 if (argc - 1 > tp->maxargs) {
46 fprintf(stderr, "%s: too many arguments\n", tp->cmd);
47 exit(1);
48 }
49 if (argc - 1 < tp->minargs) {
50 fprintf(stderr, "%s: too few arguments\n", tp->cmd);
51 exit(1);
52 }
53 return tp->func(argc, argv);
54 }