xref: /netbsd-src/sys/arch/mvme68k/stand/libsa/parse_args.c (revision de1dfb1250df962f1ff3a011772cf58e605aed11)
1 /*	$NetBSD: parse_args.c,v 1.8 2003/12/10 12:06:25 agc 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  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  */
28 
29 #include <sys/param.h>
30 #include <sys/reboot.h>
31 #include <sys/disklabel.h>
32 #include <machine/prom.h>
33 #include <sys/boot_flag.h>
34 
35 #include "stand.h"
36 #include "libsa.h"
37 
38 #define KERNEL_NAME "netbsd"
39 
40 void
41 parse_args(filep, flagp, partp)
42 char **filep;
43 int *flagp;
44 int *partp;
45 {
46 	char *name = KERNEL_NAME, *ptr;
47 	int howto = 0, part = 0;
48 	char c;
49 
50 	if (bugargs.arg_start != bugargs.arg_end) {
51 		ptr = bugargs.arg_start;
52 		while ((c = *ptr)) {
53 			while (c == ' ')
54 				c = *++ptr;
55 			if (c == '\0')
56 				return;
57 			if (c != '-') {
58 				if (ptr[1] == ':') {
59 					part = (int) (*ptr - 'A');
60 					if (part >= MAXPARTITIONS)
61 						part -= 0x20;
62 					if (part < 0 || part >= MAXPARTITIONS)
63 						part = 0;
64 					if (ptr[2] == ' ' || ptr[2] == '\0') {
65 						ptr += 2;
66 						continue;
67 					}
68 					name = &(ptr[2]);
69 				} else
70 					name = ptr;
71 				while ((c = *++ptr) && c != ' ')
72 					;
73 				if (c)
74 					*ptr++ = 0;
75 				continue;
76 			}
77 			while ((c = *++ptr) && c != ' ')
78 				BOOT_FLAG(c, howto);
79 		}
80 	}
81 	*flagp = howto;
82 	*filep = name;
83 	*partp = part;
84 }
85