Home | History | Annotate | Line # | Download | only in libsa
parse_args.c revision 1.1
      1  1.1  scw /*	$NetBSD: parse_args.c,v 1.1 2002/02/27 21:02:27 scw Exp $	*/
      2  1.1  scw 
      3  1.1  scw /*-
      4  1.1  scw  * Copyright (c) 1995 Theo de Raadt
      5  1.1  scw  *
      6  1.1  scw  * Redistribution and use in source and binary forms, with or without
      7  1.1  scw  * modification, are permitted provided that the following conditions
      8  1.1  scw  * are met:
      9  1.1  scw  * 1. Redistributions of source code must retain the above copyright
     10  1.1  scw  *    notice, this list of conditions and the following disclaimer.
     11  1.1  scw  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.1  scw  *    notice, this list of conditions and the following disclaimer in the
     13  1.1  scw  *    documentation and/or other materials provided with the distribution.
     14  1.1  scw  * 3. All advertising materials mentioning features or use of this software
     15  1.1  scw  *    must display the following acknowledgement:
     16  1.1  scw  *	This product includes software developed under OpenBSD by
     17  1.1  scw  *	Theo de Raadt for Willowglen Singapore.
     18  1.1  scw  * 4. The name of the author may not be used to endorse or promote products
     19  1.1  scw  *    derived from this software without specific prior written permission.
     20  1.1  scw  *
     21  1.1  scw  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     22  1.1  scw  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     23  1.1  scw  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  1.1  scw  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
     25  1.1  scw  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  1.1  scw  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  1.1  scw  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  1.1  scw  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  1.1  scw  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  1.1  scw  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  1.1  scw  * SUCH DAMAGE.
     32  1.1  scw  *
     33  1.1  scw  */
     34  1.1  scw 
     35  1.1  scw #include <sys/param.h>
     36  1.1  scw #include <sys/reboot.h>
     37  1.1  scw #include <sys/disklabel.h>
     38  1.1  scw #include <sys/boot_flag.h>
     39  1.1  scw 
     40  1.1  scw #include "stand.h"
     41  1.1  scw #include "libsa.h"
     42  1.1  scw 
     43  1.1  scw #define KERNEL_NAME "netbsd"
     44  1.1  scw 
     45  1.1  scw void
     46  1.1  scw parse_args(astart, aend, filep, flagp, partp)
     47  1.1  scw 	char *astart;
     48  1.1  scw 	const char *aend;
     49  1.1  scw 	const char **filep;
     50  1.1  scw 	int *flagp;
     51  1.1  scw 	int *partp;
     52  1.1  scw {
     53  1.1  scw 	const char *name = KERNEL_NAME;
     54  1.1  scw 	char *ptr;
     55  1.1  scw 	int howto = 0, part = 0;
     56  1.1  scw 	char c;
     57  1.1  scw 
     58  1.1  scw 	if (astart != aend) {
     59  1.1  scw 		ptr = astart;
     60  1.1  scw 		while ((c = *ptr)) {
     61  1.1  scw 			while (c == ' ')
     62  1.1  scw 				c = *++ptr;
     63  1.1  scw 			if (c == '\0')
     64  1.1  scw 				return;
     65  1.1  scw 			if (c != '-') {
     66  1.1  scw 				if (ptr[1] == ':') {
     67  1.1  scw 					part = (int) (*ptr - 'A');
     68  1.1  scw 					if (part >= MAXPARTITIONS)
     69  1.1  scw 						part -= 0x20;
     70  1.1  scw 					if (part < 0 || part >= MAXPARTITIONS)
     71  1.1  scw 						part = 0;
     72  1.1  scw 					if (ptr[2] == ' ' || ptr[2] == '\0') {
     73  1.1  scw 						ptr += 2;
     74  1.1  scw 						continue;
     75  1.1  scw 					}
     76  1.1  scw 					name = &(ptr[2]);
     77  1.1  scw 				} else
     78  1.1  scw 					name = ptr;
     79  1.1  scw 				while ((c = *++ptr) && c != ' ')
     80  1.1  scw 					;
     81  1.1  scw 				if (c)
     82  1.1  scw 					*ptr++ = 0;
     83  1.1  scw 				continue;
     84  1.1  scw 			}
     85  1.1  scw 			while ((c = *++ptr) && c != ' ')
     86  1.1  scw 				BOOT_FLAG(c, howto);
     87  1.1  scw 		}
     88  1.1  scw 	}
     89  1.1  scw 	*flagp = howto;
     90  1.1  scw 	*filep = name;
     91  1.1  scw 	*partp = part;
     92  1.1  scw }
     93