Home | History | Annotate | Line # | Download | only in acpisrc
ascase.c revision 1.1.1.2.24.1
      1           1.1  jruoho /******************************************************************************
      2           1.1  jruoho  *
      3           1.1  jruoho  * Module Name: ascase - Source conversion - lower/upper case utilities
      4           1.1  jruoho  *
      5           1.1  jruoho  *****************************************************************************/
      6           1.1  jruoho 
      7       1.1.1.2  jruoho /*
      8  1.1.1.2.24.1   rmind  * Copyright (C) 2000 - 2013, Intel Corp.
      9           1.1  jruoho  * All rights reserved.
     10           1.1  jruoho  *
     11       1.1.1.2  jruoho  * Redistribution and use in source and binary forms, with or without
     12       1.1.1.2  jruoho  * modification, are permitted provided that the following conditions
     13       1.1.1.2  jruoho  * are met:
     14       1.1.1.2  jruoho  * 1. Redistributions of source code must retain the above copyright
     15       1.1.1.2  jruoho  *    notice, this list of conditions, and the following disclaimer,
     16       1.1.1.2  jruoho  *    without modification.
     17       1.1.1.2  jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18       1.1.1.2  jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19       1.1.1.2  jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20       1.1.1.2  jruoho  *    including a substantially similar Disclaimer requirement for further
     21       1.1.1.2  jruoho  *    binary redistribution.
     22       1.1.1.2  jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23       1.1.1.2  jruoho  *    of any contributors may be used to endorse or promote products derived
     24       1.1.1.2  jruoho  *    from this software without specific prior written permission.
     25       1.1.1.2  jruoho  *
     26       1.1.1.2  jruoho  * Alternatively, this software may be distributed under the terms of the
     27       1.1.1.2  jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28       1.1.1.2  jruoho  * Software Foundation.
     29       1.1.1.2  jruoho  *
     30       1.1.1.2  jruoho  * NO WARRANTY
     31       1.1.1.2  jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32       1.1.1.2  jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33       1.1.1.2  jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34       1.1.1.2  jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35       1.1.1.2  jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36       1.1.1.2  jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37       1.1.1.2  jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38       1.1.1.2  jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39       1.1.1.2  jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40       1.1.1.2  jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41       1.1.1.2  jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42       1.1.1.2  jruoho  */
     43           1.1  jruoho 
     44           1.1  jruoho #include "acpisrc.h"
     45           1.1  jruoho 
     46           1.1  jruoho /* Local prototypes */
     47           1.1  jruoho 
     48           1.1  jruoho void
     49           1.1  jruoho AsUppercaseTokens (
     50           1.1  jruoho     char                    *Buffer,
     51           1.1  jruoho     char                    *PrefixString);
     52           1.1  jruoho 
     53           1.1  jruoho 
     54           1.1  jruoho /******************************************************************************
     55           1.1  jruoho  *
     56           1.1  jruoho  * FUNCTION:    AsLowerCaseString
     57           1.1  jruoho  *
     58           1.1  jruoho  * DESCRIPTION: LowerCase all instances of a target string with a replacement
     59  1.1.1.2.24.1   rmind  *              string. Returns count of the strings replaced.
     60           1.1  jruoho  *
     61           1.1  jruoho  ******************************************************************************/
     62           1.1  jruoho 
     63           1.1  jruoho int
     64           1.1  jruoho AsLowerCaseString (
     65           1.1  jruoho     char                    *Target,
     66           1.1  jruoho     char                    *Buffer)
     67           1.1  jruoho {
     68           1.1  jruoho     char                    *SubString1;
     69           1.1  jruoho     char                    *SubString2;
     70           1.1  jruoho     char                    *SubBuffer;
     71           1.1  jruoho     int                     TargetLength;
     72           1.1  jruoho     int                     LowerCaseCount = 0;
     73           1.1  jruoho     int                     i;
     74           1.1  jruoho 
     75           1.1  jruoho 
     76           1.1  jruoho     TargetLength = strlen (Target);
     77           1.1  jruoho 
     78           1.1  jruoho     SubBuffer = Buffer;
     79           1.1  jruoho     SubString1 = Buffer;
     80           1.1  jruoho 
     81           1.1  jruoho     while (SubString1)
     82           1.1  jruoho     {
     83           1.1  jruoho         /* Find the target string */
     84           1.1  jruoho 
     85           1.1  jruoho         SubString1 = strstr (SubBuffer, Target);
     86           1.1  jruoho         if (!SubString1)
     87           1.1  jruoho         {
     88  1.1.1.2.24.1   rmind             return (LowerCaseCount);
     89           1.1  jruoho         }
     90           1.1  jruoho 
     91           1.1  jruoho         /*
     92           1.1  jruoho          * Check for translation escape string -- means to ignore
     93           1.1  jruoho          * blocks of code while replacing
     94           1.1  jruoho          */
     95  1.1.1.2.24.1   rmind         if (Gbl_IgnoreTranslationEscapes)
     96  1.1.1.2.24.1   rmind         {
     97  1.1.1.2.24.1   rmind             SubString2 = NULL;
     98  1.1.1.2.24.1   rmind         }
     99  1.1.1.2.24.1   rmind         else
    100  1.1.1.2.24.1   rmind         {
    101  1.1.1.2.24.1   rmind             SubString2 = strstr (SubBuffer, AS_START_IGNORE);
    102  1.1.1.2.24.1   rmind         }
    103           1.1  jruoho 
    104           1.1  jruoho         if ((SubString2) &&
    105           1.1  jruoho             (SubString2 < SubString1))
    106           1.1  jruoho         {
    107           1.1  jruoho             /* Find end of the escape block starting at "Substring2" */
    108           1.1  jruoho 
    109           1.1  jruoho             SubString2 = strstr (SubString2, AS_STOP_IGNORE);
    110           1.1  jruoho             if (!SubString2)
    111           1.1  jruoho             {
    112           1.1  jruoho                 /* Didn't find terminator */
    113           1.1  jruoho 
    114  1.1.1.2.24.1   rmind                 return (LowerCaseCount);
    115           1.1  jruoho             }
    116           1.1  jruoho 
    117           1.1  jruoho             /* Move buffer to end of escape block and continue */
    118           1.1  jruoho 
    119           1.1  jruoho             SubBuffer = SubString2;
    120           1.1  jruoho         }
    121           1.1  jruoho 
    122           1.1  jruoho         /* Do the actual replace if the target was found */
    123           1.1  jruoho 
    124           1.1  jruoho         else
    125           1.1  jruoho         {
    126           1.1  jruoho             if (!AsMatchExactWord (SubString1, TargetLength))
    127           1.1  jruoho             {
    128           1.1  jruoho                 SubBuffer = SubString1 + 1;
    129           1.1  jruoho                 continue;
    130           1.1  jruoho             }
    131           1.1  jruoho 
    132           1.1  jruoho             for (i = 0; i < TargetLength; i++)
    133           1.1  jruoho             {
    134           1.1  jruoho                 SubString1[i] = (char) tolower ((int) SubString1[i]);
    135           1.1  jruoho             }
    136           1.1  jruoho 
    137           1.1  jruoho             SubBuffer = SubString1 + TargetLength;
    138           1.1  jruoho 
    139           1.1  jruoho             if ((Gbl_WidenDeclarations) && (!Gbl_StructDefs))
    140           1.1  jruoho             {
    141           1.1  jruoho                 if ((SubBuffer[0] == ' ') && (SubBuffer[1] == ' '))
    142           1.1  jruoho                 {
    143           1.1  jruoho                     AsInsertData (SubBuffer, "        ", 8);
    144           1.1  jruoho                 }
    145           1.1  jruoho             }
    146           1.1  jruoho 
    147           1.1  jruoho             LowerCaseCount++;
    148           1.1  jruoho         }
    149           1.1  jruoho     }
    150           1.1  jruoho 
    151  1.1.1.2.24.1   rmind     return (LowerCaseCount);
    152           1.1  jruoho }
    153           1.1  jruoho 
    154           1.1  jruoho 
    155           1.1  jruoho /******************************************************************************
    156           1.1  jruoho  *
    157           1.1  jruoho  * FUNCTION:    AsMixedCaseToUnderscores
    158           1.1  jruoho  *
    159           1.1  jruoho  * DESCRIPTION: Converts mixed case identifiers to underscored identifiers.
    160           1.1  jruoho  *              for example,
    161           1.1  jruoho  *
    162           1.1  jruoho  *              ThisUsefullyNamedIdentifier   becomes:
    163           1.1  jruoho  *
    164           1.1  jruoho  *              this_usefully_named_identifier
    165           1.1  jruoho  *
    166           1.1  jruoho  ******************************************************************************/
    167           1.1  jruoho 
    168           1.1  jruoho void
    169           1.1  jruoho AsMixedCaseToUnderscores (
    170  1.1.1.2.24.1   rmind     char                    *Buffer,
    171  1.1.1.2.24.1   rmind     char                    *Filename)
    172           1.1  jruoho {
    173           1.1  jruoho     UINT32                  Length;
    174           1.1  jruoho     char                    *SubBuffer = Buffer;
    175           1.1  jruoho     char                    *TokenEnd;
    176           1.1  jruoho     char                    *TokenStart = NULL;
    177           1.1  jruoho     char                    *SubString;
    178  1.1.1.2.24.1   rmind     UINT32                  LineNumber = 1;
    179  1.1.1.2.24.1   rmind     UINT32                  Count;
    180           1.1  jruoho 
    181           1.1  jruoho 
    182  1.1.1.2.24.1   rmind     /*
    183  1.1.1.2.24.1   rmind      * Examine the entire buffer (contains the entire file)
    184  1.1.1.2.24.1   rmind      * We are only interested in these tokens:
    185  1.1.1.2.24.1   rmind      *      Escape sequences - ignore entire sequence
    186  1.1.1.2.24.1   rmind      *      Single-quoted constants - ignore
    187  1.1.1.2.24.1   rmind      *      Quoted strings - ignore entire string
    188  1.1.1.2.24.1   rmind      *      Translation escape - starts with /,*,!
    189  1.1.1.2.24.1   rmind      *      Decimal and hex numeric constants - ignore entire token
    190  1.1.1.2.24.1   rmind      *      Entire uppercase token - ignore, it is a macro or define
    191  1.1.1.2.24.1   rmind      *      Starts with underscore, then a lowercase or digit: convert
    192  1.1.1.2.24.1   rmind      */
    193           1.1  jruoho     while (*SubBuffer)
    194           1.1  jruoho     {
    195  1.1.1.2.24.1   rmind         if (*SubBuffer == '\n')
    196  1.1.1.2.24.1   rmind         {
    197  1.1.1.2.24.1   rmind             LineNumber++;
    198  1.1.1.2.24.1   rmind             SubBuffer++;
    199  1.1.1.2.24.1   rmind             continue;
    200  1.1.1.2.24.1   rmind         }
    201           1.1  jruoho 
    202  1.1.1.2.24.1   rmind         /* Ignore standard escape sequences (\n, \r, etc.)  Not Hex or Octal escapes */
    203  1.1.1.2.24.1   rmind 
    204  1.1.1.2.24.1   rmind         if (*SubBuffer == '\\')
    205           1.1  jruoho         {
    206  1.1.1.2.24.1   rmind             SubBuffer += 2;
    207           1.1  jruoho             continue;
    208           1.1  jruoho         }
    209           1.1  jruoho 
    210  1.1.1.2.24.1   rmind         /* Ignore single-quoted characters */
    211           1.1  jruoho 
    212  1.1.1.2.24.1   rmind         if (*SubBuffer == '\'')
    213           1.1  jruoho         {
    214  1.1.1.2.24.1   rmind             SubBuffer += 3;
    215           1.1  jruoho             continue;
    216           1.1  jruoho         }
    217           1.1  jruoho 
    218  1.1.1.2.24.1   rmind         /* Ignore standard double-quoted strings */
    219           1.1  jruoho 
    220           1.1  jruoho         if (*SubBuffer == '"')
    221           1.1  jruoho         {
    222           1.1  jruoho             SubBuffer++;
    223  1.1.1.2.24.1   rmind             Count = 0;
    224           1.1  jruoho             while (*SubBuffer != '"')
    225           1.1  jruoho             {
    226  1.1.1.2.24.1   rmind                 Count++;
    227  1.1.1.2.24.1   rmind                 if ((!*SubBuffer) ||
    228  1.1.1.2.24.1   rmind                      (Count > 8192))
    229           1.1  jruoho                 {
    230  1.1.1.2.24.1   rmind                     printf ("Found an unterminated quoted string!, line %u: %s\n",
    231  1.1.1.2.24.1   rmind                         LineNumber, Filename);
    232           1.1  jruoho                     return;
    233           1.1  jruoho                 }
    234           1.1  jruoho 
    235  1.1.1.2.24.1   rmind                 /* Handle escape sequences */
    236           1.1  jruoho 
    237           1.1  jruoho                 if (*SubBuffer == '\\')
    238           1.1  jruoho                 {
    239           1.1  jruoho                     SubBuffer++;
    240           1.1  jruoho                 }
    241  1.1.1.2.24.1   rmind 
    242           1.1  jruoho                 SubBuffer++;
    243           1.1  jruoho             }
    244           1.1  jruoho             SubBuffer++;
    245           1.1  jruoho             continue;
    246           1.1  jruoho         }
    247           1.1  jruoho 
    248           1.1  jruoho         /*
    249  1.1.1.2.24.1   rmind          * Check for translation escape string. It means to ignore
    250  1.1.1.2.24.1   rmind          * blocks of code during this code conversion.
    251           1.1  jruoho          */
    252           1.1  jruoho         if ((SubBuffer[0] == '/') &&
    253           1.1  jruoho             (SubBuffer[1] == '*') &&
    254           1.1  jruoho             (SubBuffer[2] == '!'))
    255           1.1  jruoho         {
    256           1.1  jruoho             SubBuffer = strstr (SubBuffer, "!*/");
    257           1.1  jruoho             if (!SubBuffer)
    258           1.1  jruoho             {
    259  1.1.1.2.24.1   rmind                 printf ("Found an unterminated translation escape!, line %u: %s\n",
    260  1.1.1.2.24.1   rmind                     LineNumber, Filename);
    261           1.1  jruoho                 return;
    262           1.1  jruoho             }
    263           1.1  jruoho             continue;
    264           1.1  jruoho         }
    265           1.1  jruoho 
    266  1.1.1.2.24.1   rmind         /* Ignore anything that starts with a number (0-9) */
    267           1.1  jruoho 
    268  1.1.1.2.24.1   rmind         if (isdigit ((int) *SubBuffer))
    269           1.1  jruoho         {
    270  1.1.1.2.24.1   rmind             /* Ignore hex constants */
    271  1.1.1.2.24.1   rmind 
    272  1.1.1.2.24.1   rmind             if ((SubBuffer[0] == '0') &&
    273  1.1.1.2.24.1   rmind                ((SubBuffer[1] == 'x') || (SubBuffer[1] == 'X')))
    274           1.1  jruoho             {
    275           1.1  jruoho                 SubBuffer += 2;
    276           1.1  jruoho             }
    277           1.1  jruoho 
    278  1.1.1.2.24.1   rmind             /* Skip over all digits, both decimal and hex */
    279           1.1  jruoho 
    280  1.1.1.2.24.1   rmind             while (isxdigit ((int) *SubBuffer))
    281           1.1  jruoho             {
    282           1.1  jruoho                 SubBuffer++;
    283           1.1  jruoho             }
    284  1.1.1.2.24.1   rmind             TokenStart = NULL;
    285           1.1  jruoho             continue;
    286           1.1  jruoho         }
    287           1.1  jruoho 
    288           1.1  jruoho         /*
    289  1.1.1.2.24.1   rmind          * Check for fully upper case identifiers. These are usually macros
    290  1.1.1.2.24.1   rmind          * or defines. Allow decimal digits and embedded underscores.
    291           1.1  jruoho          */
    292  1.1.1.2.24.1   rmind         if (isupper ((int) *SubBuffer))
    293           1.1  jruoho         {
    294  1.1.1.2.24.1   rmind             SubString = SubBuffer + 1;
    295  1.1.1.2.24.1   rmind             while ((isupper ((int) *SubString)) ||
    296  1.1.1.2.24.1   rmind                    (isdigit ((int) *SubString)) ||
    297  1.1.1.2.24.1   rmind                    (*SubString == '_'))
    298           1.1  jruoho             {
    299           1.1  jruoho                 SubString++;
    300           1.1  jruoho             }
    301           1.1  jruoho 
    302  1.1.1.2.24.1   rmind             /*
    303  1.1.1.2.24.1   rmind              * For the next character, anything other than a lower case
    304  1.1.1.2.24.1   rmind              * means that the identifier has terminated, and contains
    305  1.1.1.2.24.1   rmind              * exclusively Uppers/Digits/Underscores. Ignore the entire
    306  1.1.1.2.24.1   rmind              * identifier.
    307  1.1.1.2.24.1   rmind              */
    308  1.1.1.2.24.1   rmind             if (!islower ((int) *SubString))
    309           1.1  jruoho             {
    310  1.1.1.2.24.1   rmind                 SubBuffer = SubString + 1;
    311           1.1  jruoho                 continue;
    312           1.1  jruoho             }
    313           1.1  jruoho         }
    314           1.1  jruoho 
    315           1.1  jruoho         /*
    316  1.1.1.2.24.1   rmind          * These forms may indicate an identifier that can be converted:
    317  1.1.1.2.24.1   rmind          *      <UpperCase><LowerCase> (Ax)
    318  1.1.1.2.24.1   rmind          *      <UpperCase><Number> (An)
    319           1.1  jruoho          */
    320  1.1.1.2.24.1   rmind         if (isupper ((int) SubBuffer[0]) &&
    321  1.1.1.2.24.1   rmind           ((islower ((int) SubBuffer[1])) || isdigit ((int) SubBuffer[1])))
    322           1.1  jruoho         {
    323  1.1.1.2.24.1   rmind             TokenStart = SubBuffer;
    324  1.1.1.2.24.1   rmind             SubBuffer++;
    325  1.1.1.2.24.1   rmind 
    326  1.1.1.2.24.1   rmind             while (1)
    327           1.1  jruoho             {
    328  1.1.1.2.24.1   rmind                 /* Walk over the lower case letters and decimal digits */
    329           1.1  jruoho 
    330  1.1.1.2.24.1   rmind                 while (islower ((int) *SubBuffer) ||
    331  1.1.1.2.24.1   rmind                        isdigit ((int) *SubBuffer))
    332           1.1  jruoho                 {
    333           1.1  jruoho                     SubBuffer++;
    334           1.1  jruoho                 }
    335           1.1  jruoho 
    336  1.1.1.2.24.1   rmind                 /* Check for end of line or end of token */
    337           1.1  jruoho 
    338  1.1.1.2.24.1   rmind                 if (*SubBuffer == '\n')
    339  1.1.1.2.24.1   rmind                 {
    340  1.1.1.2.24.1   rmind                     LineNumber++;
    341  1.1.1.2.24.1   rmind                     break;
    342  1.1.1.2.24.1   rmind                 }
    343           1.1  jruoho 
    344  1.1.1.2.24.1   rmind                 if (*SubBuffer == ' ')
    345  1.1.1.2.24.1   rmind                 {
    346  1.1.1.2.24.1   rmind                     /* Check for form "Axx - " in a parameter header description */
    347           1.1  jruoho 
    348  1.1.1.2.24.1   rmind                     while (*SubBuffer == ' ')
    349  1.1.1.2.24.1   rmind                     {
    350  1.1.1.2.24.1   rmind                         SubBuffer++;
    351  1.1.1.2.24.1   rmind                     }
    352  1.1.1.2.24.1   rmind 
    353  1.1.1.2.24.1   rmind                     SubBuffer--;
    354  1.1.1.2.24.1   rmind                     if ((SubBuffer[1] == '-') &&
    355  1.1.1.2.24.1   rmind                         (SubBuffer[2] == ' '))
    356  1.1.1.2.24.1   rmind                     {
    357  1.1.1.2.24.1   rmind                         if (TokenStart)
    358  1.1.1.2.24.1   rmind                         {
    359  1.1.1.2.24.1   rmind                             *TokenStart = (char) tolower ((int) *TokenStart);
    360  1.1.1.2.24.1   rmind                         }
    361  1.1.1.2.24.1   rmind                     }
    362  1.1.1.2.24.1   rmind                     break;
    363  1.1.1.2.24.1   rmind                 }
    364           1.1  jruoho 
    365           1.1  jruoho                 /*
    366  1.1.1.2.24.1   rmind                  * Ignore these combinations:
    367  1.1.1.2.24.1   rmind                  *      <Letter><Digit><UpperCase>
    368  1.1.1.2.24.1   rmind                  *      <Digit><Digit><UpperCase>
    369  1.1.1.2.24.1   rmind                  *      <Underscore><Digit><UpperCase>
    370           1.1  jruoho                  */
    371  1.1.1.2.24.1   rmind                 if (isdigit ((int) *SubBuffer))
    372  1.1.1.2.24.1   rmind                 {
    373  1.1.1.2.24.1   rmind                     if (isalnum ((int) *(SubBuffer-1)) ||
    374  1.1.1.2.24.1   rmind                         *(SubBuffer-1) == '_')
    375  1.1.1.2.24.1   rmind                     {
    376  1.1.1.2.24.1   rmind                         break;
    377  1.1.1.2.24.1   rmind                     }
    378  1.1.1.2.24.1   rmind                 }
    379  1.1.1.2.24.1   rmind 
    380  1.1.1.2.24.1   rmind                 /* Ignore token if next character is not uppercase or digit */
    381  1.1.1.2.24.1   rmind 
    382  1.1.1.2.24.1   rmind                 if (!isupper ((int) *SubBuffer) &&
    383  1.1.1.2.24.1   rmind                     !isdigit ((int) *SubBuffer))
    384           1.1  jruoho                 {
    385           1.1  jruoho                     break;
    386           1.1  jruoho                 }
    387           1.1  jruoho 
    388  1.1.1.2.24.1   rmind                 /*
    389  1.1.1.2.24.1   rmind                  * Form <UpperCase><LowerCaseLetters><UpperCase> (AxxB):
    390  1.1.1.2.24.1   rmind                  * Convert leading character of the token to lower case
    391  1.1.1.2.24.1   rmind                  */
    392  1.1.1.2.24.1   rmind                 if (TokenStart)
    393  1.1.1.2.24.1   rmind                 {
    394  1.1.1.2.24.1   rmind                     *TokenStart = (char) tolower ((int) *TokenStart);
    395  1.1.1.2.24.1   rmind                     TokenStart = NULL;
    396  1.1.1.2.24.1   rmind                 }
    397           1.1  jruoho 
    398  1.1.1.2.24.1   rmind                 /* Find the end of this identifier (token) */
    399           1.1  jruoho 
    400  1.1.1.2.24.1   rmind                 TokenEnd = SubBuffer - 1;
    401  1.1.1.2.24.1   rmind                 while ((isalnum ((int) *TokenEnd)) ||
    402  1.1.1.2.24.1   rmind                        (*TokenEnd == '_'))
    403  1.1.1.2.24.1   rmind                 {
    404  1.1.1.2.24.1   rmind                     TokenEnd++;
    405  1.1.1.2.24.1   rmind                 }
    406           1.1  jruoho 
    407  1.1.1.2.24.1   rmind                 SubString = TokenEnd;
    408  1.1.1.2.24.1   rmind                 Length = 0;
    409           1.1  jruoho 
    410  1.1.1.2.24.1   rmind                 while (*SubString != '\n')
    411  1.1.1.2.24.1   rmind                 {
    412  1.1.1.2.24.1   rmind                     /*
    413  1.1.1.2.24.1   rmind                      * If we have at least two trailing spaces, we can get rid of
    414  1.1.1.2.24.1   rmind                      * one to make up for the newly inserted underscore. This will
    415  1.1.1.2.24.1   rmind                      * help preserve the alignment of the text
    416  1.1.1.2.24.1   rmind                      */
    417  1.1.1.2.24.1   rmind                     if ((SubString[0] == ' ') &&
    418  1.1.1.2.24.1   rmind                         (SubString[1] == ' '))
    419  1.1.1.2.24.1   rmind                     {
    420  1.1.1.2.24.1   rmind                         Length = SubString - SubBuffer - 1;
    421  1.1.1.2.24.1   rmind                         break;
    422  1.1.1.2.24.1   rmind                     }
    423  1.1.1.2.24.1   rmind 
    424  1.1.1.2.24.1   rmind                     SubString++;
    425  1.1.1.2.24.1   rmind                 }
    426  1.1.1.2.24.1   rmind 
    427  1.1.1.2.24.1   rmind                 if (!Length)
    428  1.1.1.2.24.1   rmind                 {
    429  1.1.1.2.24.1   rmind                     Length = strlen (&SubBuffer[0]);
    430  1.1.1.2.24.1   rmind                 }
    431  1.1.1.2.24.1   rmind 
    432  1.1.1.2.24.1   rmind                 /*
    433  1.1.1.2.24.1   rmind                  * Within this identifier, convert this pair of letters that
    434  1.1.1.2.24.1   rmind                  * matches the form:
    435  1.1.1.2.24.1   rmind                  *
    436  1.1.1.2.24.1   rmind                  *      <LowerCase><UpperCase>
    437  1.1.1.2.24.1   rmind                  * to
    438  1.1.1.2.24.1   rmind                  *      <LowerCase><Underscore><LowerCase>
    439  1.1.1.2.24.1   rmind                  */
    440  1.1.1.2.24.1   rmind                 Gbl_MadeChanges = TRUE;
    441  1.1.1.2.24.1   rmind 
    442  1.1.1.2.24.1   rmind                 /* Insert the underscore */
    443  1.1.1.2.24.1   rmind 
    444  1.1.1.2.24.1   rmind                 memmove (&SubBuffer[1], &SubBuffer[0], Length + 1);
    445  1.1.1.2.24.1   rmind                 SubBuffer[0] = '_';
    446  1.1.1.2.24.1   rmind 
    447  1.1.1.2.24.1   rmind                 /*
    448  1.1.1.2.24.1   rmind                  * If we have <UpperCase><UpperCase>, leave them as-is
    449  1.1.1.2.24.1   rmind                  * Enables transforms like:
    450  1.1.1.2.24.1   rmind                  *      LocalFADT -> local_FADT
    451  1.1.1.2.24.1   rmind                  */
    452  1.1.1.2.24.1   rmind                 if (isupper ((int) SubBuffer[2]))
    453  1.1.1.2.24.1   rmind                 {
    454  1.1.1.2.24.1   rmind                     SubBuffer += 1;
    455  1.1.1.2.24.1   rmind                     break;
    456  1.1.1.2.24.1   rmind                 }
    457  1.1.1.2.24.1   rmind 
    458  1.1.1.2.24.1   rmind                 /* Lower case the original upper case letter */
    459  1.1.1.2.24.1   rmind 
    460  1.1.1.2.24.1   rmind                 SubBuffer[1] = (char) tolower ((int) SubBuffer[1]);
    461  1.1.1.2.24.1   rmind                 SubBuffer += 2;
    462           1.1  jruoho             }
    463           1.1  jruoho         }
    464           1.1  jruoho 
    465           1.1  jruoho         SubBuffer++;
    466           1.1  jruoho     }
    467           1.1  jruoho }
    468           1.1  jruoho 
    469           1.1  jruoho 
    470           1.1  jruoho /******************************************************************************
    471           1.1  jruoho  *
    472           1.1  jruoho  * FUNCTION:    AsLowerCaseIdentifiers
    473           1.1  jruoho  *
    474  1.1.1.2.24.1   rmind  * DESCRIPTION: Converts mixed case identifiers to lower case. Leaves comments,
    475           1.1  jruoho  *              quoted strings, and all-upper-case macros alone.
    476           1.1  jruoho  *
    477           1.1  jruoho  ******************************************************************************/
    478           1.1  jruoho 
    479           1.1  jruoho void
    480           1.1  jruoho AsLowerCaseIdentifiers (
    481           1.1  jruoho     char                    *Buffer)
    482           1.1  jruoho {
    483           1.1  jruoho     char                    *SubBuffer = Buffer;
    484           1.1  jruoho 
    485           1.1  jruoho 
    486           1.1  jruoho     while (*SubBuffer)
    487           1.1  jruoho     {
    488           1.1  jruoho         /*
    489           1.1  jruoho          * Check for translation escape string -- means to ignore
    490           1.1  jruoho          * blocks of code while replacing
    491           1.1  jruoho          */
    492           1.1  jruoho         if ((SubBuffer[0] == '/') &&
    493           1.1  jruoho             (SubBuffer[1] == '*') &&
    494           1.1  jruoho             (SubBuffer[2] == '!'))
    495           1.1  jruoho         {
    496           1.1  jruoho             SubBuffer = strstr (SubBuffer, "!*/");
    497           1.1  jruoho             if (!SubBuffer)
    498           1.1  jruoho             {
    499           1.1  jruoho                 return;
    500           1.1  jruoho             }
    501           1.1  jruoho         }
    502           1.1  jruoho 
    503           1.1  jruoho         /* Ignore comments */
    504           1.1  jruoho 
    505           1.1  jruoho         if ((SubBuffer[0] == '/') &&
    506           1.1  jruoho             (SubBuffer[1] == '*'))
    507           1.1  jruoho         {
    508           1.1  jruoho             SubBuffer = strstr (SubBuffer, "*/");
    509           1.1  jruoho             if (!SubBuffer)
    510           1.1  jruoho             {
    511           1.1  jruoho                 return;
    512           1.1  jruoho             }
    513           1.1  jruoho 
    514           1.1  jruoho             SubBuffer += 2;
    515           1.1  jruoho         }
    516           1.1  jruoho 
    517           1.1  jruoho         /* Ignore quoted strings */
    518           1.1  jruoho 
    519           1.1  jruoho         if ((SubBuffer[0] == '\"') && (SubBuffer[1] != '\''))
    520           1.1  jruoho         {
    521           1.1  jruoho             SubBuffer++;
    522           1.1  jruoho 
    523           1.1  jruoho             /* Find the closing quote */
    524           1.1  jruoho 
    525           1.1  jruoho             while (SubBuffer[0])
    526           1.1  jruoho             {
    527           1.1  jruoho                 /* Ignore escaped quote characters */
    528           1.1  jruoho 
    529           1.1  jruoho                 if (SubBuffer[0] == '\\')
    530           1.1  jruoho                 {
    531           1.1  jruoho                     SubBuffer++;
    532           1.1  jruoho                 }
    533           1.1  jruoho                 else if (SubBuffer[0] == '\"')
    534           1.1  jruoho                 {
    535           1.1  jruoho                     SubBuffer++;
    536           1.1  jruoho                     break;
    537           1.1  jruoho                 }
    538           1.1  jruoho                 SubBuffer++;
    539           1.1  jruoho             }
    540           1.1  jruoho         }
    541           1.1  jruoho 
    542           1.1  jruoho         if (!SubBuffer[0])
    543           1.1  jruoho         {
    544           1.1  jruoho             return;
    545           1.1  jruoho         }
    546           1.1  jruoho 
    547           1.1  jruoho         /*
    548           1.1  jruoho          * Only lower case if we have an upper followed by a lower
    549           1.1  jruoho          * This leaves the all-uppercase things (macros, etc.) intact
    550           1.1  jruoho          */
    551           1.1  jruoho         if ((isupper ((int) SubBuffer[0])) &&
    552           1.1  jruoho             (islower ((int) SubBuffer[1])))
    553           1.1  jruoho         {
    554           1.1  jruoho             Gbl_MadeChanges = TRUE;
    555           1.1  jruoho             *SubBuffer = (char) tolower ((int) *SubBuffer);
    556           1.1  jruoho         }
    557           1.1  jruoho 
    558           1.1  jruoho         SubBuffer++;
    559           1.1  jruoho     }
    560           1.1  jruoho }
    561           1.1  jruoho 
    562           1.1  jruoho 
    563           1.1  jruoho /******************************************************************************
    564           1.1  jruoho  *
    565           1.1  jruoho  * FUNCTION:    AsUppercaseTokens
    566           1.1  jruoho  *
    567           1.1  jruoho  * DESCRIPTION: Force to uppercase all tokens that begin with the prefix string.
    568           1.1  jruoho  *              used to convert mixed-case macros and constants to uppercase.
    569           1.1  jruoho  *
    570           1.1  jruoho  ******************************************************************************/
    571           1.1  jruoho 
    572           1.1  jruoho void
    573           1.1  jruoho AsUppercaseTokens (
    574           1.1  jruoho     char                    *Buffer,
    575           1.1  jruoho     char                    *PrefixString)
    576           1.1  jruoho {
    577           1.1  jruoho     char                    *SubBuffer;
    578           1.1  jruoho     char                    *TokenEnd;
    579           1.1  jruoho     char                    *SubString;
    580           1.1  jruoho     int                     i;
    581           1.1  jruoho     UINT32                  Length;
    582           1.1  jruoho 
    583           1.1  jruoho 
    584           1.1  jruoho     SubBuffer = Buffer;
    585           1.1  jruoho 
    586           1.1  jruoho     while (SubBuffer)
    587           1.1  jruoho     {
    588           1.1  jruoho         SubBuffer = strstr (SubBuffer, PrefixString);
    589           1.1  jruoho         if (SubBuffer)
    590           1.1  jruoho         {
    591           1.1  jruoho             TokenEnd = SubBuffer;
    592           1.1  jruoho             while ((isalnum ((int) *TokenEnd)) || (*TokenEnd == '_'))
    593           1.1  jruoho             {
    594           1.1  jruoho                 TokenEnd++;
    595           1.1  jruoho             }
    596           1.1  jruoho 
    597           1.1  jruoho             for (i = 0; i < (TokenEnd - SubBuffer); i++)
    598           1.1  jruoho             {
    599           1.1  jruoho                 if ((islower ((int) SubBuffer[i])) &&
    600           1.1  jruoho                     (isupper ((int) SubBuffer[i+1])))
    601           1.1  jruoho                 {
    602           1.1  jruoho 
    603           1.1  jruoho                     SubString = TokenEnd;
    604           1.1  jruoho                     Length = 0;
    605           1.1  jruoho 
    606           1.1  jruoho                     while (*SubString != '\n')
    607           1.1  jruoho                     {
    608           1.1  jruoho                         if ((SubString[0] == ' ') &&
    609           1.1  jruoho                             (SubString[1] == ' '))
    610           1.1  jruoho                         {
    611           1.1  jruoho                             Length = SubString - &SubBuffer[i] - 2;
    612           1.1  jruoho                             break;
    613           1.1  jruoho                         }
    614           1.1  jruoho 
    615           1.1  jruoho                         SubString++;
    616           1.1  jruoho                     }
    617           1.1  jruoho 
    618           1.1  jruoho                     if (!Length)
    619           1.1  jruoho                     {
    620           1.1  jruoho                         Length = strlen (&SubBuffer[i+1]);
    621           1.1  jruoho                     }
    622           1.1  jruoho 
    623           1.1  jruoho                     memmove (&SubBuffer[i+2], &SubBuffer[i+1], (Length+1));
    624           1.1  jruoho                     SubBuffer[i+1] = '_';
    625           1.1  jruoho                     i +=2;
    626           1.1  jruoho                     TokenEnd++;
    627           1.1  jruoho                 }
    628           1.1  jruoho             }
    629           1.1  jruoho 
    630           1.1  jruoho             for (i = 0; i < (TokenEnd - SubBuffer); i++)
    631           1.1  jruoho             {
    632           1.1  jruoho                 SubBuffer[i] = (char) toupper ((int) SubBuffer[i]);
    633           1.1  jruoho             }
    634           1.1  jruoho 
    635           1.1  jruoho             SubBuffer = TokenEnd;
    636           1.1  jruoho         }
    637           1.1  jruoho     }
    638           1.1  jruoho }
    639