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