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