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