Update ACPI build wrappers to use new ACPICA(20050309) code.
[dragonfly.git] / sys / contrib / dev / acpica-unix-20050211 / tools / acpisrc / asmain.c
1
2 /******************************************************************************
3  *
4  * Module Name: asmain - Main module for the acpi source processor utility
5  *              $Revision: 74 $
6  *
7  *****************************************************************************/
8
9 /******************************************************************************
10  *
11  * 1. Copyright Notice
12  *
13  * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
14  * All rights reserved.
15  *
16  * 2. License
17  *
18  * 2.1. This is your license from Intel Corp. under its intellectual property
19  * rights.  You may have additional license terms from the party that provided
20  * you this software, covering your right to use that party's intellectual
21  * property rights.
22  *
23  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24  * copy of the source code appearing in this file ("Covered Code") an
25  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26  * base code distributed originally by Intel ("Original Intel Code") to copy,
27  * make derivatives, distribute, use and display any portion of the Covered
28  * Code in any form, with the right to sublicense such rights; and
29  *
30  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31  * license (with the right to sublicense), under only those claims of Intel
32  * patents that are infringed by the Original Intel Code, to make, use, sell,
33  * offer to sell, and import the Covered Code and derivative works thereof
34  * solely to the minimum extent necessary to exercise the above copyright
35  * license, and in no event shall the patent license extend to any additions
36  * to or modifications of the Original Intel Code.  No other license or right
37  * is granted directly or by implication, estoppel or otherwise;
38  *
39  * The above copyright and patent license is granted only if the following
40  * conditions are met:
41  *
42  * 3. Conditions
43  *
44  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45  * Redistribution of source code of any substantial portion of the Covered
46  * Code or modification with rights to further distribute source must include
47  * the above Copyright Notice, the above License, this list of Conditions,
48  * and the following Disclaimer and Export Compliance provision.  In addition,
49  * Licensee must cause all Covered Code to which Licensee contributes to
50  * contain a file documenting the changes Licensee made to create that Covered
51  * Code and the date of any change.  Licensee must include in that file the
52  * documentation of any changes made by any predecessor Licensee.  Licensee
53  * must include a prominent statement that the modification is derived,
54  * directly or indirectly, from Original Intel Code.
55  *
56  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57  * Redistribution of source code of any substantial portion of the Covered
58  * Code or modification without rights to further distribute source must
59  * include the following Disclaimer and Export Compliance provision in the
60  * documentation and/or other materials provided with distribution.  In
61  * addition, Licensee may not authorize further sublicense of source of any
62  * portion of the Covered Code, and must include terms to the effect that the
63  * license from Licensee to its licensee is limited to the intellectual
64  * property embodied in the software Licensee provides to its licensee, and
65  * not to intellectual property embodied in modifications its licensee may
66  * make.
67  *
68  * 3.3. Redistribution of Executable. Redistribution in executable form of any
69  * substantial portion of the Covered Code or modification must reproduce the
70  * above Copyright Notice, and the following Disclaimer and Export Compliance
71  * provision in the documentation and/or other materials provided with the
72  * distribution.
73  *
74  * 3.4. Intel retains all right, title, and interest in and to the Original
75  * Intel Code.
76  *
77  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78  * Intel shall be used in advertising or otherwise to promote the sale, use or
79  * other dealings in products derived from or relating to the Covered Code
80  * without prior written authorization from Intel.
81  *
82  * 4. Disclaimer and Export Compliance
83  *
84  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
87  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
88  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
89  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90  * PARTICULAR PURPOSE.
91  *
92  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
98  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99  * LIMITED REMEDY.
100  *
101  * 4.3. Licensee shall not export, either directly or indirectly, any of this
102  * software or system incorporating such software without first obtaining any
103  * required license or other approval from the U. S. Department of Commerce or
104  * any other agency or department of the United States Government.  In the
105  * event Licensee exports any such software from the United States or
106  * re-exports any such software from a foreign destination, Licensee shall
107  * ensure that the distribution and export/re-export of the software is in
108  * compliance with all laws, regulations, orders, or other restrictions of the
109  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110  * any of its subsidiaries will export/re-export any technical data, process,
111  * software, or service, directly or indirectly, to any country for which the
112  * United States government or any agency thereof requires an export license,
113  * other governmental approval, or letter of assurance, without first obtaining
114  * such license, approval or letter.
115  *
116  *****************************************************************************/
117
118
119 #include "acpisrc.h"
120 #include "acapps.h"
121
122
123 /* Globals */
124
125 UINT32                  Gbl_Tabs = 0;
126 UINT32                  Gbl_MissingBraces = 0;
127 UINT32                  Gbl_NonAnsiComments = 0;
128 UINT32                  Gbl_Files = 0;
129 UINT32                  Gbl_WhiteLines = 0;
130 UINT32                  Gbl_CommentLines = 0;
131 UINT32                  Gbl_SourceLines = 0;
132 UINT32                  Gbl_LongLines = 0;
133 UINT32                  Gbl_TotalLines = 0;
134
135 struct stat             Gbl_StatBuf;
136 char                    *Gbl_FileBuffer;
137 UINT32                  Gbl_FileSize;
138 UINT32                  Gbl_FileType;
139 BOOLEAN                 Gbl_VerboseMode = FALSE;
140 BOOLEAN                 Gbl_BatchMode = FALSE;
141 BOOLEAN                 Gbl_DebugStatementsMode = FALSE;
142 BOOLEAN                 Gbl_MadeChanges = FALSE;
143 BOOLEAN                 Gbl_Overwrite = FALSE;
144 BOOLEAN                 Gbl_WidenDeclarations = FALSE;
145 BOOLEAN                 Gbl_IgnoreLoneLineFeeds = FALSE;
146
147
148 /******************************************************************************
149  *
150  * Standard/Common translation tables
151  *
152  ******************************************************************************/
153
154
155 ACPI_STRING_TABLE           StandardDataTypes[] = {
156
157     /* Declarations first */
158
159     {"UINT32_BIT  ",     "unsigned int",     REPLACE_SUBSTRINGS},
160
161     {"UINT32      ",     "unsigned int",     REPLACE_SUBSTRINGS},
162     {"UINT16        ",   "unsigned short",   REPLACE_SUBSTRINGS},
163     {"UINT8        ",    "unsigned char",    REPLACE_SUBSTRINGS},
164     {"BOOLEAN      ",    "unsigned char",    REPLACE_SUBSTRINGS},
165
166     /* Now do embedded typecasts */
167
168     {"UINT32",           "unsigned int",     REPLACE_SUBSTRINGS},
169     {"UINT16",           "unsigned short",   REPLACE_SUBSTRINGS},
170     {"UINT8",            "unsigned char",    REPLACE_SUBSTRINGS},
171     {"BOOLEAN",          "unsigned char",    REPLACE_SUBSTRINGS},
172
173     {"INT32  ",          "int    ",          REPLACE_SUBSTRINGS},
174     {"INT32",            "int",              REPLACE_SUBSTRINGS},
175     {"INT16",            "short",            REPLACE_SUBSTRINGS},
176     {"INT8",             "char",             REPLACE_SUBSTRINGS},
177
178     /* Put back anything we broke (such as anything with _INT32_ in it) */
179
180     {"_int_",            "_INT32_",          REPLACE_SUBSTRINGS},
181     {"_unsigned int_",   "_UINT32_",         REPLACE_SUBSTRINGS},
182     {NULL,               NULL,               0}
183 };
184
185
186 /******************************************************************************
187  *
188  * Linux-specific translation tables
189  *
190  ******************************************************************************/
191
192 char                        LinuxHeader[] =
193 "/*\n"
194 " * Copyright (C) 2000 - 2005, R. Byron Moore\n"
195 " * All rights reserved.\n"
196 " *\n"
197 " * Redistribution and use in source and binary forms, with or without\n"
198 " * modification, are permitted provided that the following conditions\n"
199 " * are met:\n"
200 " * 1. Redistributions of source code must retain the above copyright\n"
201 " *    notice, this list of conditions, and the following disclaimer,\n"
202 " *    without modification.\n"
203 " * 2. Redistributions in binary form must reproduce at minimum a disclaimer\n"
204 " *    substantially similar to the \"NO WARRANTY\" disclaimer below\n"
205 " *    (\"Disclaimer\") and any redistribution must be conditioned upon\n"
206 " *    including a substantially similar Disclaimer requirement for further\n"
207 " *    binary redistribution.\n"
208 " * 3. Neither the names of the above-listed copyright holders nor the names\n"
209 " *    of any contributors may be used to endorse or promote products derived\n"
210 " *    from this software without specific prior written permission.\n"
211 " *\n"
212 " * Alternatively, this software may be distributed under the terms of the\n"
213 " * GNU General Public License (\"GPL\") version 2 as published by the Free\n"
214 " * Software Foundation.\n"
215 " *\n"
216 " * NO WARRANTY\n"
217 " * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n"
218 " * \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n"
219 " * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR\n"
220 " * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n"
221 " * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n"
222 " * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n"
223 " * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n"
224 " * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n"
225 " * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING\n"
226 " * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n"
227 " * POSSIBILITY OF SUCH DAMAGES.\n"
228 " */\n";
229
230 ACPI_STRING_TABLE           LinuxDataTypes[] = {
231
232     /* Declarations first */
233
234     {"UINT16_BIT  ",             "u16                 ",     REPLACE_WHOLE_WORD | EXTRA_INDENT_C},
235     {"UINT32_BIT  ",             "u32                 ",     REPLACE_WHOLE_WORD | EXTRA_INDENT_C},
236     {"INT64       ",             "s64                 ",     REPLACE_WHOLE_WORD | EXTRA_INDENT_C},
237     {"UINT64      ",             "u64                 ",     REPLACE_WHOLE_WORD | EXTRA_INDENT_C},
238     {"UINT32      ",             "u32                 ",     REPLACE_WHOLE_WORD | EXTRA_INDENT_C},
239     {"INT32       ",             "s32                 ",     REPLACE_WHOLE_WORD | EXTRA_INDENT_C},
240     {"UINT16      ",             "u16                 ",     REPLACE_WHOLE_WORD | EXTRA_INDENT_C},
241     {"INT16       ",             "s16                 ",     REPLACE_WHOLE_WORD | EXTRA_INDENT_C},
242     {"UINT8       ",             "u8                  ",     REPLACE_WHOLE_WORD | EXTRA_INDENT_C},
243     {"BOOLEAN     ",             "u8                  ",     REPLACE_WHOLE_WORD | EXTRA_INDENT_C},
244     {"char        ",             "char                ",     REPLACE_WHOLE_WORD | EXTRA_INDENT_C},
245     {"void        ",             "void                ",     REPLACE_WHOLE_WORD | EXTRA_INDENT_C},
246     {"char *      ",             "char *              ",     REPLACE_WHOLE_WORD | EXTRA_INDENT_C},
247     {"void *      ",             "void *              ",     REPLACE_WHOLE_WORD | EXTRA_INDENT_C},
248     {"int         ",             "int                 ",     REPLACE_WHOLE_WORD | EXTRA_INDENT_C},
249
250     /* Now do embedded typecasts */
251
252     {"UINT64",                   "u64",                      REPLACE_WHOLE_WORD},
253     {"UINT32",                   "u32",                      REPLACE_WHOLE_WORD},
254     {"UINT16",                   "u16",                      REPLACE_WHOLE_WORD},
255     {"UINT8",                    "u8",                       REPLACE_WHOLE_WORD},
256     {"BOOLEAN",                  "u8",                       REPLACE_WHOLE_WORD},
257
258     {"INT64  ",                  "s64    ",                  REPLACE_WHOLE_WORD},
259     {"INT64",                    "s64",                      REPLACE_WHOLE_WORD},
260     {"INT32  ",                  "s32    ",                  REPLACE_WHOLE_WORD},
261     {"INT32",                    "s32",                      REPLACE_WHOLE_WORD},
262     {"INT16  ",                  "s16    ",                  REPLACE_WHOLE_WORD},
263     {"INT8   ",                  "s8     ",                  REPLACE_WHOLE_WORD},
264     {"INT16",                    "s16",                      REPLACE_WHOLE_WORD},
265     {"INT8",                     "s8",                       REPLACE_WHOLE_WORD},
266
267     {NULL,                       NULL,                       0},
268 };
269
270
271 ACPI_TYPED_IDENTIFIER_TABLE           AcpiIdentifiers[] = {
272
273     {"ACPI_ADR_SPACE_HANDLER",           SRC_TYPE_SIMPLE},
274     {"ACPI_ADR_SPACE_SETUP",             SRC_TYPE_SIMPLE},
275     {"ACPI_ADR_SPACE_TYPE",              SRC_TYPE_SIMPLE},
276     {"ACPI_AML_OPERANDS",                SRC_TYPE_UNION},
277     {"ACPI_BIT_REGISTER_INFO",           SRC_TYPE_STRUCT},
278     {"ACPI_BUFFER",                      SRC_TYPE_STRUCT},
279     {"ACPI_BUS_ATTRIBUTE",               SRC_TYPE_STRUCT},
280     {"ACPI_COMMON_FACS",                 SRC_TYPE_STRUCT},
281     {"ACPI_COMMON_STATE",                SRC_TYPE_STRUCT},
282     {"ACPI_COMPATIBLE_ID",               SRC_TYPE_STRUCT},
283     {"ACPI_COMPATIBLE_ID_LIST",          SRC_TYPE_STRUCT},
284     {"ACPI_CONTROL_STATE",               SRC_TYPE_STRUCT},
285     {"ACPI_CONVERSION_TABLE",            SRC_TYPE_STRUCT},
286     {"ACPI_CREATE_FIELD_INFO",           SRC_TYPE_STRUCT},
287     {"ACPI_DB_METHOD_INFO",              SRC_TYPE_STRUCT},
288     {"ACPI_DEBUG_MEM_BLOCK",             SRC_TYPE_STRUCT},
289     {"ACPI_DEBUG_MEM_HEADER",            SRC_TYPE_STRUCT},
290     {"ACPI_DEBUG_PRINT_INFO",            SRC_TYPE_STRUCT},
291     {"ACPI_DESCRIPTOR",                  SRC_TYPE_UNION},
292     {"ACPI_DEVICE_ID",                   SRC_TYPE_STRUCT},
293     {"ACPI_DEVICE_INFO",                 SRC_TYPE_STRUCT},
294     {"ACPI_DEVICE_WALK_INFO",            SRC_TYPE_STRUCT},
295     {"ACPI_EVENT_HANDLER",               SRC_TYPE_SIMPLE},
296     {"ACPI_EVENT_STATUS",                SRC_TYPE_SIMPLE},
297     {"ACPI_EVENT_TYPE",                  SRC_TYPE_SIMPLE},
298     {"ACPI_EXCEPTION_HANDLER",           SRC_TYPE_SIMPLE},
299     {"ACPI_EXTERNAL_LIST",               SRC_TYPE_STRUCT},
300     {"ACPI_FIELD_INFO",                  SRC_TYPE_STRUCT},
301     {"ACPI_FIND_CONTEXT",                SRC_TYPE_STRUCT},
302     {"ACPI_FIXED_EVENT_HANDLER",         SRC_TYPE_STRUCT},
303     {"ACPI_FIXED_EVENT_INFO",            SRC_TYPE_STRUCT},
304     {"ACPI_GENERIC_ADDRESS",             SRC_TYPE_STRUCT},
305     {"ACPI_GENERIC_STATE",               SRC_TYPE_UNION},
306     {"ACPI_GET_DEVICES_INFO",            SRC_TYPE_STRUCT},
307     {"ACPI_GPE_BLOCK_INFO",              SRC_TYPE_STRUCT},
308     {"ACPI_GPE_XRUPT_INFO",              SRC_TYPE_STRUCT},
309     {"ACPI_GPE_EVENT_INFO",              SRC_TYPE_STRUCT},
310     {"ACPI_GPE_HANDLER",                 SRC_TYPE_SIMPLE},
311     {"ACPI_GPE_INDEX_INFO",              SRC_TYPE_STRUCT},
312     {"ACPI_GPE_REGISTER_INFO",           SRC_TYPE_STRUCT},
313     {"ACPI_GPE_WALK_INFO",               SRC_TYPE_STRUCT},
314     {"ACPI_HANDLE",                      SRC_TYPE_SIMPLE},
315     {"ACPI_HANDLER_INFO",                SRC_TYPE_STRUCT},
316     {"ACPI_INIT_HANDLER",                SRC_TYPE_SIMPLE},
317     {"ACPI_IDENTIFIER_TABLE",            SRC_TYPE_STRUCT},
318     {"ACPI_INIT_WALK_INFO",              SRC_TYPE_STRUCT},
319     {"ACPI_INTEGER",                     SRC_TYPE_SIMPLE},
320     {"ACPI_INTEGRITY_INFO",              SRC_TYPE_STRUCT},
321     {"ACPI_INTERPRETER_MODE",            SRC_TYPE_SIMPLE},
322     {"ACPI_IO_ADDRESS",                  SRC_TYPE_SIMPLE},
323     {"ACPI_IO_ATTRIBUTE",                SRC_TYPE_STRUCT},
324     {"ACPI_MEM_SPACE_CONTEXT",           SRC_TYPE_STRUCT},
325     {"ACPI_MEMORY_ATTRIBUTE",            SRC_TYPE_STRUCT},
326     {"ACPI_MEMORY_LIST",                 SRC_TYPE_STRUCT},
327     {"ACPI_MUTEX",                       SRC_TYPE_SIMPLE},
328     {"ACPI_MUTEX_HANDLE",                SRC_TYPE_SIMPLE},
329     {"ACPI_MUTEX_INFO",                  SRC_TYPE_STRUCT},
330     {"ACPI_NAME",                        SRC_TYPE_SIMPLE},
331     {"ACPI_NAME_UNION",                  SRC_TYPE_UNION},
332     {"ACPI_NAMESPACE_NODE",              SRC_TYPE_STRUCT},
333     {"ACPI_NAMESTRING_INFO",             SRC_TYPE_STRUCT},
334     {"ACPI_NATIVE_INT",                  SRC_TYPE_SIMPLE},
335     {"ACPI_NATIVE_UINT",                 SRC_TYPE_SIMPLE},
336     {"ACPI_NOTIFY_HANDLER",              SRC_TYPE_SIMPLE},
337     {"ACPI_NOTIFY_INFO",                 SRC_TYPE_STRUCT},
338     {"ACPI_NS_SEARCH_DATA",              SRC_TYPE_STRUCT},
339     {"ACPI_OBJ_INFO_HEADER",             SRC_TYPE_STRUCT},
340     {"ACPI_OBJECT",                      SRC_TYPE_UNION},
341     {"ACPI_OBJECT_ADDR_HANDLER",         SRC_TYPE_STRUCT},
342     {"ACPI_OBJECT_BANK_FIELD",           SRC_TYPE_STRUCT},
343     {"ACPI_OBJECT_BUFFER",               SRC_TYPE_STRUCT},
344     {"ACPI_OBJECT_BUFFER_FIELD",         SRC_TYPE_STRUCT},
345     {"ACPI_OBJECT_CACHE_LIST",           SRC_TYPE_STRUCT},
346     {"ACPI_OBJECT_COMMON",               SRC_TYPE_STRUCT},
347     {"ACPI_OBJECT_DATA",                 SRC_TYPE_STRUCT},
348     {"ACPI_OBJECT_DEVICE",               SRC_TYPE_STRUCT},
349     {"ACPI_OBJECT_EVENT",                SRC_TYPE_STRUCT},
350     {"ACPI_OBJECT_EXTRA",                SRC_TYPE_STRUCT},
351     {"ACPI_OBJECT_FIELD_COMMON",         SRC_TYPE_STRUCT},
352     {"ACPI_OBJECT_HANDLER",              SRC_TYPE_SIMPLE},
353     {"ACPI_OBJECT_INDEX_FIELD",          SRC_TYPE_STRUCT},
354     {"ACPI_OBJECT_INTEGER",              SRC_TYPE_STRUCT},
355     {"ACPI_OBJECT_LIST",                 SRC_TYPE_STRUCT},
356     {"ACPI_OBJECT_METHOD",               SRC_TYPE_STRUCT},
357     {"ACPI_OBJECT_MUTEX",                SRC_TYPE_STRUCT},
358     {"ACPI_OBJECT_NOTIFY_COMMON",        SRC_TYPE_STRUCT},
359     {"ACPI_OBJECT_NOTIFY_HANDLER",       SRC_TYPE_STRUCT},
360     {"ACPI_OBJECT_PACKAGE",              SRC_TYPE_STRUCT},
361     {"ACPI_OBJECT_POWER_RESOURCE",       SRC_TYPE_STRUCT},
362     {"ACPI_OBJECT_PROCESSOR",            SRC_TYPE_STRUCT},
363     {"ACPI_OBJECT_REFERENCE",            SRC_TYPE_STRUCT},
364     {"ACPI_OBJECT_REGION",               SRC_TYPE_STRUCT},
365     {"ACPI_OBJECT_REGION_FIELD",         SRC_TYPE_STRUCT},
366     {"ACPI_OBJECT_STRING",               SRC_TYPE_STRUCT},
367     {"ACPI_OBJECT_THERMAL_ZONE",         SRC_TYPE_STRUCT},
368     {"ACPI_OBJECT_TYPE",                 SRC_TYPE_SIMPLE},
369     {"ACPI_OBJECT_TYPE8",                SRC_TYPE_SIMPLE},
370     {"ACPI_OP_WALK_INFO",                SRC_TYPE_STRUCT},
371     {"ACPI_OPCODE_INFO",                 SRC_TYPE_STRUCT},
372     {"ACPI_OPERAND_OBJECT",              SRC_TYPE_UNION},
373     {"ACPI_OSD_HANDLER",                 SRC_TYPE_SIMPLE},
374     {"ACPI_OSD_EXEC_CALLBACK",           SRC_TYPE_SIMPLE},
375     {"ACPI_OWNER_ID",                    SRC_TYPE_SIMPLE},
376     {"ACPI_PARAMETER_INFO",              SRC_TYPE_STRUCT},
377     {"ACPI_PARSE_DOWNWARDS",             SRC_TYPE_SIMPLE},
378     {"ACPI_PARSE_OBJ_ASL",               SRC_TYPE_STRUCT},
379     {"ACPI_PARSE_OBJ_COMMON",            SRC_TYPE_STRUCT},
380     {"ACPI_PARSE_OBJ_NAMED",             SRC_TYPE_STRUCT},
381     {"ACPI_PARSE_OBJECT",                SRC_TYPE_UNION},
382     {"ACPI_PARSE_STATE",                 SRC_TYPE_STRUCT},
383     {"ACPI_PARSE_UPWARDS",               SRC_TYPE_SIMPLE},
384     {"ACPI_PARSE_VALUE",                 SRC_TYPE_UNION},
385     {"ACPI_PCI_ID",                      SRC_TYPE_STRUCT},
386     {"ACPI_PCI_ROUTING_TABLE",           SRC_TYPE_STRUCT},
387     {"ACPI_PHYSICAL_ADDRESS",            SRC_TYPE_SIMPLE},
388     {"ACPI_PKG_CALLBACK",                SRC_TYPE_SIMPLE},
389     {"ACPI_PKG_INFO",                    SRC_TYPE_STRUCT},
390     {"ACPI_PKG_STATE",                   SRC_TYPE_STRUCT},
391     {"ACPI_POINTER",                     SRC_TYPE_STRUCT},
392     {"ACPI_POINTERS",                    SRC_TYPE_UNION},
393     {"ACPI_PREDEFINED_NAMES",            SRC_TYPE_STRUCT},
394     {"ACPI_PSCOPE_STATE",                SRC_TYPE_STRUCT},
395     {"ACPI_RESOURCE",                    SRC_TYPE_STRUCT},
396     {"ACPI_RESOURCE_ADDRESS16",          SRC_TYPE_STRUCT},
397     {"ACPI_RESOURCE_ADDRESS32",          SRC_TYPE_STRUCT},
398     {"ACPI_RESOURCE_ADDRESS64",          SRC_TYPE_STRUCT},
399     {"ACPI_RESOURCE_ATTRIBUTE",          SRC_TYPE_UNION},
400     {"ACPI_RESOURCE_DATA",               SRC_TYPE_UNION},
401     {"ACPI_RESOURCE_DMA",                SRC_TYPE_STRUCT},
402     {"ACPI_RESOURCE_END_TAG",            SRC_TYPE_STRUCT},
403     {"ACPI_RESOURCE_EXT_IRQ",            SRC_TYPE_STRUCT},
404     {"ACPI_RESOURCE_FIXED_IO",           SRC_TYPE_STRUCT},
405     {"ACPI_RESOURCE_FIXED_MEM32",        SRC_TYPE_STRUCT},
406     {"ACPI_RESOURCE_IO",                 SRC_TYPE_STRUCT},
407     {"ACPI_RESOURCE_IRQ",                SRC_TYPE_STRUCT},
408     {"ACPI_RESOURCE_MEM24",              SRC_TYPE_STRUCT},
409     {"ACPI_RESOURCE_MEM32",              SRC_TYPE_STRUCT},
410     {"ACPI_RESOURCE_SOURCE",             SRC_TYPE_STRUCT},
411     {"ACPI_RESOURCE_START_DPF",          SRC_TYPE_STRUCT},
412     {"ACPI_RESOURCE_TYPE",               SRC_TYPE_SIMPLE},
413     {"ACPI_RESOURCE_VENDOR",             SRC_TYPE_STRUCT},
414     {"ACPI_RESULT_VALUES",               SRC_TYPE_STRUCT},
415     {"ACPI_SCOPE_STATE",                 SRC_TYPE_STRUCT},
416     {"ACPI_SIGNAL_FATAL_INFO",           SRC_TYPE_STRUCT},
417     {"ACPI_SIZE",                        SRC_TYPE_SIMPLE},
418     {"ACPI_STATUS",                      SRC_TYPE_SIMPLE},
419     {"ACPI_STRING",                      SRC_TYPE_SIMPLE},
420     {"ACPI_STRING_TABLE",                SRC_TYPE_STRUCT},
421     {"ACPI_SYSTEM_INFO",                 SRC_TYPE_STRUCT},
422     {"ACPI_TABLE_DESC",                  SRC_TYPE_STRUCT},
423     {"ACPI_TABLE_HEADER",                SRC_TYPE_STRUCT},
424     {"ACPI_TABLE_INFO",                  SRC_TYPE_STRUCT},
425     {"ACPI_TABLE_LIST",                  SRC_TYPE_STRUCT},
426     {"ACPI_TABLE_PTR",                   SRC_TYPE_SIMPLE},
427     {"ACPI_TABLE_SUPPORT",               SRC_TYPE_STRUCT},
428     {"ACPI_TABLE_TYPE",                  SRC_TYPE_SIMPLE},
429     {"ACPI_THREAD_STATE",                SRC_TYPE_STRUCT},
430     {"ACPI_TYPED_IDENTIFIER_TABLE",      SRC_TYPE_STRUCT},
431     {"ACPI_UPDATE_STATE",                SRC_TYPE_STRUCT},
432     {"ACPI_WALK_CALLBACK",               SRC_TYPE_SIMPLE},
433     {"ACPI_WALK_INFO",                   SRC_TYPE_STRUCT},
434     {"ACPI_WALK_STATE",                  SRC_TYPE_STRUCT},
435     {"APIC_HEADER",                      SRC_TYPE_STRUCT},
436     {"ARGUMENT_INFO",                    SRC_TYPE_STRUCT},
437     {"ASL_ANALYSIS_WALK_INFO",           SRC_TYPE_STRUCT},
438     {"ASL_DMA_FORMAT_DESC",              SRC_TYPE_STRUCT},
439     {"ASL_DWORD_ADDRESS_DESC",           SRC_TYPE_STRUCT},
440     {"ASL_END_DEPENDENT_DESC",           SRC_TYPE_STRUCT},
441     {"ASL_END_TAG_DESC",                 SRC_TYPE_STRUCT},
442     {"ASL_ERROR_MSG",                    SRC_TYPE_STRUCT},
443     {"ASL_EVENT_INFO",                   SRC_TYPE_STRUCT},
444     {"ASL_EXTENDED_ADDRESS_DESC",        SRC_TYPE_STRUCT},
445     {"ASL_EXTENDED_XRUPT_DESC",          SRC_TYPE_STRUCT},
446     {"ASL_FILE_INFO",                    SRC_TYPE_STRUCT},
447     {"ASL_FIXED_IO_PORT_DESC",           SRC_TYPE_STRUCT},
448     {"ASL_FIXED_MEMORY_32_DESC",         SRC_TYPE_STRUCT},
449     {"ASL_GENERAL_REGISTER_DESC",        SRC_TYPE_STRUCT},
450     {"ASL_IO_PORT_DESC",                 SRC_TYPE_STRUCT},
451     {"ASL_IRQ_FORMAT_DESC",              SRC_TYPE_STRUCT},
452     {"ASL_IRQ_NOFLAGS_DESC",             SRC_TYPE_STRUCT},
453     {"ASL_LARGE_VENDOR_DESC",            SRC_TYPE_STRUCT},
454     {"ASL_LISTING_NODE",                 SRC_TYPE_STRUCT},
455     {"ASL_MAPPING_ENTRY",                SRC_TYPE_STRUCT},
456     {"ASL_MEMORY_24_DESC",               SRC_TYPE_STRUCT},
457     {"ASL_MEMORY_32_DESC",               SRC_TYPE_STRUCT},
458     {"ASL_METHOD_INFO",                  SRC_TYPE_STRUCT},
459     {"ASL_QWORD_ADDRESS_DESC",           SRC_TYPE_STRUCT},
460     {"ASL_RESERVED_INFO",                SRC_TYPE_STRUCT},
461     {"ASL_RESOURCE_DESC",                SRC_TYPE_UNION},
462     {"ASL_RESOURCE_NODE",                SRC_TYPE_STRUCT},
463     {"ASL_SMALL_VENDOR_DESC",            SRC_TYPE_STRUCT},
464     {"ASL_START_DEPENDENT_DESC",         SRC_TYPE_STRUCT},
465     {"ASL_START_DEPENDENT_NOPRIO_DESC",  SRC_TYPE_STRUCT},
466     {"ASL_WALK_CALLBACK",                SRC_TYPE_SIMPLE},
467     {"ASL_WORD_ADDRESS_DESC",            SRC_TYPE_STRUCT},
468     {"COMMAND_INFO",                     SRC_TYPE_STRUCT},
469 /*    {"FACS_DESCRIPTOR",                  SRC_TYPE_SIMPLE}, */
470     {"FACS_DESCRIPTOR_REV1",             SRC_TYPE_STRUCT},
471     {"FACS_DESCRIPTOR_REV2",             SRC_TYPE_STRUCT},
472 /*    {"FADT_DESCRIPTOR",                  SRC_TYPE_SIMPLE}, */
473     {"FADT_DESCRIPTOR_REV1",             SRC_TYPE_STRUCT},
474     {"FADT_DESCRIPTOR_REV2",             SRC_TYPE_STRUCT},
475     {"FADT_DESCRIPTOR_REV2_MINUS",       SRC_TYPE_STRUCT},
476     {"RSDP_DESCRIPTOR",                  SRC_TYPE_STRUCT},
477 /*    {"RSDT_DESCRIPTOR",                  SRC_TYPE_SIMPLE}, */
478     {"RSDT_DESCRIPTOR_REV1",             SRC_TYPE_STRUCT},
479     {"RSDT_DESCRIPTOR_REV2",             SRC_TYPE_STRUCT},
480     {"UINT32_STRUCT",                    SRC_TYPE_STRUCT},
481     {"UINT64_OVERLAY",                   SRC_TYPE_UNION},
482     {"UINT64_STRUCT",                    SRC_TYPE_STRUCT},
483 /*    {"XSDT_DESCRIPTOR",                  SRC_TYPE_SIMPLE}, */
484     {"XSDT_DESCRIPTOR_REV2",             SRC_TYPE_STRUCT},
485
486     {NULL}
487 };
488
489 ACPI_IDENTIFIER_TABLE       LinuxAddStruct[] = {
490     {"acpi_namespace_node"},
491     {"acpi_parse_object"},
492     {"acpi_table_desc"},
493     {"acpi_walk_state"},
494     {NULL}
495 };
496
497
498 ACPI_IDENTIFIER_TABLE       LinuxEliminateMacros[] = {
499
500     {"ACPI_GET_ADDRESS"},
501     {"ACPI_VALID_ADDRESS"},
502     {NULL}
503 };
504
505
506 ACPI_IDENTIFIER_TABLE       LinuxEliminateLines_C[] = {
507
508     {"#define __"},
509     {"$Revision"},
510     {NULL}
511 };
512
513
514 ACPI_IDENTIFIER_TABLE       LinuxEliminateLines_H[] = {
515
516     {"$Revision"},
517     {NULL}
518 };
519
520
521 ACPI_IDENTIFIER_TABLE       LinuxConditionalIdentifiers[] = {
522
523 //    {"ACPI_USE_STANDARD_HEADERS"},
524     {"WIN32"},
525     {"_MSC_VER"},
526     {NULL}
527 };
528
529 ACPI_CONVERSION_TABLE       LinuxConversionTable = {
530
531     LinuxHeader,
532     FLG_NO_CARRIAGE_RETURNS | FLG_LOWERCASE_DIRNAMES,
533
534     AcpiIdentifiers,
535
536     /* C source files */
537
538     LinuxDataTypes,
539     LinuxEliminateLines_C,
540     NULL,
541     LinuxEliminateMacros,
542     AcpiIdentifiers,
543     (CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES |
544      CVT_CHECK_BRACES | CVT_TRIM_LINES | CVT_BRACES_ON_SAME_LINE |
545      CVT_MIXED_CASE_TO_UNDERSCORES | CVT_LOWER_CASE_IDENTIFIERS |
546      CVT_REMOVE_DEBUG_MACROS | CVT_TRIM_WHITESPACE |
547      CVT_REMOVE_EMPTY_BLOCKS | CVT_SPACES_TO_TABS8),
548
549     /* C header files */
550
551     LinuxDataTypes,
552     LinuxEliminateLines_H,
553     LinuxConditionalIdentifiers,
554     NULL,
555     AcpiIdentifiers,
556     (CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES |
557      CVT_TRIM_LINES | CVT_MIXED_CASE_TO_UNDERSCORES |
558      CVT_LOWER_CASE_IDENTIFIERS | CVT_TRIM_WHITESPACE |
559      CVT_REMOVE_EMPTY_BLOCKS| CVT_REDUCE_TYPEDEFS | CVT_SPACES_TO_TABS8),
560 };
561
562
563 /******************************************************************************
564  *
565  * Code cleanup translation tables
566  *
567  ******************************************************************************/
568
569
570 ACPI_CONVERSION_TABLE       CleanupConversionTable = {
571
572     NULL,
573     FLG_DEFAULT_FLAGS,
574     NULL,
575     /* C source files */
576
577     NULL,
578     NULL,
579     NULL,
580     NULL,
581     NULL,
582     (CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES |
583      CVT_CHECK_BRACES | CVT_TRIM_LINES | CVT_TRIM_WHITESPACE),
584
585     /* C header files */
586
587     NULL,
588     NULL,
589     NULL,
590     NULL,
591     NULL,
592     (CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES |
593      CVT_TRIM_LINES | CVT_TRIM_WHITESPACE),
594 };
595
596
597 ACPI_CONVERSION_TABLE       StatsConversionTable = {
598
599     NULL,
600     FLG_NO_FILE_OUTPUT,
601     NULL,
602
603     /* C source files */
604
605     NULL,
606     NULL,
607     NULL,
608     NULL,
609     NULL,
610     (CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES),
611
612     /* C header files */
613
614     NULL,
615     NULL,
616     NULL,
617     NULL,
618     NULL,
619     (CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES),
620 };
621
622
623 /******************************************************************************
624  *
625  * Customizable translation tables
626  *
627  ******************************************************************************/
628
629 ACPI_STRING_TABLE           CustomReplacements[] = {
630
631     {"(c) 1999 - 2005",      "(c) 1999 - 2005",         REPLACE_WHOLE_WORD},
632
633 #if 0
634     "ACPI_NATIVE_UINT",     "ACPI_NATIVE_UINT",         REPLACE_WHOLE_WORD,
635     "ACPI_NATIVE_UINT *",   "ACPI_NATIVE_UINT *",       REPLACE_WHOLE_WORD,
636     "ACPI_NATIVE_UINT",     "ACPI_NATIVE_UINT",         REPLACE_WHOLE_WORD,
637     "ACPI_NATIVE_INT",      "ACPI_NATIVE_INT",          REPLACE_WHOLE_WORD,
638     "ACPI_NATIVE_INT *",    "ACPI_NATIVE_INT *",        REPLACE_WHOLE_WORD,
639     "ACPI_NATIVE_INT",      "ACPI_NATIVE_INT",          REPLACE_WHOLE_WORD,
640 #endif
641
642     {NULL,                    NULL, 0}
643 };
644
645
646 ACPI_CONVERSION_TABLE       CustomConversionTable = {
647
648     NULL,
649     FLG_DEFAULT_FLAGS,
650     NULL,
651
652     /* C source files */
653
654     CustomReplacements,
655     NULL,
656     NULL,
657     NULL,
658     NULL,
659     (CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES |
660      CVT_TRIM_LINES | CVT_TRIM_WHITESPACE),
661
662     /* C header files */
663
664     CustomReplacements,
665     NULL,
666     NULL,
667     NULL,
668     NULL,
669     (CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES |
670      CVT_TRIM_LINES | CVT_TRIM_WHITESPACE),
671 };
672
673
674 /******************************************************************************
675  *
676  * FUNCTION:    AsExaminePaths
677  *
678  * DESCRIPTION: Source and Target pathname verification and handling
679  *
680  ******************************************************************************/
681
682 int
683 AsExaminePaths (
684     ACPI_CONVERSION_TABLE   *ConversionTable,
685     char                    *Source,
686     char                    *Target,
687     UINT32                  *SourceFileType)
688 {
689     int                     Status;
690     char                    Response;
691
692
693     Status = stat (Source, &Gbl_StatBuf);
694     if (Status)
695     {
696         printf ("Source path \"%s\" does not exist\n", Source);
697         return -1;
698     }
699
700     /* Return the filetype -- file or a directory */
701
702     *SourceFileType = 0;
703     if (Gbl_StatBuf.st_mode & S_IFDIR)
704     {
705         *SourceFileType = S_IFDIR;
706     }
707
708     /*
709      * If we are in no-output mode or in batch mode, we are done
710      */
711     if ((ConversionTable->Flags & FLG_NO_FILE_OUTPUT) ||
712         (Gbl_BatchMode))
713     {
714         return 0;
715     }
716
717     if (!stricmp (Source, Target))
718     {
719         printf ("Target path is the same as the source path, overwrite?\n");
720         scanf ("%c", &Response);
721
722         /* Check response */
723
724         if ((char) Response != 'y')
725         {
726             return -1;
727         }
728
729         Gbl_Overwrite = TRUE;
730     }
731     else
732     {
733         Status = stat (Target, &Gbl_StatBuf);
734         if (!Status)
735         {
736             printf ("Target path already exists, overwrite?\n");
737             scanf ("%c", &Response);
738
739             /* Check response */
740
741             if ((char) Response != 'y')
742             {
743                 return -1;
744             }
745         }
746     }
747
748     return 0;
749 }
750
751
752 /******************************************************************************
753  *
754  * FUNCTION:    AsDisplayStats
755  *
756  * DESCRIPTION: Display global statistics gathered during translation
757  *
758  ******************************************************************************/
759
760 void
761 AsDisplayStats (void)
762 {
763
764     printf ("\nAcpiSrc statistics:\n\n");
765     printf ("%6d Files processed\n", Gbl_Files);
766     printf ("%6d Tabs found\n", Gbl_Tabs);
767     printf ("%6d Missing if/else braces\n", Gbl_MissingBraces);
768     printf ("%6d Non-ANSI comments found\n", Gbl_NonAnsiComments);
769     printf ("%6d Total Lines\n", Gbl_TotalLines);
770     printf ("%6d Lines of code\n", Gbl_SourceLines);
771     printf ("%6d Lines of non-comment whitespace\n", Gbl_WhiteLines);
772     printf ("%6d Lines of comments\n", Gbl_CommentLines);
773     printf ("%6d Long lines found\n", Gbl_LongLines);
774     printf ("%6.1f Ratio of code to whitespace\n", ((float) Gbl_SourceLines / (float) Gbl_WhiteLines));
775     printf ("%6.1f Ratio of code to comments\n", ((float) Gbl_SourceLines / (float) Gbl_CommentLines));
776     return;
777 }
778
779
780 /******************************************************************************
781  *
782  * FUNCTION:    AsDisplayUsage
783  *
784  * DESCRIPTION: Usage message
785  *
786  ******************************************************************************/
787
788 void
789 AsDisplayUsage (void)
790 {
791
792     printf ("\n");
793     printf ("Usage: acpisrc [-c|l|u] [-dsvy] <SourceDir> <DestinationDir>\n\n");
794     printf ("Where: -c          Generate cleaned version of the source\n");
795     printf ("       -l          Generate Linux version of the source\n");
796     printf ("       -u          Generate Custom source translation\n");
797     printf ("\n");
798     printf ("       -d          Leave debug statements in code\n");
799     printf ("       -s          Generate source statistics only\n");
800     printf ("       -v          Verbose mode\n");
801     printf ("       -y          Suppress file overwrite prompts\n");
802     printf ("\n");
803     return;
804 }
805
806
807 /******************************************************************************
808  *
809  * FUNCTION:    main
810  *
811  * DESCRIPTION: C main function
812  *
813  ******************************************************************************/
814
815 int ACPI_SYSTEM_XFACE
816 main (
817     int                     argc,
818     char                    *argv[])
819 {
820     int                     j;
821     ACPI_CONVERSION_TABLE   *ConversionTable = NULL;
822     char                    *SourcePath;
823     char                    *TargetPath;
824     UINT32                  FileType;
825
826
827     printf ("ACPI Source Code Conversion Utility");
828     printf (" version %8.8X", ((UINT32) ACPI_CA_VERSION));
829     printf (" [%s]\n\n",  __DATE__);
830
831     if (argc < 2)
832     {
833         AsDisplayUsage ();
834         return 0;
835     }
836
837     /* Command line options */
838
839     while ((j = AcpiGetopt (argc, argv, "lcsuvyd")) != EOF) switch(j)
840     {
841     case 'l':
842         /* Linux code generation */
843
844         printf ("Creating Linux source code\n");
845         ConversionTable = &LinuxConversionTable;
846         Gbl_WidenDeclarations = TRUE;
847         Gbl_IgnoreLoneLineFeeds = TRUE;
848         break;
849
850     case 'c':
851         /* Cleanup code */
852
853         printf ("Code cleanup\n");
854         ConversionTable = &CleanupConversionTable;
855         break;
856
857     case 's':
858         /* Statistics only */
859
860         break;
861
862     case 'u':
863         /* custom conversion  */
864
865         printf ("Custom source translation\n");
866         ConversionTable = &CustomConversionTable;
867         break;
868
869     case 'v':
870         /* Verbose mode */
871
872         Gbl_VerboseMode = TRUE;
873         break;
874
875     case 'y':
876         /* Batch mode */
877
878         Gbl_BatchMode = TRUE;
879         break;
880
881     case 'd':
882         /* Leave debug statements in */
883
884         Gbl_DebugStatementsMode = TRUE;
885         break;
886
887     default:
888         AsDisplayUsage ();
889         return -1;
890     }
891
892
893     SourcePath = argv[AcpiGbl_Optind];
894     if (!SourcePath)
895     {
896         printf ("Missing source path\n");
897         AsDisplayUsage ();
898         return -1;
899     }
900
901     TargetPath = argv[AcpiGbl_Optind+1];
902
903     if (!ConversionTable)
904     {
905         /* Just generate statistics.  Ignore target path */
906
907         TargetPath = SourcePath;
908
909         printf ("Source code statistics only\n");
910         ConversionTable = &StatsConversionTable;
911     }
912     else if (!TargetPath)
913     {
914         TargetPath = SourcePath;
915     }
916
917     if (Gbl_DebugStatementsMode)
918     {
919         ConversionTable->SourceFunctions &= ~CVT_REMOVE_DEBUG_MACROS;
920     }
921
922     /* Check source and target paths and files */
923
924     if (AsExaminePaths (ConversionTable, SourcePath, TargetPath, &FileType))
925     {
926         return -1;
927     }
928
929     /* Source/target can be either directories or a files */
930
931     if (FileType == S_IFDIR)
932     {
933         /* Process the directory tree */
934
935         AsProcessTree (ConversionTable, SourcePath, TargetPath);
936     }
937     else
938     {
939         /* Process a single file */
940
941         /* Differentiate between source and header files */
942
943         if (strstr (SourcePath, ".h"))
944         {
945             AsProcessOneFile (ConversionTable, NULL, TargetPath, 0, SourcePath, FILE_TYPE_HEADER);
946         }
947         else
948         {
949             AsProcessOneFile (ConversionTable, NULL, TargetPath, 0, SourcePath, FILE_TYPE_SOURCE);
950         }
951     }
952
953     /* Always display final summary and stats */
954
955     AsDisplayStats ();
956
957     return 0;
958 }