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