Home | History | Annotate | Line # | Download | only in libsa
parse_args.c revision 1.4
      1  1.4  dsl /*	$NetBSD: parse_args.c,v 1.4 2009/03/14 15:36:11 dsl 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  *
     15  1.1  scw  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     16  1.1  scw  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     17  1.1  scw  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     18  1.1  scw  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
     19  1.1  scw  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20  1.1  scw  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     21  1.1  scw  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22  1.1  scw  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23  1.1  scw  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24  1.1  scw  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25  1.1  scw  * SUCH DAMAGE.
     26  1.1  scw  *
     27  1.1  scw  */
     28  1.1  scw 
     29  1.1  scw #include <sys/param.h>
     30  1.1  scw #include <sys/reboot.h>
     31  1.1  scw #include <sys/disklabel.h>
     32  1.1  scw #include <sys/boot_flag.h>
     33  1.1  scw 
     34  1.1  scw #include "stand.h"
     35  1.1  scw #include "libsa.h"
     36  1.1  scw 
     37  1.1  scw #define KERNEL_NAME "netbsd"
     38  1.1  scw 
     39  1.1  scw void
     40  1.4  dsl parse_args(char *astart, const char *aend, const char **filep, int *flagp, int *partp)
     41  1.1  scw {
     42  1.1  scw 	const char *name = KERNEL_NAME;
     43  1.1  scw 	char *ptr;
     44  1.1  scw 	int howto = 0, part = 0;
     45  1.1  scw 	char c;
     46  1.1  scw 
     47  1.1  scw 	if (astart != aend) {
     48  1.1  scw 		ptr = astart;
     49  1.1  scw 		while ((c = *ptr)) {
     50  1.1  scw 			while (c == ' ')
     51  1.1  scw 				c = *++ptr;
     52  1.1  scw 			if (c == '\0')
     53  1.1  scw 				return;
     54  1.1  scw 			if (c != '-') {
     55  1.1  scw 				if (ptr[1] == ':') {
     56  1.1  scw 					part = (int) (*ptr - 'A');
     57  1.1  scw 					if (part >= MAXPARTITIONS)
     58  1.1  scw 						part -= 0x20;
     59  1.1  scw 					if (part < 0 || part >= MAXPARTITIONS)
     60  1.1  scw 						part = 0;
     61  1.1  scw 					if (ptr[2] == ' ' || ptr[2] == '\0') {
     62  1.1  scw 						ptr += 2;
     63  1.1  scw 						continue;
     64  1.1  scw 					}
     65  1.1  scw 					name = &(ptr[2]);
     66  1.1  scw 				} else
     67  1.1  scw 					name = ptr;
     68  1.1  scw 				while ((c = *++ptr) && c != ' ')
     69  1.1  scw 					;
     70  1.1  scw 				if (c)
     71  1.1  scw 					*ptr++ = 0;
     72  1.1  scw 				continue;
     73  1.1  scw 			}
     74  1.1  scw 			while ((c = *++ptr) && c != ' ')
     75  1.1  scw 				BOOT_FLAG(c, howto);
     76  1.1  scw 		}
     77  1.1  scw 	}
     78  1.1  scw 	*flagp = howto;
     79  1.1  scw 	*filep = name;
     80  1.1  scw 	*partp = part;
     81  1.1  scw }
     82