![]() |
|
|||
0001 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 0002 /******************************************************************************* 0003 * 0004 * Module Name: utstring - Common functions for strings and characters 0005 * 0006 ******************************************************************************/ 0007 0008 #include <acpi/acpi.h> 0009 #include "accommon.h" 0010 #include "acnamesp.h" 0011 0012 #define _COMPONENT ACPI_UTILITIES 0013 ACPI_MODULE_NAME("utstring") 0014 0015 /******************************************************************************* 0016 * 0017 * FUNCTION: acpi_ut_print_string 0018 * 0019 * PARAMETERS: string - Null terminated ASCII string 0020 * max_length - Maximum output length. Used to constrain the 0021 * length of strings during debug output only. 0022 * 0023 * RETURN: None 0024 * 0025 * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape 0026 * sequences. 0027 * 0028 ******************************************************************************/ 0029 void acpi_ut_print_string(char *string, u16 max_length) 0030 { 0031 u32 i; 0032 0033 if (!string) { 0034 acpi_os_printf("<\"NULL STRING PTR\">"); 0035 return; 0036 } 0037 0038 acpi_os_printf("\""); 0039 for (i = 0; (i < max_length) && string[i]; i++) { 0040 0041 /* Escape sequences */ 0042 0043 switch (string[i]) { 0044 case 0x07: 0045 0046 acpi_os_printf("\\a"); /* BELL */ 0047 break; 0048 0049 case 0x08: 0050 0051 acpi_os_printf("\\b"); /* BACKSPACE */ 0052 break; 0053 0054 case 0x0C: 0055 0056 acpi_os_printf("\\f"); /* FORMFEED */ 0057 break; 0058 0059 case 0x0A: 0060 0061 acpi_os_printf("\\n"); /* LINEFEED */ 0062 break; 0063 0064 case 0x0D: 0065 0066 acpi_os_printf("\\r"); /* CARRIAGE RETURN */ 0067 break; 0068 0069 case 0x09: 0070 0071 acpi_os_printf("\\t"); /* HORIZONTAL TAB */ 0072 break; 0073 0074 case 0x0B: 0075 0076 acpi_os_printf("\\v"); /* VERTICAL TAB */ 0077 break; 0078 0079 case '\'': /* Single Quote */ 0080 case '\"': /* Double Quote */ 0081 case '\\': /* Backslash */ 0082 0083 acpi_os_printf("\\%c", (int)string[i]); 0084 break; 0085 0086 default: 0087 0088 /* Check for printable character or hex escape */ 0089 0090 if (isprint((int)string[i])) { 0091 /* This is a normal character */ 0092 0093 acpi_os_printf("%c", (int)string[i]); 0094 } else { 0095 /* All others will be Hex escapes */ 0096 0097 acpi_os_printf("\\x%2.2X", (s32)string[i]); 0098 } 0099 break; 0100 } 0101 } 0102 0103 acpi_os_printf("\""); 0104 0105 if (i == max_length && string[i]) { 0106 acpi_os_printf("..."); 0107 } 0108 } 0109 0110 /******************************************************************************* 0111 * 0112 * FUNCTION: acpi_ut_repair_name 0113 * 0114 * PARAMETERS: name - The ACPI name to be repaired 0115 * 0116 * RETURN: Repaired version of the name 0117 * 0118 * DESCRIPTION: Repair an ACPI name: Change invalid characters to '*' and 0119 * return the new name. NOTE: the Name parameter must reside in 0120 * read/write memory, cannot be a const. 0121 * 0122 * An ACPI Name must consist of valid ACPI characters. We will repair the name 0123 * if necessary because we don't want to abort because of this, but we want 0124 * all namespace names to be printable. A warning message is appropriate. 0125 * 0126 * This issue came up because there are in fact machines that exhibit 0127 * this problem, and we want to be able to enable ACPI support for them, 0128 * even though there are a few bad names. 0129 * 0130 ******************************************************************************/ 0131 0132 void acpi_ut_repair_name(char *name) 0133 { 0134 u32 i; 0135 u8 found_bad_char = FALSE; 0136 u32 original_name; 0137 0138 ACPI_FUNCTION_NAME(ut_repair_name); 0139 0140 /* 0141 * Special case for the root node. This can happen if we get an 0142 * error during the execution of module-level code. 0143 */ 0144 if (ACPI_COMPARE_NAMESEG(name, ACPI_ROOT_PATHNAME)) { 0145 return; 0146 } 0147 0148 ACPI_COPY_NAMESEG(&original_name, name); 0149 0150 /* Check each character in the name */ 0151 0152 for (i = 0; i < ACPI_NAMESEG_SIZE; i++) { 0153 if (acpi_ut_valid_name_char(name[i], i)) { 0154 continue; 0155 } 0156 0157 /* 0158 * Replace a bad character with something printable, yet technically 0159 * still invalid. This prevents any collisions with existing "good" 0160 * names in the namespace. 0161 */ 0162 name[i] = '*'; 0163 found_bad_char = TRUE; 0164 } 0165 0166 if (found_bad_char) { 0167 0168 /* Report warning only if in strict mode or debug mode */ 0169 0170 if (!acpi_gbl_enable_interpreter_slack) { 0171 ACPI_WARNING((AE_INFO, 0172 "Invalid character(s) in name (0x%.8X), repaired: [%4.4s]", 0173 original_name, name)); 0174 } else { 0175 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 0176 "Invalid character(s) in name (0x%.8X), repaired: [%4.4s]", 0177 original_name, name)); 0178 } 0179 } 0180 } 0181 0182 #if defined ACPI_ASL_COMPILER || defined ACPI_EXEC_APP 0183 /******************************************************************************* 0184 * 0185 * FUNCTION: ut_convert_backslashes 0186 * 0187 * PARAMETERS: pathname - File pathname string to be converted 0188 * 0189 * RETURN: Modifies the input Pathname 0190 * 0191 * DESCRIPTION: Convert all backslashes (0x5C) to forward slashes (0x2F) within 0192 * the entire input file pathname string. 0193 * 0194 ******************************************************************************/ 0195 0196 void ut_convert_backslashes(char *pathname) 0197 { 0198 0199 if (!pathname) { 0200 return; 0201 } 0202 0203 while (*pathname) { 0204 if (*pathname == '\\') { 0205 *pathname = '/'; 0206 } 0207 0208 pathname++; 0209 } 0210 } 0211 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |