]>
git.saurik.com Git - apple/xnu.git/blob - pexpert/gen/bootargs.c
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 #include <pexpert/pexpert.h>
30 extern boolean_t
isargsep( char c
);
31 extern int argstrcpy(char *from
, char *to
);
32 extern int getval(char *s
, int *val
);
34 int argstrcpy2(char *from
,char *to
, unsigned maxlen
);
41 const char *arg_string
,
47 /* Limit arg size to 4 byte when no size is given */
51 return PE_parse_boot_argn(arg_string
, arg_ptr
, max_len
);
56 const char *arg_string
,
64 boolean_t arg_boolean
;
67 args
= PE_boot_args();
68 if (*args
== '\0') return FALSE
;
72 while(isargsep(*args
)) args
++;
82 while (!isargsep (*cp
) && *cp
!= '=')
84 if (*cp
!= '=' && !arg_boolean
)
90 if (strncmp(args
, arg_string
, i
) ||
91 (i
!=strlen(arg_string
)))
94 *(unsigned int *)arg_ptr
= TRUE
;
98 while (isargsep (*cp
))
100 if (*cp
== '=' && c
!= '=') {
104 if ('_' == *arg_string
) /* Force a string copy if the argument name begins with an underscore */
106 int hacklen
= 17 > max_len
? 17 : max_len
;
107 argstrcpy2 (++cp
, (char *)arg_ptr
, hacklen
- 1); /* Hack - terminate after 16 characters */
111 switch (getval(cp
, &val
))
114 *(unsigned int *)arg_ptr
= val
;
118 if(max_len
> 0) //max_len of 0 performs no copy at all
119 argstrcpy2(++cp
, (char *)arg_ptr
, max_len
- 1);
120 else if(max_len
== -1)
121 argstrcpy(++cp
, (char *)arg_ptr
);
128 /* Skip over current arg */
129 while(!isargsep(*args
)) args
++;
131 /* Skip leading white space (catch end of args) */
132 while(*args
&& isargsep(*args
)) args
++;
141 if (c
== ' ' || c
== '\0' || c
== '\t')
154 while (!isargsep(*from
)) {
170 while (!isargsep(*from
) && i
< maxlen
) {
183 unsigned int radix
, intval
;
206 case '0': case '1': case '2': case '3':
207 case '4': case '5': case '6': case '7':
217 } else if (intval
>= radix
) {
225 ((c
>= '0') && (c
<= ('9' - (10 - radix
))))) {
227 } else if ((radix
== 16) &&
228 ((c
>= '0') && (c
<= '9'))) {
230 } else if ((radix
== 16) &&
231 ((c
>= 'a') && (c
<= 'f'))) {
233 } else if ((radix
== 16) &&
234 ((c
>= 'A') && (c
<= 'F'))) {
236 } else if (c
== 'k' || c
== 'K') {
239 } else if (c
== 'm' || c
== 'M') {
242 } else if (c
== 'g' || c
== 'G') {
243 sign
*= 1024 * 1024 * 1024;
253 if (!isargsep(c
) && !isargsep(*s
))
255 *val
= intval
* sign
;