acpisrc.h revision 1.1.1.2 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 /* Fixups for non-Win32 compilation */
68 #ifndef WIN32
69 #ifndef O_BINARY
70 #define O_BINARY 0x0
71 #endif
72
73 #define mkdir(x) mkdir(x, 0770)
74 char * strlwr(char* str);
75 #endif
76
77
78 /* Constants */
79
80 #define ASRC_MAX_FILE_SIZE (1024 * 100)
81
82 #define FILE_TYPE_SOURCE 1
83 #define FILE_TYPE_HEADER 2
84 #define FILE_TYPE_DIRECTORY 3
85
86 #define CVT_COUNT_TABS 0x00000001
87 #define CVT_COUNT_NON_ANSI_COMMENTS 0x00000002
88 #define CVT_TRIM_LINES 0x00000004
89 #define CVT_CHECK_BRACES 0x00000008
90 #define CVT_COUNT_LINES 0x00000010
91 #define CVT_BRACES_ON_SAME_LINE 0x00000020
92 #define CVT_MIXED_CASE_TO_UNDERSCORES 0x00000040
93 #define CVT_LOWER_CASE_IDENTIFIERS 0x00000080
94 #define CVT_REMOVE_DEBUG_MACROS 0x00000100
95 #define CVT_TRIM_WHITESPACE 0x00000200 /* Should be after all line removal */
96 #define CVT_REMOVE_EMPTY_BLOCKS 0x00000400 /* Should be after trimming lines */
97 #define CVT_REDUCE_TYPEDEFS 0x00000800
98 #define CVT_COUNT_SHORTMULTILINE_COMMENTS 0x00001000
99 #define CVT_SPACES_TO_TABS4 0x40000000 /* Tab conversion should be last */
100 #define CVT_SPACES_TO_TABS8 0x80000000 /* Tab conversion should be last */
101
102 #define FLG_DEFAULT_FLAGS 0x00000000
103 #define FLG_NO_CARRIAGE_RETURNS 0x00000001
104 #define FLG_NO_FILE_OUTPUT 0x00000002
105 #define FLG_LOWERCASE_DIRNAMES 0x00000004
106
107 #define AS_START_IGNORE "/*!"
108 #define AS_STOP_IGNORE "!*/"
109
110
111 /* Globals */
112
113 extern UINT32 Gbl_Files;
114 extern UINT32 Gbl_MissingBraces;
115 extern UINT32 Gbl_Tabs;
116 extern UINT32 Gbl_NonAnsiComments;
117 extern UINT32 Gbl_SourceLines;
118 extern UINT32 Gbl_WhiteLines;
119 extern UINT32 Gbl_CommentLines;
120 extern UINT32 Gbl_LongLines;
121 extern UINT32 Gbl_TotalLines;
122 extern UINT32 Gbl_HeaderSize;
123 extern UINT32 Gbl_HeaderLines;
124 extern struct stat Gbl_StatBuf;
125 extern char *Gbl_FileBuffer;
126 extern UINT32 Gbl_TotalSize;
127 extern UINT32 Gbl_FileSize;
128 extern UINT32 Gbl_FileType;
129 extern BOOLEAN Gbl_VerboseMode;
130 extern BOOLEAN Gbl_QuietMode;
131 extern BOOLEAN Gbl_BatchMode;
132 extern BOOLEAN Gbl_MadeChanges;
133 extern BOOLEAN Gbl_Overwrite;
134 extern BOOLEAN Gbl_WidenDeclarations;
135 extern BOOLEAN Gbl_IgnoreLoneLineFeeds;
136 extern BOOLEAN Gbl_HasLoneLineFeeds;
137 extern void *Gbl_StructDefs;
138
139 #define PARAM_LIST(pl) pl
140 #define TERSE_PRINT(a) if (!Gbl_VerboseMode) printf PARAM_LIST(a)
141 #define VERBOSE_PRINT(a) if (Gbl_VerboseMode) printf PARAM_LIST(a)
142
143 #define REPLACE_WHOLE_WORD 0x00
144 #define REPLACE_SUBSTRINGS 0x01
145 #define REPLACE_MASK 0x01
146
147 #define EXTRA_INDENT_C 0x02
148
149
150 /* Conversion table structs */
151
152 typedef struct acpi_string_table
153 {
154 char *Target;
155 char *Replacement;
156 UINT8 Type;
157
158 } ACPI_STRING_TABLE;
159
160
161 typedef struct acpi_typed_identifier_table
162 {
163 char *Identifier;
164 UINT8 Type;
165
166 } ACPI_TYPED_IDENTIFIER_TABLE;
167
168 #define SRC_TYPE_SIMPLE 0
169 #define SRC_TYPE_STRUCT 1
170 #define SRC_TYPE_UNION 2
171
172
173 typedef struct acpi_identifier_table
174 {
175 char *Identifier;
176
177 } ACPI_IDENTIFIER_TABLE;
178
179 typedef struct acpi_conversion_table
180 {
181 char *NewHeader;
182 UINT32 Flags;
183
184 ACPI_TYPED_IDENTIFIER_TABLE *LowerCaseTable;
185
186 ACPI_STRING_TABLE *SourceStringTable;
187 ACPI_IDENTIFIER_TABLE *SourceLineTable;
188 ACPI_IDENTIFIER_TABLE *SourceConditionalTable;
189 ACPI_IDENTIFIER_TABLE *SourceMacroTable;
190 ACPI_TYPED_IDENTIFIER_TABLE *SourceStructTable;
191 UINT32 SourceFunctions;
192
193 ACPI_STRING_TABLE *HeaderStringTable;
194 ACPI_IDENTIFIER_TABLE *HeaderLineTable;
195 ACPI_IDENTIFIER_TABLE *HeaderConditionalTable;
196 ACPI_IDENTIFIER_TABLE *HeaderMacroTable;
197 ACPI_TYPED_IDENTIFIER_TABLE *HeaderStructTable;
198 UINT32 HeaderFunctions;
199
200 } ACPI_CONVERSION_TABLE;
201
202
203 /* Conversion tables */
204
205 extern ACPI_CONVERSION_TABLE LinuxConversionTable;
206 extern ACPI_CONVERSION_TABLE CleanupConversionTable;
207 extern ACPI_CONVERSION_TABLE StatsConversionTable;
208 extern ACPI_CONVERSION_TABLE CustomConversionTable;
209 extern ACPI_CONVERSION_TABLE LicenseConversionTable;
210
211
212 /* Prototypes */
213
214 char *
215 AsSkipUntilChar (
216 char *Buffer,
217 char Target);
218
219 char *
220 AsSkipPastChar (
221 char *Buffer,
222 char Target);
223
224 char *
225 AsReplaceData (
226 char *Buffer,
227 UINT32 LengthToRemove,
228 char *BufferToAdd,
229 UINT32 LengthToAdd);
230
231 int
232 AsReplaceString (
233 char *Target,
234 char *Replacement,
235 UINT8 Type,
236 char *Buffer);
237
238 int
239 AsLowerCaseString (
240 char *Target,
241 char *Buffer);
242
243 void
244 AsRemoveLine (
245 char *Buffer,
246 char *Keyword);
247
248 void
249 AsRemoveMacro (
250 char *Buffer,
251 char *Keyword);
252
253 void
254 AsCheckForBraces (
255 char *Buffer,
256 char *Filename);
257
258 void
259 AsTrimLines (
260 char *Buffer,
261 char *Filename);
262
263 void
264 AsMixedCaseToUnderscores (
265 char *Buffer);
266
267 void
268 AsCountTabs (
269 char *Buffer,
270 char *Filename);
271
272 void
273 AsBracesOnSameLine (
274 char *Buffer);
275
276 void
277 AsLowerCaseIdentifiers (
278 char *Buffer);
279
280 void
281 AsReduceTypedefs (
282 char *Buffer,
283 char *Keyword);
284
285 void
286 AsRemoveDebugMacros (
287 char *Buffer);
288
289 void
290 AsRemoveEmptyBlocks (
291 char *Buffer,
292 char *Filename);
293
294 void
295 AsCountSourceLines (
296 char *Buffer,
297 char *Filename);
298
299 void
300 AsCountNonAnsiComments (
301 char *Buffer,
302 char *Filename);
303
304 void
305 AsTrimWhitespace (
306 char *Buffer);
307
308 void
309 AsTabify4 (
310 char *Buffer);
311
312 void
313 AsTabify8 (
314 char *Buffer);
315
316 void
317 AsRemoveConditionalCompile (
318 char *Buffer,
319 char *Keyword);
320
321 ACPI_NATIVE_INT
322 AsProcessTree (
323 ACPI_CONVERSION_TABLE *ConversionTable,
324 char *SourcePath,
325 char *TargetPath);
326
327 int
328 AsGetFile (
329 char *FileName,
330 char **FileBuffer,
331 UINT32 *FileSize);
332
333 int
334 AsPutFile (
335 char *Pathname,
336 char *FileBuffer,
337 UINT32 SystemFlags);
338
339 void
340 AsReplaceHeader (
341 char *Buffer,
342 char *NewHeader);
343
344 void
345 AsConvertFile (
346 ACPI_CONVERSION_TABLE *ConversionTable,
347 char *FileBuffer,
348 char *Filename,
349 ACPI_NATIVE_INT FileType);
350
351 ACPI_NATIVE_INT
352 AsProcessOneFile (
353 ACPI_CONVERSION_TABLE *ConversionTable,
354 char *SourcePath,
355 char *TargetPath,
356 int MaxPathLength,
357 char *Filename,
358 ACPI_NATIVE_INT FileType);
359
360 ACPI_NATIVE_INT
361 AsCheckForDirectory (
362 char *SourceDirPath,
363 char *TargetDirPath,
364 char *Filename,
365 char **SourcePath,
366 char **TargetPath);
367
368 BOOLEAN
369 AsMatchExactWord (
370 char *Word,
371 UINT32 WordLength);
372
373 void
374 AsPrint (
375 char *Message,
376 UINT32 Count,
377 char *Filename);
378
379 void
380 AsInsertPrefix (
381 char *Buffer,
382 char *Keyword,
383 UINT8 Type);
384
385 char *
386 AsInsertData (
387 char *Buffer,
388 char *BufferToAdd,
389 UINT32 LengthToAdd);
390
391 char *
392 AsRemoveData (
393 char *StartPointer,
394 char *EndPointer);
395
396 void
397 AsInsertCarriageReturns (
398 char *Buffer);
399
400 void
401 AsConvertToLineFeeds (
402 char *Buffer);
403
404
405