Home | History | Annotate | Line # | Download | only in utilities
utstring.c revision 1.1.1.1.10.3
      1  1.1.1.1.10.2       tls /*******************************************************************************
      2  1.1.1.1.10.2       tls  *
      3  1.1.1.1.10.2       tls  * Module Name: utstring - Common functions for strings and characters
      4  1.1.1.1.10.2       tls  *
      5  1.1.1.1.10.2       tls  ******************************************************************************/
      6  1.1.1.1.10.2       tls 
      7  1.1.1.1.10.2       tls /*
      8  1.1.1.1.10.3  jdolecek  * Copyright (C) 2000 - 2017, Intel Corp.
      9  1.1.1.1.10.2       tls  * All rights reserved.
     10  1.1.1.1.10.2       tls  *
     11  1.1.1.1.10.2       tls  * Redistribution and use in source and binary forms, with or without
     12  1.1.1.1.10.2       tls  * modification, are permitted provided that the following conditions
     13  1.1.1.1.10.2       tls  * are met:
     14  1.1.1.1.10.2       tls  * 1. Redistributions of source code must retain the above copyright
     15  1.1.1.1.10.2       tls  *    notice, this list of conditions, and the following disclaimer,
     16  1.1.1.1.10.2       tls  *    without modification.
     17  1.1.1.1.10.2       tls  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  1.1.1.1.10.2       tls  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  1.1.1.1.10.2       tls  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  1.1.1.1.10.2       tls  *    including a substantially similar Disclaimer requirement for further
     21  1.1.1.1.10.2       tls  *    binary redistribution.
     22  1.1.1.1.10.2       tls  * 3. Neither the names of the above-listed copyright holders nor the names
     23  1.1.1.1.10.2       tls  *    of any contributors may be used to endorse or promote products derived
     24  1.1.1.1.10.2       tls  *    from this software without specific prior written permission.
     25  1.1.1.1.10.2       tls  *
     26  1.1.1.1.10.2       tls  * Alternatively, this software may be distributed under the terms of the
     27  1.1.1.1.10.2       tls  * GNU General Public License ("GPL") version 2 as published by the Free
     28  1.1.1.1.10.2       tls  * Software Foundation.
     29  1.1.1.1.10.2       tls  *
     30  1.1.1.1.10.2       tls  * NO WARRANTY
     31  1.1.1.1.10.2       tls  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  1.1.1.1.10.2       tls  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.1.10.2       tls  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  1.1.1.1.10.2       tls  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  1.1.1.1.10.2       tls  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  1.1.1.1.10.2       tls  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  1.1.1.1.10.2       tls  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  1.1.1.1.10.2       tls  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  1.1.1.1.10.2       tls  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  1.1.1.1.10.2       tls  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  1.1.1.1.10.2       tls  * POSSIBILITY OF SUCH DAMAGES.
     42  1.1.1.1.10.2       tls  */
     43  1.1.1.1.10.2       tls 
     44  1.1.1.1.10.2       tls #include "acpi.h"
     45  1.1.1.1.10.2       tls #include "accommon.h"
     46  1.1.1.1.10.2       tls #include "acnamesp.h"
     47  1.1.1.1.10.2       tls 
     48  1.1.1.1.10.2       tls 
     49  1.1.1.1.10.2       tls #define _COMPONENT          ACPI_UTILITIES
     50  1.1.1.1.10.2       tls         ACPI_MODULE_NAME    ("utstring")
     51  1.1.1.1.10.2       tls 
     52  1.1.1.1.10.2       tls 
     53  1.1.1.1.10.2       tls /*******************************************************************************
     54  1.1.1.1.10.2       tls  *
     55  1.1.1.1.10.2       tls  * FUNCTION:    AcpiUtPrintString
     56  1.1.1.1.10.2       tls  *
     57  1.1.1.1.10.2       tls  * PARAMETERS:  String          - Null terminated ASCII string
     58  1.1.1.1.10.2       tls  *              MaxLength       - Maximum output length. Used to constrain the
     59  1.1.1.1.10.2       tls  *                                length of strings during debug output only.
     60  1.1.1.1.10.2       tls  *
     61  1.1.1.1.10.2       tls  * RETURN:      None
     62  1.1.1.1.10.2       tls  *
     63  1.1.1.1.10.2       tls  * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape
     64  1.1.1.1.10.2       tls  *              sequences.
     65  1.1.1.1.10.2       tls  *
     66  1.1.1.1.10.2       tls  ******************************************************************************/
     67  1.1.1.1.10.2       tls 
     68  1.1.1.1.10.2       tls void
     69  1.1.1.1.10.2       tls AcpiUtPrintString (
     70  1.1.1.1.10.2       tls     char                    *String,
     71  1.1.1.1.10.2       tls     UINT16                  MaxLength)
     72  1.1.1.1.10.2       tls {
     73  1.1.1.1.10.2       tls     UINT32                  i;
     74  1.1.1.1.10.2       tls 
     75  1.1.1.1.10.2       tls 
     76  1.1.1.1.10.2       tls     if (!String)
     77  1.1.1.1.10.2       tls     {
     78  1.1.1.1.10.2       tls         AcpiOsPrintf ("<\"NULL STRING PTR\">");
     79  1.1.1.1.10.2       tls         return;
     80  1.1.1.1.10.2       tls     }
     81  1.1.1.1.10.2       tls 
     82  1.1.1.1.10.2       tls     AcpiOsPrintf ("\"");
     83  1.1.1.1.10.3  jdolecek     for (i = 0; (i < MaxLength) && String[i]; i++)
     84  1.1.1.1.10.2       tls     {
     85  1.1.1.1.10.2       tls         /* Escape sequences */
     86  1.1.1.1.10.2       tls 
     87  1.1.1.1.10.2       tls         switch (String[i])
     88  1.1.1.1.10.2       tls         {
     89  1.1.1.1.10.2       tls         case 0x07:
     90  1.1.1.1.10.2       tls 
     91  1.1.1.1.10.2       tls             AcpiOsPrintf ("\\a");       /* BELL */
     92  1.1.1.1.10.2       tls             break;
     93  1.1.1.1.10.2       tls 
     94  1.1.1.1.10.2       tls         case 0x08:
     95  1.1.1.1.10.2       tls 
     96  1.1.1.1.10.2       tls             AcpiOsPrintf ("\\b");       /* BACKSPACE */
     97  1.1.1.1.10.2       tls             break;
     98  1.1.1.1.10.2       tls 
     99  1.1.1.1.10.2       tls         case 0x0C:
    100  1.1.1.1.10.2       tls 
    101  1.1.1.1.10.2       tls             AcpiOsPrintf ("\\f");       /* FORMFEED */
    102  1.1.1.1.10.2       tls             break;
    103  1.1.1.1.10.2       tls 
    104  1.1.1.1.10.2       tls         case 0x0A:
    105  1.1.1.1.10.2       tls 
    106  1.1.1.1.10.2       tls             AcpiOsPrintf ("\\n");       /* LINEFEED */
    107  1.1.1.1.10.2       tls             break;
    108  1.1.1.1.10.2       tls 
    109  1.1.1.1.10.2       tls         case 0x0D:
    110  1.1.1.1.10.2       tls 
    111  1.1.1.1.10.2       tls             AcpiOsPrintf ("\\r");       /* CARRIAGE RETURN*/
    112  1.1.1.1.10.2       tls             break;
    113  1.1.1.1.10.2       tls 
    114  1.1.1.1.10.2       tls         case 0x09:
    115  1.1.1.1.10.2       tls 
    116  1.1.1.1.10.2       tls             AcpiOsPrintf ("\\t");       /* HORIZONTAL TAB */
    117  1.1.1.1.10.2       tls             break;
    118  1.1.1.1.10.2       tls 
    119  1.1.1.1.10.2       tls         case 0x0B:
    120  1.1.1.1.10.2       tls 
    121  1.1.1.1.10.2       tls             AcpiOsPrintf ("\\v");       /* VERTICAL TAB */
    122  1.1.1.1.10.2       tls             break;
    123  1.1.1.1.10.2       tls 
    124  1.1.1.1.10.2       tls         case '\'':                      /* Single Quote */
    125  1.1.1.1.10.2       tls         case '\"':                      /* Double Quote */
    126  1.1.1.1.10.2       tls         case '\\':                      /* Backslash */
    127  1.1.1.1.10.2       tls 
    128  1.1.1.1.10.2       tls             AcpiOsPrintf ("\\%c", (int) String[i]);
    129  1.1.1.1.10.2       tls             break;
    130  1.1.1.1.10.2       tls 
    131  1.1.1.1.10.2       tls         default:
    132  1.1.1.1.10.2       tls 
    133  1.1.1.1.10.2       tls             /* Check for printable character or hex escape */
    134  1.1.1.1.10.2       tls 
    135  1.1.1.1.10.3  jdolecek             if (isprint ((int) String[i]))
    136  1.1.1.1.10.2       tls             {
    137  1.1.1.1.10.2       tls                 /* This is a normal character */
    138  1.1.1.1.10.2       tls 
    139  1.1.1.1.10.2       tls                 AcpiOsPrintf ("%c", (int) String[i]);
    140  1.1.1.1.10.2       tls             }
    141  1.1.1.1.10.2       tls             else
    142  1.1.1.1.10.2       tls             {
    143  1.1.1.1.10.2       tls                 /* All others will be Hex escapes */
    144  1.1.1.1.10.2       tls 
    145  1.1.1.1.10.2       tls                 AcpiOsPrintf ("\\x%2.2X", (INT32) String[i]);
    146  1.1.1.1.10.2       tls             }
    147  1.1.1.1.10.2       tls             break;
    148  1.1.1.1.10.2       tls         }
    149  1.1.1.1.10.2       tls     }
    150  1.1.1.1.10.3  jdolecek 
    151  1.1.1.1.10.2       tls     AcpiOsPrintf ("\"");
    152  1.1.1.1.10.2       tls 
    153  1.1.1.1.10.2       tls     if (i == MaxLength && String[i])
    154  1.1.1.1.10.2       tls     {
    155  1.1.1.1.10.2       tls         AcpiOsPrintf ("...");
    156  1.1.1.1.10.2       tls     }
    157  1.1.1.1.10.2       tls }
    158  1.1.1.1.10.2       tls 
    159  1.1.1.1.10.2       tls 
    160  1.1.1.1.10.2       tls /*******************************************************************************
    161  1.1.1.1.10.2       tls  *
    162  1.1.1.1.10.2       tls  * FUNCTION:    AcpiUtRepairName
    163  1.1.1.1.10.2       tls  *
    164  1.1.1.1.10.2       tls  * PARAMETERS:  Name            - The ACPI name to be repaired
    165  1.1.1.1.10.2       tls  *
    166  1.1.1.1.10.2       tls  * RETURN:      Repaired version of the name
    167  1.1.1.1.10.2       tls  *
    168  1.1.1.1.10.2       tls  * DESCRIPTION: Repair an ACPI name: Change invalid characters to '*' and
    169  1.1.1.1.10.2       tls  *              return the new name. NOTE: the Name parameter must reside in
    170  1.1.1.1.10.2       tls  *              read/write memory, cannot be a const.
    171  1.1.1.1.10.2       tls  *
    172  1.1.1.1.10.2       tls  * An ACPI Name must consist of valid ACPI characters. We will repair the name
    173  1.1.1.1.10.2       tls  * if necessary because we don't want to abort because of this, but we want
    174  1.1.1.1.10.2       tls  * all namespace names to be printable. A warning message is appropriate.
    175  1.1.1.1.10.2       tls  *
    176  1.1.1.1.10.2       tls  * This issue came up because there are in fact machines that exhibit
    177  1.1.1.1.10.2       tls  * this problem, and we want to be able to enable ACPI support for them,
    178  1.1.1.1.10.2       tls  * even though there are a few bad names.
    179  1.1.1.1.10.2       tls  *
    180  1.1.1.1.10.2       tls  ******************************************************************************/
    181  1.1.1.1.10.2       tls 
    182  1.1.1.1.10.2       tls void
    183  1.1.1.1.10.2       tls AcpiUtRepairName (
    184  1.1.1.1.10.2       tls     char                    *Name)
    185  1.1.1.1.10.2       tls {
    186  1.1.1.1.10.2       tls     UINT32                  i;
    187  1.1.1.1.10.2       tls     BOOLEAN                 FoundBadChar = FALSE;
    188  1.1.1.1.10.2       tls     UINT32                  OriginalName;
    189  1.1.1.1.10.2       tls 
    190  1.1.1.1.10.2       tls 
    191  1.1.1.1.10.2       tls     ACPI_FUNCTION_NAME (UtRepairName);
    192  1.1.1.1.10.2       tls 
    193  1.1.1.1.10.2       tls 
    194  1.1.1.1.10.3  jdolecek     /*
    195  1.1.1.1.10.3  jdolecek      * Special case for the root node. This can happen if we get an
    196  1.1.1.1.10.3  jdolecek      * error during the execution of module-level code.
    197  1.1.1.1.10.3  jdolecek      */
    198  1.1.1.1.10.3  jdolecek     if (ACPI_COMPARE_NAME (Name, "\\___"))
    199  1.1.1.1.10.3  jdolecek     {
    200  1.1.1.1.10.3  jdolecek         return;
    201  1.1.1.1.10.3  jdolecek     }
    202  1.1.1.1.10.3  jdolecek 
    203  1.1.1.1.10.2       tls     ACPI_MOVE_NAME (&OriginalName, Name);
    204  1.1.1.1.10.2       tls 
    205  1.1.1.1.10.2       tls     /* Check each character in the name */
    206  1.1.1.1.10.2       tls 
    207  1.1.1.1.10.2       tls     for (i = 0; i < ACPI_NAME_SIZE; i++)
    208  1.1.1.1.10.2       tls     {
    209  1.1.1.1.10.3  jdolecek         if (AcpiUtValidNameChar (Name[i], i))
    210  1.1.1.1.10.2       tls         {
    211  1.1.1.1.10.2       tls             continue;
    212  1.1.1.1.10.2       tls         }
    213  1.1.1.1.10.2       tls 
    214  1.1.1.1.10.2       tls         /*
    215  1.1.1.1.10.2       tls          * Replace a bad character with something printable, yet technically
    216  1.1.1.1.10.2       tls          * still invalid. This prevents any collisions with existing "good"
    217  1.1.1.1.10.2       tls          * names in the namespace.
    218  1.1.1.1.10.2       tls          */
    219  1.1.1.1.10.2       tls         Name[i] = '*';
    220  1.1.1.1.10.2       tls         FoundBadChar = TRUE;
    221  1.1.1.1.10.2       tls     }
    222  1.1.1.1.10.2       tls 
    223  1.1.1.1.10.2       tls     if (FoundBadChar)
    224  1.1.1.1.10.2       tls     {
    225  1.1.1.1.10.2       tls         /* Report warning only if in strict mode or debug mode */
    226  1.1.1.1.10.2       tls 
    227  1.1.1.1.10.2       tls         if (!AcpiGbl_EnableInterpreterSlack)
    228  1.1.1.1.10.2       tls         {
    229  1.1.1.1.10.2       tls             ACPI_WARNING ((AE_INFO,
    230  1.1.1.1.10.2       tls                 "Invalid character(s) in name (0x%.8X), repaired: [%4.4s]",
    231  1.1.1.1.10.2       tls                 OriginalName, Name));
    232  1.1.1.1.10.2       tls         }
    233  1.1.1.1.10.2       tls         else
    234  1.1.1.1.10.2       tls         {
    235  1.1.1.1.10.2       tls             ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
    236  1.1.1.1.10.2       tls                 "Invalid character(s) in name (0x%.8X), repaired: [%4.4s]",
    237  1.1.1.1.10.2       tls                 OriginalName, Name));
    238  1.1.1.1.10.2       tls         }
    239  1.1.1.1.10.2       tls     }
    240  1.1.1.1.10.2       tls }
    241  1.1.1.1.10.2       tls 
    242  1.1.1.1.10.2       tls 
    243  1.1.1.1.10.2       tls #if defined ACPI_ASL_COMPILER || defined ACPI_EXEC_APP
    244  1.1.1.1.10.2       tls /*******************************************************************************
    245  1.1.1.1.10.2       tls  *
    246  1.1.1.1.10.2       tls  * FUNCTION:    UtConvertBackslashes
    247  1.1.1.1.10.2       tls  *
    248  1.1.1.1.10.2       tls  * PARAMETERS:  Pathname        - File pathname string to be converted
    249  1.1.1.1.10.2       tls  *
    250  1.1.1.1.10.2       tls  * RETURN:      Modifies the input Pathname
    251  1.1.1.1.10.2       tls  *
    252  1.1.1.1.10.2       tls  * DESCRIPTION: Convert all backslashes (0x5C) to forward slashes (0x2F) within
    253  1.1.1.1.10.2       tls  *              the entire input file pathname string.
    254  1.1.1.1.10.2       tls  *
    255  1.1.1.1.10.2       tls  ******************************************************************************/
    256  1.1.1.1.10.2       tls 
    257  1.1.1.1.10.2       tls void
    258  1.1.1.1.10.2       tls UtConvertBackslashes (
    259  1.1.1.1.10.2       tls     char                    *Pathname)
    260  1.1.1.1.10.2       tls {
    261  1.1.1.1.10.2       tls 
    262  1.1.1.1.10.2       tls     if (!Pathname)
    263  1.1.1.1.10.2       tls     {
    264  1.1.1.1.10.2       tls         return;
    265  1.1.1.1.10.2       tls     }
    266  1.1.1.1.10.2       tls 
    267  1.1.1.1.10.2       tls     while (*Pathname)
    268  1.1.1.1.10.2       tls     {
    269  1.1.1.1.10.2       tls         if (*Pathname == '\\')
    270  1.1.1.1.10.2       tls         {
    271  1.1.1.1.10.2       tls             *Pathname = '/';
    272  1.1.1.1.10.2       tls         }
    273  1.1.1.1.10.2       tls 
    274  1.1.1.1.10.2       tls         Pathname++;
    275  1.1.1.1.10.2       tls     }
    276  1.1.1.1.10.2       tls }
    277  1.1.1.1.10.2       tls #endif
    278