1129198Scognet/* $NetBSD: bootconfig.c,v 1.2 2002/03/10 19:56:39 lukem Exp $ */ 2129198Scognet 3139735Simp/*- 4129198Scognet * Copyright (c) 1994-1998 Mark Brinicombe. 5129198Scognet * Copyright (c) 1994 Brini. 6129198Scognet * All rights reserved. 7129198Scognet * 8129198Scognet * This code is derived from software written for Brini by Mark Brinicombe 9129198Scognet * 10129198Scognet * Redistribution and use in source and binary forms, with or without 11129198Scognet * modification, are permitted provided that the following conditions 12129198Scognet * are met: 13129198Scognet * 1. Redistributions of source code must retain the above copyright 14129198Scognet * notice, this list of conditions and the following disclaimer. 15129198Scognet * 2. Redistributions in binary form must reproduce the above copyright 16129198Scognet * notice, this list of conditions and the following disclaimer in the 17129198Scognet * documentation and/or other materials provided with the distribution. 18129198Scognet * 3. All advertising materials mentioning features or use of this software 19129198Scognet * must display the following acknowledgement: 20129198Scognet * This product includes software developed by Mark Brinicombe 21129198Scognet * for the NetBSD Project. 22129198Scognet * 4. The name of the company nor the name of the author may be used to 23129198Scognet * endorse or promote products derived from this software without specific 24129198Scognet * prior written permission. 25129198Scognet * 26129198Scognet * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 27129198Scognet * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28129198Scognet * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 29129198Scognet * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 30129198Scognet * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 31129198Scognet * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32129198Scognet * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33129198Scognet * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34129198Scognet * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35129198Scognet * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36129198Scognet * SUCH DAMAGE. 37129198Scognet */ 38129198Scognet 39129198Scognet#include <sys/cdefs.h> 40129198Scognet__FBSDID("$FreeBSD$"); 41129198Scognet 42129198Scognet#include <sys/param.h> 43129198Scognet 44129198Scognet#include <sys/systm.h> 45129198Scognet 46129198Scognet#include <machine/bootconfig.h> 47129198Scognet 48129198Scognet 49236991Simp/* 50129198Scognet * Function to identify and process different types of boot argument 51129198Scognet */ 52129198Scognet 53129198Scognetint 54129198Scognetget_bootconf_option(opts, opt, type, result) 55129198Scognet char *opts; 56129198Scognet char *opt; 57129198Scognet int type; 58129198Scognet void *result; 59129198Scognet{ 60129198Scognet char *ptr; 61129198Scognet char *optstart; 62129198Scognet int not; 63129198Scognet 64129198Scognet ptr = opts; 65129198Scognet 66129198Scognet while (*ptr) { 67129198Scognet /* Find start of option */ 68129198Scognet while (*ptr == ' ' || *ptr == '\t') 69129198Scognet ++ptr; 70129198Scognet 71129198Scognet if (*ptr == 0) 72129198Scognet break; 73129198Scognet 74129198Scognet not = 0; 75129198Scognet 76129198Scognet /* Is it a negate option */ 77129198Scognet if ((type & BOOTOPT_TYPE_MASK) == BOOTOPT_TYPE_BOOLEAN && *ptr == '!') { 78129198Scognet not = 1; 79129198Scognet ++ptr; 80129198Scognet } 81129198Scognet 82129198Scognet /* Find the end of option */ 83129198Scognet optstart = ptr; 84129198Scognet while (*ptr != 0 && *ptr != ' ' && *ptr != '\t' && *ptr != '=') 85129198Scognet ++ptr; 86129198Scognet 87129198Scognet if ((*ptr == '=') 88129198Scognet || (*ptr != '=' && ((type & BOOTOPT_TYPE_MASK) == BOOTOPT_TYPE_BOOLEAN))) { 89129198Scognet /* compare the option */ 90129198Scognet if (strncmp(optstart, opt, (ptr - optstart)) == 0) { 91129198Scognet /* found */ 92129198Scognet 93129198Scognet if (*ptr == '=') 94129198Scognet ++ptr; 95129198Scognet 96129198Scognet switch(type & BOOTOPT_TYPE_MASK) { 97129198Scognet case BOOTOPT_TYPE_BOOLEAN : 98129198Scognet if (*(ptr - 1) == '=') 99129198Scognet *((int *)result) = ((u_int)strtoul(ptr, NULL, 10) != 0); 100129198Scognet else 101129198Scognet *((int *)result) = !not; 102129198Scognet break; 103129198Scognet case BOOTOPT_TYPE_STRING : 104129198Scognet *((char **)result) = ptr; 105129198Scognet break; 106129198Scognet case BOOTOPT_TYPE_INT : 107129198Scognet *((int *)result) = (u_int)strtoul(ptr, NULL, 10); 108129198Scognet break; 109129198Scognet case BOOTOPT_TYPE_BININT : 110129198Scognet *((int *)result) = (u_int)strtoul(ptr, NULL, 2); 111129198Scognet break; 112129198Scognet case BOOTOPT_TYPE_HEXINT : 113129198Scognet *((int *)result) = (u_int)strtoul(ptr, NULL, 16); 114129198Scognet break; 115129198Scognet default: 116129198Scognet return(0); 117129198Scognet } 118129198Scognet return(1); 119129198Scognet } 120129198Scognet } 121129198Scognet /* skip to next option */ 122129198Scognet while (*ptr != ' ' && *ptr != '\t' && *ptr != 0) 123129198Scognet ++ptr; 124129198Scognet } 125129198Scognet return(0); 126129198Scognet} 127