Home | History | Annotate | Line # | Download | only in acpisrc
acpisrc.h revision 1.1.1.13
      1 /******************************************************************************
      2  *
      3  * Module Name: acpisrc.h - Include file for AcpiSrc utility
      4  *
      5  *****************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2018, 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 MERCHANTIBILITY 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 "acpi.h"
     45 #include "accommon.h"
     46 #include "acapps.h"
     47 
     48 /* mkdir support */
     49 
     50 #ifdef WIN32
     51 #include <direct.h>
     52 #else
     53 #define mkdir(x) mkdir(x, 0770)
     54 #endif
     55 
     56 
     57 /* Constants */
     58 
     59 #define LINES_IN_LEGAL_HEADER               115+36 /* intel+dual license. See legal header above at module start */
     60 #define LEGAL_HEADER_SIGNATURE              " * 2.1. This is your license from Intel Corp. under its intellectual property"
     61 #define LINES_IN_LINUX_HEADER               2 /* SPDX header is 1 line Intel copyright is another line */
     62 #define LINUX_HEADER_SIGNATURE              " * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS"
     63 #define LINES_IN_ASL_HEADER                 29 /* Header as output from disassembler */
     64 
     65 #define ASRC_MAX_FILE_SIZE                  (1024 * 100)
     66 
     67 #define FILE_TYPE_SOURCE                    1
     68 #define FILE_TYPE_HEADER                    2
     69 #define FILE_TYPE_DIRECTORY                 3
     70 #define FILE_TYPE_PATCH                     4
     71 
     72 #define CVT_COUNT_TABS                      0x00000001
     73 #define CVT_COUNT_NON_ANSI_COMMENTS         0x00000002
     74 #define CVT_TRIM_LINES                      0x00000004
     75 #define CVT_CHECK_BRACES                    0x00000008
     76 #define CVT_COUNT_LINES                     0x00000010
     77 #define CVT_BRACES_ON_SAME_LINE             0x00000020
     78 #define CVT_MIXED_CASE_TO_UNDERSCORES       0x00000040
     79 #define CVT_LOWER_CASE_IDENTIFIERS          0x00000080
     80 #define CVT_REMOVE_DEBUG_MACROS             0x00000100
     81 #define CVT_TRIM_WHITESPACE                 0x00000200  /* Should be after all line removal */
     82 #define CVT_REMOVE_EMPTY_BLOCKS             0x00000400  /* Should be after trimming lines */
     83 #define CVT_REDUCE_TYPEDEFS                 0x00000800
     84 #define CVT_COUNT_SHORTMULTILINE_COMMENTS   0x00001000
     85 #define CVT_SPACES_TO_TABS4                 0x40000000  /* Tab conversion should be last */
     86 #define CVT_SPACES_TO_TABS8                 0x80000000  /* Tab conversion should be last */
     87 
     88 #define FLG_DEFAULT_FLAGS                   0x00000000
     89 #define FLG_NO_CARRIAGE_RETURNS             0x00000001
     90 #define FLG_NO_FILE_OUTPUT                  0x00000002
     91 #define FLG_LOWERCASE_DIRNAMES              0x00000004
     92 
     93 #define AS_START_IGNORE                     "/*!"
     94 #define AS_STOP_IGNORE                      "!*/"
     95 
     96 
     97 /* Globals */
     98 
     99 extern UINT32                   Gbl_Files;
    100 extern UINT32                   Gbl_MissingBraces;
    101 extern UINT32                   Gbl_Tabs;
    102 extern UINT32                   Gbl_NonAnsiComments;
    103 extern UINT32                   Gbl_SourceLines;
    104 extern UINT32                   Gbl_WhiteLines;
    105 extern UINT32                   Gbl_CommentLines;
    106 extern UINT32                   Gbl_LongLines;
    107 extern UINT32                   Gbl_TotalLines;
    108 extern UINT32                   Gbl_HeaderSize;
    109 extern UINT32                   Gbl_HeaderLines;
    110 extern struct stat              Gbl_StatBuf;
    111 extern char                     *Gbl_FileBuffer;
    112 extern UINT32                   Gbl_TotalSize;
    113 extern UINT32                   Gbl_FileSize;
    114 extern UINT32                   Gbl_FileType;
    115 extern BOOLEAN                  Gbl_VerboseMode;
    116 extern BOOLEAN                  Gbl_QuietMode;
    117 extern BOOLEAN                  Gbl_BatchMode;
    118 extern BOOLEAN                  Gbl_MadeChanges;
    119 extern BOOLEAN                  Gbl_Overwrite;
    120 extern BOOLEAN                  Gbl_WidenDeclarations;
    121 extern BOOLEAN                  Gbl_IgnoreLoneLineFeeds;
    122 extern BOOLEAN                  Gbl_HasLoneLineFeeds;
    123 extern BOOLEAN                  Gbl_Cleanup;
    124 extern BOOLEAN                  Gbl_IgnoreTranslationEscapes;
    125 extern BOOLEAN                  Gbl_CheckAscii;
    126 extern void                     *Gbl_StructDefs;
    127 
    128 #define PARAM_LIST(pl)          pl
    129 #define TERSE_PRINT(a)          if (!Gbl_VerboseMode) printf PARAM_LIST(a)
    130 #define VERBOSE_PRINT(a)        if (Gbl_VerboseMode) printf PARAM_LIST(a)
    131 
    132 #define REPLACE_WHOLE_WORD      0x00
    133 #define REPLACE_SUBSTRINGS      0x01
    134 #define REPLACE_MASK            0x01
    135 
    136 #define EXTRA_INDENT_C          0x02
    137 
    138 
    139 /* Conversion table structs */
    140 
    141 typedef struct acpi_string_table
    142 {
    143     char                        *Target;
    144     char                        *Replacement;
    145     UINT8                       Type;
    146 
    147 } ACPI_STRING_TABLE;
    148 
    149 
    150 typedef struct acpi_typed_identifier_table
    151 {
    152     char                        *Identifier;
    153     UINT8                       Type;
    154 
    155 } ACPI_TYPED_IDENTIFIER_TABLE;
    156 
    157 #define SRC_TYPE_SIMPLE         0
    158 #define SRC_TYPE_STRUCT         1
    159 #define SRC_TYPE_UNION          2
    160 
    161 
    162 typedef struct acpi_identifier_table
    163 {
    164     char                        *Identifier;
    165 
    166 } ACPI_IDENTIFIER_TABLE;
    167 
    168 typedef struct acpi_conversion_table
    169 {
    170     char                        *NewHeader;
    171     UINT32                      Flags;
    172 
    173     ACPI_TYPED_IDENTIFIER_TABLE *LowerCaseTable;
    174 
    175     char                        *SourceSpdxHeader;
    176     ACPI_STRING_TABLE           *SourceStringTable;
    177     ACPI_IDENTIFIER_TABLE       *SourceLineTable;
    178     ACPI_IDENTIFIER_TABLE       *SourceConditionalTable;
    179     ACPI_IDENTIFIER_TABLE       *SourceMacroTable;
    180     ACPI_TYPED_IDENTIFIER_TABLE *SourceStructTable;
    181     ACPI_IDENTIFIER_TABLE       *SourceSpecialMacroTable;
    182     UINT32                      SourceFunctions;
    183 
    184     char                        *HeaderSpdxHeader;
    185     ACPI_STRING_TABLE           *HeaderStringTable;
    186     ACPI_IDENTIFIER_TABLE       *HeaderLineTable;
    187     ACPI_IDENTIFIER_TABLE       *HeaderConditionalTable;
    188     ACPI_IDENTIFIER_TABLE       *HeaderMacroTable;
    189     ACPI_TYPED_IDENTIFIER_TABLE *HeaderStructTable;
    190     ACPI_IDENTIFIER_TABLE       *HeaderSpecialMacroTable;
    191     UINT32                      HeaderFunctions;
    192 
    193     /* SPDX header conversion for patches is not supported */
    194     ACPI_STRING_TABLE           *PatchStringTable;
    195     ACPI_IDENTIFIER_TABLE       *PatchLineTable;
    196     ACPI_IDENTIFIER_TABLE       *PatchConditionalTable;
    197     ACPI_IDENTIFIER_TABLE       *PatchMacroTable;
    198     ACPI_TYPED_IDENTIFIER_TABLE *PatchStructTable;
    199     ACPI_IDENTIFIER_TABLE       *PatchSpecialMacroTable;
    200     UINT32                      PatchFunctions;
    201 
    202 } ACPI_CONVERSION_TABLE;
    203 
    204 
    205 /* Conversion tables */
    206 
    207 extern ACPI_CONVERSION_TABLE       LinuxConversionTable;
    208 extern ACPI_CONVERSION_TABLE       CleanupConversionTable;
    209 extern ACPI_CONVERSION_TABLE       StatsConversionTable;
    210 extern ACPI_CONVERSION_TABLE       CustomConversionTable;
    211 extern ACPI_CONVERSION_TABLE       LicenseConversionTable;
    212 extern ACPI_CONVERSION_TABLE       IndentConversionTable;
    213 
    214 typedef
    215 char * (*AS_SCAN_CALLBACK) (
    216     char                    *Buffer,
    217     char                    *Filename,
    218     UINT32                  LineNumber);
    219 
    220 typedef struct as_brace_info
    221 {
    222     char                    *Operator;
    223     UINT32                  Length;
    224 
    225 } AS_BRACE_INFO;
    226 
    227 
    228 /* Prototypes */
    229 
    230 char *
    231 AsSkipUntilChar (
    232     char                    *Buffer,
    233     char                    Target);
    234 
    235 char *
    236 AsSkipPastChar (
    237     char                    *Buffer,
    238     char                    Target);
    239 
    240 char *
    241 AsReplaceData (
    242     char                    *Buffer,
    243     UINT32                  LengthToRemove,
    244     char                    *BufferToAdd,
    245     UINT32                  LengthToAdd);
    246 
    247 int
    248 AsReplaceString (
    249     char                    *Target,
    250     char                    *Replacement,
    251     UINT8                   Type,
    252     char                    *Buffer);
    253 
    254 int
    255 AsLowerCaseString (
    256     char                    *Target,
    257     char                    *Buffer);
    258 
    259 void
    260 AsRemoveLine (
    261     char                    *Buffer,
    262     char                    *Keyword);
    263 
    264 void
    265 AsCheckForBraces (
    266     char                    *Buffer,
    267     char                    *Filename);
    268 
    269 void
    270 AsTrimLines (
    271     char                    *Buffer,
    272     char                    *Filename);
    273 
    274 void
    275 AsMixedCaseToUnderscores (
    276     char                    *Buffer,
    277     char                    *Filename);
    278 
    279 void
    280 AsCountTabs (
    281     char                    *Buffer,
    282     char                    *Filename);
    283 
    284 void
    285 AsBracesOnSameLine (
    286     char                    *Buffer);
    287 
    288 void
    289 AsLowerCaseIdentifiers (
    290     char                    *Buffer);
    291 
    292 void
    293 AsReduceTypedefs (
    294     char                    *Buffer,
    295     char                    *Keyword);
    296 
    297 void
    298 AsRemoveDebugMacros (
    299     char                    *Buffer);
    300 
    301 void
    302 AsRemoveEmptyBlocks (
    303     char                    *Buffer,
    304     char                    *Filename);
    305 
    306 void
    307 AsCleanupSpecialMacro (
    308     char                    *Buffer,
    309     char                    *Keyword);
    310 
    311 void
    312 AsCountSourceLines (
    313     char                    *Buffer,
    314     char                    *Filename);
    315 
    316 void
    317 AsCountNonAnsiComments (
    318     char                    *Buffer,
    319     char                    *Filename);
    320 
    321 void
    322 AsTrimWhitespace (
    323     char                    *Buffer);
    324 
    325 void
    326 AsTabify4 (
    327     char                    *Buffer);
    328 
    329 void
    330 AsTabify8 (
    331     char                    *Buffer);
    332 
    333 void
    334 AsRemoveConditionalCompile (
    335     char                    *Buffer,
    336     char                    *Keyword);
    337 
    338 ACPI_NATIVE_INT
    339 AsProcessTree (
    340     ACPI_CONVERSION_TABLE   *ConversionTable,
    341     char                    *SourcePath,
    342     char                    *TargetPath);
    343 
    344 int
    345 AsGetFile (
    346     char                    *FileName,
    347     char                    **FileBuffer,
    348     UINT32                  *FileSize);
    349 
    350 int
    351 AsPutFile (
    352     char                    *Pathname,
    353     char                    *FileBuffer,
    354     UINT32                  SystemFlags);
    355 
    356 void
    357 AsReplaceHeader (
    358     char                    *Buffer,
    359     char                    *NewHeader);
    360 
    361 void
    362 AsDoSpdxHeader (
    363     char                    *Buffer,
    364     char                    *SpdxHeader);
    365 
    366 void
    367 AsConvertFile (
    368     ACPI_CONVERSION_TABLE   *ConversionTable,
    369     char                    *FileBuffer,
    370     char                    *Filename,
    371     ACPI_NATIVE_INT         FileType);
    372 
    373 ACPI_NATIVE_INT
    374 AsProcessOneFile (
    375     ACPI_CONVERSION_TABLE   *ConversionTable,
    376     char                    *SourcePath,
    377     char                    *TargetPath,
    378     int                     MaxPathLength,
    379     char                    *Filename,
    380     ACPI_NATIVE_INT         FileType);
    381 
    382 ACPI_NATIVE_INT
    383 AsCheckForDirectory (
    384     char                    *SourceDirPath,
    385     char                    *TargetDirPath,
    386     char                    *Filename,
    387     char                    **SourcePath,
    388     char                    **TargetPath);
    389 
    390 void
    391 AsRemoveExtraLines (
    392     char                    *FileBuffer,
    393     char                    *Filename);
    394 
    395 void
    396 AsRemoveSpacesAfterPeriod (
    397     char                    *FileBuffer,
    398     char                    *Filename);
    399 
    400 BOOLEAN
    401 AsMatchExactWord (
    402     char                    *Word,
    403     UINT32                  WordLength);
    404 
    405 void
    406 AsPrint (
    407     char                    *Message,
    408     UINT32                  Count,
    409     char                    *Filename);
    410 
    411 void
    412 AsInsertPrefix (
    413     char                    *Buffer,
    414     char                    *Keyword,
    415     UINT8                   Type);
    416 
    417 char *
    418 AsInsertData (
    419     char                    *Buffer,
    420     char                    *BufferToAdd,
    421     UINT32                  LengthToAdd);
    422 
    423 char *
    424 AsRemoveData (
    425     char                    *StartPointer,
    426     char                    *EndPointer);
    427 
    428 void
    429 AsInsertCarriageReturns (
    430     char                    *Buffer);
    431 
    432 void
    433 AsConvertToLineFeeds (
    434     char                    *Buffer);
    435