1 /* $NetBSD: parseutils.c,v 1.1 2001/09/27 10:03:28 minoura Exp $ */ 2 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 */ 7 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 15 * 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. 32 * 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. 43 */ 44 45 #include <lib/libkern/libkern.h> 46 #include <lib/libsa/stand.h> 47 #include <sys/boot_flag.h> 48 49 #include "libx68k.h" 50 51 52 /* 53 * chops the head from the arguments and returns the arguments if any, 54 * or possibly an empty string. 55 */ 56 char * 57 gettrailer(arg) 58 char *arg; 59 { 60 char *options; 61 62 if ((options = strchr(arg, ' ')) == NULL) 63 return (""); 64 else 65 *options++ = '\0'; 66 67 /* trim leading blanks */ 68 while (*options && *options == ' ') 69 options++; 70 71 return (options); 72 } 73 74 int 75 parseopts(opts, howto) 76 const char *opts; 77 int *howto; 78 { 79 int r, tmpopt = 0; 80 81 opts++; /* skip - */ 82 while (*opts && *opts != ' ') { 83 r = 0; 84 BOOT_FLAG(*opts, r); 85 if (r == 0) { 86 printf("-%c: unknown flag\n", *opts); 87 return(0); 88 } 89 tmpopt |= r; 90 opts++; 91 } 92 93 *howto = tmpopt; 94 return(1); 95 } 96 97 int 98 parseboot(arg, filename, howto) 99 char *arg; 100 char **filename; 101 int *howto; 102 { 103 char *opts = NULL; 104 105 *filename = 0; 106 *howto = 0; 107 108 /* if there were no arguments */ 109 if (!*arg) 110 return(1); 111 112 /* format is... */ 113 /* [[xxNx:]filename] [-adqsv] */ 114 115 /* check for just args */ 116 if (arg[0] == '-') 117 opts = arg; 118 else { 119 /* there's a file name */ 120 *filename = arg; 121 122 opts = gettrailer(arg); 123 if (!*opts) 124 opts = NULL; 125 else if (*opts != '-') { 126 printf("invalid arguments\n"); 127 return(0); 128 } 129 } 130 131 /* at this point, we have dealt with filenames. */ 132 133 /* now, deal with options */ 134 if (opts) { 135 if (parseopts(opts, howto) == 0) 136 return(0); 137 } 138 139 return(1); 140 } 141