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