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