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