Home | History | Annotate | Line # | Download | only in acpisrc
asconvrt.c revision 1.1.1.13
      1 /******************************************************************************
      2  *
      3  * Module Name: asconvrt - Source conversion code
      4  *
      5  *****************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2021, Intel Corp.
      9  * All rights reserved.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions, and the following disclaimer,
     16  *    without modification.
     17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  *    including a substantially similar Disclaimer requirement for further
     21  *    binary redistribution.
     22  * 3. Neither the names of the above-listed copyright holders nor the names
     23  *    of any contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * Alternatively, this software may be distributed under the terms of the
     27  * GNU General Public License ("GPL") version 2 as published by the Free
     28  * Software Foundation.
     29  *
     30  * NO WARRANTY
     31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  * POSSIBILITY OF SUCH DAMAGES.
     42  */
     43 
     44 #include "acpisrc.h"
     45 
     46 AS_BRACE_INFO               Gbl_BraceInfo[] =
     47 {
     48     {" if",         3},
     49     {" else if",    8},
     50     {" else while", 11},
     51     {" else",       5},
     52     {" do ",        4},
     53     {NULL,          0}
     54 };
     55 
     56 
     57 /* Local prototypes */
     58 
     59 static char *
     60 AsMatchValidToken (
     61     char                    *Buffer,
     62     char                    *Filename,
     63     char                    TargetChar,
     64     AS_SCAN_CALLBACK        Callback);
     65 
     66 static char *
     67 AsCheckBracesCallback (
     68     char                    *Buffer,
     69     char                    *Filename,
     70     UINT32                  LineNumber);
     71 
     72 static UINT32
     73 AsCountLines (
     74     char                    *Buffer,
     75     char                    *Filename);
     76 
     77 
     78 #define MODULE_HEADER_BEGIN "/******************************************************************************\n *\n * Module Name:";
     79 #define MODULE_HEADER_END   " *****************************************************************************/\n\n"
     80 #define INTEL_COPYRIGHT     " * Copyright (C) 2000 - 2021, Intel Corp.\n"
     81 
     82 /* Opening signature of the Intel legal header */
     83 
     84 char        *HeaderBegin = "/******************************************************************************\n *\n * 1. Copyright Notice";
     85 
     86 UINT32      NonAnsiCommentCount;
     87 
     88 char        CopyRightHeaderEnd[] = INTEL_COPYRIGHT " *\n" MODULE_HEADER_END;
     89 
     90 /******************************************************************************
     91  *
     92  * FUNCTION:    AsCountNonAnsiComments
     93  *
     94  * DESCRIPTION: Count the number of "//" comments. This type of comment is
     95  *              non-ANSI C.
     96  *
     97  * NOTE: July 2014: Allows // within quoted strings and within normal
     98  *       comments. Eliminates extraneous warnings from this utility.
     99  *
    100  ******************************************************************************/
    101 
    102 void
    103 AsCountNonAnsiComments (
    104     char                    *Buffer,
    105     char                    *Filename)
    106 {
    107 
    108     AsMatchValidToken (Buffer, Filename, 0, NULL);
    109 
    110     /* Error if any slash-slash comments found */
    111 
    112     if (NonAnsiCommentCount)
    113     {
    114         AsPrint ("Non-ANSI // Comments Found", NonAnsiCommentCount, Filename);
    115         Gbl_NonAnsiComments += NonAnsiCommentCount;
    116     }
    117 }
    118 
    119 
    120 /******************************************************************************
    121  *
    122  * FUNCTION:    AsCheckForBraces
    123  *
    124  * DESCRIPTION: Check for an open brace after each if/else/do (etc.)
    125  *              statement
    126  *
    127  ******************************************************************************/
    128 
    129 void
    130 AsCheckForBraces (
    131     char                    *Buffer,
    132     char                    *Filename)
    133 {
    134 
    135     AsMatchValidToken (Buffer, Filename, 0, AsCheckBracesCallback);
    136 }
    137 
    138 
    139 /******************************************************************************
    140  *
    141  * FUNCTION:    AsCheckBracesCallback
    142  *
    143  * DESCRIPTION: Check if/else/do statements. Ensure that braces
    144  *              are always used.
    145  *
    146  * TBD: Currently, don't check while() statements. The problem is that there
    147  * are two forms: do {} while (); and while () {}.
    148  *
    149  ******************************************************************************/
    150 
    151 static char *
    152 AsCheckBracesCallback (
    153     char                    *Buffer,
    154     char                    *Filename,
    155     UINT32                  LineNumber)
    156 {
    157     char                    *SubBuffer = Buffer;
    158     char                    *NextBrace;
    159     char                    *NextSemicolon;
    160     AS_BRACE_INFO           *BraceInfo;
    161 
    162 
    163     for (BraceInfo = Gbl_BraceInfo; BraceInfo->Operator; BraceInfo++)
    164     {
    165         if (!(strncmp (BraceInfo->Operator, SubBuffer, BraceInfo->Length)))
    166         {
    167             SubBuffer += (BraceInfo->Length - 1);
    168 
    169             /* Find next brace and the next semicolon */
    170 
    171             NextBrace = AsMatchValidToken (SubBuffer, Filename, '{', NULL);
    172             NextSemicolon = AsMatchValidToken (SubBuffer, Filename, ';', NULL);
    173 
    174             /* Next brace should appear before next semicolon */
    175 
    176             if ((!NextBrace) ||
    177                (NextSemicolon && (NextBrace > NextSemicolon)))
    178             {
    179                 Gbl_MissingBraces++;
    180 
    181                 if (!Gbl_QuietMode)
    182                 {
    183                     printf ("Missing braces for <%s>, line %u: %s\n",
    184                         BraceInfo->Operator + 1, LineNumber, Filename);
    185                 }
    186             }
    187 
    188             return (SubBuffer);
    189         }
    190     }
    191 
    192     /* No match, just return original buffer */
    193 
    194     return (Buffer);
    195 }
    196 
    197 
    198 /******************************************************************************
    199  *
    200  * FUNCTION:    AsMatchValidToken
    201  *
    202  * DESCRIPTION: Find the next matching token in the input buffer.
    203  *
    204  ******************************************************************************/
    205 
    206 static char *
    207 AsMatchValidToken (
    208     char                    *Buffer,
    209     char                    *Filename,
    210     char                    TargetChar,
    211     AS_SCAN_CALLBACK        Callback)
    212 {
    213     char                    *SubBuffer = Buffer;
    214     char                    *StringStart;
    215     UINT32                  TotalLines;
    216 
    217 
    218     TotalLines = 1;
    219     NonAnsiCommentCount = 0;
    220 
    221     /* Scan from current position up to the end if necessary */
    222 
    223     while (*SubBuffer)
    224     {
    225         /* Skip normal comments */
    226 
    227         if ((*SubBuffer == '/') &&
    228             (*(SubBuffer + 1) == '*'))
    229         {
    230             /* Must maintain line count */
    231 
    232             SubBuffer += 2;
    233             while (strncmp ("*/", SubBuffer, 2))
    234             {
    235                 if (*SubBuffer == '\n')
    236                 {
    237                     TotalLines++;
    238                 }
    239                 SubBuffer++;
    240             }
    241 
    242             SubBuffer += 2;
    243             continue;
    244         }
    245 
    246         /* Skip single quoted chars */
    247 
    248         if (*SubBuffer == '\'')
    249         {
    250             SubBuffer++;
    251             if (!(*SubBuffer))
    252             {
    253                 break;
    254             }
    255 
    256             if (*SubBuffer == '\\')
    257             {
    258                 SubBuffer++;
    259             }
    260 
    261             SubBuffer++;
    262             continue;
    263         }
    264 
    265         /* Skip quoted strings */
    266 
    267         if (*SubBuffer == '"')
    268         {
    269             StringStart = SubBuffer;
    270             SubBuffer++;
    271             if (!(*SubBuffer))
    272             {
    273                 break;
    274             }
    275 
    276             while (*SubBuffer != '"')
    277             {
    278                 if ((*SubBuffer == '\n') ||
    279                     (!(*SubBuffer)))
    280                 {
    281                     AsPrint ("Unbalanced quoted string",1, Filename);
    282                     printf ("    %.32s (line %u)\n", StringStart, TotalLines);
    283                     break;
    284                 }
    285 
    286                 /* Handle escapes within the string */
    287 
    288                 if (*SubBuffer == '\\')
    289                 {
    290                     SubBuffer++;
    291                 }
    292 
    293                 SubBuffer++;
    294             }
    295 
    296             SubBuffer++;
    297             continue;
    298         }
    299 
    300         /* Now we can check for a slash-slash comment */
    301 
    302         if ((*SubBuffer == '/') &&
    303             (*(SubBuffer + 1) == '/'))
    304         {
    305             NonAnsiCommentCount++;
    306 
    307             /* Skip to end-of-line */
    308 
    309             while ((*SubBuffer != '\n') &&
    310                 (*SubBuffer))
    311             {
    312                 SubBuffer++;
    313             }
    314 
    315             if (!(*SubBuffer))
    316             {
    317                 break;
    318             }
    319 
    320             if (*SubBuffer == '\n')
    321             {
    322                 TotalLines++;
    323             }
    324 
    325             SubBuffer++;
    326             continue;
    327         }
    328 
    329         /* Finally, check for a newline */
    330 
    331         if (*SubBuffer == '\n')
    332         {
    333             TotalLines++;
    334             SubBuffer++;
    335             continue;
    336         }
    337 
    338         /* Normal character, do the user actions */
    339 
    340         if (Callback)
    341         {
    342             SubBuffer = Callback (SubBuffer, Filename, TotalLines);
    343         }
    344 
    345         if (TargetChar && (*SubBuffer == TargetChar))
    346         {
    347             return (SubBuffer);
    348         }
    349 
    350         SubBuffer++;
    351     }
    352 
    353     return (NULL);
    354 }
    355 
    356 
    357 /******************************************************************************
    358  *
    359  * FUNCTION:    AsRemoveExtraLines
    360  *
    361  * DESCRIPTION: Remove all extra lines at the start and end of the file.
    362  *
    363  ******************************************************************************/
    364 
    365 void
    366 AsRemoveExtraLines (
    367     char                    *FileBuffer,
    368     char                    *Filename)
    369 {
    370     char                    *FileEnd;
    371     int                     Length;
    372 
    373 
    374     /* Remove any extra lines at the start of the file */
    375 
    376     while (*FileBuffer == '\n')
    377     {
    378         printf ("Removing extra line at start of file: %s\n", Filename);
    379         AsRemoveData (FileBuffer, FileBuffer + 1);
    380     }
    381 
    382     /* Remove any extra lines at the end of the file */
    383 
    384     Length = strlen (FileBuffer);
    385     FileEnd = FileBuffer + (Length - 2);
    386 
    387     while (*FileEnd == '\n')
    388     {
    389         printf ("Removing extra line at end of file: %s\n", Filename);
    390         AsRemoveData (FileEnd, FileEnd + 1);
    391         FileEnd--;
    392     }
    393 }
    394 
    395 
    396 /******************************************************************************
    397  *
    398  * FUNCTION:    AsRemoveSpacesAfterPeriod
    399  *
    400  * DESCRIPTION: Remove an extra space after a period.
    401  *
    402  ******************************************************************************/
    403 
    404 void
    405 AsRemoveSpacesAfterPeriod (
    406     char                    *FileBuffer,
    407     char                    *Filename)
    408 {
    409     int                     ReplaceCount = 0;
    410     char                    *Possible;
    411 
    412 
    413     Possible = FileBuffer;
    414     while (Possible)
    415     {
    416         Possible = strstr (Possible, ".  ");
    417         if (Possible)
    418         {
    419             if ((*(Possible -1) == '.')  ||
    420                 (*(Possible -1) == '\"') ||
    421                 (*(Possible -1) == '\n'))
    422             {
    423                 Possible += 3;
    424                 continue;
    425             }
    426 
    427             Possible = AsReplaceData (Possible, 3, ". ", 2);
    428             ReplaceCount++;
    429         }
    430     }
    431 
    432     if (ReplaceCount)
    433     {
    434         printf ("Removed %d extra blanks after a period: %s\n",
    435             ReplaceCount, Filename);
    436     }
    437 }
    438 
    439 
    440 /******************************************************************************
    441  *
    442  * FUNCTION:    AsMatchExactWord
    443  *
    444  * DESCRIPTION: Check previous and next characters for whitespace
    445  *
    446  ******************************************************************************/
    447 
    448 BOOLEAN
    449 AsMatchExactWord (
    450     char                    *Word,
    451     UINT32                  WordLength)
    452 {
    453     char                    NextChar;
    454     char                    PrevChar;
    455 
    456 
    457     NextChar = Word[WordLength];
    458     PrevChar = * (Word -1);
    459 
    460     if (isalnum ((int) NextChar) ||
    461         (NextChar == '_')  ||
    462         isalnum ((int) PrevChar) ||
    463         (PrevChar == '_'))
    464     {
    465         return (FALSE);
    466     }
    467 
    468     return (TRUE);
    469 }
    470 
    471 
    472 /******************************************************************************
    473  *
    474  * FUNCTION:    AsPrint
    475  *
    476  * DESCRIPTION: Common formatted print
    477  *
    478  ******************************************************************************/
    479 
    480 void
    481 AsPrint (
    482     char                    *Message,
    483     UINT32                  Count,
    484     char                    *Filename)
    485 {
    486 
    487     if (Gbl_QuietMode)
    488     {
    489         return;
    490     }
    491 
    492     printf ("-- %4u %28.28s : %s\n", Count, Message, Filename);
    493 }
    494 
    495 
    496 /******************************************************************************
    497  *
    498  * FUNCTION:    AsTrimLines
    499  *
    500  * DESCRIPTION: Remove extra blanks from the end of source lines. Does not
    501  *              check for tabs.
    502  *
    503  ******************************************************************************/
    504 
    505 void
    506 AsTrimLines (
    507     char                    *Buffer,
    508     char                    *Filename)
    509 {
    510     char                    *SubBuffer = Buffer;
    511     char                    *StartWhiteSpace = NULL;
    512     UINT32                  SpaceCount = 0;
    513 
    514 
    515     while (*SubBuffer)
    516     {
    517         while (*SubBuffer != '\n')
    518         {
    519             if (!*SubBuffer)
    520             {
    521                 goto Exit;
    522             }
    523 
    524             if (*SubBuffer == ' ')
    525             {
    526                 if (!StartWhiteSpace)
    527                 {
    528                     StartWhiteSpace = SubBuffer;
    529                 }
    530             }
    531             else
    532             {
    533                 StartWhiteSpace = NULL;
    534             }
    535 
    536             SubBuffer++;
    537         }
    538 
    539         if (StartWhiteSpace)
    540         {
    541             SpaceCount += (SubBuffer - StartWhiteSpace);
    542 
    543             /* Remove the spaces */
    544 
    545             SubBuffer = AsRemoveData (StartWhiteSpace, SubBuffer);
    546             StartWhiteSpace = NULL;
    547         }
    548 
    549         SubBuffer++;
    550     }
    551 
    552 
    553 Exit:
    554     if (SpaceCount)
    555     {
    556         Gbl_MadeChanges = TRUE;
    557         AsPrint ("Extraneous spaces removed", SpaceCount, Filename);
    558     }
    559 }
    560 
    561 
    562 /******************************************************************************
    563  *
    564  * FUNCTION:    AsTrimWhitespace
    565  *
    566  * DESCRIPTION: Remove "excess" blank lines - any more than 2 blank lines.
    567  *              this can happen during the translation when lines are removed.
    568  *
    569  ******************************************************************************/
    570 
    571 void
    572 AsTrimWhitespace (
    573     char                    *Buffer)
    574 {
    575     char                    *SubBuffer;
    576     int                     ReplaceCount = 1;
    577 
    578 
    579     while (ReplaceCount)
    580     {
    581         ReplaceCount = AsReplaceString ("\n\n\n\n", "\n\n\n",
    582             REPLACE_SUBSTRINGS, Buffer);
    583     }
    584 
    585     /*
    586      * Check for exactly one blank line after the copyright header
    587      */
    588 
    589     /* Find the header */
    590 
    591     SubBuffer = strstr (Buffer, HeaderBegin);
    592     if (!SubBuffer)
    593     {
    594         return;
    595     }
    596 
    597     /* Find the end of the header */
    598 
    599     SubBuffer = strstr (SubBuffer, "*/");
    600     SubBuffer = AsSkipPastChar (SubBuffer, '\n');
    601 
    602     /* Replace a double blank line with a single */
    603 
    604     if (!strncmp (SubBuffer, "\n\n", 2))
    605     {
    606         AsReplaceData (SubBuffer, 2, "\n", 1);
    607         AcpiOsPrintf ("Found multiple blank lines after copyright\n");
    608     }
    609 
    610     /* If no blank line after header, insert one */
    611 
    612     else if (*SubBuffer != '\n')
    613     {
    614         AsInsertData (SubBuffer, "\n", 1);
    615         AcpiOsPrintf ("Inserted blank line after copyright\n");
    616     }
    617 }
    618 
    619 
    620 /******************************************************************************
    621  *
    622  * FUNCTION:    AsReplaceHeader
    623  *
    624  * DESCRIPTION: Replace the default Intel legal header with a new header
    625  *
    626  ******************************************************************************/
    627 
    628 void
    629 AsReplaceHeader (
    630     char                    *Buffer,
    631     char                    *NewHeader)
    632 {
    633     char                    *SubBuffer;
    634     char                    *TokenEnd;
    635 
    636 
    637     /* Find the original header */
    638 
    639     SubBuffer = strstr (Buffer, HeaderBegin);
    640     if (!SubBuffer)
    641     {
    642         return;
    643     }
    644 
    645     /* Find the end of the original header */
    646 
    647     TokenEnd = strstr (SubBuffer, "*/");
    648     TokenEnd = AsSkipPastChar (TokenEnd, '\n');
    649 
    650     /* Delete old header, insert new one */
    651 
    652     AsReplaceData (SubBuffer, TokenEnd - SubBuffer,
    653         NewHeader, strlen (NewHeader));
    654 }
    655 
    656 
    657 /******************************************************************************
    658  *
    659  * FUNCTION:    AsDoSpdxHeader
    660  *
    661  * DESCRIPTION: Replace the default Intel legal header with a new header
    662  *
    663  ******************************************************************************/
    664 
    665 void
    666 AsDoSpdxHeader (
    667     char                    *Buffer,
    668     char                    *SpdxHeader)
    669 {
    670     char                    *SubBuffer;
    671 
    672 
    673     /* Place an SPDX header at the very top */
    674 
    675     AsReplaceData (Buffer, 0,
    676         SpdxHeader, strlen (SpdxHeader));
    677 
    678     /* Place an Intel copyright notice in the module header */
    679 
    680     SubBuffer = strstr (Buffer, MODULE_HEADER_END);
    681     if (!SubBuffer)
    682     {
    683         return;
    684     }
    685 
    686     AsReplaceData (SubBuffer, strlen (MODULE_HEADER_END),
    687         CopyRightHeaderEnd, strlen (CopyRightHeaderEnd));
    688 }
    689 
    690 /******************************************************************************
    691  *
    692  * FUNCTION:    AsReplaceString
    693  *
    694  * DESCRIPTION: Replace all instances of a target string with a replacement
    695  *              string. Returns count of the strings replaced.
    696  *
    697  ******************************************************************************/
    698 
    699 int
    700 AsReplaceString (
    701     char                    *Target,
    702     char                    *Replacement,
    703     UINT8                   Type,
    704     char                    *Buffer)
    705 {
    706     char                    *SubString1;
    707     char                    *SubString2;
    708     char                    *SubBuffer;
    709     int                     TargetLength;
    710     int                     ReplacementLength;
    711     int                     ReplaceCount = 0;
    712 
    713 
    714     TargetLength = strlen (Target);
    715     ReplacementLength = strlen (Replacement);
    716 
    717     SubBuffer = Buffer;
    718     SubString1 = Buffer;
    719 
    720     while (SubString1)
    721     {
    722         /* Find the target string */
    723 
    724         SubString1 = strstr (SubBuffer, Target);
    725         if (!SubString1)
    726         {
    727             return (ReplaceCount);
    728         }
    729 
    730         /*
    731          * Check for translation escape string -- means to ignore
    732          * blocks of code while replacing
    733          */
    734         if (Gbl_IgnoreTranslationEscapes)
    735         {
    736             SubString2 = NULL;
    737         }
    738         else
    739         {
    740             SubString2 = strstr (SubBuffer, AS_START_IGNORE);
    741         }
    742 
    743         if ((SubString2) &&
    744             (SubString2 < SubString1))
    745         {
    746             /* Find end of the escape block starting at "Substring2" */
    747 
    748             SubString2 = strstr (SubString2, AS_STOP_IGNORE);
    749             if (!SubString2)
    750             {
    751                 /* Didn't find terminator */
    752 
    753                 return (ReplaceCount);
    754             }
    755 
    756             /* Move buffer to end of escape block and continue */
    757 
    758             SubBuffer = SubString2;
    759         }
    760 
    761         /* Do the actual replace if the target was found */
    762 
    763         else
    764         {
    765             if ((Type & REPLACE_MASK) == REPLACE_WHOLE_WORD)
    766             {
    767                 if (!AsMatchExactWord (SubString1, TargetLength))
    768                 {
    769                     SubBuffer = SubString1 + 1;
    770                     continue;
    771                 }
    772             }
    773 
    774             SubBuffer = AsReplaceData (SubString1, TargetLength,
    775                 Replacement, ReplacementLength);
    776 
    777             if ((Type & EXTRA_INDENT_C) &&
    778                 (!Gbl_StructDefs))
    779             {
    780                 SubBuffer = AsInsertData (SubBuffer, "        ", 8);
    781             }
    782 
    783             ReplaceCount++;
    784         }
    785     }
    786 
    787     return (ReplaceCount);
    788 }
    789 
    790 
    791 /******************************************************************************
    792  *
    793  * FUNCTION:    AsConvertToLineFeeds
    794  *
    795  * DESCRIPTION: Convert all CR/LF pairs to LF only.
    796  *
    797  ******************************************************************************/
    798 
    799 void
    800 AsConvertToLineFeeds (
    801     char                    *Buffer)
    802 {
    803     char                    *SubString;
    804     char                    *SubBuffer;
    805 
    806 
    807     SubBuffer = Buffer;
    808     SubString = Buffer;
    809 
    810     while (SubString)
    811     {
    812         /* Find the target string */
    813 
    814         SubString = strstr (SubBuffer, "\r\n");
    815         if (!SubString)
    816         {
    817             return;
    818         }
    819 
    820         SubBuffer = AsReplaceData (SubString, 1, NULL, 0);
    821     }
    822 }
    823 
    824 
    825 /******************************************************************************
    826  *
    827  * FUNCTION:    AsInsertCarriageReturns
    828  *
    829  * DESCRIPTION: Convert lone LFs to CR/LF pairs.
    830  *
    831  ******************************************************************************/
    832 
    833 void
    834 AsInsertCarriageReturns (
    835     char                    *Buffer)
    836 {
    837     char                    *SubString;
    838     char                    *SubBuffer;
    839 
    840 
    841     SubBuffer = Buffer;
    842     SubString = Buffer;
    843 
    844     while (SubString)
    845     {
    846         /* Find the target string */
    847 
    848         SubString = strstr (SubBuffer, "\n");
    849         if (!SubString)
    850         {
    851             return;
    852         }
    853 
    854         SubBuffer = AsInsertData (SubString, "\r", 1);
    855         SubBuffer += 1;
    856     }
    857 }
    858 
    859 
    860 /******************************************************************************
    861  *
    862  * FUNCTION:    AsBracesOnSameLine
    863  *
    864  * DESCRIPTION: Move opening braces up to the same line as an if, for, else,
    865  *              or while statement (leave function opening brace on separate
    866  *              line).
    867  *
    868  ******************************************************************************/
    869 
    870 void
    871 AsBracesOnSameLine (
    872     char                    *Buffer)
    873 {
    874     char                    *SubBuffer = Buffer;
    875     char                    *Beginning;
    876     char                    *StartOfThisLine;
    877     char                    *Next;
    878     BOOLEAN                 BlockBegin = TRUE;
    879 
    880 
    881     while (*SubBuffer)
    882     {
    883         /* Ignore comments */
    884 
    885         if ((SubBuffer[0] == '/') &&
    886             (SubBuffer[1] == '*'))
    887         {
    888             SubBuffer = strstr (SubBuffer, "*/");
    889             if (!SubBuffer)
    890             {
    891                 return;
    892             }
    893 
    894             SubBuffer += 2;
    895             continue;
    896         }
    897 
    898         /* Ignore quoted strings */
    899 
    900         if (*SubBuffer == '\"')
    901         {
    902             SubBuffer++;
    903             SubBuffer = AsSkipPastChar (SubBuffer, '\"');
    904             if (!SubBuffer)
    905             {
    906                 return;
    907             }
    908         }
    909 
    910         if (!strncmp ("\n}", SubBuffer, 2))
    911         {
    912             /*
    913              * A newline followed by a closing brace closes a function
    914              * or struct or initializer block
    915              */
    916             BlockBegin = TRUE;
    917         }
    918 
    919         /*
    920          * Move every standalone brace up to the previous line
    921          * Check for digit will ignore initializer lists surrounded by braces.
    922          * This will work until we we need more complex detection.
    923          */
    924         if ((*SubBuffer == '{') && !isdigit ((int) SubBuffer[1]))
    925         {
    926             if (BlockBegin)
    927             {
    928                 BlockBegin = FALSE;
    929             }
    930             else
    931             {
    932                 /*
    933                  * Backup to previous non-whitespace
    934                  */
    935                 Beginning = SubBuffer - 1;
    936                 while ((*Beginning == ' ')   ||
    937                        (*Beginning == '\n'))
    938                 {
    939                     Beginning--;
    940                 }
    941 
    942                 StartOfThisLine = Beginning;
    943                 while (*StartOfThisLine != '\n')
    944                 {
    945                     StartOfThisLine--;
    946                 }
    947 
    948                 /*
    949                  * Move the brace up to the previous line, UNLESS:
    950                  *
    951                  * 1) There is a conditional compile on the line (starts with '#')
    952                  * 2) Previous line ends with an '=' (Start of initializer block)
    953                  * 3) Previous line ends with a comma (part of an init list)
    954                  * 4) Previous line ends with a backslash (part of a macro)
    955                  */
    956                 if ((StartOfThisLine[1] != '#') &&
    957                     (*Beginning != '\\') &&
    958                     (*Beginning != '/') &&
    959                     (*Beginning != '{') &&
    960                     (*Beginning != '=') &&
    961                     (*Beginning != ','))
    962                 {
    963                     Beginning++;
    964                     SubBuffer++;
    965 
    966                     Gbl_MadeChanges = TRUE;
    967 
    968 #ifdef ADD_EXTRA_WHITESPACE
    969                     AsReplaceData (Beginning, SubBuffer - Beginning, " {\n", 3);
    970 #else
    971                     /* Find non-whitespace start of next line */
    972 
    973                     Next = SubBuffer + 1;
    974                     while ((*Next == ' ')   ||
    975                            (*Next == '\t'))
    976                     {
    977                         Next++;
    978                     }
    979 
    980                     /* Find non-whitespace start of this line */
    981 
    982                     StartOfThisLine++;
    983                     while ((*StartOfThisLine == ' ')   ||
    984                            (*StartOfThisLine == '\t'))
    985                     {
    986                         StartOfThisLine++;
    987                     }
    988 
    989                     /*
    990                      * Must be a single-line comment to need more whitespace
    991                      * Even then, we don't need more if the previous statement
    992                      * is an "else".
    993                      */
    994                     if ((Next[0] == '/')  &&
    995                         (Next[1] == '*')  &&
    996                         (Next[2] != '\n') &&
    997 
    998                         (!strncmp (StartOfThisLine, "else if", 7)     ||
    999                          !strncmp (StartOfThisLine, "else while", 10) ||
   1000                           strncmp (StartOfThisLine, "else", 4)))
   1001                     {
   1002                         AsReplaceData (Beginning, SubBuffer - Beginning, " {\n", 3);
   1003                     }
   1004                     else
   1005                     {
   1006                         AsReplaceData (Beginning, SubBuffer - Beginning, " {", 2);
   1007                     }
   1008 #endif
   1009                 }
   1010             }
   1011         }
   1012 
   1013         SubBuffer++;
   1014     }
   1015 }
   1016 
   1017 
   1018 /******************************************************************************
   1019  *
   1020  * FUNCTION:    AsTabify4
   1021  *
   1022  * DESCRIPTION: Convert the text to tabbed text. Alignment of text is
   1023  *              preserved.
   1024  *
   1025  ******************************************************************************/
   1026 
   1027 void
   1028 AsTabify4 (
   1029     char                    *Buffer)
   1030 {
   1031     char                    *SubBuffer = Buffer;
   1032     char                    *NewSubBuffer;
   1033     UINT32                  SpaceCount = 0;
   1034     UINT32                  Column = 0;
   1035 
   1036 
   1037     while (*SubBuffer)
   1038     {
   1039         if (*SubBuffer == '\n')
   1040         {
   1041             Column = 0;
   1042         }
   1043         else
   1044         {
   1045             Column++;
   1046         }
   1047 
   1048         /* Ignore comments */
   1049 
   1050         if ((SubBuffer[0] == '/') &&
   1051             (SubBuffer[1] == '*'))
   1052         {
   1053             SubBuffer = strstr (SubBuffer, "*/");
   1054             if (!SubBuffer)
   1055             {
   1056                 return;
   1057             }
   1058 
   1059             SubBuffer += 2;
   1060             continue;
   1061         }
   1062 
   1063         /* Ignore quoted strings */
   1064 
   1065         if (*SubBuffer == '\"')
   1066         {
   1067             SubBuffer++;
   1068             SubBuffer = AsSkipPastChar (SubBuffer, '\"');
   1069             if (!SubBuffer)
   1070             {
   1071                 return;
   1072             }
   1073             SpaceCount = 0;
   1074         }
   1075 
   1076         if (*SubBuffer == ' ')
   1077         {
   1078             SpaceCount++;
   1079 
   1080             if (SpaceCount >= 4)
   1081             {
   1082                 SpaceCount = 0;
   1083 
   1084                 NewSubBuffer = (SubBuffer + 1) - 4;
   1085                 *NewSubBuffer = '\t';
   1086                 NewSubBuffer++;
   1087 
   1088                 /* Remove the spaces */
   1089 
   1090                 SubBuffer = AsRemoveData (NewSubBuffer, SubBuffer + 1);
   1091             }
   1092 
   1093             if ((Column % 4) == 0)
   1094             {
   1095                 SpaceCount = 0;
   1096             }
   1097         }
   1098         else
   1099         {
   1100             SpaceCount = 0;
   1101         }
   1102 
   1103         SubBuffer++;
   1104     }
   1105 }
   1106 
   1107 
   1108 /******************************************************************************
   1109  *
   1110  * FUNCTION:    AsTabify8
   1111  *
   1112  * DESCRIPTION: Convert the text to tabbed text. Alignment of text is
   1113  *              preserved.
   1114  *
   1115  ******************************************************************************/
   1116 
   1117 void
   1118 AsTabify8 (
   1119     char                    *Buffer)
   1120 {
   1121     char                    *SubBuffer = Buffer;
   1122     char                    *NewSubBuffer;
   1123     char                    *CommentEnd = NULL;
   1124     UINT32                  SpaceCount = 0;
   1125     UINT32                  Column = 0;
   1126     UINT32                  TabCount = 0;
   1127     UINT32                  LastLineTabCount = 0;
   1128     UINT32                  LastLineColumnStart = 0;
   1129     UINT32                  ThisColumnStart = 0;
   1130     UINT32                  ThisTabCount =  0;
   1131     char                    *FirstNonBlank = NULL;
   1132 
   1133 
   1134     while (*SubBuffer)
   1135     {
   1136         if (*SubBuffer == '\n')
   1137         {
   1138             /* This is a standalone blank line */
   1139 
   1140             FirstNonBlank = NULL;
   1141             Column = 0;
   1142             SpaceCount = 0;
   1143             TabCount = 0;
   1144             SubBuffer++;
   1145             continue;
   1146         }
   1147 
   1148         if (!FirstNonBlank)
   1149         {
   1150             /* Find the first non-blank character on this line */
   1151 
   1152             FirstNonBlank = SubBuffer;
   1153             while (*FirstNonBlank == ' ')
   1154             {
   1155                 FirstNonBlank++;
   1156             }
   1157 
   1158             /*
   1159              * This mechanism limits the difference in tab counts from
   1160              * line to line. It helps avoid the situation where a second
   1161              * continuation line (which was indented correctly for tabs=4) would
   1162              * get indented off the screen if we just blindly converted to tabs.
   1163              */
   1164             ThisColumnStart = FirstNonBlank - SubBuffer;
   1165 
   1166             if (LastLineTabCount == 0)
   1167             {
   1168                 ThisTabCount = 0;
   1169             }
   1170             else if (ThisColumnStart == LastLineColumnStart)
   1171             {
   1172                 ThisTabCount = LastLineTabCount -1;
   1173             }
   1174             else
   1175             {
   1176                 ThisTabCount = LastLineTabCount + 1;
   1177             }
   1178         }
   1179 
   1180         Column++;
   1181 
   1182         /* Check if we are in a comment */
   1183 
   1184         if ((SubBuffer[0] == '*') &&
   1185             (SubBuffer[1] == '/'))
   1186         {
   1187             SpaceCount = 0;
   1188             SubBuffer += 2;
   1189 
   1190             if (*SubBuffer == '\n')
   1191             {
   1192                 if (TabCount > 0)
   1193                 {
   1194                     LastLineTabCount = TabCount;
   1195                     TabCount = 0;
   1196                 }
   1197 
   1198                 FirstNonBlank = NULL;
   1199                 LastLineColumnStart = ThisColumnStart;
   1200                 SubBuffer++;
   1201             }
   1202 
   1203             continue;
   1204         }
   1205 
   1206         /* Check for comment open */
   1207 
   1208         if ((SubBuffer[0] == '/') &&
   1209             (SubBuffer[1] == '*'))
   1210         {
   1211             /* Find the end of the comment, it must exist */
   1212 
   1213             CommentEnd = strstr (SubBuffer, "*/");
   1214             if (!CommentEnd)
   1215             {
   1216                 return;
   1217             }
   1218 
   1219             /* Toss the rest of this line or single-line comment */
   1220 
   1221             while ((SubBuffer < CommentEnd) &&
   1222                    (*SubBuffer != '\n'))
   1223             {
   1224                 SubBuffer++;
   1225             }
   1226 
   1227             if (*SubBuffer == '\n')
   1228             {
   1229                 if (TabCount > 0)
   1230                 {
   1231                     LastLineTabCount = TabCount;
   1232                     TabCount = 0;
   1233                 }
   1234 
   1235                 FirstNonBlank = NULL;
   1236                 LastLineColumnStart = ThisColumnStart;
   1237             }
   1238 
   1239             SpaceCount = 0;
   1240             continue;
   1241         }
   1242 
   1243         /* Ignore quoted strings */
   1244 
   1245         if ((!CommentEnd) && (*SubBuffer == '\"'))
   1246         {
   1247             SubBuffer++;
   1248             SubBuffer = AsSkipPastChar (SubBuffer, '\"');
   1249             if (!SubBuffer)
   1250             {
   1251                 return;
   1252             }
   1253 
   1254             SpaceCount = 0;
   1255         }
   1256 
   1257         if (*SubBuffer != ' ')
   1258         {
   1259             /* Not a space, skip to end of line */
   1260 
   1261             SubBuffer = AsSkipUntilChar (SubBuffer, '\n');
   1262             if (!SubBuffer)
   1263             {
   1264                 return;
   1265             }
   1266             if (TabCount > 0)
   1267             {
   1268                 LastLineTabCount = TabCount;
   1269                 TabCount = 0;
   1270             }
   1271 
   1272             FirstNonBlank = NULL;
   1273             LastLineColumnStart = ThisColumnStart;
   1274             Column = 0;
   1275             SpaceCount = 0;
   1276         }
   1277         else
   1278         {
   1279             /* Another space */
   1280 
   1281             SpaceCount++;
   1282 
   1283             if (SpaceCount >= 4)
   1284             {
   1285                 /* Replace this group of spaces with a tab character */
   1286 
   1287                 SpaceCount = 0;
   1288 
   1289                 NewSubBuffer = SubBuffer - 3;
   1290 
   1291                 if (TabCount <= ThisTabCount ? (ThisTabCount +1) : 0)
   1292                 {
   1293                     *NewSubBuffer = '\t';
   1294                     NewSubBuffer++;
   1295                     SubBuffer++;
   1296                     TabCount++;
   1297                 }
   1298 
   1299                 /* Remove the spaces */
   1300 
   1301                 SubBuffer = AsRemoveData (NewSubBuffer, SubBuffer);
   1302                 continue;
   1303             }
   1304         }
   1305 
   1306         SubBuffer++;
   1307     }
   1308 }
   1309 
   1310 
   1311 /******************************************************************************
   1312  *
   1313  * FUNCTION:    AsCountLines
   1314  *
   1315  * DESCRIPTION: Count the number of lines in the input buffer. Also count
   1316  *              the number of long lines (lines longer than 80 chars).
   1317  *
   1318  ******************************************************************************/
   1319 
   1320 static UINT32
   1321 AsCountLines (
   1322     char                    *Buffer,
   1323     char                    *Filename)
   1324 {
   1325     char                    *SubBuffer = Buffer;
   1326     char                    *EndOfLine;
   1327     UINT32                  LineCount = 0;
   1328     UINT32                  LongLineCount = 0;
   1329 
   1330 
   1331     while (*SubBuffer)
   1332     {
   1333         EndOfLine = AsSkipUntilChar (SubBuffer, '\n');
   1334         if (!EndOfLine)
   1335         {
   1336             Gbl_TotalLines += LineCount;
   1337             return (LineCount);
   1338         }
   1339 
   1340         if ((EndOfLine - SubBuffer) > 80)
   1341         {
   1342             LongLineCount++;
   1343             VERBOSE_PRINT (("long: %.80s\n", SubBuffer));
   1344         }
   1345 
   1346         LineCount++;
   1347         SubBuffer = EndOfLine + 1;
   1348     }
   1349 
   1350     if (LongLineCount)
   1351     {
   1352         VERBOSE_PRINT (("%u Lines longer than 80 found in %s\n",
   1353             LongLineCount, Filename));
   1354 
   1355         Gbl_LongLines += LongLineCount;
   1356     }
   1357 
   1358     Gbl_TotalLines += LineCount;
   1359     return (LineCount);
   1360 }
   1361 
   1362 
   1363 /******************************************************************************
   1364  *
   1365  * FUNCTION:    AsCountTabs
   1366  *
   1367  * DESCRIPTION: Simply count the number of tabs in the input file buffer
   1368  *
   1369  ******************************************************************************/
   1370 
   1371 void
   1372 AsCountTabs (
   1373     char                    *Buffer,
   1374     char                    *Filename)
   1375 {
   1376     UINT32                  i;
   1377     UINT32                  TabCount = 0;
   1378 
   1379 
   1380     for (i = 0; Buffer[i]; i++)
   1381     {
   1382         if (Buffer[i] == '\t')
   1383         {
   1384             TabCount++;
   1385         }
   1386     }
   1387 
   1388     if (TabCount)
   1389     {
   1390         AsPrint ("Tabs found", TabCount, Filename);
   1391         Gbl_Tabs += TabCount;
   1392     }
   1393 
   1394     AsCountLines (Buffer, Filename);
   1395 }
   1396 
   1397 
   1398 /******************************************************************************
   1399  *
   1400  * FUNCTION:    AsCountSourceLines
   1401  *
   1402  * DESCRIPTION: Count the number of C source lines. Defined by 1) not a
   1403  *              comment, and 2) not a blank line.
   1404  *
   1405  ******************************************************************************/
   1406 
   1407 void
   1408 AsCountSourceLines (
   1409     char                    *Buffer,
   1410     char                    *Filename)
   1411 {
   1412     char                    *SubBuffer = Buffer;
   1413     UINT32                  LineCount = 0;
   1414     UINT32                  WhiteCount = 0;
   1415     UINT32                  CommentCount = 0;
   1416 
   1417 
   1418     while (*SubBuffer)
   1419     {
   1420         /* Detect comments (// comments are not used, non-ansii) */
   1421 
   1422         if ((SubBuffer[0] == '/') &&
   1423             (SubBuffer[1] == '*'))
   1424         {
   1425             SubBuffer += 2;
   1426 
   1427             /* First line of multi-line comment is often just whitespace */
   1428 
   1429             if (SubBuffer[0] == '\n')
   1430             {
   1431                 WhiteCount++;
   1432                 SubBuffer++;
   1433             }
   1434             else
   1435             {
   1436                 CommentCount++;
   1437             }
   1438 
   1439             /* Find end of comment */
   1440 
   1441             while (SubBuffer[0] && SubBuffer[1] &&
   1442                 !(((SubBuffer[0] == '*') &&
   1443                     (SubBuffer[1] == '/'))))
   1444             {
   1445                 if (SubBuffer[0] == '\n')
   1446                 {
   1447                     CommentCount++;
   1448                 }
   1449 
   1450                 SubBuffer++;
   1451             }
   1452         }
   1453 
   1454         /* A linefeed followed by a non-linefeed is a valid source line */
   1455 
   1456         else if ((SubBuffer[0] == '\n') &&
   1457                  (SubBuffer[1] != '\n'))
   1458         {
   1459             LineCount++;
   1460         }
   1461 
   1462         /* Two back-to-back linefeeds indicate a whitespace line */
   1463 
   1464         else if ((SubBuffer[0] == '\n') &&
   1465                  (SubBuffer[1] == '\n'))
   1466         {
   1467             WhiteCount++;
   1468         }
   1469 
   1470         SubBuffer++;
   1471     }
   1472 
   1473     /* Adjust comment count for legal header */
   1474 
   1475     if (Gbl_HeaderSize < CommentCount)
   1476     {
   1477         CommentCount -= Gbl_HeaderSize;
   1478         Gbl_HeaderLines += Gbl_HeaderSize;
   1479     }
   1480 
   1481     Gbl_SourceLines += LineCount;
   1482     Gbl_WhiteLines += WhiteCount;
   1483     Gbl_CommentLines += CommentCount;
   1484 
   1485     VERBOSE_PRINT (("%u Comment %u White %u Code %u Lines in %s\n",
   1486         CommentCount, WhiteCount, LineCount,
   1487         LineCount + WhiteCount + CommentCount, Filename));
   1488 }
   1489 
   1490 
   1491 /******************************************************************************
   1492  *
   1493  * FUNCTION:    AsInsertPrefix
   1494  *
   1495  * DESCRIPTION: Insert struct or union prefixes
   1496  *
   1497  ******************************************************************************/
   1498 
   1499 void
   1500 AsInsertPrefix (
   1501     char                    *Buffer,
   1502     char                    *Keyword,
   1503     UINT8                   Type)
   1504 {
   1505     char                    *SubString;
   1506     char                    *SubBuffer;
   1507     char                    *EndKeyword;
   1508     int                     InsertLength;
   1509     char                    *InsertString;
   1510     int                     TrailingSpaces;
   1511     char                    LowerKeyword[128];
   1512     int                     KeywordLength;
   1513 
   1514 
   1515     switch (Type)
   1516     {
   1517     case SRC_TYPE_STRUCT:
   1518 
   1519         InsertString = "struct ";
   1520         break;
   1521 
   1522     case SRC_TYPE_UNION:
   1523 
   1524         InsertString = "union ";
   1525         break;
   1526 
   1527     default:
   1528 
   1529         return;
   1530     }
   1531 
   1532     strcpy (LowerKeyword, Keyword);
   1533     AcpiUtStrlwr (LowerKeyword);
   1534 
   1535     SubBuffer = Buffer;
   1536     SubString = Buffer;
   1537     InsertLength = strlen (InsertString);
   1538     KeywordLength = strlen (Keyword);
   1539 
   1540 
   1541     while (SubString)
   1542     {
   1543         /* Find an instance of the keyword */
   1544 
   1545         SubString = strstr (SubBuffer, LowerKeyword);
   1546         if (!SubString)
   1547         {
   1548             return;
   1549         }
   1550 
   1551         SubBuffer = SubString;
   1552 
   1553         /* Must be standalone word, not a substring */
   1554 
   1555         if (AsMatchExactWord (SubString, KeywordLength))
   1556         {
   1557             /* Make sure the keyword isn't already prefixed with the insert */
   1558 
   1559             if (!strncmp (SubString - InsertLength, InsertString, InsertLength))
   1560             {
   1561                 /* Add spaces if not already at the end-of-line */
   1562 
   1563                 if (*(SubBuffer + KeywordLength) != '\n')
   1564                 {
   1565                     /* Already present, add spaces after to align structure members */
   1566 
   1567 #if 0
   1568 /* ONLY FOR C FILES */
   1569                     AsInsertData (SubBuffer + KeywordLength, "        ", 8);
   1570 #endif
   1571                 }
   1572                 goto Next;
   1573             }
   1574 
   1575             /* Make sure the keyword isn't at the end of a struct/union */
   1576             /* Note: This code depends on a single space after the brace */
   1577 
   1578             if (*(SubString - 2) == '}')
   1579             {
   1580                 goto Next;
   1581             }
   1582 
   1583             /* Prefix the keyword with the insert string */
   1584 
   1585             Gbl_MadeChanges = TRUE;
   1586 
   1587             /* Is there room for insertion */
   1588 
   1589             EndKeyword = SubString + strlen (LowerKeyword);
   1590 
   1591             TrailingSpaces = 0;
   1592             while (EndKeyword[TrailingSpaces] == ' ')
   1593             {
   1594                 TrailingSpaces++;
   1595             }
   1596 
   1597             /*
   1598              * Use "if (TrailingSpaces > 1)" if we want to ignore casts
   1599              */
   1600             SubBuffer = SubString + InsertLength;
   1601 
   1602             if (TrailingSpaces > InsertLength)
   1603             {
   1604                 /* Insert the keyword */
   1605 
   1606                 memmove (SubBuffer, SubString, KeywordLength);
   1607 
   1608                 /* Insert the keyword */
   1609 
   1610                 memmove (SubString, InsertString, InsertLength);
   1611             }
   1612             else
   1613             {
   1614                 AsInsertData (SubString, InsertString, InsertLength);
   1615             }
   1616         }
   1617 
   1618 Next:
   1619         SubBuffer += KeywordLength;
   1620     }
   1621 }
   1622 
   1623 #ifdef ACPI_FUTURE_IMPLEMENTATION
   1624 /******************************************************************************
   1625  *
   1626  * FUNCTION:    AsTrimComments
   1627  *
   1628  * DESCRIPTION: Finds 3-line comments with only a single line of text
   1629  *
   1630  ******************************************************************************/
   1631 
   1632 void
   1633 AsTrimComments (
   1634     char                    *Buffer,
   1635     char                    *Filename)
   1636 {
   1637     char                    *SubBuffer = Buffer;
   1638     char                    *Ptr1;
   1639     char                    *Ptr2;
   1640     UINT32                  LineCount;
   1641     UINT32                  ShortCommentCount = 0;
   1642 
   1643 
   1644     while (1)
   1645     {
   1646         /* Find comment open, within procedure level */
   1647 
   1648         SubBuffer = strstr (SubBuffer, "    /*");
   1649         if (!SubBuffer)
   1650         {
   1651             goto Exit;
   1652         }
   1653 
   1654         /* Find comment terminator */
   1655 
   1656         Ptr1 = strstr (SubBuffer, "*/");
   1657         if (!Ptr1)
   1658         {
   1659             goto Exit;
   1660         }
   1661 
   1662         /* Find next EOL (from original buffer) */
   1663 
   1664         Ptr2 = strstr (SubBuffer, "\n");
   1665         if (!Ptr2)
   1666         {
   1667             goto Exit;
   1668         }
   1669 
   1670         /* Ignore one-line comments */
   1671 
   1672         if (Ptr1 < Ptr2)
   1673         {
   1674             /* Normal comment, ignore and continue; */
   1675 
   1676             SubBuffer = Ptr2;
   1677             continue;
   1678         }
   1679 
   1680         /* Examine multi-line comment */
   1681 
   1682         LineCount = 1;
   1683         while (Ptr1 > Ptr2)
   1684         {
   1685             /* Find next EOL */
   1686 
   1687             Ptr2++;
   1688             Ptr2 = strstr (Ptr2, "\n");
   1689             if (!Ptr2)
   1690             {
   1691                 goto Exit;
   1692             }
   1693 
   1694             LineCount++;
   1695         }
   1696 
   1697         SubBuffer = Ptr1;
   1698 
   1699         if (LineCount <= 3)
   1700         {
   1701             ShortCommentCount++;
   1702         }
   1703     }
   1704 
   1705 
   1706 Exit:
   1707 
   1708     if (ShortCommentCount)
   1709     {
   1710         AsPrint ("Short Comments found", ShortCommentCount, Filename);
   1711     }
   1712 }
   1713 #endif
   1714 
   1715 #ifdef ACPI_UNUSED_FUNCTIONS
   1716 /******************************************************************************
   1717  *
   1718  * FUNCTION:    AsCheckAndSkipLiterals
   1719  *
   1720  * DESCRIPTION: Generic routine to skip comments and quoted string literals.
   1721  *              Keeps a line count.
   1722  *
   1723  ******************************************************************************/
   1724 
   1725 static char *
   1726 AsCheckAndSkipLiterals (
   1727     char                    *Buffer,
   1728     UINT32                  *TotalLines);
   1729 
   1730 
   1731 static char *
   1732 AsCheckAndSkipLiterals (
   1733     char                    *Buffer,
   1734     UINT32                  *TotalLines)
   1735 {
   1736     UINT32                  NewLines = 0;
   1737     char                    *SubBuffer = Buffer;
   1738     char                    *LiteralEnd;
   1739 
   1740 
   1741     /* Ignore comments */
   1742 
   1743     if ((SubBuffer[0] == '/') &&
   1744         (SubBuffer[1] == '*'))
   1745     {
   1746         LiteralEnd = strstr (SubBuffer, "*/");
   1747         SubBuffer += 2;     /* Get past comment opening */
   1748 
   1749         if (!LiteralEnd)
   1750         {
   1751             return (SubBuffer);
   1752         }
   1753 
   1754         while (SubBuffer < LiteralEnd)
   1755         {
   1756             if (*SubBuffer == '\n')
   1757             {
   1758                 NewLines++;
   1759             }
   1760 
   1761             SubBuffer++;
   1762         }
   1763 
   1764         SubBuffer += 2;     /* Get past comment close */
   1765     }
   1766 
   1767     /* Ignore quoted strings */
   1768 
   1769     else if (*SubBuffer == '\"')
   1770     {
   1771         SubBuffer++;
   1772         LiteralEnd = AsSkipPastChar (SubBuffer, '\"');
   1773         if (!LiteralEnd)
   1774         {
   1775             return (SubBuffer);
   1776         }
   1777     }
   1778 
   1779     if (TotalLines)
   1780     {
   1781         (*TotalLines) += NewLines;
   1782     }
   1783     return (SubBuffer);
   1784 }
   1785 #endif
   1786