Home | History | Annotate | Line # | Download | only in acpisrc
acpisrc.h revision 1.1.1.3
      1 
      2 /******************************************************************************
      3  *
      4  * Module Name: acpisrc.h - Include file for AcpiSrc utility
      5  *
      6  *****************************************************************************/
      7 
      8 /*
      9  * Copyright (C) 2000 - 2011, Intel Corp.
     10  * All rights reserved.
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     15  * 1. Redistributions of source code must retain the above copyright
     16  *    notice, this list of conditions, and the following disclaimer,
     17  *    without modification.
     18  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     19  *    substantially similar to the "NO WARRANTY" disclaimer below
     20  *    ("Disclaimer") and any redistribution must be conditioned upon
     21  *    including a substantially similar Disclaimer requirement for further
     22  *    binary redistribution.
     23  * 3. Neither the names of the above-listed copyright holders nor the names
     24  *    of any contributors may be used to endorse or promote products derived
     25  *    from this software without specific prior written permission.
     26  *
     27  * Alternatively, this software may be distributed under the terms of the
     28  * GNU General Public License ("GPL") version 2 as published by the Free
     29  * Software Foundation.
     30  *
     31  * NO WARRANTY
     32  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     33  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     34  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     35  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     36  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     40  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     41  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     42  * POSSIBILITY OF SUCH DAMAGES.
     43  */
     44 
     45 
     46 #define LINES_IN_LEGAL_HEADER               105 /* See above */
     47 #define LEGAL_HEADER_SIGNATURE              " * 2.1. This is your license from Intel Corp. under its intellectual property"
     48 #define LINES_IN_LINUX_HEADER               34
     49 #define LINUX_HEADER_SIGNATURE              " * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS"
     50 #define LINES_IN_ASL_HEADER                 29 /* Header as output from disassembler */
     51 
     52 #include "acpi.h"
     53 #include "accommon.h"
     54 
     55 #include <stdio.h>
     56 #include <sys/stat.h>
     57 #include <sys/types.h>
     58 #include <fcntl.h>
     59 #include <ctype.h>
     60 #ifdef WIN32
     61 #include <io.h>
     62 #include <direct.h>
     63 #endif
     64 #include <errno.h>
     65 
     66 
     67 /* O_BINARY is not always defined */
     68 #ifndef O_BINARY
     69 #define O_BINARY    0x0
     70 #endif
     71 
     72 /* Fixups for non-Win32 compilation */
     73 #ifndef WIN32
     74 #define mkdir(x) mkdir(x, 0770)
     75 char * strlwr(char* str);
     76 #endif
     77 
     78 
     79 /* Constants */
     80 
     81 #define ASRC_MAX_FILE_SIZE                  (1024 * 100)
     82 
     83 #define FILE_TYPE_SOURCE                    1
     84 #define FILE_TYPE_HEADER                    2
     85 #define FILE_TYPE_DIRECTORY                 3
     86 
     87 #define CVT_COUNT_TABS                      0x00000001
     88 #define CVT_COUNT_NON_ANSI_COMMENTS         0x00000002
     89 #define CVT_TRIM_LINES                      0x00000004
     90 #define CVT_CHECK_BRACES                    0x00000008
     91 #define CVT_COUNT_LINES                     0x00000010
     92 #define CVT_BRACES_ON_SAME_LINE             0x00000020
     93 #define CVT_MIXED_CASE_TO_UNDERSCORES       0x00000040
     94 #define CVT_LOWER_CASE_IDENTIFIERS          0x00000080
     95 #define CVT_REMOVE_DEBUG_MACROS             0x00000100
     96 #define CVT_TRIM_WHITESPACE                 0x00000200  /* Should be after all line removal */
     97 #define CVT_REMOVE_EMPTY_BLOCKS             0x00000400  /* Should be after trimming lines */
     98 #define CVT_REDUCE_TYPEDEFS                 0x00000800
     99 #define CVT_COUNT_SHORTMULTILINE_COMMENTS   0x00001000
    100 #define CVT_SPACES_TO_TABS4                 0x40000000  /* Tab conversion should be last */
    101 #define CVT_SPACES_TO_TABS8                 0x80000000  /* Tab conversion should be last */
    102 
    103 #define FLG_DEFAULT_FLAGS                   0x00000000
    104 #define FLG_NO_CARRIAGE_RETURNS             0x00000001
    105 #define FLG_NO_FILE_OUTPUT                  0x00000002
    106 #define FLG_LOWERCASE_DIRNAMES              0x00000004
    107 
    108 #define AS_START_IGNORE                     "/*!"
    109 #define AS_STOP_IGNORE                      "!*/"
    110 
    111 
    112 /* Globals */
    113 
    114 extern UINT32                   Gbl_Files;
    115 extern UINT32                   Gbl_MissingBraces;
    116 extern UINT32                   Gbl_Tabs;
    117 extern UINT32                   Gbl_NonAnsiComments;
    118 extern UINT32                   Gbl_SourceLines;
    119 extern UINT32                   Gbl_WhiteLines;
    120 extern UINT32                   Gbl_CommentLines;
    121 extern UINT32                   Gbl_LongLines;
    122 extern UINT32                   Gbl_TotalLines;
    123 extern UINT32                   Gbl_HeaderSize;
    124 extern UINT32                   Gbl_HeaderLines;
    125 extern struct stat              Gbl_StatBuf;
    126 extern char                     *Gbl_FileBuffer;
    127 extern UINT32                   Gbl_TotalSize;
    128 extern UINT32                   Gbl_FileSize;
    129 extern UINT32                   Gbl_FileType;
    130 extern BOOLEAN                  Gbl_VerboseMode;
    131 extern BOOLEAN                  Gbl_QuietMode;
    132 extern BOOLEAN                  Gbl_BatchMode;
    133 extern BOOLEAN                  Gbl_MadeChanges;
    134 extern BOOLEAN                  Gbl_Overwrite;
    135 extern BOOLEAN                  Gbl_WidenDeclarations;
    136 extern BOOLEAN                  Gbl_IgnoreLoneLineFeeds;
    137 extern BOOLEAN                  Gbl_HasLoneLineFeeds;
    138 extern void                     *Gbl_StructDefs;
    139 
    140 #define PARAM_LIST(pl)          pl
    141 #define TERSE_PRINT(a)          if (!Gbl_VerboseMode) printf PARAM_LIST(a)
    142 #define VERBOSE_PRINT(a)        if (Gbl_VerboseMode) printf PARAM_LIST(a)
    143 
    144 #define REPLACE_WHOLE_WORD      0x00
    145 #define REPLACE_SUBSTRINGS      0x01
    146 #define REPLACE_MASK            0x01
    147 
    148 #define EXTRA_INDENT_C          0x02
    149 
    150 
    151 /* Conversion table structs */
    152 
    153 typedef struct acpi_string_table
    154 {
    155     char                        *Target;
    156     char                        *Replacement;
    157     UINT8                       Type;
    158 
    159 } ACPI_STRING_TABLE;
    160 
    161 
    162 typedef struct acpi_typed_identifier_table
    163 {
    164     char                        *Identifier;
    165     UINT8                       Type;
    166 
    167 } ACPI_TYPED_IDENTIFIER_TABLE;
    168 
    169 #define SRC_TYPE_SIMPLE         0
    170 #define SRC_TYPE_STRUCT         1
    171 #define SRC_TYPE_UNION          2
    172 
    173 
    174 typedef struct acpi_identifier_table
    175 {
    176     char                        *Identifier;
    177 
    178 } ACPI_IDENTIFIER_TABLE;
    179 
    180 typedef struct acpi_conversion_table
    181 {
    182     char                        *NewHeader;
    183     UINT32                      Flags;
    184 
    185     ACPI_TYPED_IDENTIFIER_TABLE *LowerCaseTable;
    186 
    187     ACPI_STRING_TABLE           *SourceStringTable;
    188     ACPI_IDENTIFIER_TABLE       *SourceLineTable;
    189     ACPI_IDENTIFIER_TABLE       *SourceConditionalTable;
    190     ACPI_IDENTIFIER_TABLE       *SourceMacroTable;
    191     ACPI_TYPED_IDENTIFIER_TABLE *SourceStructTable;
    192     UINT32                      SourceFunctions;
    193 
    194     ACPI_STRING_TABLE           *HeaderStringTable;
    195     ACPI_IDENTIFIER_TABLE       *HeaderLineTable;
    196     ACPI_IDENTIFIER_TABLE       *HeaderConditionalTable;
    197     ACPI_IDENTIFIER_TABLE       *HeaderMacroTable;
    198     ACPI_TYPED_IDENTIFIER_TABLE *HeaderStructTable;
    199     UINT32                      HeaderFunctions;
    200 
    201 } ACPI_CONVERSION_TABLE;
    202 
    203 
    204 /* Conversion tables */
    205 
    206 extern ACPI_CONVERSION_TABLE       LinuxConversionTable;
    207 extern ACPI_CONVERSION_TABLE       CleanupConversionTable;
    208 extern ACPI_CONVERSION_TABLE       StatsConversionTable;
    209 extern ACPI_CONVERSION_TABLE       CustomConversionTable;
    210 extern ACPI_CONVERSION_TABLE       LicenseConversionTable;
    211 
    212 
    213 /* Prototypes */
    214 
    215 char *
    216 AsSkipUntilChar (
    217     char                    *Buffer,
    218     char                    Target);
    219 
    220 char *
    221 AsSkipPastChar (
    222     char                    *Buffer,
    223     char                    Target);
    224 
    225 char *
    226 AsReplaceData (
    227     char                    *Buffer,
    228     UINT32                  LengthToRemove,
    229     char                    *BufferToAdd,
    230     UINT32                  LengthToAdd);
    231 
    232 int
    233 AsReplaceString (
    234     char                    *Target,
    235     char                    *Replacement,
    236     UINT8                   Type,
    237     char                    *Buffer);
    238 
    239 int
    240 AsLowerCaseString (
    241     char                    *Target,
    242     char                    *Buffer);
    243 
    244 void
    245 AsRemoveLine (
    246     char                    *Buffer,
    247     char                    *Keyword);
    248 
    249 void
    250 AsRemoveMacro (
    251     char                    *Buffer,
    252     char                    *Keyword);
    253 
    254 void
    255 AsCheckForBraces (
    256     char                    *Buffer,
    257     char                    *Filename);
    258 
    259 void
    260 AsTrimLines (
    261     char                    *Buffer,
    262     char                    *Filename);
    263 
    264 void
    265 AsMixedCaseToUnderscores (
    266     char                    *Buffer);
    267 
    268 void
    269 AsCountTabs (
    270     char                    *Buffer,
    271     char                    *Filename);
    272 
    273 void
    274 AsBracesOnSameLine (
    275     char                    *Buffer);
    276 
    277 void
    278 AsLowerCaseIdentifiers (
    279     char                    *Buffer);
    280 
    281 void
    282 AsReduceTypedefs (
    283     char                    *Buffer,
    284     char                    *Keyword);
    285 
    286 void
    287 AsRemoveDebugMacros (
    288     char                    *Buffer);
    289 
    290 void
    291 AsRemoveEmptyBlocks (
    292     char                    *Buffer,
    293     char                    *Filename);
    294 
    295 void
    296 AsCountSourceLines (
    297     char                    *Buffer,
    298     char                    *Filename);
    299 
    300 void
    301 AsCountNonAnsiComments (
    302     char                    *Buffer,
    303     char                    *Filename);
    304 
    305 void
    306 AsTrimWhitespace (
    307     char                    *Buffer);
    308 
    309 void
    310 AsTabify4 (
    311     char                    *Buffer);
    312 
    313 void
    314 AsTabify8 (
    315     char                    *Buffer);
    316 
    317 void
    318 AsRemoveConditionalCompile (
    319     char                    *Buffer,
    320     char                    *Keyword);
    321 
    322 ACPI_NATIVE_INT
    323 AsProcessTree (
    324     ACPI_CONVERSION_TABLE   *ConversionTable,
    325     char                    *SourcePath,
    326     char                    *TargetPath);
    327 
    328 int
    329 AsGetFile (
    330     char                    *FileName,
    331     char                    **FileBuffer,
    332     UINT32                  *FileSize);
    333 
    334 int
    335 AsPutFile (
    336     char                    *Pathname,
    337     char                    *FileBuffer,
    338     UINT32                  SystemFlags);
    339 
    340 void
    341 AsReplaceHeader (
    342     char                    *Buffer,
    343     char                    *NewHeader);
    344 
    345 void
    346 AsConvertFile (
    347     ACPI_CONVERSION_TABLE   *ConversionTable,
    348     char                    *FileBuffer,
    349     char                    *Filename,
    350     ACPI_NATIVE_INT         FileType);
    351 
    352 ACPI_NATIVE_INT
    353 AsProcessOneFile (
    354     ACPI_CONVERSION_TABLE   *ConversionTable,
    355     char                    *SourcePath,
    356     char                    *TargetPath,
    357     int                     MaxPathLength,
    358     char                    *Filename,
    359     ACPI_NATIVE_INT         FileType);
    360 
    361 ACPI_NATIVE_INT
    362 AsCheckForDirectory (
    363     char                    *SourceDirPath,
    364     char                    *TargetDirPath,
    365     char                    *Filename,
    366     char                    **SourcePath,
    367     char                    **TargetPath);
    368 
    369 BOOLEAN
    370 AsMatchExactWord (
    371     char                    *Word,
    372     UINT32                  WordLength);
    373 
    374 void
    375 AsPrint (
    376     char                    *Message,
    377     UINT32                  Count,
    378     char                    *Filename);
    379 
    380 void
    381 AsInsertPrefix (
    382     char                    *Buffer,
    383     char                    *Keyword,
    384     UINT8                   Type);
    385 
    386 char *
    387 AsInsertData (
    388     char                    *Buffer,
    389     char                    *BufferToAdd,
    390     UINT32                  LengthToAdd);
    391 
    392 char *
    393 AsRemoveData (
    394     char                    *StartPointer,
    395     char                    *EndPointer);
    396 
    397 void
    398 AsInsertCarriageReturns (
    399     char                    *Buffer);
    400 
    401 void
    402 AsConvertToLineFeeds (
    403     char                    *Buffer);
    404 
    405 
    406