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