Home | History | Annotate | Line # | Download | only in utilities
utstring.c revision 1.1.1.7.12.2
      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.1.7.12.1  pgoyette  * Copyright (C) 2000 - 2018, 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 #include "acpi.h"
     45           1.1  christos #include "accommon.h"
     46           1.1  christos #include "acnamesp.h"
     47           1.1  christos 
     48           1.1  christos 
     49           1.1  christos #define _COMPONENT          ACPI_UTILITIES
     50           1.1  christos         ACPI_MODULE_NAME    ("utstring")
     51           1.1  christos 
     52           1.1  christos 
     53           1.1  christos /*******************************************************************************
     54           1.1  christos  *
     55           1.1  christos  * FUNCTION:    AcpiUtPrintString
     56           1.1  christos  *
     57           1.1  christos  * PARAMETERS:  String          - Null terminated ASCII string
     58           1.1  christos  *              MaxLength       - Maximum output length. Used to constrain the
     59           1.1  christos  *                                length of strings during debug output only.
     60           1.1  christos  *
     61           1.1  christos  * RETURN:      None
     62           1.1  christos  *
     63           1.1  christos  * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape
     64           1.1  christos  *              sequences.
     65           1.1  christos  *
     66           1.1  christos  ******************************************************************************/
     67           1.1  christos 
     68           1.1  christos void
     69           1.1  christos AcpiUtPrintString (
     70           1.1  christos     char                    *String,
     71           1.1  christos     UINT16                  MaxLength)
     72           1.1  christos {
     73           1.1  christos     UINT32                  i;
     74           1.1  christos 
     75           1.1  christos 
     76           1.1  christos     if (!String)
     77           1.1  christos     {
     78           1.1  christos         AcpiOsPrintf ("<\"NULL STRING PTR\">");
     79           1.1  christos         return;
     80           1.1  christos     }
     81           1.1  christos 
     82           1.1  christos     AcpiOsPrintf ("\"");
     83       1.1.1.2  christos     for (i = 0; (i < MaxLength) && String[i]; i++)
     84           1.1  christos     {
     85           1.1  christos         /* Escape sequences */
     86           1.1  christos 
     87           1.1  christos         switch (String[i])
     88           1.1  christos         {
     89           1.1  christos         case 0x07:
     90           1.1  christos 
     91           1.1  christos             AcpiOsPrintf ("\\a");       /* BELL */
     92           1.1  christos             break;
     93           1.1  christos 
     94           1.1  christos         case 0x08:
     95           1.1  christos 
     96           1.1  christos             AcpiOsPrintf ("\\b");       /* BACKSPACE */
     97           1.1  christos             break;
     98           1.1  christos 
     99           1.1  christos         case 0x0C:
    100           1.1  christos 
    101           1.1  christos             AcpiOsPrintf ("\\f");       /* FORMFEED */
    102           1.1  christos             break;
    103           1.1  christos 
    104           1.1  christos         case 0x0A:
    105           1.1  christos 
    106           1.1  christos             AcpiOsPrintf ("\\n");       /* LINEFEED */
    107           1.1  christos             break;
    108           1.1  christos 
    109           1.1  christos         case 0x0D:
    110           1.1  christos 
    111           1.1  christos             AcpiOsPrintf ("\\r");       /* CARRIAGE RETURN*/
    112           1.1  christos             break;
    113           1.1  christos 
    114           1.1  christos         case 0x09:
    115           1.1  christos 
    116           1.1  christos             AcpiOsPrintf ("\\t");       /* HORIZONTAL TAB */
    117           1.1  christos             break;
    118           1.1  christos 
    119           1.1  christos         case 0x0B:
    120           1.1  christos 
    121           1.1  christos             AcpiOsPrintf ("\\v");       /* VERTICAL TAB */
    122           1.1  christos             break;
    123           1.1  christos 
    124           1.1  christos         case '\'':                      /* Single Quote */
    125           1.1  christos         case '\"':                      /* Double Quote */
    126           1.1  christos         case '\\':                      /* Backslash */
    127           1.1  christos 
    128           1.1  christos             AcpiOsPrintf ("\\%c", (int) String[i]);
    129           1.1  christos             break;
    130           1.1  christos 
    131           1.1  christos         default:
    132           1.1  christos 
    133           1.1  christos             /* Check for printable character or hex escape */
    134           1.1  christos 
    135       1.1.1.4  christos             if (isprint ((int) String[i]))
    136           1.1  christos             {
    137           1.1  christos                 /* This is a normal character */
    138           1.1  christos 
    139           1.1  christos                 AcpiOsPrintf ("%c", (int) String[i]);
    140           1.1  christos             }
    141           1.1  christos             else
    142           1.1  christos             {
    143           1.1  christos                 /* All others will be Hex escapes */
    144           1.1  christos 
    145           1.1  christos                 AcpiOsPrintf ("\\x%2.2X", (INT32) String[i]);
    146           1.1  christos             }
    147           1.1  christos             break;
    148           1.1  christos         }
    149           1.1  christos     }
    150       1.1.1.5  christos 
    151           1.1  christos     AcpiOsPrintf ("\"");
    152           1.1  christos 
    153           1.1  christos     if (i == MaxLength && String[i])
    154           1.1  christos     {
    155           1.1  christos         AcpiOsPrintf ("...");
    156           1.1  christos     }
    157           1.1  christos }
    158           1.1  christos 
    159           1.1  christos 
    160           1.1  christos /*******************************************************************************
    161           1.1  christos  *
    162           1.1  christos  * FUNCTION:    AcpiUtRepairName
    163           1.1  christos  *
    164           1.1  christos  * PARAMETERS:  Name            - The ACPI name to be repaired
    165           1.1  christos  *
    166           1.1  christos  * RETURN:      Repaired version of the name
    167           1.1  christos  *
    168           1.1  christos  * DESCRIPTION: Repair an ACPI name: Change invalid characters to '*' and
    169           1.1  christos  *              return the new name. NOTE: the Name parameter must reside in
    170           1.1  christos  *              read/write memory, cannot be a const.
    171           1.1  christos  *
    172           1.1  christos  * An ACPI Name must consist of valid ACPI characters. We will repair the name
    173           1.1  christos  * if necessary because we don't want to abort because of this, but we want
    174           1.1  christos  * all namespace names to be printable. A warning message is appropriate.
    175           1.1  christos  *
    176           1.1  christos  * This issue came up because there are in fact machines that exhibit
    177           1.1  christos  * this problem, and we want to be able to enable ACPI support for them,
    178           1.1  christos  * even though there are a few bad names.
    179           1.1  christos  *
    180           1.1  christos  ******************************************************************************/
    181           1.1  christos 
    182           1.1  christos void
    183           1.1  christos AcpiUtRepairName (
    184           1.1  christos     char                    *Name)
    185           1.1  christos {
    186           1.1  christos     UINT32                  i;
    187           1.1  christos     BOOLEAN                 FoundBadChar = FALSE;
    188           1.1  christos     UINT32                  OriginalName;
    189           1.1  christos 
    190           1.1  christos 
    191           1.1  christos     ACPI_FUNCTION_NAME (UtRepairName);
    192           1.1  christos 
    193           1.1  christos 
    194       1.1.1.5  christos     /*
    195       1.1.1.5  christos      * Special case for the root node. This can happen if we get an
    196       1.1.1.5  christos      * error during the execution of module-level code.
    197       1.1.1.5  christos      */
    198  1.1.1.7.12.2  pgoyette     if (ACPI_COMPARE_NAME (Name, ACPI_ROOT_PATHNAME))
    199       1.1.1.5  christos     {
    200       1.1.1.5  christos         return;
    201       1.1.1.5  christos     }
    202       1.1.1.5  christos 
    203           1.1  christos     ACPI_MOVE_NAME (&OriginalName, Name);
    204           1.1  christos 
    205           1.1  christos     /* Check each character in the name */
    206           1.1  christos 
    207           1.1  christos     for (i = 0; i < ACPI_NAME_SIZE; i++)
    208           1.1  christos     {
    209       1.1.1.6  christos         if (AcpiUtValidNameChar (Name[i], i))
    210           1.1  christos         {
    211           1.1  christos             continue;
    212           1.1  christos         }
    213           1.1  christos 
    214           1.1  christos         /*
    215           1.1  christos          * Replace a bad character with something printable, yet technically
    216           1.1  christos          * still invalid. This prevents any collisions with existing "good"
    217           1.1  christos          * names in the namespace.
    218           1.1  christos          */
    219           1.1  christos         Name[i] = '*';
    220           1.1  christos         FoundBadChar = TRUE;
    221           1.1  christos     }
    222           1.1  christos 
    223           1.1  christos     if (FoundBadChar)
    224           1.1  christos     {
    225           1.1  christos         /* Report warning only if in strict mode or debug mode */
    226           1.1  christos 
    227           1.1  christos         if (!AcpiGbl_EnableInterpreterSlack)
    228           1.1  christos         {
    229           1.1  christos             ACPI_WARNING ((AE_INFO,
    230           1.1  christos                 "Invalid character(s) in name (0x%.8X), repaired: [%4.4s]",
    231           1.1  christos                 OriginalName, Name));
    232           1.1  christos         }
    233           1.1  christos         else
    234           1.1  christos         {
    235           1.1  christos             ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
    236           1.1  christos                 "Invalid character(s) in name (0x%.8X), repaired: [%4.4s]",
    237           1.1  christos                 OriginalName, Name));
    238           1.1  christos         }
    239           1.1  christos     }
    240           1.1  christos }
    241           1.1  christos 
    242           1.1  christos 
    243           1.1  christos #if defined ACPI_ASL_COMPILER || defined ACPI_EXEC_APP
    244           1.1  christos /*******************************************************************************
    245           1.1  christos  *
    246           1.1  christos  * FUNCTION:    UtConvertBackslashes
    247           1.1  christos  *
    248           1.1  christos  * PARAMETERS:  Pathname        - File pathname string to be converted
    249           1.1  christos  *
    250           1.1  christos  * RETURN:      Modifies the input Pathname
    251           1.1  christos  *
    252           1.1  christos  * DESCRIPTION: Convert all backslashes (0x5C) to forward slashes (0x2F) within
    253           1.1  christos  *              the entire input file pathname string.
    254           1.1  christos  *
    255           1.1  christos  ******************************************************************************/
    256           1.1  christos 
    257           1.1  christos void
    258           1.1  christos UtConvertBackslashes (
    259           1.1  christos     char                    *Pathname)
    260           1.1  christos {
    261           1.1  christos 
    262           1.1  christos     if (!Pathname)
    263           1.1  christos     {
    264           1.1  christos         return;
    265           1.1  christos     }
    266           1.1  christos 
    267           1.1  christos     while (*Pathname)
    268           1.1  christos     {
    269           1.1  christos         if (*Pathname == '\\')
    270           1.1  christos         {
    271           1.1  christos             *Pathname = '/';
    272           1.1  christos         }
    273           1.1  christos 
    274           1.1  christos         Pathname++;
    275           1.1  christos     }
    276           1.1  christos }
    277           1.1  christos #endif
    278