Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / x68k / stand / libsa / parseutils.c
blob99f385427119f7359be2cf73493b5134475db1dd
1 /* $NetBSD: parseutils.c,v 1.1 2001/09/27 10:03:28 minoura Exp $ */
3 /*
4 * from /sys/arch/i386/lib/parseutils.c
5 * NetBSD: parseutils.c,v 1.3 2000/09/24 12:32:35 jdolecek Exp
6 */
8 /*
9 * Copyright (c) 1996, 1997
10 * Matthias Drochner. All rights reserved.
11 * Copyright (c) 1996, 1997
12 * Perry E. Metzger. All rights reserved.
13 * Copyright (c) 1997
14 * Jason R. Thorpe. All rights reserved
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. All advertising materials mentioning features or use of this software
25 * must display the following acknowledgements:
26 * This product includes software developed for the NetBSD Project
27 * by Matthias Drochner.
28 * This product includes software developed for the NetBSD Project
29 * by Perry E. Metzger.
30 * 4. The names of the authors may not be used to endorse or promote products
31 * derived from this software without specific prior written permission.
33 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
34 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
35 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
36 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
37 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
38 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
39 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
40 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
41 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
42 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 #include <lib/libkern/libkern.h>
46 #include <lib/libsa/stand.h>
47 #include <sys/boot_flag.h>
49 #include "libx68k.h"
53 * chops the head from the arguments and returns the arguments if any,
54 * or possibly an empty string.
56 char *
57 gettrailer(char *arg)
59 char *options;
61 if ((options = strchr(arg, ' ')) == NULL)
62 return "";
63 else
64 *options++ = '\0';
66 /* trim leading blanks */
67 while (*options && *options == ' ')
68 options++;
70 return options;
73 int
74 parseopts(const char *opts, int *howto)
76 int r, tmpopt = 0;
78 opts++; /* skip - */
79 while (*opts && *opts != ' ') {
80 r = 0;
81 BOOT_FLAG(*opts, r);
82 if (r == 0) {
83 printf("-%c: unknown flag\n", *opts);
84 return 0;
86 tmpopt |= r;
87 opts++;
90 *howto = tmpopt;
91 return 1;
94 int
95 parseboot(char *arg, char **filename, int *howto)
97 char *opts = NULL;
99 *filename = 0;
100 *howto = 0;
102 /* if there were no arguments */
103 if (!*arg)
104 return 1;
106 /* format is... */
107 /* [[xxNx:]filename] [-adqsv] */
109 /* check for just args */
110 if (arg[0] == '-') {
111 opts = arg;
112 } else {
113 /* there's a file name */
114 *filename = arg;
116 opts = gettrailer(arg);
117 if (!*opts) {
118 opts = NULL;
119 } else if (*opts != '-') {
120 printf("invalid arguments\n");
121 return 0;
125 /* at this point, we have dealt with filenames. */
127 /* now, deal with options */
128 if (opts) {
129 if (parseopts(opts, howto) == 0)
130 return 0;
133 return 1;