1 /*******************************************************************************
3 * Module Name: utstring - Common functions for strings and characters
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2015, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
49 #define _COMPONENT ACPI_UTILITIES
50 ACPI_MODULE_NAME ("utstring")
53 /*******************************************************************************
55 * FUNCTION: AcpiUtPrintString
57 * PARAMETERS: String - Null terminated ASCII string
58 * MaxLength - Maximum output length. Used to constrain the
59 * length of strings during debug output only.
63 * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape
66 ******************************************************************************/
78 AcpiOsPrintf ("<\"NULL STRING PTR\">");
83 for (i = 0; (i < MaxLength) && String[i]; i++)
85 /* Escape sequences */
91 AcpiOsPrintf ("\\a"); /* BELL */
96 AcpiOsPrintf ("\\b"); /* BACKSPACE */
101 AcpiOsPrintf ("\\f"); /* FORMFEED */
106 AcpiOsPrintf ("\\n"); /* LINEFEED */
111 AcpiOsPrintf ("\\r"); /* CARRIAGE RETURN*/
116 AcpiOsPrintf ("\\t"); /* HORIZONTAL TAB */
121 AcpiOsPrintf ("\\v"); /* VERTICAL TAB */
124 case '\'': /* Single Quote */
125 case '\"': /* Double Quote */
126 case '\\': /* Backslash */
128 AcpiOsPrintf ("\\%c", (int) String[i]);
133 /* Check for printable character or hex escape */
135 if (isprint ((int) String[i]))
137 /* This is a normal character */
139 AcpiOsPrintf ("%c", (int) String[i]);
143 /* All others will be Hex escapes */
145 AcpiOsPrintf ("\\x%2.2X", (INT32) String[i]);
153 if (i == MaxLength && String[i])
155 AcpiOsPrintf ("...");
160 /*******************************************************************************
162 * FUNCTION: AcpiUtValidAcpiChar
164 * PARAMETERS: Char - The character to be examined
165 * Position - Byte position (0-3)
167 * RETURN: TRUE if the character is valid, FALSE otherwise
169 * DESCRIPTION: Check for a valid ACPI character. Must be one of:
170 * 1) Upper case alpha
174 * We allow a '!' as the last character because of the ASF! table
176 ******************************************************************************/
179 AcpiUtValidAcpiChar (
184 if (!((Character >= 'A' && Character <= 'Z') ||
185 (Character >= '0' && Character <= '9') ||
188 /* Allow a '!' in the last position */
190 if (Character == '!' && Position == 3)
202 /*******************************************************************************
204 * FUNCTION: AcpiUtValidAcpiName
206 * PARAMETERS: Name - The name to be examined. Does not have to
207 * be NULL terminated string.
209 * RETURN: TRUE if the name is valid, FALSE otherwise
211 * DESCRIPTION: Check for a valid ACPI name. Each character must be one of:
212 * 1) Upper case alpha
216 ******************************************************************************/
219 AcpiUtValidAcpiName (
225 ACPI_FUNCTION_ENTRY ();
228 for (i = 0; i < ACPI_NAME_SIZE; i++)
230 if (!AcpiUtValidAcpiChar (Name[i], i))
240 /*******************************************************************************
242 * FUNCTION: AcpiUtRepairName
244 * PARAMETERS: Name - The ACPI name to be repaired
246 * RETURN: Repaired version of the name
248 * DESCRIPTION: Repair an ACPI name: Change invalid characters to '*' and
249 * return the new name. NOTE: the Name parameter must reside in
250 * read/write memory, cannot be a const.
252 * An ACPI Name must consist of valid ACPI characters. We will repair the name
253 * if necessary because we don't want to abort because of this, but we want
254 * all namespace names to be printable. A warning message is appropriate.
256 * This issue came up because there are in fact machines that exhibit
257 * this problem, and we want to be able to enable ACPI support for them,
258 * even though there are a few bad names.
260 ******************************************************************************/
267 BOOLEAN FoundBadChar = FALSE;
271 ACPI_FUNCTION_NAME (UtRepairName);
274 ACPI_MOVE_NAME (&OriginalName, Name);
276 /* Check each character in the name */
278 for (i = 0; i < ACPI_NAME_SIZE; i++)
280 if (AcpiUtValidAcpiChar (Name[i], i))
286 * Replace a bad character with something printable, yet technically
287 * still invalid. This prevents any collisions with existing "good"
288 * names in the namespace.
296 /* Report warning only if in strict mode or debug mode */
298 if (!AcpiGbl_EnableInterpreterSlack)
300 ACPI_WARNING ((AE_INFO,
301 "Invalid character(s) in name (0x%.8X), repaired: [%4.4s]",
302 OriginalName, Name));
306 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
307 "Invalid character(s) in name (0x%.8X), repaired: [%4.4s]",
308 OriginalName, Name));
314 #if defined ACPI_ASL_COMPILER || defined ACPI_EXEC_APP
315 /*******************************************************************************
317 * FUNCTION: UtConvertBackslashes
319 * PARAMETERS: Pathname - File pathname string to be converted
321 * RETURN: Modifies the input Pathname
323 * DESCRIPTION: Convert all backslashes (0x5C) to forward slashes (0x2F) within
324 * the entire input file pathname string.
326 ******************************************************************************/
329 UtConvertBackslashes (
340 if (*Pathname == '\\')