commands.c revision 1.2.2.2 1 1.2.2.2 simonb /* $NetBSD: commands.c,v 1.2.2.2 2006/04/22 11:37:38 simonb Exp $ */
2 1.2.2.2 simonb
3 1.2.2.2 simonb /*-
4 1.2.2.2 simonb * Copyright (c) 1998 Michael Smith <msmith (at) freebsd.org>
5 1.2.2.2 simonb * All rights reserved.
6 1.2.2.2 simonb *
7 1.2.2.2 simonb * Redistribution and use in source and binary forms, with or without
8 1.2.2.2 simonb * modification, are permitted provided that the following conditions
9 1.2.2.2 simonb * are met:
10 1.2.2.2 simonb * 1. Redistributions of source code must retain the above copyright
11 1.2.2.2 simonb * notice, this list of conditions and the following disclaimer.
12 1.2.2.2 simonb * 2. Redistributions in binary form must reproduce the above copyright
13 1.2.2.2 simonb * notice, this list of conditions and the following disclaimer in the
14 1.2.2.2 simonb * documentation and/or other materials provided with the distribution.
15 1.2.2.2 simonb *
16 1.2.2.2 simonb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 1.2.2.2 simonb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.2.2.2 simonb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.2.2.2 simonb * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 1.2.2.2 simonb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.2.2.2 simonb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.2.2.2 simonb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.2.2.2 simonb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.2.2.2 simonb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.2.2.2 simonb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.2.2.2 simonb * SUCH DAMAGE.
27 1.2.2.2 simonb */
28 1.2.2.2 simonb
29 1.2.2.2 simonb #include <sys/cdefs.h>
30 1.2.2.2 simonb
31 1.2.2.2 simonb #include <lib/libsa/stand.h>
32 1.2.2.2 simonb #include <lib/libkern/libkern.h>
33 1.2.2.2 simonb
34 1.2.2.2 simonb #include "bootstrap.h"
35 1.2.2.2 simonb
36 1.2.2.2 simonb char *command_errmsg;
37 1.2.2.2 simonb char command_errbuf[256]; /* XXX should have procedural interface for setting, size limit? */
38 1.2.2.2 simonb
39 1.2.2.2 simonb static int page_file(char *filename);
40 1.2.2.2 simonb
41 1.2.2.2 simonb /*
42 1.2.2.2 simonb * Help is read from a formatted text file.
43 1.2.2.2 simonb *
44 1.2.2.2 simonb * Entries in the file are formatted as
45 1.2.2.2 simonb
46 1.2.2.2 simonb # Ttopic [Ssubtopic] Ddescription
47 1.2.2.2 simonb help
48 1.2.2.2 simonb text
49 1.2.2.2 simonb here
50 1.2.2.2 simonb #
51 1.2.2.2 simonb
52 1.2.2.2 simonb *
53 1.2.2.2 simonb * Note that for code simplicity's sake, the above format must be followed
54 1.2.2.2 simonb * exactly.
55 1.2.2.2 simonb *
56 1.2.2.2 simonb * Subtopic entries must immediately follow the topic (this is used to
57 1.2.2.2 simonb * produce the listing of subtopics).
58 1.2.2.2 simonb *
59 1.2.2.2 simonb * If no argument(s) are supplied by the user, the help for 'help' is displayed.
60 1.2.2.2 simonb */
61 1.2.2.2 simonb
62 1.2.2.2 simonb static int
63 1.2.2.2 simonb help_getnext(int fd, char **topic, char **subtopic, char **desc)
64 1.2.2.2 simonb {
65 1.2.2.2 simonb char line[81], *cp, *ep;
66 1.2.2.2 simonb
67 1.2.2.2 simonb for (;;) {
68 1.2.2.2 simonb if (fgetstr(line, 80, fd) < 0)
69 1.2.2.2 simonb return(0);
70 1.2.2.2 simonb
71 1.2.2.2 simonb if ((strlen(line) < 3) || (line[0] != '#') || (line[1] != ' '))
72 1.2.2.2 simonb continue;
73 1.2.2.2 simonb
74 1.2.2.2 simonb *topic = *subtopic = *desc = NULL;
75 1.2.2.2 simonb cp = line + 2;
76 1.2.2.2 simonb while((cp != NULL) && (*cp != 0)) {
77 1.2.2.2 simonb ep = strchr(cp, ' ');
78 1.2.2.2 simonb if ((*cp == 'T') && (*topic == NULL)) {
79 1.2.2.2 simonb if (ep != NULL)
80 1.2.2.2 simonb *ep++ = 0;
81 1.2.2.2 simonb *topic = strdup(cp + 1);
82 1.2.2.2 simonb } else if ((*cp == 'S') && (*subtopic == NULL)) {
83 1.2.2.2 simonb if (ep != NULL)
84 1.2.2.2 simonb *ep++ = 0;
85 1.2.2.2 simonb *subtopic = strdup(cp + 1);
86 1.2.2.2 simonb } else if (*cp == 'D') {
87 1.2.2.2 simonb *desc = strdup(cp + 1);
88 1.2.2.2 simonb ep = NULL;
89 1.2.2.2 simonb }
90 1.2.2.2 simonb cp = ep;
91 1.2.2.2 simonb }
92 1.2.2.2 simonb if (*topic == NULL) {
93 1.2.2.2 simonb if (*subtopic != NULL)
94 1.2.2.2 simonb free(*subtopic);
95 1.2.2.2 simonb if (*desc != NULL)
96 1.2.2.2 simonb free(*desc);
97 1.2.2.2 simonb continue;
98 1.2.2.2 simonb }
99 1.2.2.2 simonb return(1);
100 1.2.2.2 simonb }
101 1.2.2.2 simonb }
102 1.2.2.2 simonb
103 1.2.2.2 simonb static int
104 1.2.2.2 simonb help_emitsummary(char *topic, char *subtopic, char *desc)
105 1.2.2.2 simonb {
106 1.2.2.2 simonb int i;
107 1.2.2.2 simonb
108 1.2.2.2 simonb pager_output(" ");
109 1.2.2.2 simonb pager_output(topic);
110 1.2.2.2 simonb i = strlen(topic);
111 1.2.2.2 simonb if (subtopic != NULL) {
112 1.2.2.2 simonb pager_output(" ");
113 1.2.2.2 simonb pager_output(subtopic);
114 1.2.2.2 simonb i += strlen(subtopic) + 1;
115 1.2.2.2 simonb }
116 1.2.2.2 simonb if (desc != NULL) {
117 1.2.2.2 simonb do {
118 1.2.2.2 simonb pager_output(" ");
119 1.2.2.2 simonb } while (i++ < 30);
120 1.2.2.2 simonb pager_output(desc);
121 1.2.2.2 simonb }
122 1.2.2.2 simonb return (pager_output("\n"));
123 1.2.2.2 simonb }
124 1.2.2.2 simonb
125 1.2.2.2 simonb
126 1.2.2.2 simonb int
127 1.2.2.2 simonb command_help(int argc, char *argv[])
128 1.2.2.2 simonb {
129 1.2.2.2 simonb char buf[81]; /* XXX buffer size? */
130 1.2.2.2 simonb int hfd, matched, doindex;
131 1.2.2.2 simonb char *topic, *subtopic, *t, *s, *d;
132 1.2.2.2 simonb
133 1.2.2.2 simonb /* page the help text from our load path */
134 1.2.2.2 simonb sprintf(buf, "%s/boot/loader.help", getenv("loaddev"));
135 1.2.2.2 simonb if ((hfd = open(buf, O_RDONLY)) < 0) {
136 1.2.2.2 simonb printf("Verbose help not available, use '?' to list commands\n");
137 1.2.2.2 simonb return(CMD_OK);
138 1.2.2.2 simonb }
139 1.2.2.2 simonb
140 1.2.2.2 simonb /* pick up request from arguments */
141 1.2.2.2 simonb topic = subtopic = NULL;
142 1.2.2.2 simonb switch(argc) {
143 1.2.2.2 simonb case 3:
144 1.2.2.2 simonb subtopic = strdup(argv[2]);
145 1.2.2.2 simonb case 2:
146 1.2.2.2 simonb topic = strdup(argv[1]);
147 1.2.2.2 simonb break;
148 1.2.2.2 simonb case 1:
149 1.2.2.2 simonb topic = strdup("help");
150 1.2.2.2 simonb break;
151 1.2.2.2 simonb default:
152 1.2.2.2 simonb command_errmsg = "usage is 'help <topic> [<subtopic>]";
153 1.2.2.2 simonb return(CMD_ERROR);
154 1.2.2.2 simonb }
155 1.2.2.2 simonb
156 1.2.2.2 simonb /* magic "index" keyword */
157 1.2.2.2 simonb doindex = !strcmp(topic, "index");
158 1.2.2.2 simonb matched = doindex;
159 1.2.2.2 simonb
160 1.2.2.2 simonb /* Scan the helpfile looking for help matching the request */
161 1.2.2.2 simonb pager_open();
162 1.2.2.2 simonb while(help_getnext(hfd, &t, &s, &d)) {
163 1.2.2.2 simonb
164 1.2.2.2 simonb if (doindex) { /* dink around formatting */
165 1.2.2.2 simonb if (help_emitsummary(t, s, d))
166 1.2.2.2 simonb break;
167 1.2.2.2 simonb
168 1.2.2.2 simonb } else if (strcmp(topic, t)) {
169 1.2.2.2 simonb /* topic mismatch */
170 1.2.2.2 simonb if(matched) /* nothing more on this topic, stop scanning */
171 1.2.2.2 simonb break;
172 1.2.2.2 simonb
173 1.2.2.2 simonb } else {
174 1.2.2.2 simonb /* topic matched */
175 1.2.2.2 simonb matched = 1;
176 1.2.2.2 simonb if (((subtopic == NULL) && (s == NULL)) ||
177 1.2.2.2 simonb ((subtopic != NULL) && (s != NULL) && !strcmp(subtopic, s))) {
178 1.2.2.2 simonb /* exact match, print text */
179 1.2.2.2 simonb while((fgetstr(buf, 80, hfd) >= 0) && (buf[0] != '#')) {
180 1.2.2.2 simonb if (pager_output(buf))
181 1.2.2.2 simonb break;
182 1.2.2.2 simonb if (pager_output("\n"))
183 1.2.2.2 simonb break;
184 1.2.2.2 simonb }
185 1.2.2.2 simonb } else if ((subtopic == NULL) && (s != NULL)) {
186 1.2.2.2 simonb /* topic match, list subtopics */
187 1.2.2.2 simonb if (help_emitsummary(t, s, d))
188 1.2.2.2 simonb break;
189 1.2.2.2 simonb }
190 1.2.2.2 simonb }
191 1.2.2.2 simonb free(t);
192 1.2.2.2 simonb free(s);
193 1.2.2.2 simonb free(d);
194 1.2.2.2 simonb }
195 1.2.2.2 simonb pager_close();
196 1.2.2.2 simonb close(hfd);
197 1.2.2.2 simonb if (!matched) {
198 1.2.2.2 simonb sprintf(command_errbuf, "no help available for '%s'", topic);
199 1.2.2.2 simonb free(topic);
200 1.2.2.2 simonb if (subtopic)
201 1.2.2.2 simonb free(subtopic);
202 1.2.2.2 simonb return(CMD_ERROR);
203 1.2.2.2 simonb }
204 1.2.2.2 simonb free(topic);
205 1.2.2.2 simonb if (subtopic)
206 1.2.2.2 simonb free(subtopic);
207 1.2.2.2 simonb return(CMD_OK);
208 1.2.2.2 simonb }
209 1.2.2.2 simonb
210 1.2.2.2 simonb
211 1.2.2.2 simonb int
212 1.2.2.2 simonb command_commandlist(int argc, char *argv[])
213 1.2.2.2 simonb {
214 1.2.2.2 simonb struct bootblk_command *cmdp;
215 1.2.2.2 simonb int res;
216 1.2.2.2 simonb char name[20];
217 1.2.2.2 simonb int i;
218 1.2.2.2 simonb
219 1.2.2.2 simonb res = 0;
220 1.2.2.2 simonb pager_open();
221 1.2.2.2 simonb res = pager_output("Available commands:\n");
222 1.2.2.2 simonb
223 1.2.2.2 simonb for (i = 0, cmdp = commands; (cmdp->c_name != NULL) && (cmdp->c_desc != NULL ); i++, cmdp = commands + i) {
224 1.2.2.2 simonb if (res)
225 1.2.2.2 simonb break;
226 1.2.2.2 simonb if ((cmdp->c_name != NULL) && (cmdp->c_desc != NULL)) {
227 1.2.2.2 simonb sprintf(name, " %s ", cmdp->c_name);
228 1.2.2.2 simonb pager_output(name);
229 1.2.2.2 simonb pager_output(cmdp->c_desc);
230 1.2.2.2 simonb res = pager_output("\n");
231 1.2.2.2 simonb }
232 1.2.2.2 simonb }
233 1.2.2.2 simonb pager_close();
234 1.2.2.2 simonb return(CMD_OK);
235 1.2.2.2 simonb }
236 1.2.2.2 simonb
237 1.2.2.2 simonb /*
238 1.2.2.2 simonb * XXX set/show should become set/echo if we have variable
239 1.2.2.2 simonb * substitution happening.
240 1.2.2.2 simonb */
241 1.2.2.2 simonb
242 1.2.2.2 simonb int
243 1.2.2.2 simonb command_show(int argc, char *argv[])
244 1.2.2.2 simonb {
245 1.2.2.2 simonb struct env_var *ev;
246 1.2.2.2 simonb char *cp;
247 1.2.2.2 simonb
248 1.2.2.2 simonb if (argc < 2) {
249 1.2.2.2 simonb /*
250 1.2.2.2 simonb * With no arguments, print everything.
251 1.2.2.2 simonb */
252 1.2.2.2 simonb pager_open();
253 1.2.2.2 simonb for (ev = environ; ev != NULL; ev = ev->ev_next) {
254 1.2.2.2 simonb pager_output(ev->ev_name);
255 1.2.2.2 simonb cp = getenv(ev->ev_name);
256 1.2.2.2 simonb if (cp != NULL) {
257 1.2.2.2 simonb pager_output("=");
258 1.2.2.2 simonb pager_output(cp);
259 1.2.2.2 simonb }
260 1.2.2.2 simonb if (pager_output("\n"))
261 1.2.2.2 simonb break;
262 1.2.2.2 simonb }
263 1.2.2.2 simonb pager_close();
264 1.2.2.2 simonb } else {
265 1.2.2.2 simonb if ((cp = getenv(argv[1])) != NULL) {
266 1.2.2.2 simonb printf("%s\n", cp);
267 1.2.2.2 simonb } else {
268 1.2.2.2 simonb sprintf(command_errbuf, "variable '%s' not found", argv[1]);
269 1.2.2.2 simonb return(CMD_ERROR);
270 1.2.2.2 simonb }
271 1.2.2.2 simonb }
272 1.2.2.2 simonb return(CMD_OK);
273 1.2.2.2 simonb }
274 1.2.2.2 simonb
275 1.2.2.2 simonb
276 1.2.2.2 simonb int
277 1.2.2.2 simonb command_set(int argc, char *argv[])
278 1.2.2.2 simonb {
279 1.2.2.2 simonb int err;
280 1.2.2.2 simonb
281 1.2.2.2 simonb if (argc != 2) {
282 1.2.2.2 simonb command_errmsg = "wrong number of arguments";
283 1.2.2.2 simonb return(CMD_ERROR);
284 1.2.2.2 simonb } else {
285 1.2.2.2 simonb if ((err = putenv(argv[1])) != 0) {
286 1.2.2.2 simonb command_errmsg = strerror(err);
287 1.2.2.2 simonb return(CMD_ERROR);
288 1.2.2.2 simonb }
289 1.2.2.2 simonb }
290 1.2.2.2 simonb return(CMD_OK);
291 1.2.2.2 simonb }
292 1.2.2.2 simonb
293 1.2.2.2 simonb
294 1.2.2.2 simonb int
295 1.2.2.2 simonb command_unset(int argc, char *argv[])
296 1.2.2.2 simonb {
297 1.2.2.2 simonb int err;
298 1.2.2.2 simonb
299 1.2.2.2 simonb if (argc != 2) {
300 1.2.2.2 simonb command_errmsg = "wrong number of arguments";
301 1.2.2.2 simonb return(CMD_ERROR);
302 1.2.2.2 simonb } else {
303 1.2.2.2 simonb if ((err = unsetenv(argv[1])) != 0) {
304 1.2.2.2 simonb command_errmsg = strerror(err);
305 1.2.2.2 simonb return(CMD_ERROR);
306 1.2.2.2 simonb }
307 1.2.2.2 simonb }
308 1.2.2.2 simonb return(CMD_OK);
309 1.2.2.2 simonb }
310 1.2.2.2 simonb
311 1.2.2.2 simonb
312 1.2.2.2 simonb int
313 1.2.2.2 simonb command_echo(int argc, char *argv[])
314 1.2.2.2 simonb {
315 1.2.2.2 simonb char *s;
316 1.2.2.2 simonb int nl, ch;
317 1.2.2.2 simonb
318 1.2.2.2 simonb nl = 0;
319 1.2.2.2 simonb optind = 1;
320 1.2.2.2 simonb optreset = 1;
321 1.2.2.2 simonb while ((ch = getopt(argc, argv, "n")) != -1) {
322 1.2.2.2 simonb switch(ch) {
323 1.2.2.2 simonb case 'n':
324 1.2.2.2 simonb nl = 1;
325 1.2.2.2 simonb break;
326 1.2.2.2 simonb case '?':
327 1.2.2.2 simonb default:
328 1.2.2.2 simonb /* getopt has already reported an error */
329 1.2.2.2 simonb return(CMD_OK);
330 1.2.2.2 simonb }
331 1.2.2.2 simonb }
332 1.2.2.2 simonb argv += (optind);
333 1.2.2.2 simonb argc -= (optind);
334 1.2.2.2 simonb
335 1.2.2.2 simonb s = unargv(argc, argv);
336 1.2.2.2 simonb if (s != NULL) {
337 1.2.2.2 simonb printf("%s", s);
338 1.2.2.2 simonb free(s);
339 1.2.2.2 simonb }
340 1.2.2.2 simonb if (!nl)
341 1.2.2.2 simonb printf("\n");
342 1.2.2.2 simonb return(CMD_OK);
343 1.2.2.2 simonb }
344 1.2.2.2 simonb
345 1.2.2.2 simonb /*
346 1.2.2.2 simonb * A passable emulation of the sh(1) command of the same name.
347 1.2.2.2 simonb */
348 1.2.2.2 simonb
349 1.2.2.2 simonb
350 1.2.2.2 simonb int
351 1.2.2.2 simonb command_read(int argc, char *argv[])
352 1.2.2.2 simonb {
353 1.2.2.2 simonb char *prompt;
354 1.2.2.2 simonb int timeout;
355 1.2.2.2 simonb time_t when;
356 1.2.2.2 simonb char *cp;
357 1.2.2.2 simonb char *name;
358 1.2.2.2 simonb char buf[256]; /* XXX size? */
359 1.2.2.2 simonb int c;
360 1.2.2.2 simonb
361 1.2.2.2 simonb timeout = -1;
362 1.2.2.2 simonb prompt = NULL;
363 1.2.2.2 simonb optind = 1;
364 1.2.2.2 simonb optreset = 1;
365 1.2.2.2 simonb while ((c = getopt(argc, argv, "p:t:")) != -1) {
366 1.2.2.2 simonb switch(c) {
367 1.2.2.2 simonb
368 1.2.2.2 simonb case 'p':
369 1.2.2.2 simonb prompt = optarg;
370 1.2.2.2 simonb break;
371 1.2.2.2 simonb case 't':
372 1.2.2.2 simonb timeout = strtol(optarg, &cp, 0);
373 1.2.2.2 simonb if (cp == optarg) {
374 1.2.2.2 simonb sprintf(command_errbuf, "bad timeout '%s'", optarg);
375 1.2.2.2 simonb return(CMD_ERROR);
376 1.2.2.2 simonb }
377 1.2.2.2 simonb break;
378 1.2.2.2 simonb default:
379 1.2.2.2 simonb return(CMD_OK);
380 1.2.2.2 simonb }
381 1.2.2.2 simonb }
382 1.2.2.2 simonb
383 1.2.2.2 simonb argv += (optind);
384 1.2.2.2 simonb argc -= (optind);
385 1.2.2.2 simonb name = (argc > 0) ? argv[0]: NULL;
386 1.2.2.2 simonb
387 1.2.2.2 simonb if (prompt != NULL)
388 1.2.2.2 simonb printf("%s", prompt);
389 1.2.2.2 simonb if (timeout >= 0) {
390 1.2.2.2 simonb when = time(NULL) + timeout;
391 1.2.2.2 simonb while (!ischar())
392 1.2.2.2 simonb if (time(NULL) >= when)
393 1.2.2.2 simonb return(CMD_OK); /* is timeout an error? */
394 1.2.2.2 simonb }
395 1.2.2.2 simonb
396 1.2.2.2 simonb ngets(buf, sizeof(buf));
397 1.2.2.2 simonb
398 1.2.2.2 simonb if (name != NULL)
399 1.2.2.2 simonb setenv(name, buf, 1);
400 1.2.2.2 simonb return(CMD_OK);
401 1.2.2.2 simonb }
402 1.2.2.2 simonb
403 1.2.2.2 simonb /*
404 1.2.2.2 simonb * File pager
405 1.2.2.2 simonb */
406 1.2.2.2 simonb
407 1.2.2.2 simonb int
408 1.2.2.2 simonb command_more(int argc, char *argv[])
409 1.2.2.2 simonb {
410 1.2.2.2 simonb int i;
411 1.2.2.2 simonb int res;
412 1.2.2.2 simonb char line[80];
413 1.2.2.2 simonb
414 1.2.2.2 simonb res=0;
415 1.2.2.2 simonb pager_open();
416 1.2.2.2 simonb for (i = 1; (i < argc) && (res == 0); i++) {
417 1.2.2.2 simonb sprintf(line, "*** FILE %s BEGIN ***\n", argv[i]);
418 1.2.2.2 simonb if (pager_output(line))
419 1.2.2.2 simonb break;
420 1.2.2.2 simonb res = page_file(argv[i]);
421 1.2.2.2 simonb if (!res) {
422 1.2.2.2 simonb sprintf(line, "*** FILE %s END ***\n", argv[i]);
423 1.2.2.2 simonb res = pager_output(line);
424 1.2.2.2 simonb }
425 1.2.2.2 simonb }
426 1.2.2.2 simonb pager_close();
427 1.2.2.2 simonb
428 1.2.2.2 simonb if (res == 0)
429 1.2.2.2 simonb return CMD_OK;
430 1.2.2.2 simonb else
431 1.2.2.2 simonb return CMD_ERROR;
432 1.2.2.2 simonb }
433 1.2.2.2 simonb
434 1.2.2.2 simonb static int
435 1.2.2.2 simonb page_file(char *filename)
436 1.2.2.2 simonb {
437 1.2.2.2 simonb int result;
438 1.2.2.2 simonb
439 1.2.2.2 simonb result = pager_file(filename);
440 1.2.2.2 simonb
441 1.2.2.2 simonb if (result == -1)
442 1.2.2.2 simonb sprintf(command_errbuf, "error showing %s", filename);
443 1.2.2.2 simonb
444 1.2.2.2 simonb return result;
445 1.2.2.2 simonb }
446 1.2.2.2 simonb
447 1.2.2.2 simonb /*
448 1.2.2.2 simonb * List all disk-like devices
449 1.2.2.2 simonb */
450 1.2.2.2 simonb
451 1.2.2.2 simonb int
452 1.2.2.2 simonb command_lsdev(int argc, char *argv[])
453 1.2.2.2 simonb {
454 1.2.2.2 simonb int verbose, ch, i;
455 1.2.2.2 simonb char line[80];
456 1.2.2.2 simonb
457 1.2.2.2 simonb verbose = 0;
458 1.2.2.2 simonb optind = 1;
459 1.2.2.2 simonb optreset = 1;
460 1.2.2.2 simonb while ((ch = getopt(argc, argv, "v")) != -1) {
461 1.2.2.2 simonb switch(ch) {
462 1.2.2.2 simonb case 'v':
463 1.2.2.2 simonb verbose = 1;
464 1.2.2.2 simonb break;
465 1.2.2.2 simonb case '?':
466 1.2.2.2 simonb default:
467 1.2.2.2 simonb /* getopt has already reported an error */
468 1.2.2.2 simonb return(CMD_OK);
469 1.2.2.2 simonb }
470 1.2.2.2 simonb }
471 1.2.2.2 simonb argv += (optind);
472 1.2.2.2 simonb argc -= (optind);
473 1.2.2.2 simonb
474 1.2.2.2 simonb pager_open();
475 1.2.2.2 simonb
476 1.2.2.2 simonb sprintf(line, "Device Enumeration:\n");
477 1.2.2.2 simonb pager_output(line);
478 1.2.2.2 simonb
479 1.2.2.2 simonb for (i = 0; i < ndevs; i++) {
480 1.2.2.2 simonb sprintf(line, "%s\n", devsw[i].dv_name);
481 1.2.2.2 simonb if (pager_output(line))
482 1.2.2.2 simonb break;
483 1.2.2.2 simonb }
484 1.2.2.2 simonb
485 1.2.2.2 simonb pager_close();
486 1.2.2.2 simonb return(CMD_OK);
487 1.2.2.2 simonb }
488 1.2.2.2 simonb
489