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