Home | History | Annotate | Line # | Download | only in libsa
parse_args.c revision 1.1
      1  1.1  chuck /*	$NetBSD: parse_args.c,v 1.1 1996/05/17 21:00:22 chuck 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.1  chuck #include <machine/prom.h>
     38  1.1  chuck #include <a.out.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.1  chuck parse_args(filep, flagp)
     60  1.1  chuck 
     61  1.1  chuck char **filep;
     62  1.1  chuck int *flagp;
     63  1.1  chuck 
     64  1.1  chuck {
     65  1.1  chuck 	char *name = KERNEL_NAME, *ptr;
     66  1.1  chuck 	int i, howto = 0;
     67  1.1  chuck 	char c;
     68  1.1  chuck 
     69  1.1  chuck 	if (bugargs.arg_start != bugargs.arg_end) {
     70  1.1  chuck 		ptr = bugargs.arg_start;
     71  1.1  chuck 		while (c = *ptr) {
     72  1.1  chuck 			while (c == ' ')
     73  1.1  chuck 				c = *++ptr;
     74  1.1  chuck 			if (c == '\0')
     75  1.1  chuck 				return;
     76  1.1  chuck 			if (c != '-') {
     77  1.1  chuck 				name = ptr;
     78  1.1  chuck 				while ((c = *++ptr) && c != ' ')
     79  1.1  chuck 					;
     80  1.1  chuck 				if (c)
     81  1.1  chuck 					*ptr++ = 0;
     82  1.1  chuck 				continue;
     83  1.1  chuck 			}
     84  1.1  chuck 			while ((c = *++ptr) && c != ' ') {
     85  1.1  chuck 				for (i = 0; i < sizeof(bf)/sizeof(bf[0]); i++)
     86  1.1  chuck 					if (bf[i].c == c) {
     87  1.1  chuck 						howto |= bf[i].bit;
     88  1.1  chuck 					}
     89  1.1  chuck 			}
     90  1.1  chuck 		}
     91  1.1  chuck 	}
     92  1.1  chuck 	*flagp = howto;
     93  1.1  chuck 	*filep = name;
     94  1.1  chuck }
     95