parse_args.c revision 1.4 1 1.4 jdolecek /* $NetBSD: parse_args.c,v 1.4 2000/07/10 22:48:25 jdolecek Exp $ */
2 1.1 chuck
3 1.1 chuck /*-
4 1.1 chuck * Copyright (c) 1995 Theo de Raadt
5 1.1 chuck *
6 1.1 chuck * Redistribution and use in source and binary forms, with or without
7 1.1 chuck * modification, are permitted provided that the following conditions
8 1.1 chuck * are met:
9 1.1 chuck * 1. Redistributions of source code must retain the above copyright
10 1.1 chuck * notice, this list of conditions and the following disclaimer.
11 1.1 chuck * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 chuck * notice, this list of conditions and the following disclaimer in the
13 1.1 chuck * documentation and/or other materials provided with the distribution.
14 1.1 chuck * 3. All advertising materials mentioning features or use of this software
15 1.1 chuck * must display the following acknowledgement:
16 1.1 chuck * This product includes software developed under OpenBSD by
17 1.1 chuck * Theo de Raadt for Willowglen Singapore.
18 1.1 chuck * 4. The name of the author may not be used to endorse or promote products
19 1.1 chuck * derived from this software without specific prior written permission.
20 1.1 chuck *
21 1.1 chuck * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
22 1.1 chuck * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 1.1 chuck * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.1 chuck * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
25 1.1 chuck * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.1 chuck * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.1 chuck * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.1 chuck * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.1 chuck * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.1 chuck * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1 chuck * SUCH DAMAGE.
32 1.1 chuck *
33 1.1 chuck */
34 1.1 chuck
35 1.1 chuck #include <sys/param.h>
36 1.1 chuck #include <sys/reboot.h>
37 1.1 chuck #include <machine/prom.h>
38 1.1 chuck
39 1.1 chuck #include "stand.h"
40 1.1 chuck #include "libsa.h"
41 1.1 chuck
42 1.1 chuck #define KERNEL_NAME "netbsd"
43 1.1 chuck
44 1.1 chuck struct flags {
45 1.1 chuck char c;
46 1.1 chuck short bit;
47 1.1 chuck } bf[] = {
48 1.1 chuck { 'a', RB_ASKNAME },
49 1.1 chuck { 'b', RB_HALT },
50 1.1 chuck { 'y', RB_NOSYM },
51 1.1 chuck { 'd', RB_KDB },
52 1.1 chuck { 'm', RB_MINIROOT },
53 1.1 chuck { 'r', RB_DFLTROOT },
54 1.1 chuck { 's', RB_SINGLE },
55 1.1 chuck };
56 1.1 chuck
57 1.1 chuck void
58 1.1 chuck parse_args(filep, flagp)
59 1.1 chuck
60 1.1 chuck char **filep;
61 1.1 chuck int *flagp;
62 1.1 chuck
63 1.1 chuck {
64 1.1 chuck char *name = KERNEL_NAME, *ptr;
65 1.1 chuck int i, howto = 0;
66 1.1 chuck char c;
67 1.1 chuck
68 1.1 chuck if (bugargs.arg_start != bugargs.arg_end) {
69 1.1 chuck ptr = bugargs.arg_start;
70 1.4 jdolecek while ((c = *ptr)) {
71 1.1 chuck while (c == ' ')
72 1.1 chuck c = *++ptr;
73 1.1 chuck if (c == '\0')
74 1.1 chuck return;
75 1.1 chuck if (c != '-') {
76 1.2 scw if ( ptr[1] == ':' ) {
77 1.2 scw howto |= RB_ASKNAME;
78 1.2 scw if ( ptr[2] == ' ' || ptr[2] == '\0' ) {
79 1.2 scw ptr += 2;
80 1.2 scw continue;
81 1.2 scw }
82 1.2 scw name = &(ptr[2]);
83 1.2 scw } else
84 1.2 scw name = ptr;
85 1.1 chuck while ((c = *++ptr) && c != ' ')
86 1.1 chuck ;
87 1.1 chuck if (c)
88 1.1 chuck *ptr++ = 0;
89 1.1 chuck continue;
90 1.1 chuck }
91 1.1 chuck while ((c = *++ptr) && c != ' ') {
92 1.1 chuck for (i = 0; i < sizeof(bf)/sizeof(bf[0]); i++)
93 1.1 chuck if (bf[i].c == c) {
94 1.1 chuck howto |= bf[i].bit;
95 1.1 chuck }
96 1.1 chuck }
97 1.1 chuck }
98 1.1 chuck }
99 1.1 chuck *flagp = howto;
100 1.1 chuck *filep = name;
101 1.1 chuck }
102