utstring.c revision 1.1.1.1.6.2 1 1.1.1.1.6.2 yamt /*******************************************************************************
2 1.1.1.1.6.2 yamt *
3 1.1.1.1.6.2 yamt * Module Name: utstring - Common functions for strings and characters
4 1.1.1.1.6.2 yamt *
5 1.1.1.1.6.2 yamt ******************************************************************************/
6 1.1.1.1.6.2 yamt
7 1.1.1.1.6.2 yamt /*
8 1.1.1.1.6.2 yamt * Copyright (C) 2000 - 2013, Intel Corp.
9 1.1.1.1.6.2 yamt * All rights reserved.
10 1.1.1.1.6.2 yamt *
11 1.1.1.1.6.2 yamt * Redistribution and use in source and binary forms, with or without
12 1.1.1.1.6.2 yamt * modification, are permitted provided that the following conditions
13 1.1.1.1.6.2 yamt * are met:
14 1.1.1.1.6.2 yamt * 1. Redistributions of source code must retain the above copyright
15 1.1.1.1.6.2 yamt * notice, this list of conditions, and the following disclaimer,
16 1.1.1.1.6.2 yamt * without modification.
17 1.1.1.1.6.2 yamt * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.1.6.2 yamt * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.1.6.2 yamt * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.1.6.2 yamt * including a substantially similar Disclaimer requirement for further
21 1.1.1.1.6.2 yamt * binary redistribution.
22 1.1.1.1.6.2 yamt * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.1.6.2 yamt * of any contributors may be used to endorse or promote products derived
24 1.1.1.1.6.2 yamt * from this software without specific prior written permission.
25 1.1.1.1.6.2 yamt *
26 1.1.1.1.6.2 yamt * Alternatively, this software may be distributed under the terms of the
27 1.1.1.1.6.2 yamt * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.1.6.2 yamt * Software Foundation.
29 1.1.1.1.6.2 yamt *
30 1.1.1.1.6.2 yamt * NO WARRANTY
31 1.1.1.1.6.2 yamt * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.1.6.2 yamt * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.1.6.2 yamt * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.1.6.2 yamt * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.1.6.2 yamt * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.1.6.2 yamt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.1.6.2 yamt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.1.6.2 yamt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.1.6.2 yamt * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.1.6.2 yamt * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.1.6.2 yamt * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.1.6.2 yamt */
43 1.1.1.1.6.2 yamt
44 1.1.1.1.6.2 yamt
45 1.1.1.1.6.2 yamt #define __UTSTRING_C__
46 1.1.1.1.6.2 yamt
47 1.1.1.1.6.2 yamt #include "acpi.h"
48 1.1.1.1.6.2 yamt #include "accommon.h"
49 1.1.1.1.6.2 yamt #include "acnamesp.h"
50 1.1.1.1.6.2 yamt
51 1.1.1.1.6.2 yamt
52 1.1.1.1.6.2 yamt #define _COMPONENT ACPI_UTILITIES
53 1.1.1.1.6.2 yamt ACPI_MODULE_NAME ("utstring")
54 1.1.1.1.6.2 yamt
55 1.1.1.1.6.2 yamt
56 1.1.1.1.6.2 yamt /*
57 1.1.1.1.6.2 yamt * Non-ANSI C library functions - strlwr, strupr, stricmp, and a 64-bit
58 1.1.1.1.6.2 yamt * version of strtoul.
59 1.1.1.1.6.2 yamt */
60 1.1.1.1.6.2 yamt
61 1.1.1.1.6.2 yamt #ifdef ACPI_ASL_COMPILER
62 1.1.1.1.6.2 yamt /*******************************************************************************
63 1.1.1.1.6.2 yamt *
64 1.1.1.1.6.2 yamt * FUNCTION: AcpiUtStrlwr (strlwr)
65 1.1.1.1.6.2 yamt *
66 1.1.1.1.6.2 yamt * PARAMETERS: SrcString - The source string to convert
67 1.1.1.1.6.2 yamt *
68 1.1.1.1.6.2 yamt * RETURN: None
69 1.1.1.1.6.2 yamt *
70 1.1.1.1.6.2 yamt * DESCRIPTION: Convert string to lowercase
71 1.1.1.1.6.2 yamt *
72 1.1.1.1.6.2 yamt * NOTE: This is not a POSIX function, so it appears here, not in utclib.c
73 1.1.1.1.6.2 yamt *
74 1.1.1.1.6.2 yamt ******************************************************************************/
75 1.1.1.1.6.2 yamt
76 1.1.1.1.6.2 yamt void
77 1.1.1.1.6.2 yamt AcpiUtStrlwr (
78 1.1.1.1.6.2 yamt char *SrcString)
79 1.1.1.1.6.2 yamt {
80 1.1.1.1.6.2 yamt char *String;
81 1.1.1.1.6.2 yamt
82 1.1.1.1.6.2 yamt
83 1.1.1.1.6.2 yamt ACPI_FUNCTION_ENTRY ();
84 1.1.1.1.6.2 yamt
85 1.1.1.1.6.2 yamt
86 1.1.1.1.6.2 yamt if (!SrcString)
87 1.1.1.1.6.2 yamt {
88 1.1.1.1.6.2 yamt return;
89 1.1.1.1.6.2 yamt }
90 1.1.1.1.6.2 yamt
91 1.1.1.1.6.2 yamt /* Walk entire string, lowercasing the letters */
92 1.1.1.1.6.2 yamt
93 1.1.1.1.6.2 yamt for (String = SrcString; *String; String++)
94 1.1.1.1.6.2 yamt {
95 1.1.1.1.6.2 yamt *String = (char) ACPI_TOLOWER (*String);
96 1.1.1.1.6.2 yamt }
97 1.1.1.1.6.2 yamt
98 1.1.1.1.6.2 yamt return;
99 1.1.1.1.6.2 yamt }
100 1.1.1.1.6.2 yamt
101 1.1.1.1.6.2 yamt
102 1.1.1.1.6.2 yamt /******************************************************************************
103 1.1.1.1.6.2 yamt *
104 1.1.1.1.6.2 yamt * FUNCTION: AcpiUtStricmp (stricmp)
105 1.1.1.1.6.2 yamt *
106 1.1.1.1.6.2 yamt * PARAMETERS: String1 - first string to compare
107 1.1.1.1.6.2 yamt * String2 - second string to compare
108 1.1.1.1.6.2 yamt *
109 1.1.1.1.6.2 yamt * RETURN: int that signifies string relationship. Zero means strings
110 1.1.1.1.6.2 yamt * are equal.
111 1.1.1.1.6.2 yamt *
112 1.1.1.1.6.2 yamt * DESCRIPTION: Implementation of the non-ANSI stricmp function (compare
113 1.1.1.1.6.2 yamt * strings with no case sensitivity)
114 1.1.1.1.6.2 yamt *
115 1.1.1.1.6.2 yamt ******************************************************************************/
116 1.1.1.1.6.2 yamt
117 1.1.1.1.6.2 yamt int
118 1.1.1.1.6.2 yamt AcpiUtStricmp (
119 1.1.1.1.6.2 yamt char *String1,
120 1.1.1.1.6.2 yamt char *String2)
121 1.1.1.1.6.2 yamt {
122 1.1.1.1.6.2 yamt int c1;
123 1.1.1.1.6.2 yamt int c2;
124 1.1.1.1.6.2 yamt
125 1.1.1.1.6.2 yamt
126 1.1.1.1.6.2 yamt do
127 1.1.1.1.6.2 yamt {
128 1.1.1.1.6.2 yamt c1 = tolower ((int) *String1);
129 1.1.1.1.6.2 yamt c2 = tolower ((int) *String2);
130 1.1.1.1.6.2 yamt
131 1.1.1.1.6.2 yamt String1++;
132 1.1.1.1.6.2 yamt String2++;
133 1.1.1.1.6.2 yamt }
134 1.1.1.1.6.2 yamt while ((c1 == c2) && (c1));
135 1.1.1.1.6.2 yamt
136 1.1.1.1.6.2 yamt return (c1 - c2);
137 1.1.1.1.6.2 yamt }
138 1.1.1.1.6.2 yamt #endif
139 1.1.1.1.6.2 yamt
140 1.1.1.1.6.2 yamt
141 1.1.1.1.6.2 yamt /*******************************************************************************
142 1.1.1.1.6.2 yamt *
143 1.1.1.1.6.2 yamt * FUNCTION: AcpiUtStrupr (strupr)
144 1.1.1.1.6.2 yamt *
145 1.1.1.1.6.2 yamt * PARAMETERS: SrcString - The source string to convert
146 1.1.1.1.6.2 yamt *
147 1.1.1.1.6.2 yamt * RETURN: None
148 1.1.1.1.6.2 yamt *
149 1.1.1.1.6.2 yamt * DESCRIPTION: Convert string to uppercase
150 1.1.1.1.6.2 yamt *
151 1.1.1.1.6.2 yamt * NOTE: This is not a POSIX function, so it appears here, not in utclib.c
152 1.1.1.1.6.2 yamt *
153 1.1.1.1.6.2 yamt ******************************************************************************/
154 1.1.1.1.6.2 yamt
155 1.1.1.1.6.2 yamt void
156 1.1.1.1.6.2 yamt AcpiUtStrupr (
157 1.1.1.1.6.2 yamt char *SrcString)
158 1.1.1.1.6.2 yamt {
159 1.1.1.1.6.2 yamt char *String;
160 1.1.1.1.6.2 yamt
161 1.1.1.1.6.2 yamt
162 1.1.1.1.6.2 yamt ACPI_FUNCTION_ENTRY ();
163 1.1.1.1.6.2 yamt
164 1.1.1.1.6.2 yamt
165 1.1.1.1.6.2 yamt if (!SrcString)
166 1.1.1.1.6.2 yamt {
167 1.1.1.1.6.2 yamt return;
168 1.1.1.1.6.2 yamt }
169 1.1.1.1.6.2 yamt
170 1.1.1.1.6.2 yamt /* Walk entire string, uppercasing the letters */
171 1.1.1.1.6.2 yamt
172 1.1.1.1.6.2 yamt for (String = SrcString; *String; String++)
173 1.1.1.1.6.2 yamt {
174 1.1.1.1.6.2 yamt *String = (char) ACPI_TOUPPER (*String);
175 1.1.1.1.6.2 yamt }
176 1.1.1.1.6.2 yamt
177 1.1.1.1.6.2 yamt return;
178 1.1.1.1.6.2 yamt }
179 1.1.1.1.6.2 yamt
180 1.1.1.1.6.2 yamt
181 1.1.1.1.6.2 yamt /*******************************************************************************
182 1.1.1.1.6.2 yamt *
183 1.1.1.1.6.2 yamt * FUNCTION: AcpiUtStrtoul64
184 1.1.1.1.6.2 yamt *
185 1.1.1.1.6.2 yamt * PARAMETERS: String - Null terminated string
186 1.1.1.1.6.2 yamt * Base - Radix of the string: 16 or ACPI_ANY_BASE;
187 1.1.1.1.6.2 yamt * ACPI_ANY_BASE means 'in behalf of ToInteger'
188 1.1.1.1.6.2 yamt * RetInteger - Where the converted integer is returned
189 1.1.1.1.6.2 yamt *
190 1.1.1.1.6.2 yamt * RETURN: Status and Converted value
191 1.1.1.1.6.2 yamt *
192 1.1.1.1.6.2 yamt * DESCRIPTION: Convert a string into an unsigned value. Performs either a
193 1.1.1.1.6.2 yamt * 32-bit or 64-bit conversion, depending on the current mode
194 1.1.1.1.6.2 yamt * of the interpreter.
195 1.1.1.1.6.2 yamt * NOTE: Does not support Octal strings, not needed.
196 1.1.1.1.6.2 yamt *
197 1.1.1.1.6.2 yamt ******************************************************************************/
198 1.1.1.1.6.2 yamt
199 1.1.1.1.6.2 yamt ACPI_STATUS
200 1.1.1.1.6.2 yamt AcpiUtStrtoul64 (
201 1.1.1.1.6.2 yamt char *String,
202 1.1.1.1.6.2 yamt UINT32 Base,
203 1.1.1.1.6.2 yamt UINT64 *RetInteger)
204 1.1.1.1.6.2 yamt {
205 1.1.1.1.6.2 yamt UINT32 ThisDigit = 0;
206 1.1.1.1.6.2 yamt UINT64 ReturnValue = 0;
207 1.1.1.1.6.2 yamt UINT64 Quotient;
208 1.1.1.1.6.2 yamt UINT64 Dividend;
209 1.1.1.1.6.2 yamt UINT32 ToIntegerOp = (Base == ACPI_ANY_BASE);
210 1.1.1.1.6.2 yamt UINT32 Mode32 = (AcpiGbl_IntegerByteWidth == 4);
211 1.1.1.1.6.2 yamt UINT8 ValidDigits = 0;
212 1.1.1.1.6.2 yamt UINT8 SignOf0x = 0;
213 1.1.1.1.6.2 yamt UINT8 Term = 0;
214 1.1.1.1.6.2 yamt
215 1.1.1.1.6.2 yamt
216 1.1.1.1.6.2 yamt ACPI_FUNCTION_TRACE_STR (UtStroul64, String);
217 1.1.1.1.6.2 yamt
218 1.1.1.1.6.2 yamt
219 1.1.1.1.6.2 yamt switch (Base)
220 1.1.1.1.6.2 yamt {
221 1.1.1.1.6.2 yamt case ACPI_ANY_BASE:
222 1.1.1.1.6.2 yamt case 16:
223 1.1.1.1.6.2 yamt
224 1.1.1.1.6.2 yamt break;
225 1.1.1.1.6.2 yamt
226 1.1.1.1.6.2 yamt default:
227 1.1.1.1.6.2 yamt
228 1.1.1.1.6.2 yamt /* Invalid Base */
229 1.1.1.1.6.2 yamt
230 1.1.1.1.6.2 yamt return_ACPI_STATUS (AE_BAD_PARAMETER);
231 1.1.1.1.6.2 yamt }
232 1.1.1.1.6.2 yamt
233 1.1.1.1.6.2 yamt if (!String)
234 1.1.1.1.6.2 yamt {
235 1.1.1.1.6.2 yamt goto ErrorExit;
236 1.1.1.1.6.2 yamt }
237 1.1.1.1.6.2 yamt
238 1.1.1.1.6.2 yamt /* Skip over any white space in the buffer */
239 1.1.1.1.6.2 yamt
240 1.1.1.1.6.2 yamt while ((*String) && (ACPI_IS_SPACE (*String) || *String == '\t'))
241 1.1.1.1.6.2 yamt {
242 1.1.1.1.6.2 yamt String++;
243 1.1.1.1.6.2 yamt }
244 1.1.1.1.6.2 yamt
245 1.1.1.1.6.2 yamt if (ToIntegerOp)
246 1.1.1.1.6.2 yamt {
247 1.1.1.1.6.2 yamt /*
248 1.1.1.1.6.2 yamt * Base equal to ACPI_ANY_BASE means 'ToInteger operation case'.
249 1.1.1.1.6.2 yamt * We need to determine if it is decimal or hexadecimal.
250 1.1.1.1.6.2 yamt */
251 1.1.1.1.6.2 yamt if ((*String == '0') && (ACPI_TOLOWER (*(String + 1)) == 'x'))
252 1.1.1.1.6.2 yamt {
253 1.1.1.1.6.2 yamt SignOf0x = 1;
254 1.1.1.1.6.2 yamt Base = 16;
255 1.1.1.1.6.2 yamt
256 1.1.1.1.6.2 yamt /* Skip over the leading '0x' */
257 1.1.1.1.6.2 yamt String += 2;
258 1.1.1.1.6.2 yamt }
259 1.1.1.1.6.2 yamt else
260 1.1.1.1.6.2 yamt {
261 1.1.1.1.6.2 yamt Base = 10;
262 1.1.1.1.6.2 yamt }
263 1.1.1.1.6.2 yamt }
264 1.1.1.1.6.2 yamt
265 1.1.1.1.6.2 yamt /* Any string left? Check that '0x' is not followed by white space. */
266 1.1.1.1.6.2 yamt
267 1.1.1.1.6.2 yamt if (!(*String) || ACPI_IS_SPACE (*String) || *String == '\t')
268 1.1.1.1.6.2 yamt {
269 1.1.1.1.6.2 yamt if (ToIntegerOp)
270 1.1.1.1.6.2 yamt {
271 1.1.1.1.6.2 yamt goto ErrorExit;
272 1.1.1.1.6.2 yamt }
273 1.1.1.1.6.2 yamt else
274 1.1.1.1.6.2 yamt {
275 1.1.1.1.6.2 yamt goto AllDone;
276 1.1.1.1.6.2 yamt }
277 1.1.1.1.6.2 yamt }
278 1.1.1.1.6.2 yamt
279 1.1.1.1.6.2 yamt /*
280 1.1.1.1.6.2 yamt * Perform a 32-bit or 64-bit conversion, depending upon the current
281 1.1.1.1.6.2 yamt * execution mode of the interpreter
282 1.1.1.1.6.2 yamt */
283 1.1.1.1.6.2 yamt Dividend = (Mode32) ? ACPI_UINT32_MAX : ACPI_UINT64_MAX;
284 1.1.1.1.6.2 yamt
285 1.1.1.1.6.2 yamt /* Main loop: convert the string to a 32- or 64-bit integer */
286 1.1.1.1.6.2 yamt
287 1.1.1.1.6.2 yamt while (*String)
288 1.1.1.1.6.2 yamt {
289 1.1.1.1.6.2 yamt if (ACPI_IS_DIGIT (*String))
290 1.1.1.1.6.2 yamt {
291 1.1.1.1.6.2 yamt /* Convert ASCII 0-9 to Decimal value */
292 1.1.1.1.6.2 yamt
293 1.1.1.1.6.2 yamt ThisDigit = ((UINT8) *String) - '0';
294 1.1.1.1.6.2 yamt }
295 1.1.1.1.6.2 yamt else if (Base == 10)
296 1.1.1.1.6.2 yamt {
297 1.1.1.1.6.2 yamt /* Digit is out of range; possible in ToInteger case only */
298 1.1.1.1.6.2 yamt
299 1.1.1.1.6.2 yamt Term = 1;
300 1.1.1.1.6.2 yamt }
301 1.1.1.1.6.2 yamt else
302 1.1.1.1.6.2 yamt {
303 1.1.1.1.6.2 yamt ThisDigit = (UINT8) ACPI_TOUPPER (*String);
304 1.1.1.1.6.2 yamt if (ACPI_IS_XDIGIT ((char) ThisDigit))
305 1.1.1.1.6.2 yamt {
306 1.1.1.1.6.2 yamt /* Convert ASCII Hex char to value */
307 1.1.1.1.6.2 yamt
308 1.1.1.1.6.2 yamt ThisDigit = ThisDigit - 'A' + 10;
309 1.1.1.1.6.2 yamt }
310 1.1.1.1.6.2 yamt else
311 1.1.1.1.6.2 yamt {
312 1.1.1.1.6.2 yamt Term = 1;
313 1.1.1.1.6.2 yamt }
314 1.1.1.1.6.2 yamt }
315 1.1.1.1.6.2 yamt
316 1.1.1.1.6.2 yamt if (Term)
317 1.1.1.1.6.2 yamt {
318 1.1.1.1.6.2 yamt if (ToIntegerOp)
319 1.1.1.1.6.2 yamt {
320 1.1.1.1.6.2 yamt goto ErrorExit;
321 1.1.1.1.6.2 yamt }
322 1.1.1.1.6.2 yamt else
323 1.1.1.1.6.2 yamt {
324 1.1.1.1.6.2 yamt break;
325 1.1.1.1.6.2 yamt }
326 1.1.1.1.6.2 yamt }
327 1.1.1.1.6.2 yamt else if ((ValidDigits == 0) && (ThisDigit == 0) && !SignOf0x)
328 1.1.1.1.6.2 yamt {
329 1.1.1.1.6.2 yamt /* Skip zeros */
330 1.1.1.1.6.2 yamt String++;
331 1.1.1.1.6.2 yamt continue;
332 1.1.1.1.6.2 yamt }
333 1.1.1.1.6.2 yamt
334 1.1.1.1.6.2 yamt ValidDigits++;
335 1.1.1.1.6.2 yamt
336 1.1.1.1.6.2 yamt if (SignOf0x && ((ValidDigits > 16) || ((ValidDigits > 8) && Mode32)))
337 1.1.1.1.6.2 yamt {
338 1.1.1.1.6.2 yamt /*
339 1.1.1.1.6.2 yamt * This is ToInteger operation case.
340 1.1.1.1.6.2 yamt * No any restrictions for string-to-integer conversion,
341 1.1.1.1.6.2 yamt * see ACPI spec.
342 1.1.1.1.6.2 yamt */
343 1.1.1.1.6.2 yamt goto ErrorExit;
344 1.1.1.1.6.2 yamt }
345 1.1.1.1.6.2 yamt
346 1.1.1.1.6.2 yamt /* Divide the digit into the correct position */
347 1.1.1.1.6.2 yamt
348 1.1.1.1.6.2 yamt (void) AcpiUtShortDivide ((Dividend - (UINT64) ThisDigit),
349 1.1.1.1.6.2 yamt Base, &Quotient, NULL);
350 1.1.1.1.6.2 yamt
351 1.1.1.1.6.2 yamt if (ReturnValue > Quotient)
352 1.1.1.1.6.2 yamt {
353 1.1.1.1.6.2 yamt if (ToIntegerOp)
354 1.1.1.1.6.2 yamt {
355 1.1.1.1.6.2 yamt goto ErrorExit;
356 1.1.1.1.6.2 yamt }
357 1.1.1.1.6.2 yamt else
358 1.1.1.1.6.2 yamt {
359 1.1.1.1.6.2 yamt break;
360 1.1.1.1.6.2 yamt }
361 1.1.1.1.6.2 yamt }
362 1.1.1.1.6.2 yamt
363 1.1.1.1.6.2 yamt ReturnValue *= Base;
364 1.1.1.1.6.2 yamt ReturnValue += ThisDigit;
365 1.1.1.1.6.2 yamt String++;
366 1.1.1.1.6.2 yamt }
367 1.1.1.1.6.2 yamt
368 1.1.1.1.6.2 yamt /* All done, normal exit */
369 1.1.1.1.6.2 yamt
370 1.1.1.1.6.2 yamt AllDone:
371 1.1.1.1.6.2 yamt
372 1.1.1.1.6.2 yamt ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n",
373 1.1.1.1.6.2 yamt ACPI_FORMAT_UINT64 (ReturnValue)));
374 1.1.1.1.6.2 yamt
375 1.1.1.1.6.2 yamt *RetInteger = ReturnValue;
376 1.1.1.1.6.2 yamt return_ACPI_STATUS (AE_OK);
377 1.1.1.1.6.2 yamt
378 1.1.1.1.6.2 yamt
379 1.1.1.1.6.2 yamt ErrorExit:
380 1.1.1.1.6.2 yamt /* Base was set/validated above */
381 1.1.1.1.6.2 yamt
382 1.1.1.1.6.2 yamt if (Base == 10)
383 1.1.1.1.6.2 yamt {
384 1.1.1.1.6.2 yamt return_ACPI_STATUS (AE_BAD_DECIMAL_CONSTANT);
385 1.1.1.1.6.2 yamt }
386 1.1.1.1.6.2 yamt else
387 1.1.1.1.6.2 yamt {
388 1.1.1.1.6.2 yamt return_ACPI_STATUS (AE_BAD_HEX_CONSTANT);
389 1.1.1.1.6.2 yamt }
390 1.1.1.1.6.2 yamt }
391 1.1.1.1.6.2 yamt
392 1.1.1.1.6.2 yamt
393 1.1.1.1.6.2 yamt /*******************************************************************************
394 1.1.1.1.6.2 yamt *
395 1.1.1.1.6.2 yamt * FUNCTION: AcpiUtPrintString
396 1.1.1.1.6.2 yamt *
397 1.1.1.1.6.2 yamt * PARAMETERS: String - Null terminated ASCII string
398 1.1.1.1.6.2 yamt * MaxLength - Maximum output length. Used to constrain the
399 1.1.1.1.6.2 yamt * length of strings during debug output only.
400 1.1.1.1.6.2 yamt *
401 1.1.1.1.6.2 yamt * RETURN: None
402 1.1.1.1.6.2 yamt *
403 1.1.1.1.6.2 yamt * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape
404 1.1.1.1.6.2 yamt * sequences.
405 1.1.1.1.6.2 yamt *
406 1.1.1.1.6.2 yamt ******************************************************************************/
407 1.1.1.1.6.2 yamt
408 1.1.1.1.6.2 yamt void
409 1.1.1.1.6.2 yamt AcpiUtPrintString (
410 1.1.1.1.6.2 yamt char *String,
411 1.1.1.1.6.2 yamt UINT16 MaxLength)
412 1.1.1.1.6.2 yamt {
413 1.1.1.1.6.2 yamt UINT32 i;
414 1.1.1.1.6.2 yamt
415 1.1.1.1.6.2 yamt
416 1.1.1.1.6.2 yamt if (!String)
417 1.1.1.1.6.2 yamt {
418 1.1.1.1.6.2 yamt AcpiOsPrintf ("<\"NULL STRING PTR\">");
419 1.1.1.1.6.2 yamt return;
420 1.1.1.1.6.2 yamt }
421 1.1.1.1.6.2 yamt
422 1.1.1.1.6.2 yamt AcpiOsPrintf ("\"");
423 1.1.1.1.6.2 yamt for (i = 0; String[i] && (i < MaxLength); i++)
424 1.1.1.1.6.2 yamt {
425 1.1.1.1.6.2 yamt /* Escape sequences */
426 1.1.1.1.6.2 yamt
427 1.1.1.1.6.2 yamt switch (String[i])
428 1.1.1.1.6.2 yamt {
429 1.1.1.1.6.2 yamt case 0x07:
430 1.1.1.1.6.2 yamt
431 1.1.1.1.6.2 yamt AcpiOsPrintf ("\\a"); /* BELL */
432 1.1.1.1.6.2 yamt break;
433 1.1.1.1.6.2 yamt
434 1.1.1.1.6.2 yamt case 0x08:
435 1.1.1.1.6.2 yamt
436 1.1.1.1.6.2 yamt AcpiOsPrintf ("\\b"); /* BACKSPACE */
437 1.1.1.1.6.2 yamt break;
438 1.1.1.1.6.2 yamt
439 1.1.1.1.6.2 yamt case 0x0C:
440 1.1.1.1.6.2 yamt
441 1.1.1.1.6.2 yamt AcpiOsPrintf ("\\f"); /* FORMFEED */
442 1.1.1.1.6.2 yamt break;
443 1.1.1.1.6.2 yamt
444 1.1.1.1.6.2 yamt case 0x0A:
445 1.1.1.1.6.2 yamt
446 1.1.1.1.6.2 yamt AcpiOsPrintf ("\\n"); /* LINEFEED */
447 1.1.1.1.6.2 yamt break;
448 1.1.1.1.6.2 yamt
449 1.1.1.1.6.2 yamt case 0x0D:
450 1.1.1.1.6.2 yamt
451 1.1.1.1.6.2 yamt AcpiOsPrintf ("\\r"); /* CARRIAGE RETURN*/
452 1.1.1.1.6.2 yamt break;
453 1.1.1.1.6.2 yamt
454 1.1.1.1.6.2 yamt case 0x09:
455 1.1.1.1.6.2 yamt
456 1.1.1.1.6.2 yamt AcpiOsPrintf ("\\t"); /* HORIZONTAL TAB */
457 1.1.1.1.6.2 yamt break;
458 1.1.1.1.6.2 yamt
459 1.1.1.1.6.2 yamt case 0x0B:
460 1.1.1.1.6.2 yamt
461 1.1.1.1.6.2 yamt AcpiOsPrintf ("\\v"); /* VERTICAL TAB */
462 1.1.1.1.6.2 yamt break;
463 1.1.1.1.6.2 yamt
464 1.1.1.1.6.2 yamt case '\'': /* Single Quote */
465 1.1.1.1.6.2 yamt case '\"': /* Double Quote */
466 1.1.1.1.6.2 yamt case '\\': /* Backslash */
467 1.1.1.1.6.2 yamt
468 1.1.1.1.6.2 yamt AcpiOsPrintf ("\\%c", (int) String[i]);
469 1.1.1.1.6.2 yamt break;
470 1.1.1.1.6.2 yamt
471 1.1.1.1.6.2 yamt default:
472 1.1.1.1.6.2 yamt
473 1.1.1.1.6.2 yamt /* Check for printable character or hex escape */
474 1.1.1.1.6.2 yamt
475 1.1.1.1.6.2 yamt if (ACPI_IS_PRINT (String[i]))
476 1.1.1.1.6.2 yamt {
477 1.1.1.1.6.2 yamt /* This is a normal character */
478 1.1.1.1.6.2 yamt
479 1.1.1.1.6.2 yamt AcpiOsPrintf ("%c", (int) String[i]);
480 1.1.1.1.6.2 yamt }
481 1.1.1.1.6.2 yamt else
482 1.1.1.1.6.2 yamt {
483 1.1.1.1.6.2 yamt /* All others will be Hex escapes */
484 1.1.1.1.6.2 yamt
485 1.1.1.1.6.2 yamt AcpiOsPrintf ("\\x%2.2X", (INT32) String[i]);
486 1.1.1.1.6.2 yamt }
487 1.1.1.1.6.2 yamt break;
488 1.1.1.1.6.2 yamt }
489 1.1.1.1.6.2 yamt }
490 1.1.1.1.6.2 yamt AcpiOsPrintf ("\"");
491 1.1.1.1.6.2 yamt
492 1.1.1.1.6.2 yamt if (i == MaxLength && String[i])
493 1.1.1.1.6.2 yamt {
494 1.1.1.1.6.2 yamt AcpiOsPrintf ("...");
495 1.1.1.1.6.2 yamt }
496 1.1.1.1.6.2 yamt }
497 1.1.1.1.6.2 yamt
498 1.1.1.1.6.2 yamt
499 1.1.1.1.6.2 yamt /*******************************************************************************
500 1.1.1.1.6.2 yamt *
501 1.1.1.1.6.2 yamt * FUNCTION: AcpiUtValidAcpiChar
502 1.1.1.1.6.2 yamt *
503 1.1.1.1.6.2 yamt * PARAMETERS: Char - The character to be examined
504 1.1.1.1.6.2 yamt * Position - Byte position (0-3)
505 1.1.1.1.6.2 yamt *
506 1.1.1.1.6.2 yamt * RETURN: TRUE if the character is valid, FALSE otherwise
507 1.1.1.1.6.2 yamt *
508 1.1.1.1.6.2 yamt * DESCRIPTION: Check for a valid ACPI character. Must be one of:
509 1.1.1.1.6.2 yamt * 1) Upper case alpha
510 1.1.1.1.6.2 yamt * 2) numeric
511 1.1.1.1.6.2 yamt * 3) underscore
512 1.1.1.1.6.2 yamt *
513 1.1.1.1.6.2 yamt * We allow a '!' as the last character because of the ASF! table
514 1.1.1.1.6.2 yamt *
515 1.1.1.1.6.2 yamt ******************************************************************************/
516 1.1.1.1.6.2 yamt
517 1.1.1.1.6.2 yamt BOOLEAN
518 1.1.1.1.6.2 yamt AcpiUtValidAcpiChar (
519 1.1.1.1.6.2 yamt char Character,
520 1.1.1.1.6.2 yamt UINT32 Position)
521 1.1.1.1.6.2 yamt {
522 1.1.1.1.6.2 yamt
523 1.1.1.1.6.2 yamt if (!((Character >= 'A' && Character <= 'Z') ||
524 1.1.1.1.6.2 yamt (Character >= '0' && Character <= '9') ||
525 1.1.1.1.6.2 yamt (Character == '_')))
526 1.1.1.1.6.2 yamt {
527 1.1.1.1.6.2 yamt /* Allow a '!' in the last position */
528 1.1.1.1.6.2 yamt
529 1.1.1.1.6.2 yamt if (Character == '!' && Position == 3)
530 1.1.1.1.6.2 yamt {
531 1.1.1.1.6.2 yamt return (TRUE);
532 1.1.1.1.6.2 yamt }
533 1.1.1.1.6.2 yamt
534 1.1.1.1.6.2 yamt return (FALSE);
535 1.1.1.1.6.2 yamt }
536 1.1.1.1.6.2 yamt
537 1.1.1.1.6.2 yamt return (TRUE);
538 1.1.1.1.6.2 yamt }
539 1.1.1.1.6.2 yamt
540 1.1.1.1.6.2 yamt
541 1.1.1.1.6.2 yamt /*******************************************************************************
542 1.1.1.1.6.2 yamt *
543 1.1.1.1.6.2 yamt * FUNCTION: AcpiUtValidAcpiName
544 1.1.1.1.6.2 yamt *
545 1.1.1.1.6.2 yamt * PARAMETERS: Name - The name to be examined. Does not have to
546 1.1.1.1.6.2 yamt * be NULL terminated string.
547 1.1.1.1.6.2 yamt *
548 1.1.1.1.6.2 yamt * RETURN: TRUE if the name is valid, FALSE otherwise
549 1.1.1.1.6.2 yamt *
550 1.1.1.1.6.2 yamt * DESCRIPTION: Check for a valid ACPI name. Each character must be one of:
551 1.1.1.1.6.2 yamt * 1) Upper case alpha
552 1.1.1.1.6.2 yamt * 2) numeric
553 1.1.1.1.6.2 yamt * 3) underscore
554 1.1.1.1.6.2 yamt *
555 1.1.1.1.6.2 yamt ******************************************************************************/
556 1.1.1.1.6.2 yamt
557 1.1.1.1.6.2 yamt BOOLEAN
558 1.1.1.1.6.2 yamt AcpiUtValidAcpiName (
559 1.1.1.1.6.2 yamt char *Name)
560 1.1.1.1.6.2 yamt {
561 1.1.1.1.6.2 yamt UINT32 i;
562 1.1.1.1.6.2 yamt
563 1.1.1.1.6.2 yamt
564 1.1.1.1.6.2 yamt ACPI_FUNCTION_ENTRY ();
565 1.1.1.1.6.2 yamt
566 1.1.1.1.6.2 yamt
567 1.1.1.1.6.2 yamt for (i = 0; i < ACPI_NAME_SIZE; i++)
568 1.1.1.1.6.2 yamt {
569 1.1.1.1.6.2 yamt if (!AcpiUtValidAcpiChar (Name[i], i))
570 1.1.1.1.6.2 yamt {
571 1.1.1.1.6.2 yamt return (FALSE);
572 1.1.1.1.6.2 yamt }
573 1.1.1.1.6.2 yamt }
574 1.1.1.1.6.2 yamt
575 1.1.1.1.6.2 yamt return (TRUE);
576 1.1.1.1.6.2 yamt }
577 1.1.1.1.6.2 yamt
578 1.1.1.1.6.2 yamt
579 1.1.1.1.6.2 yamt /*******************************************************************************
580 1.1.1.1.6.2 yamt *
581 1.1.1.1.6.2 yamt * FUNCTION: AcpiUtRepairName
582 1.1.1.1.6.2 yamt *
583 1.1.1.1.6.2 yamt * PARAMETERS: Name - The ACPI name to be repaired
584 1.1.1.1.6.2 yamt *
585 1.1.1.1.6.2 yamt * RETURN: Repaired version of the name
586 1.1.1.1.6.2 yamt *
587 1.1.1.1.6.2 yamt * DESCRIPTION: Repair an ACPI name: Change invalid characters to '*' and
588 1.1.1.1.6.2 yamt * return the new name. NOTE: the Name parameter must reside in
589 1.1.1.1.6.2 yamt * read/write memory, cannot be a const.
590 1.1.1.1.6.2 yamt *
591 1.1.1.1.6.2 yamt * An ACPI Name must consist of valid ACPI characters. We will repair the name
592 1.1.1.1.6.2 yamt * if necessary because we don't want to abort because of this, but we want
593 1.1.1.1.6.2 yamt * all namespace names to be printable. A warning message is appropriate.
594 1.1.1.1.6.2 yamt *
595 1.1.1.1.6.2 yamt * This issue came up because there are in fact machines that exhibit
596 1.1.1.1.6.2 yamt * this problem, and we want to be able to enable ACPI support for them,
597 1.1.1.1.6.2 yamt * even though there are a few bad names.
598 1.1.1.1.6.2 yamt *
599 1.1.1.1.6.2 yamt ******************************************************************************/
600 1.1.1.1.6.2 yamt
601 1.1.1.1.6.2 yamt void
602 1.1.1.1.6.2 yamt AcpiUtRepairName (
603 1.1.1.1.6.2 yamt char *Name)
604 1.1.1.1.6.2 yamt {
605 1.1.1.1.6.2 yamt UINT32 i;
606 1.1.1.1.6.2 yamt BOOLEAN FoundBadChar = FALSE;
607 1.1.1.1.6.2 yamt UINT32 OriginalName;
608 1.1.1.1.6.2 yamt
609 1.1.1.1.6.2 yamt
610 1.1.1.1.6.2 yamt ACPI_FUNCTION_NAME (UtRepairName);
611 1.1.1.1.6.2 yamt
612 1.1.1.1.6.2 yamt
613 1.1.1.1.6.2 yamt ACPI_MOVE_NAME (&OriginalName, Name);
614 1.1.1.1.6.2 yamt
615 1.1.1.1.6.2 yamt /* Check each character in the name */
616 1.1.1.1.6.2 yamt
617 1.1.1.1.6.2 yamt for (i = 0; i < ACPI_NAME_SIZE; i++)
618 1.1.1.1.6.2 yamt {
619 1.1.1.1.6.2 yamt if (AcpiUtValidAcpiChar (Name[i], i))
620 1.1.1.1.6.2 yamt {
621 1.1.1.1.6.2 yamt continue;
622 1.1.1.1.6.2 yamt }
623 1.1.1.1.6.2 yamt
624 1.1.1.1.6.2 yamt /*
625 1.1.1.1.6.2 yamt * Replace a bad character with something printable, yet technically
626 1.1.1.1.6.2 yamt * still invalid. This prevents any collisions with existing "good"
627 1.1.1.1.6.2 yamt * names in the namespace.
628 1.1.1.1.6.2 yamt */
629 1.1.1.1.6.2 yamt Name[i] = '*';
630 1.1.1.1.6.2 yamt FoundBadChar = TRUE;
631 1.1.1.1.6.2 yamt }
632 1.1.1.1.6.2 yamt
633 1.1.1.1.6.2 yamt if (FoundBadChar)
634 1.1.1.1.6.2 yamt {
635 1.1.1.1.6.2 yamt /* Report warning only if in strict mode or debug mode */
636 1.1.1.1.6.2 yamt
637 1.1.1.1.6.2 yamt if (!AcpiGbl_EnableInterpreterSlack)
638 1.1.1.1.6.2 yamt {
639 1.1.1.1.6.2 yamt ACPI_WARNING ((AE_INFO,
640 1.1.1.1.6.2 yamt "Invalid character(s) in name (0x%.8X), repaired: [%4.4s]",
641 1.1.1.1.6.2 yamt OriginalName, Name));
642 1.1.1.1.6.2 yamt }
643 1.1.1.1.6.2 yamt else
644 1.1.1.1.6.2 yamt {
645 1.1.1.1.6.2 yamt ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
646 1.1.1.1.6.2 yamt "Invalid character(s) in name (0x%.8X), repaired: [%4.4s]",
647 1.1.1.1.6.2 yamt OriginalName, Name));
648 1.1.1.1.6.2 yamt }
649 1.1.1.1.6.2 yamt }
650 1.1.1.1.6.2 yamt }
651 1.1.1.1.6.2 yamt
652 1.1.1.1.6.2 yamt
653 1.1.1.1.6.2 yamt #if defined ACPI_ASL_COMPILER || defined ACPI_EXEC_APP
654 1.1.1.1.6.2 yamt /*******************************************************************************
655 1.1.1.1.6.2 yamt *
656 1.1.1.1.6.2 yamt * FUNCTION: UtConvertBackslashes
657 1.1.1.1.6.2 yamt *
658 1.1.1.1.6.2 yamt * PARAMETERS: Pathname - File pathname string to be converted
659 1.1.1.1.6.2 yamt *
660 1.1.1.1.6.2 yamt * RETURN: Modifies the input Pathname
661 1.1.1.1.6.2 yamt *
662 1.1.1.1.6.2 yamt * DESCRIPTION: Convert all backslashes (0x5C) to forward slashes (0x2F) within
663 1.1.1.1.6.2 yamt * the entire input file pathname string.
664 1.1.1.1.6.2 yamt *
665 1.1.1.1.6.2 yamt ******************************************************************************/
666 1.1.1.1.6.2 yamt
667 1.1.1.1.6.2 yamt void
668 1.1.1.1.6.2 yamt UtConvertBackslashes (
669 1.1.1.1.6.2 yamt char *Pathname)
670 1.1.1.1.6.2 yamt {
671 1.1.1.1.6.2 yamt
672 1.1.1.1.6.2 yamt if (!Pathname)
673 1.1.1.1.6.2 yamt {
674 1.1.1.1.6.2 yamt return;
675 1.1.1.1.6.2 yamt }
676 1.1.1.1.6.2 yamt
677 1.1.1.1.6.2 yamt while (*Pathname)
678 1.1.1.1.6.2 yamt {
679 1.1.1.1.6.2 yamt if (*Pathname == '\\')
680 1.1.1.1.6.2 yamt {
681 1.1.1.1.6.2 yamt *Pathname = '/';
682 1.1.1.1.6.2 yamt }
683 1.1.1.1.6.2 yamt
684 1.1.1.1.6.2 yamt Pathname++;
685 1.1.1.1.6.2 yamt }
686 1.1.1.1.6.2 yamt }
687 1.1.1.1.6.2 yamt #endif
688 1.1.1.1.6.2 yamt
689 1.1.1.1.6.2 yamt #if defined (ACPI_DEBUGGER) || defined (ACPI_APPLICATION)
690 1.1.1.1.6.2 yamt /*******************************************************************************
691 1.1.1.1.6.2 yamt *
692 1.1.1.1.6.2 yamt * FUNCTION: AcpiUtSafeStrcpy, AcpiUtSafeStrcat, AcpiUtSafeStrncat
693 1.1.1.1.6.2 yamt *
694 1.1.1.1.6.2 yamt * PARAMETERS: Adds a "DestSize" parameter to each of the standard string
695 1.1.1.1.6.2 yamt * functions. This is the size of the Destination buffer.
696 1.1.1.1.6.2 yamt *
697 1.1.1.1.6.2 yamt * RETURN: TRUE if the operation would overflow the destination buffer.
698 1.1.1.1.6.2 yamt *
699 1.1.1.1.6.2 yamt * DESCRIPTION: Safe versions of standard Clib string functions. Ensure that
700 1.1.1.1.6.2 yamt * the result of the operation will not overflow the output string
701 1.1.1.1.6.2 yamt * buffer.
702 1.1.1.1.6.2 yamt *
703 1.1.1.1.6.2 yamt * NOTE: These functions are typically only helpful for processing
704 1.1.1.1.6.2 yamt * user input and command lines. For most ACPICA code, the
705 1.1.1.1.6.2 yamt * required buffer length is precisely calculated before buffer
706 1.1.1.1.6.2 yamt * allocation, so the use of these functions is unnecessary.
707 1.1.1.1.6.2 yamt *
708 1.1.1.1.6.2 yamt ******************************************************************************/
709 1.1.1.1.6.2 yamt
710 1.1.1.1.6.2 yamt BOOLEAN
711 1.1.1.1.6.2 yamt AcpiUtSafeStrcpy (
712 1.1.1.1.6.2 yamt char *Dest,
713 1.1.1.1.6.2 yamt ACPI_SIZE DestSize,
714 1.1.1.1.6.2 yamt char *Source)
715 1.1.1.1.6.2 yamt {
716 1.1.1.1.6.2 yamt
717 1.1.1.1.6.2 yamt if (ACPI_STRLEN (Source) >= DestSize)
718 1.1.1.1.6.2 yamt {
719 1.1.1.1.6.2 yamt return (TRUE);
720 1.1.1.1.6.2 yamt }
721 1.1.1.1.6.2 yamt
722 1.1.1.1.6.2 yamt ACPI_STRCPY (Dest, Source);
723 1.1.1.1.6.2 yamt return (FALSE);
724 1.1.1.1.6.2 yamt }
725 1.1.1.1.6.2 yamt
726 1.1.1.1.6.2 yamt BOOLEAN
727 1.1.1.1.6.2 yamt AcpiUtSafeStrcat (
728 1.1.1.1.6.2 yamt char *Dest,
729 1.1.1.1.6.2 yamt ACPI_SIZE DestSize,
730 1.1.1.1.6.2 yamt char *Source)
731 1.1.1.1.6.2 yamt {
732 1.1.1.1.6.2 yamt
733 1.1.1.1.6.2 yamt if ((ACPI_STRLEN (Dest) + ACPI_STRLEN (Source)) >= DestSize)
734 1.1.1.1.6.2 yamt {
735 1.1.1.1.6.2 yamt return (TRUE);
736 1.1.1.1.6.2 yamt }
737 1.1.1.1.6.2 yamt
738 1.1.1.1.6.2 yamt ACPI_STRCAT (Dest, Source);
739 1.1.1.1.6.2 yamt return (FALSE);
740 1.1.1.1.6.2 yamt }
741 1.1.1.1.6.2 yamt
742 1.1.1.1.6.2 yamt BOOLEAN
743 1.1.1.1.6.2 yamt AcpiUtSafeStrncat (
744 1.1.1.1.6.2 yamt char *Dest,
745 1.1.1.1.6.2 yamt ACPI_SIZE DestSize,
746 1.1.1.1.6.2 yamt char *Source,
747 1.1.1.1.6.2 yamt ACPI_SIZE MaxTransferLength)
748 1.1.1.1.6.2 yamt {
749 1.1.1.1.6.2 yamt ACPI_SIZE ActualTransferLength;
750 1.1.1.1.6.2 yamt
751 1.1.1.1.6.2 yamt
752 1.1.1.1.6.2 yamt ActualTransferLength = ACPI_MIN (MaxTransferLength, ACPI_STRLEN (Source));
753 1.1.1.1.6.2 yamt
754 1.1.1.1.6.2 yamt if ((ACPI_STRLEN (Dest) + ActualTransferLength) >= DestSize)
755 1.1.1.1.6.2 yamt {
756 1.1.1.1.6.2 yamt return (TRUE);
757 1.1.1.1.6.2 yamt }
758 1.1.1.1.6.2 yamt
759 1.1.1.1.6.2 yamt ACPI_STRNCAT (Dest, Source, MaxTransferLength);
760 1.1.1.1.6.2 yamt return (FALSE);
761 1.1.1.1.6.2 yamt }
762 1.1.1.1.6.2 yamt #endif
763