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