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