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