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