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)
75char * 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
114extern UINT32                   Gbl_Files;
115extern UINT32                   Gbl_MissingBraces;
116extern UINT32                   Gbl_Tabs;
117extern UINT32                   Gbl_NonAnsiComments;
118extern UINT32                   Gbl_SourceLines;
119extern UINT32                   Gbl_WhiteLines;
120extern UINT32                   Gbl_CommentLines;
121extern UINT32                   Gbl_LongLines;
122extern UINT32                   Gbl_TotalLines;
123extern UINT32                   Gbl_HeaderSize;
124extern UINT32                   Gbl_HeaderLines;
125extern struct stat              Gbl_StatBuf;
126extern char                     *Gbl_FileBuffer;
127extern UINT32                   Gbl_TotalSize;
128extern UINT32                   Gbl_FileSize;
129extern UINT32                   Gbl_FileType;
130extern BOOLEAN                  Gbl_VerboseMode;
131extern BOOLEAN                  Gbl_QuietMode;
132extern BOOLEAN                  Gbl_BatchMode;
133extern BOOLEAN                  Gbl_MadeChanges;
134extern BOOLEAN                  Gbl_Overwrite;
135extern BOOLEAN                  Gbl_WidenDeclarations;
136extern BOOLEAN                  Gbl_IgnoreLoneLineFeeds;
137extern BOOLEAN                  Gbl_HasLoneLineFeeds;
138extern 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
153typedef struct acpi_string_table
154{
155    char                        *Target;
156    char                        *Replacement;
157    UINT8                       Type;
158
159} ACPI_STRING_TABLE;
160
161
162typedef 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
174typedef struct acpi_identifier_table
175{
176    char                        *Identifier;
177
178} ACPI_IDENTIFIER_TABLE;
179
180typedef 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
206extern ACPI_CONVERSION_TABLE       LinuxConversionTable;
207extern ACPI_CONVERSION_TABLE       CleanupConversionTable;
208extern ACPI_CONVERSION_TABLE       StatsConversionTable;
209extern ACPI_CONVERSION_TABLE       CustomConversionTable;
210extern ACPI_CONVERSION_TABLE       LicenseConversionTable;
211
212
213/* Prototypes */
214
215char *
216AsSkipUntilChar (
217    char                    *Buffer,
218    char                    Target);
219
220char *
221AsSkipPastChar (
222    char                    *Buffer,
223    char                    Target);
224
225char *
226AsReplaceData (
227    char                    *Buffer,
228    UINT32                  LengthToRemove,
229    char                    *BufferToAdd,
230    UINT32                  LengthToAdd);
231
232int
233AsReplaceString (
234    char                    *Target,
235    char                    *Replacement,
236    UINT8                   Type,
237    char                    *Buffer);
238
239int
240AsLowerCaseString (
241    char                    *Target,
242    char                    *Buffer);
243
244void
245AsRemoveLine (
246    char                    *Buffer,
247    char                    *Keyword);
248
249void
250AsRemoveMacro (
251    char                    *Buffer,
252    char                    *Keyword);
253
254void
255AsCheckForBraces (
256    char                    *Buffer,
257    char                    *Filename);
258
259void
260AsTrimLines (
261    char                    *Buffer,
262    char                    *Filename);
263
264void
265AsMixedCaseToUnderscores (
266    char                    *Buffer);
267
268void
269AsCountTabs (
270    char                    *Buffer,
271    char                    *Filename);
272
273void
274AsBracesOnSameLine (
275    char                    *Buffer);
276
277void
278AsLowerCaseIdentifiers (
279    char                    *Buffer);
280
281void
282AsReduceTypedefs (
283    char                    *Buffer,
284    char                    *Keyword);
285
286void
287AsRemoveDebugMacros (
288    char                    *Buffer);
289
290void
291AsRemoveEmptyBlocks (
292    char                    *Buffer,
293    char                    *Filename);
294
295void
296AsCountSourceLines (
297    char                    *Buffer,
298    char                    *Filename);
299
300void
301AsCountNonAnsiComments (
302    char                    *Buffer,
303    char                    *Filename);
304
305void
306AsTrimWhitespace (
307    char                    *Buffer);
308
309void
310AsTabify4 (
311    char                    *Buffer);
312
313void
314AsTabify8 (
315    char                    *Buffer);
316
317void
318AsRemoveConditionalCompile (
319    char                    *Buffer,
320    char                    *Keyword);
321
322ACPI_NATIVE_INT
323AsProcessTree (
324    ACPI_CONVERSION_TABLE   *ConversionTable,
325    char                    *SourcePath,
326    char                    *TargetPath);
327
328int
329AsGetFile (
330    char                    *FileName,
331    char                    **FileBuffer,
332    UINT32                  *FileSize);
333
334int
335AsPutFile (
336    char                    *Pathname,
337    char                    *FileBuffer,
338    UINT32                  SystemFlags);
339
340void
341AsReplaceHeader (
342    char                    *Buffer,
343    char                    *NewHeader);
344
345void
346AsConvertFile (
347    ACPI_CONVERSION_TABLE   *ConversionTable,
348    char                    *FileBuffer,
349    char                    *Filename,
350    ACPI_NATIVE_INT         FileType);
351
352ACPI_NATIVE_INT
353AsProcessOneFile (
354    ACPI_CONVERSION_TABLE   *ConversionTable,
355    char                    *SourcePath,
356    char                    *TargetPath,
357    int                     MaxPathLength,
358    char                    *Filename,
359    ACPI_NATIVE_INT         FileType);
360
361ACPI_NATIVE_INT
362AsCheckForDirectory (
363    char                    *SourceDirPath,
364    char                    *TargetDirPath,
365    char                    *Filename,
366    char                    **SourcePath,
367    char                    **TargetPath);
368
369BOOLEAN
370AsMatchExactWord (
371    char                    *Word,
372    UINT32                  WordLength);
373
374void
375AsPrint (
376    char                    *Message,
377    UINT32                  Count,
378    char                    *Filename);
379
380void
381AsInsertPrefix (
382    char                    *Buffer,
383    char                    *Keyword,
384    UINT8                   Type);
385
386char *
387AsInsertData (
388    char                    *Buffer,
389    char                    *BufferToAdd,
390    UINT32                  LengthToAdd);
391
392char *
393AsRemoveData (
394    char                    *StartPointer,
395    char                    *EndPointer);
396
397void
398AsInsertCarriageReturns (
399    char                    *Buffer);
400
401void
402AsConvertToLineFeeds (
403    char                    *Buffer);
404
405
406