1 /* $NetBSD: cmd.c,v 1.1 2005/12/29 15:20:09 tsutsui Exp $ */
4 * Copyright (c) 2004 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <lib/libsa/stand.h>
33 #include <lib/libkern/libkern.h>
40 int (*func
)(int, char**, int);
42 { "batch", cmd_batch
},
45 { "bootux", cmd_boot_ux
},
46 { "loadbin", cmd_load_binary
},
48 { "reboot", cmd_reboot
},
52 { "disklabel", cmd_disklabel
},
54 { "log_save", cmd_log_save
},
59 { "ks", cmd_kbd_scancode
},
60 { "ether_test", cmd_ether_test
},
61 { "ga_test", cmd_ga_test
},
62 { 0, 0 } /* terminate */
66 cmd_exec(const char *buf
)
68 char cmdbuf
[CMDBUF_SIZE
];
69 char *argp
[CMDARG_MAX
];
75 strncpy(cmdbuf
, buf
, CMDBUF_SIZE
);
76 printf("%s\n", cmdbuf
);
79 for (cmd
= cmdtab
; cmd
->name
; cmd
++) {
80 for (q
= cmdbuf
, p
= cmd
->name
; *p
; p
++, q
++) {
84 if (*p
== 0 && (*q
== '\0' || *q
== ' '))
87 printf("***ERROR*** %s\n", cmdbuf
);
98 for (i
= 0; (i
< CMDBUF_SIZE
) && (argc
< CMDARG_MAX
); i
++, p
++) {
102 } else if (sep
&& (*p
!= ' ' || *p
== '\0')) {
109 cmd
->func (argc
, argp
, 1);
113 cmd_batch(int argc
, char *argp
[], int interactive
)
115 struct cmd_batch_tab
*p
;
116 char *args
[CMDARG_MAX
];
120 for (p
= cmd_batch_tab
; p
->func
; p
++) {
121 for (i
= 0; i
< p
->argc
; i
++)
122 args
[i
+ 1] = p
->arg
[i
];
124 if (p
->func(p
->argc
+ 1, args
, interactive
)) {
125 printf("batch aborted.\n");
134 cmd_help(int argc
, char *argp
[], int interactive
)
139 for (cmd
= cmdtab
; cmd
->name
; cmd
++)
140 printf("%s ", cmd
->name
);