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