Home | History | Annotate | Line # | Download | only in acpisrc
acpisrc.h revision 1.1.1.12
      1 /******************************************************************************
      2  *
      3  * Module Name: acpisrc.h - Include file for AcpiSrc utility
      4  *
      5  *****************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2017, 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               34
     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     ACPI_STRING_TABLE           *SourceStringTable;
    176     ACPI_IDENTIFIER_TABLE       *SourceLineTable;
    177     ACPI_IDENTIFIER_TABLE       *SourceConditionalTable;
    178     ACPI_IDENTIFIER_TABLE       *SourceMacroTable;
    179     ACPI_TYPED_IDENTIFIER_TABLE *SourceStructTable;
    180     ACPI_IDENTIFIER_TABLE       *SourceSpecialMacroTable;
    181     UINT32                      SourceFunctions;
    182 
    183     ACPI_STRING_TABLE           *HeaderStringTable;
    184     ACPI_IDENTIFIER_TABLE       *HeaderLineTable;
    185     ACPI_IDENTIFIER_TABLE       *HeaderConditionalTable;
    186     ACPI_IDENTIFIER_TABLE       *HeaderMacroTable;
    187     ACPI_TYPED_IDENTIFIER_TABLE *HeaderStructTable;
    188     ACPI_IDENTIFIER_TABLE       *HeaderSpecialMacroTable;
    189     UINT32                      HeaderFunctions;
    190 
    191     ACPI_STRING_TABLE           *PatchStringTable;
    192     ACPI_IDENTIFIER_TABLE       *PatchLineTable;
    193     ACPI_IDENTIFIER_TABLE       *PatchConditionalTable;
    194     ACPI_IDENTIFIER_TABLE       *PatchMacroTable;
    195     ACPI_TYPED_IDENTIFIER_TABLE *PatchStructTable;
    196     ACPI_IDENTIFIER_TABLE       *PatchSpecialMacroTable;
    197     UINT32                      PatchFunctions;
    198 
    199 } ACPI_CONVERSION_TABLE;
    200 
    201 
    202 /* Conversion tables */
    203 
    204 extern ACPI_CONVERSION_TABLE       LinuxConversionTable;
    205 extern ACPI_CONVERSION_TABLE       CleanupConversionTable;
    206 extern ACPI_CONVERSION_TABLE       StatsConversionTable;
    207 extern ACPI_CONVERSION_TABLE       CustomConversionTable;
    208 extern ACPI_CONVERSION_TABLE       LicenseConversionTable;
    209 extern ACPI_CONVERSION_TABLE       IndentConversionTable;
    210 
    211 typedef
    212 char * (*AS_SCAN_CALLBACK) (
    213     char                    *Buffer,
    214     char                    *Filename,
    215     UINT32                  LineNumber);
    216 
    217 typedef struct as_brace_info
    218 {
    219     char                    *Operator;
    220     UINT32                  Length;
    221 
    222 } AS_BRACE_INFO;
    223 
    224 
    225 /* Prototypes */
    226 
    227 char *
    228 AsSkipUntilChar (
    229     char                    *Buffer,
    230     char                    Target);
    231 
    232 char *
    233 AsSkipPastChar (
    234     char                    *Buffer,
    235     char                    Target);
    236 
    237 char *
    238 AsReplaceData (
    239     char                    *Buffer,
    240     UINT32                  LengthToRemove,
    241     char                    *BufferToAdd,
    242     UINT32                  LengthToAdd);
    243 
    244 int
    245 AsReplaceString (
    246     char                    *Target,
    247     char                    *Replacement,
    248     UINT8                   Type,
    249     char                    *Buffer);
    250 
    251 int
    252 AsLowerCaseString (
    253     char                    *Target,
    254     char                    *Buffer);
    255 
    256 void
    257 AsRemoveLine (
    258     char                    *Buffer,
    259     char                    *Keyword);
    260 
    261 void
    262 AsCheckForBraces (
    263     char                    *Buffer,
    264     char                    *Filename);
    265 
    266 void
    267 AsTrimLines (
    268     char                    *Buffer,
    269     char                    *Filename);
    270 
    271 void
    272 AsMixedCaseToUnderscores (
    273     char                    *Buffer,
    274     char                    *Filename);
    275 
    276 void
    277 AsCountTabs (
    278     char                    *Buffer,
    279     char                    *Filename);
    280 
    281 void
    282 AsBracesOnSameLine (
    283     char                    *Buffer);
    284 
    285 void
    286 AsLowerCaseIdentifiers (
    287     char                    *Buffer);
    288 
    289 void
    290 AsReduceTypedefs (
    291     char                    *Buffer,
    292     char                    *Keyword);
    293 
    294 void
    295 AsRemoveDebugMacros (
    296     char                    *Buffer);
    297 
    298 void
    299 AsRemoveEmptyBlocks (
    300     char                    *Buffer,
    301     char                    *Filename);
    302 
    303 void
    304 AsCleanupSpecialMacro (
    305     char                    *Buffer,
    306     char                    *Keyword);
    307 
    308 void
    309 AsCountSourceLines (
    310     char                    *Buffer,
    311     char                    *Filename);
    312 
    313 void
    314 AsCountNonAnsiComments (
    315     char                    *Buffer,
    316     char                    *Filename);
    317 
    318 void
    319 AsTrimWhitespace (
    320     char                    *Buffer);
    321 
    322 void
    323 AsTabify4 (
    324     char                    *Buffer);
    325 
    326 void
    327 AsTabify8 (
    328     char                    *Buffer);
    329 
    330 void
    331 AsRemoveConditionalCompile (
    332     char                    *Buffer,
    333     char                    *Keyword);
    334 
    335 ACPI_NATIVE_INT
    336 AsProcessTree (
    337     ACPI_CONVERSION_TABLE   *ConversionTable,
    338     char                    *SourcePath,
    339     char                    *TargetPath);
    340 
    341 int
    342 AsGetFile (
    343     char                    *FileName,
    344     char                    **FileBuffer,
    345     UINT32                  *FileSize);
    346 
    347 int
    348 AsPutFile (
    349     char                    *Pathname,
    350     char                    *FileBuffer,
    351     UINT32                  SystemFlags);
    352 
    353 void
    354 AsReplaceHeader (
    355     char                    *Buffer,
    356     char                    *NewHeader);
    357 
    358 void
    359 AsConvertFile (
    360     ACPI_CONVERSION_TABLE   *ConversionTable,
    361     char                    *FileBuffer,
    362     char                    *Filename,
    363     ACPI_NATIVE_INT         FileType);
    364 
    365 ACPI_NATIVE_INT
    366 AsProcessOneFile (
    367     ACPI_CONVERSION_TABLE   *ConversionTable,
    368     char                    *SourcePath,
    369     char                    *TargetPath,
    370     int                     MaxPathLength,
    371     char                    *Filename,
    372     ACPI_NATIVE_INT         FileType);
    373 
    374 ACPI_NATIVE_INT
    375 AsCheckForDirectory (
    376     char                    *SourceDirPath,
    377     char                    *TargetDirPath,
    378     char                    *Filename,
    379     char                    **SourcePath,
    380     char                    **TargetPath);
    381 
    382 void
    383 AsRemoveExtraLines (
    384     char                    *FileBuffer,
    385     char                    *Filename);
    386 
    387 void
    388 AsRemoveSpacesAfterPeriod (
    389     char                    *FileBuffer,
    390     char                    *Filename);
    391 
    392 BOOLEAN
    393 AsMatchExactWord (
    394     char                    *Word,
    395     UINT32                  WordLength);
    396 
    397 void
    398 AsPrint (
    399     char                    *Message,
    400     UINT32                  Count,
    401     char                    *Filename);
    402 
    403 void
    404 AsInsertPrefix (
    405     char                    *Buffer,
    406     char                    *Keyword,
    407     UINT8                   Type);
    408 
    409 char *
    410 AsInsertData (
    411     char                    *Buffer,
    412     char                    *BufferToAdd,
    413     UINT32                  LengthToAdd);
    414 
    415 char *
    416 AsRemoveData (
    417     char                    *StartPointer,
    418     char                    *EndPointer);
    419 
    420 void
    421 AsInsertCarriageReturns (
    422     char                    *Buffer);
    423 
    424 void
    425 AsConvertToLineFeeds (
    426     char                    *Buffer);
    427