|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 6: * The contents of this file constitute Original Code as defined in and ! 7: * are subject to the Apple Public Source License Version 1.1 (the ! 8: * "License"). You may not use this file except in compliance with the ! 9: * License. Please obtain a copy of the License at ! 10: * http://www.apple.com/publicsource and read it before using this file. ! 11: * ! 12: * This Original Code and all software distributed under the License are ! 13: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ! 14: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ! 15: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ! 16: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the ! 17: * License for the specific language governing rights and limitations ! 18: * under the License. ! 19: * ! 20: * @APPLE_LICENSE_HEADER_END@ ! 21: */ ! 22: #include <pexpert/pexpert.h> ! 23: ! 24: extern boolean_t isargsep( char c); ! 25: extern int argstrcpy(char *from, char *to); ! 26: extern int getval(char *s, int *val); ! 27: ! 28: #define NUM 0 ! 29: #define STR 1 ! 30: ! 31: boolean_t ! 32: PE_parse_boot_arg( ! 33: char *arg_string, ! 34: void *arg_ptr) ! 35: { ! 36: char *args; ! 37: char *cp, c; ! 38: int i; ! 39: int val; ! 40: boolean_t arg_boolean; ! 41: boolean_t arg_found; ! 42: ! 43: args = PE_boot_args(); ! 44: arg_found = FALSE; ! 45: ! 46: while(isargsep(*args)) args++; ! 47: ! 48: while (*args) ! 49: { ! 50: if (*args == '-') ! 51: arg_boolean = TRUE; ! 52: else ! 53: arg_boolean = FALSE; ! 54: ! 55: cp = args; ! 56: while (!isargsep (*cp) && *cp != '=') ! 57: cp++; ! 58: if (*cp != '=' && !arg_boolean) ! 59: goto gotit; ! 60: ! 61: c = *cp; ! 62: ! 63: i = cp-args; ! 64: if (strncmp(args, arg_string, i) || ! 65: (i!=strlen(arg_string))) ! 66: goto gotit; ! 67: if (arg_boolean) { ! 68: *(unsigned int *)arg_ptr = TRUE; ! 69: arg_found = TRUE; ! 70: break; ! 71: } else { ! 72: while (isargsep (*cp)) ! 73: cp++; ! 74: if (*cp == '=' && c != '=') { ! 75: args = cp+1; ! 76: goto gotit; ! 77: } ! 78: ! 79: switch (getval(cp, &val)) ! 80: { ! 81: case NUM: ! 82: *(unsigned int *)arg_ptr = val; ! 83: arg_found = TRUE; ! 84: break; ! 85: case STR: ! 86: argstrcpy(++cp, (char *)arg_ptr); ! 87: arg_found = TRUE; ! 88: break; ! 89: } ! 90: goto gotit; ! 91: } ! 92: gotit: ! 93: /* Skip over current arg */ ! 94: while(!isargsep(*args)) args++; ! 95: ! 96: /* Skip leading white space (catch end of args) */ ! 97: while(*args && isargsep(*args)) args++; ! 98: } ! 99: ! 100: return(arg_found); ! 101: } ! 102: ! 103: boolean_t isargsep( ! 104: char c) ! 105: { ! 106: if (c == ' ' || c == '\0' || c == '\t') ! 107: return(TRUE); ! 108: else ! 109: return(FALSE); ! 110: } ! 111: ! 112: int ! 113: argstrcpy( ! 114: char *from, ! 115: char *to) ! 116: { ! 117: int i = 0; ! 118: ! 119: while (!isargsep(*from)) { ! 120: i++; ! 121: *to++ = *from++; ! 122: } ! 123: *to = 0; ! 124: return(i); ! 125: } ! 126: ! 127: int ! 128: getval( ! 129: char *s, ! 130: int *val) ! 131: { ! 132: register unsigned radix, intval; ! 133: register unsigned char c; ! 134: int sign = 1; ! 135: ! 136: if (*s == '=') { ! 137: s++; ! 138: if (*s == '-') ! 139: sign = -1, s++; ! 140: intval = *s++-'0'; ! 141: radix = 10; ! 142: if (intval == 0) ! 143: switch(*s) { ! 144: ! 145: case 'x': ! 146: radix = 16; ! 147: s++; ! 148: break; ! 149: ! 150: case 'b': ! 151: radix = 2; ! 152: s++; ! 153: break; ! 154: ! 155: case '0': case '1': case '2': case '3': ! 156: case '4': case '5': case '6': case '7': ! 157: intval = *s-'0'; ! 158: s++; ! 159: radix = 8; ! 160: break; ! 161: ! 162: default: ! 163: if (!isargsep(*s)) ! 164: return (STR); ! 165: } ! 166: for(;;) { ! 167: if (((c = *s++) >= '0') && (c <= '9')) ! 168: c -= '0'; ! 169: else if ((c >= 'a') && (c <= 'f')) ! 170: c -= 'a' - 10; ! 171: else if ((c >= 'A') && (c <= 'F')) ! 172: c -= 'A' - 10; ! 173: else if (isargsep(c)) ! 174: break; ! 175: else ! 176: return (STR); ! 177: if (c >= radix) ! 178: return (STR); ! 179: intval *= radix; ! 180: intval += c; ! 181: } ! 182: *val = intval * sign; ! 183: return (NUM); ! 184: } ! 185: *val = 1; ! 186: return (NUM); ! 187: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.