Home | History | Annotate | Line # | Download | only in libsa
parse_args.c revision 1.5
      1  1.5       scw /*	$NetBSD: parse_args.c,v 1.5 2000/07/24 09:25:53 scw Exp $	*/
      2  1.1     chuck 
      3  1.1     chuck /*-
      4  1.1     chuck  * Copyright (c) 1995 Theo de Raadt
      5  1.1     chuck  *
      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  * 3. All advertising materials mentioning features or use of this software
     15  1.1     chuck  *    must display the following acknowledgement:
     16  1.1     chuck  *	This product includes software developed under OpenBSD by
     17  1.1     chuck  *	Theo de Raadt for Willowglen Singapore.
     18  1.1     chuck  * 4. The name of the author may not be used to endorse or promote products
     19  1.1     chuck  *    derived from this software without specific prior written permission.
     20  1.1     chuck  *
     21  1.1     chuck  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     22  1.1     chuck  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     23  1.1     chuck  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  1.1     chuck  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
     25  1.1     chuck  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  1.1     chuck  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  1.1     chuck  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  1.1     chuck  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  1.1     chuck  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  1.1     chuck  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  1.1     chuck  * SUCH DAMAGE.
     32  1.1     chuck  *
     33  1.1     chuck  */
     34  1.1     chuck 
     35  1.1     chuck #include <sys/param.h>
     36  1.1     chuck #include <sys/reboot.h>
     37  1.5       scw #include <sys/disklabel.h>
     38  1.1     chuck #include <machine/prom.h>
     39  1.1     chuck 
     40  1.1     chuck #include "stand.h"
     41  1.1     chuck #include "libsa.h"
     42  1.1     chuck 
     43  1.1     chuck #define KERNEL_NAME "netbsd"
     44  1.1     chuck 
     45  1.1     chuck struct flags {
     46  1.1     chuck 	char c;
     47  1.1     chuck 	short bit;
     48  1.1     chuck } bf[] = {
     49  1.1     chuck 	{ 'a', RB_ASKNAME },
     50  1.1     chuck 	{ 'b', RB_HALT },
     51  1.1     chuck 	{ 'y', RB_NOSYM },
     52  1.1     chuck 	{ 'd', RB_KDB },
     53  1.1     chuck 	{ 'm', RB_MINIROOT },
     54  1.1     chuck 	{ 'r', RB_DFLTROOT },
     55  1.1     chuck 	{ 's', RB_SINGLE },
     56  1.1     chuck };
     57  1.1     chuck 
     58  1.1     chuck void
     59  1.5       scw parse_args(filep, flagp, partp)
     60  1.1     chuck char **filep;
     61  1.1     chuck int *flagp;
     62  1.5       scw int *partp;
     63  1.1     chuck {
     64  1.1     chuck 	char *name = KERNEL_NAME, *ptr;
     65  1.5       scw 	int i, howto = 0, part = 0;
     66  1.1     chuck 	char c;
     67  1.1     chuck 
     68  1.1     chuck 	if (bugargs.arg_start != bugargs.arg_end) {
     69  1.1     chuck 		ptr = bugargs.arg_start;
     70  1.4  jdolecek 		while ((c = *ptr)) {
     71  1.1     chuck 			while (c == ' ')
     72  1.1     chuck 				c = *++ptr;
     73  1.1     chuck 			if (c == '\0')
     74  1.1     chuck 				return;
     75  1.1     chuck 			if (c != '-') {
     76  1.5       scw 				if (ptr[1] == ':') {
     77  1.5       scw 					part = (int) (*ptr - 'A');
     78  1.5       scw 					if (part >= MAXPARTITIONS)
     79  1.5       scw 						part -= 0x20;
     80  1.5       scw 					if (part < 0 || part >= MAXPARTITIONS)
     81  1.5       scw 						part = 0;
     82  1.5       scw 					if (ptr[2] == ' ' || ptr[2] == '\0') {
     83  1.2       scw 						ptr += 2;
     84  1.2       scw 						continue;
     85  1.2       scw 					}
     86  1.2       scw 					name = &(ptr[2]);
     87  1.2       scw 				} else
     88  1.2       scw 					name = ptr;
     89  1.1     chuck 				while ((c = *++ptr) && c != ' ')
     90  1.1     chuck 					;
     91  1.1     chuck 				if (c)
     92  1.1     chuck 					*ptr++ = 0;
     93  1.1     chuck 				continue;
     94  1.1     chuck 			}
     95  1.1     chuck 			while ((c = *++ptr) && c != ' ') {
     96  1.1     chuck 				for (i = 0; i < sizeof(bf)/sizeof(bf[0]); i++)
     97  1.1     chuck 					if (bf[i].c == c) {
     98  1.1     chuck 						howto |= bf[i].bit;
     99  1.1     chuck 					}
    100  1.1     chuck 			}
    101  1.1     chuck 		}
    102  1.1     chuck 	}
    103  1.1     chuck 	*flagp = howto;
    104  1.1     chuck 	*filep = name;
    105  1.5       scw 	*partp = part;
    106  1.1     chuck }
    107