Bring in acpica-20040527 from intel. See: http://developer.intel.com/technology...
[dragonfly.git] / sys / contrib / dev / acpica-unix-20040527 / tools / acpisrc / asmain.c
1
2 /******************************************************************************
3  *
4  * Module Name: asmain - Main module for the acpi source processor utility
5  *              $Revision: 68 $
6  *
7  *****************************************************************************/
8
9 /******************************************************************************
10  *
11  * 1. Copyright Notice
12  *
13  * Some or all of this work - Copyright (c) 1999 - 2004, 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 - 2004, 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_EXTERNAL_LIST",               SRC_TYPE_STRUCT},
299     {"ACPI_FIELD_INFO",                  SRC_TYPE_STRUCT},
300     {"ACPI_FIND_CONTEXT",                SRC_TYPE_STRUCT},
301     {"ACPI_FIXED_EVENT_HANDLER",         SRC_TYPE_STRUCT},
302     {"ACPI_FIXED_EVENT_INFO",            SRC_TYPE_STRUCT},
303     {"ACPI_GENERIC_ADDRESS",             SRC_TYPE_STRUCT},
304     {"ACPI_GENERIC_STATE",               SRC_TYPE_UNION},
305     {"ACPI_GET_DEVICES_INFO",            SRC_TYPE_STRUCT},
306     {"ACPI_GPE_BLOCK_INFO",              SRC_TYPE_STRUCT},
307     {"ACPI_GPE_XRUPT_INFO",              SRC_TYPE_STRUCT},
308     {"ACPI_GPE_EVENT_INFO",              SRC_TYPE_STRUCT},
309     {"ACPI_GPE_HANDLER",                 SRC_TYPE_SIMPLE},
310     {"ACPI_GPE_INDEX_INFO",              SRC_TYPE_STRUCT},
311     {"ACPI_GPE_REGISTER_INFO",           SRC_TYPE_STRUCT},
312     {"ACPI_GPE_WALK_INFO",               SRC_TYPE_STRUCT},
313     {"ACPI_HANDLE",                      SRC_TYPE_SIMPLE},
314     {"ACPI_HANDLER_INFO",                SRC_TYPE_STRUCT},
315     {"ACPI_INIT_HANDLER",                SRC_TYPE_SIMPLE},
316     {"ACPI_IDENTIFIER_TABLE",            SRC_TYPE_STRUCT},
317     {"ACPI_INIT_WALK_INFO",              SRC_TYPE_STRUCT},
318     {"ACPI_INTEGER",                     SRC_TYPE_SIMPLE},
319     {"ACPI_INTEGRITY_INFO",              SRC_TYPE_STRUCT},
320     {"ACPI_INTERPRETER_MODE",            SRC_TYPE_SIMPLE},
321     {"ACPI_IO_ADDRESS",                  SRC_TYPE_SIMPLE},
322     {"ACPI_IO_ATTRIBUTE",                SRC_TYPE_STRUCT},
323     {"ACPI_MEM_SPACE_CONTEXT",           SRC_TYPE_STRUCT},
324     {"ACPI_MEMORY_ATTRIBUTE",            SRC_TYPE_STRUCT},
325     {"ACPI_MEMORY_LIST",                 SRC_TYPE_STRUCT},
326     {"ACPI_MUTEX",                       SRC_TYPE_SIMPLE},
327     {"ACPI_MUTEX_HANDLE",                SRC_TYPE_SIMPLE},
328     {"ACPI_MUTEX_INFO",                  SRC_TYPE_STRUCT},
329     {"ACPI_NAME",                        SRC_TYPE_SIMPLE},
330     {"ACPI_NAME_UNION",                  SRC_TYPE_UNION},
331     {"ACPI_NAMESPACE_NODE",              SRC_TYPE_STRUCT},
332     {"ACPI_NAMESTRING_INFO",             SRC_TYPE_STRUCT},
333     {"ACPI_NATIVE_INT",                  SRC_TYPE_SIMPLE},
334     {"ACPI_NATIVE_UINT",                 SRC_TYPE_SIMPLE},
335     {"ACPI_NOTIFY_HANDLER",              SRC_TYPE_SIMPLE},
336     {"ACPI_NOTIFY_INFO",                 SRC_TYPE_STRUCT},
337     {"ACPI_NS_SEARCH_DATA",              SRC_TYPE_STRUCT},
338     {"ACPI_OBJ_INFO_HEADER",             SRC_TYPE_STRUCT},
339     {"ACPI_OBJECT",                      SRC_TYPE_UNION},
340     {"ACPI_OBJECT_ADDR_HANDLER",         SRC_TYPE_STRUCT},
341     {"ACPI_OBJECT_BANK_FIELD",           SRC_TYPE_STRUCT},
342     {"ACPI_OBJECT_BUFFER",               SRC_TYPE_STRUCT},
343     {"ACPI_OBJECT_BUFFER_FIELD",         SRC_TYPE_STRUCT},
344     {"ACPI_OBJECT_CACHE_LIST",           SRC_TYPE_STRUCT},
345     {"ACPI_OBJECT_COMMON",               SRC_TYPE_STRUCT},
346     {"ACPI_OBJECT_DATA",                 SRC_TYPE_STRUCT},
347     {"ACPI_OBJECT_DEVICE",               SRC_TYPE_STRUCT},
348     {"ACPI_OBJECT_EVENT",                SRC_TYPE_STRUCT},
349     {"ACPI_OBJECT_EXTRA",                SRC_TYPE_STRUCT},
350     {"ACPI_OBJECT_FIELD_COMMON",         SRC_TYPE_STRUCT},
351     {"ACPI_OBJECT_HANDLER",              SRC_TYPE_SIMPLE},
352     {"ACPI_OBJECT_INDEX_FIELD",          SRC_TYPE_STRUCT},
353     {"ACPI_OBJECT_INTEGER",              SRC_TYPE_STRUCT},
354     {"ACPI_OBJECT_LIST",                 SRC_TYPE_STRUCT},
355     {"ACPI_OBJECT_METHOD",               SRC_TYPE_STRUCT},
356     {"ACPI_OBJECT_MUTEX",                SRC_TYPE_STRUCT},
357     {"ACPI_OBJECT_NOTIFY_COMMON",        SRC_TYPE_STRUCT},
358     {"ACPI_OBJECT_NOTIFY_HANDLER",       SRC_TYPE_STRUCT},
359     {"ACPI_OBJECT_PACKAGE",              SRC_TYPE_STRUCT},
360     {"ACPI_OBJECT_POWER_RESOURCE",       SRC_TYPE_STRUCT},
361     {"ACPI_OBJECT_PROCESSOR",            SRC_TYPE_STRUCT},
362     {"ACPI_OBJECT_REFERENCE",            SRC_TYPE_STRUCT},
363     {"ACPI_OBJECT_REGION",               SRC_TYPE_STRUCT},
364     {"ACPI_OBJECT_REGION_FIELD",         SRC_TYPE_STRUCT},
365     {"ACPI_OBJECT_STRING",               SRC_TYPE_STRUCT},
366     {"ACPI_OBJECT_THERMAL_ZONE",         SRC_TYPE_STRUCT},
367     {"ACPI_OBJECT_TYPE",                 SRC_TYPE_SIMPLE},
368     {"ACPI_OBJECT_TYPE8",                SRC_TYPE_SIMPLE},
369     {"ACPI_OP_WALK_INFO",                SRC_TYPE_STRUCT},
370     {"ACPI_OPCODE_INFO",                 SRC_TYPE_STRUCT},
371     {"ACPI_OPERAND_OBJECT",              SRC_TYPE_UNION},
372     {"ACPI_OWNER_ID",                    SRC_TYPE_SIMPLE},
373     {"ACPI_PARAMETER_INFO",              SRC_TYPE_STRUCT},
374     {"ACPI_PARSE_DOWNWARDS",             SRC_TYPE_SIMPLE},
375     {"ACPI_PARSE_OBJ_ASL",               SRC_TYPE_STRUCT},
376     {"ACPI_PARSE_OBJ_COMMON",            SRC_TYPE_STRUCT},
377     {"ACPI_PARSE_OBJ_NAMED",             SRC_TYPE_STRUCT},
378     {"ACPI_PARSE_OBJECT",                SRC_TYPE_UNION},
379     {"ACPI_PARSE_STATE",                 SRC_TYPE_STRUCT},
380     {"ACPI_PARSE_UPWARDS",               SRC_TYPE_SIMPLE},
381     {"ACPI_PARSE_VALUE",                 SRC_TYPE_UNION},
382     {"ACPI_PCI_ID",                      SRC_TYPE_STRUCT},
383     {"ACPI_PCI_ROUTING_TABLE",           SRC_TYPE_STRUCT},
384     {"ACPI_PHYSICAL_ADDRESS",            SRC_TYPE_SIMPLE},
385     {"ACPI_PKG_CALLBACK",                SRC_TYPE_SIMPLE},
386     {"ACPI_PKG_INFO",                    SRC_TYPE_STRUCT},
387     {"ACPI_PKG_STATE",                   SRC_TYPE_STRUCT},
388     {"ACPI_POINTER",                     SRC_TYPE_STRUCT},
389     {"ACPI_POINTERS",                    SRC_TYPE_UNION},
390     {"ACPI_PREDEFINED_NAMES",            SRC_TYPE_STRUCT},
391     {"ACPI_PSCOPE_STATE",                SRC_TYPE_STRUCT},
392     {"ACPI_RESOURCE",                    SRC_TYPE_STRUCT},
393     {"ACPI_RESOURCE_ADDRESS16",          SRC_TYPE_STRUCT},
394     {"ACPI_RESOURCE_ADDRESS32",          SRC_TYPE_STRUCT},
395     {"ACPI_RESOURCE_ADDRESS64",          SRC_TYPE_STRUCT},
396     {"ACPI_RESOURCE_ATTRIBUTE",          SRC_TYPE_UNION},
397     {"ACPI_RESOURCE_DATA",               SRC_TYPE_UNION},
398     {"ACPI_RESOURCE_DMA",                SRC_TYPE_STRUCT},
399     {"ACPI_RESOURCE_END_TAG",            SRC_TYPE_STRUCT},
400     {"ACPI_RESOURCE_EXT_IRQ",            SRC_TYPE_STRUCT},
401     {"ACPI_RESOURCE_FIXED_IO",           SRC_TYPE_STRUCT},
402     {"ACPI_RESOURCE_FIXED_MEM32",        SRC_TYPE_STRUCT},
403     {"ACPI_RESOURCE_IO",                 SRC_TYPE_STRUCT},
404     {"ACPI_RESOURCE_IRQ",                SRC_TYPE_STRUCT},
405     {"ACPI_RESOURCE_MEM24",              SRC_TYPE_STRUCT},
406     {"ACPI_RESOURCE_MEM32",              SRC_TYPE_STRUCT},
407     {"ACPI_RESOURCE_SOURCE",             SRC_TYPE_STRUCT},
408     {"ACPI_RESOURCE_START_DPF",          SRC_TYPE_STRUCT},
409     {"ACPI_RESOURCE_TYPE",               SRC_TYPE_SIMPLE},
410     {"ACPI_RESOURCE_VENDOR",             SRC_TYPE_STRUCT},
411     {"ACPI_RESULT_VALUES",               SRC_TYPE_STRUCT},
412     {"ACPI_SCOPE_STATE",                 SRC_TYPE_STRUCT},
413     {"ACPI_SIGNAL_FATAL_INFO",           SRC_TYPE_STRUCT},
414     {"ACPI_SIZE",                        SRC_TYPE_SIMPLE},
415     {"ACPI_STATUS",                      SRC_TYPE_SIMPLE},
416     {"ACPI_STRING",                      SRC_TYPE_SIMPLE},
417     {"ACPI_STRING_TABLE",                SRC_TYPE_STRUCT},
418     {"ACPI_SYSTEM_INFO",                 SRC_TYPE_STRUCT},
419     {"ACPI_TABLE_DESC",                  SRC_TYPE_STRUCT},
420     {"ACPI_TABLE_HEADER",                SRC_TYPE_STRUCT},
421     {"ACPI_TABLE_INFO",                  SRC_TYPE_STRUCT},
422     {"ACPI_TABLE_LIST",                  SRC_TYPE_STRUCT},
423     {"ACPI_TABLE_PTR",                   SRC_TYPE_SIMPLE},
424     {"ACPI_TABLE_SUPPORT",               SRC_TYPE_STRUCT},
425     {"ACPI_TABLE_TYPE",                  SRC_TYPE_SIMPLE},
426     {"ACPI_THREAD_STATE",                SRC_TYPE_STRUCT},
427     {"ACPI_TYPED_IDENTIFIER_TABLE",      SRC_TYPE_STRUCT},
428     {"ACPI_UPDATE_STATE",                SRC_TYPE_STRUCT},
429     {"ACPI_WALK_CALLBACK",               SRC_TYPE_SIMPLE},
430     {"ACPI_WALK_INFO",                   SRC_TYPE_STRUCT},
431     {"ACPI_WALK_STATE",                  SRC_TYPE_STRUCT},
432     {"APIC_HEADER",                      SRC_TYPE_STRUCT},
433     {"ARGUMENT_INFO",                    SRC_TYPE_STRUCT},
434     {"ASL_ANALYSIS_WALK_INFO",           SRC_TYPE_STRUCT},
435     {"ASL_DMA_FORMAT_DESC",              SRC_TYPE_STRUCT},
436     {"ASL_DWORD_ADDRESS_DESC",           SRC_TYPE_STRUCT},
437     {"ASL_END_DEPENDENT_DESC",           SRC_TYPE_STRUCT},
438     {"ASL_END_TAG_DESC",                 SRC_TYPE_STRUCT},
439     {"ASL_ERROR_MSG",                    SRC_TYPE_STRUCT},
440     {"ASL_EVENT_INFO",                   SRC_TYPE_STRUCT},
441     {"ASL_EXTENDED_XRUPT_DESC",          SRC_TYPE_STRUCT},
442     {"ASL_FILE_INFO",                    SRC_TYPE_STRUCT},
443     {"ASL_FIXED_IO_PORT_DESC",           SRC_TYPE_STRUCT},
444     {"ASL_FIXED_MEMORY_32_DESC",         SRC_TYPE_STRUCT},
445     {"ASL_GENERAL_REGISTER_DESC",        SRC_TYPE_STRUCT},
446     {"ASL_IO_PORT_DESC",                 SRC_TYPE_STRUCT},
447     {"ASL_IRQ_FORMAT_DESC",              SRC_TYPE_STRUCT},
448     {"ASL_IRQ_NOFLAGS_DESC",             SRC_TYPE_STRUCT},
449     {"ASL_LARGE_VENDOR_DESC",            SRC_TYPE_STRUCT},
450     {"ASL_LISTING_NODE",                 SRC_TYPE_STRUCT},
451     {"ASL_MAPPING_ENTRY",                SRC_TYPE_STRUCT},
452     {"ASL_MEMORY_24_DESC",               SRC_TYPE_STRUCT},
453     {"ASL_MEMORY_32_DESC",               SRC_TYPE_STRUCT},
454     {"ASL_METHOD_INFO",                  SRC_TYPE_STRUCT},
455     {"ASL_QWORD_ADDRESS_DESC",           SRC_TYPE_STRUCT},
456     {"ASL_RESERVED_INFO",                SRC_TYPE_STRUCT},
457     {"ASL_RESOURCE_DESC",                SRC_TYPE_UNION},
458     {"ASL_RESOURCE_NODE",                SRC_TYPE_STRUCT},
459     {"ASL_SMALL_VENDOR_DESC",            SRC_TYPE_STRUCT},
460     {"ASL_START_DEPENDENT_DESC",         SRC_TYPE_STRUCT},
461     {"ASL_START_DEPENDENT_NOPRIO_DESC",  SRC_TYPE_STRUCT},
462     {"ASL_WALK_CALLBACK",                SRC_TYPE_SIMPLE},
463     {"ASL_WORD_ADDRESS_DESC",            SRC_TYPE_STRUCT},
464     {"COMMAND_INFO",                     SRC_TYPE_STRUCT},
465 /*    {"FACS_DESCRIPTOR",                  SRC_TYPE_SIMPLE}, */
466     {"FACS_DESCRIPTOR_REV1",             SRC_TYPE_STRUCT},
467     {"FACS_DESCRIPTOR_REV2",             SRC_TYPE_STRUCT},
468 /*    {"FADT_DESCRIPTOR",                  SRC_TYPE_SIMPLE}, */
469     {"FADT_DESCRIPTOR_REV1",             SRC_TYPE_STRUCT},
470     {"FADT_DESCRIPTOR_REV2",             SRC_TYPE_STRUCT},
471     {"RSDP_DESCRIPTOR",                  SRC_TYPE_STRUCT},
472 /*    {"RSDT_DESCRIPTOR",                  SRC_TYPE_SIMPLE}, */
473     {"RSDT_DESCRIPTOR_REV1",             SRC_TYPE_STRUCT},
474     {"RSDT_DESCRIPTOR_REV2",             SRC_TYPE_STRUCT},
475     {"UINT32_STRUCT",                    SRC_TYPE_STRUCT},
476     {"UINT64_OVERLAY",                   SRC_TYPE_UNION},
477     {"UINT64_STRUCT",                    SRC_TYPE_STRUCT},
478 /*    {"XSDT_DESCRIPTOR",                  SRC_TYPE_SIMPLE}, */
479     {"XSDT_DESCRIPTOR_REV2",             SRC_TYPE_STRUCT},
480
481     {NULL}
482 };
483
484 ACPI_IDENTIFIER_TABLE       LinuxAddStruct[] = {
485     {"acpi_namespace_node"},
486     {"acpi_parse_object"},
487     {"acpi_table_desc"},
488     {"acpi_walk_state"},
489     {NULL}
490 };
491
492
493 ACPI_IDENTIFIER_TABLE       LinuxEliminateMacros[] = {
494
495     {"ACPI_GET_ADDRESS"},
496     {"ACPI_VALID_ADDRESS"},
497     {NULL}
498 };
499
500
501 ACPI_IDENTIFIER_TABLE       LinuxEliminateLines_C[] = {
502
503     {"#define __"},
504     {"$Revision"},
505     {NULL}
506 };
507
508
509 ACPI_IDENTIFIER_TABLE       LinuxEliminateLines_H[] = {
510
511     {"$Revision"},
512     {NULL}
513 };
514
515
516 ACPI_IDENTIFIER_TABLE       LinuxConditionalIdentifiers[] = {
517
518 //    {"ACPI_USE_STANDARD_HEADERS"},
519     {"WIN32"},
520     {"_MSC_VER"},
521     {NULL}
522 };
523
524 ACPI_CONVERSION_TABLE       LinuxConversionTable = {
525
526     LinuxHeader,
527     FLG_NO_CARRIAGE_RETURNS | FLG_LOWERCASE_DIRNAMES,
528
529     AcpiIdentifiers,
530
531     /* C source files */
532
533     LinuxDataTypes,
534     LinuxEliminateLines_C,
535     NULL,
536     LinuxEliminateMacros,
537     AcpiIdentifiers,
538     (CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES |
539      CVT_CHECK_BRACES | CVT_TRIM_LINES | CVT_BRACES_ON_SAME_LINE |
540      CVT_MIXED_CASE_TO_UNDERSCORES | CVT_LOWER_CASE_IDENTIFIERS |
541      CVT_REMOVE_DEBUG_MACROS | CVT_TRIM_WHITESPACE |
542      CVT_REMOVE_EMPTY_BLOCKS | CVT_SPACES_TO_TABS8),
543
544     /* C header files */
545
546     LinuxDataTypes,
547     LinuxEliminateLines_H,
548     LinuxConditionalIdentifiers,
549     NULL,
550     AcpiIdentifiers,
551     (CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES |
552      CVT_TRIM_LINES | CVT_MIXED_CASE_TO_UNDERSCORES |
553      CVT_LOWER_CASE_IDENTIFIERS | CVT_TRIM_WHITESPACE |
554      CVT_REMOVE_EMPTY_BLOCKS| CVT_REDUCE_TYPEDEFS | CVT_SPACES_TO_TABS8),
555 };
556
557
558 /******************************************************************************
559  *
560  * Code cleanup translation tables
561  *
562  ******************************************************************************/
563
564
565 ACPI_CONVERSION_TABLE       CleanupConversionTable = {
566
567     NULL,
568     FLG_DEFAULT_FLAGS,
569     NULL,
570     /* C source files */
571
572     NULL,
573     NULL,
574     NULL,
575     NULL,
576     NULL,
577     (CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES |
578      CVT_CHECK_BRACES | CVT_TRIM_LINES | CVT_TRIM_WHITESPACE),
579
580     /* C header files */
581
582     NULL,
583     NULL,
584     NULL,
585     NULL,
586     NULL,
587     (CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES |
588      CVT_TRIM_LINES | CVT_TRIM_WHITESPACE),
589 };
590
591
592 ACPI_CONVERSION_TABLE       StatsConversionTable = {
593
594     NULL,
595     FLG_NO_FILE_OUTPUT,
596     NULL,
597
598     /* C source files */
599
600     NULL,
601     NULL,
602     NULL,
603     NULL,
604     NULL,
605     (CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES),
606
607     /* C header files */
608
609     NULL,
610     NULL,
611     NULL,
612     NULL,
613     NULL,
614     (CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES),
615 };
616
617
618 /******************************************************************************
619  *
620  * Customizable translation tables
621  *
622  ******************************************************************************/
623
624 ACPI_STRING_TABLE           CustomReplacements[] = {
625
626     {"(c) 1999 - 2003",      "(c) 1999 - 2004",          REPLACE_WHOLE_WORD},
627
628 #if 0
629     "ACPI_NATIVE_UINT",     "ACPI_NATIVE_UINT",         REPLACE_WHOLE_WORD,
630     "ACPI_NATIVE_UINT *",   "ACPI_NATIVE_UINT *",       REPLACE_WHOLE_WORD,
631     "ACPI_NATIVE_UINT",     "ACPI_NATIVE_UINT",         REPLACE_WHOLE_WORD,
632     "ACPI_NATIVE_INT",      "ACPI_NATIVE_INT",          REPLACE_WHOLE_WORD,
633     "ACPI_NATIVE_INT *",    "ACPI_NATIVE_INT *",        REPLACE_WHOLE_WORD,
634     "ACPI_NATIVE_INT",      "ACPI_NATIVE_INT",          REPLACE_WHOLE_WORD,
635 #endif
636
637     {NULL,                    NULL, 0}
638 };
639
640
641 ACPI_CONVERSION_TABLE       CustomConversionTable = {
642
643     NULL,
644     FLG_DEFAULT_FLAGS,
645     NULL,
646
647     /* C source files */
648
649     CustomReplacements,
650     NULL,
651     NULL,
652     NULL,
653     NULL,
654     (CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES |
655      CVT_TRIM_LINES | CVT_TRIM_WHITESPACE),
656
657     /* C header files */
658
659     CustomReplacements,
660     NULL,
661     NULL,
662     NULL,
663     NULL,
664     (CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES |
665      CVT_TRIM_LINES | CVT_TRIM_WHITESPACE),
666 };
667
668
669 /******************************************************************************
670  *
671  * FUNCTION:    AsExaminePaths
672  *
673  * DESCRIPTION: Source and Target pathname verification and handling
674  *
675  ******************************************************************************/
676
677 int
678 AsExaminePaths (
679     ACPI_CONVERSION_TABLE   *ConversionTable,
680     char                    *Source,
681     char                    *Target,
682     UINT32                  *SourceFileType)
683 {
684     int                     Status;
685     char                    Response;
686
687
688     Status = stat (Source, &Gbl_StatBuf);
689     if (Status)
690     {
691         printf ("Source path \"%s\" does not exist\n", Source);
692         return -1;
693     }
694
695     /* Return the filetype -- file or a directory */
696
697     *SourceFileType = 0;
698     if (Gbl_StatBuf.st_mode & S_IFDIR)
699     {
700         *SourceFileType = S_IFDIR;
701     }
702
703     /*
704      * If we are in no-output mode or in batch mode, we are done
705      */
706     if ((ConversionTable->Flags & FLG_NO_FILE_OUTPUT) ||
707         (Gbl_BatchMode))
708     {
709         return 0;
710     }
711
712     if (!stricmp (Source, Target))
713     {
714         printf ("Target path is the same as the source path, overwrite?\n");
715         scanf ("%c", &Response);
716
717         /* Check response */
718
719         if ((char) Response != 'y')
720         {
721             return -1;
722         }
723
724         Gbl_Overwrite = TRUE;
725     }
726     else
727     {
728         Status = stat (Target, &Gbl_StatBuf);
729         if (!Status)
730         {
731             printf ("Target path already exists, overwrite?\n");
732             scanf ("%c", &Response);
733
734             /* Check response */
735
736             if ((char) Response != 'y')
737             {
738                 return -1;
739             }
740         }
741     }
742
743     return 0;
744 }
745
746
747 /******************************************************************************
748  *
749  * FUNCTION:    AsDisplayStats
750  *
751  * DESCRIPTION: Display global statistics gathered during translation
752  *
753  ******************************************************************************/
754
755 void
756 AsDisplayStats (void)
757 {
758
759     printf ("\nAcpiSrc statistics:\n\n");
760     printf ("%6d Files processed\n", Gbl_Files);
761     printf ("%6d Tabs found\n", Gbl_Tabs);
762     printf ("%6d Missing if/else braces\n", Gbl_MissingBraces);
763     printf ("%6d Non-ANSI comments found\n", Gbl_NonAnsiComments);
764     printf ("%6d Total Lines\n", Gbl_TotalLines);
765     printf ("%6d Lines of code\n", Gbl_SourceLines);
766     printf ("%6d Lines of non-comment whitespace\n", Gbl_WhiteLines);
767     printf ("%6d Lines of comments\n", Gbl_CommentLines);
768     printf ("%6d Long lines found\n", Gbl_LongLines);
769     printf ("%6.1f Ratio of code to whitespace\n", ((float) Gbl_SourceLines / (float) Gbl_WhiteLines));
770     printf ("%6.1f Ratio of code to comments\n", ((float) Gbl_SourceLines / (float) Gbl_CommentLines));
771     return;
772 }
773
774
775 /******************************************************************************
776  *
777  * FUNCTION:    AsDisplayUsage
778  *
779  * DESCRIPTION: Usage message
780  *
781  ******************************************************************************/
782
783 void
784 AsDisplayUsage (void)
785 {
786
787     printf ("\n");
788     printf ("Usage: acpisrc [-c|l|u] [-dsvy] <SourceDir> <DestinationDir>\n\n");
789     printf ("Where: -c          Generate cleaned version of the source\n");
790     printf ("       -l          Generate Linux version of the source\n");
791     printf ("       -u          Generate Custom source translation\n");
792     printf ("\n");
793     printf ("       -d          Leave debug statements in code\n");
794     printf ("       -s          Generate source statistics only\n");
795     printf ("       -v          Verbose mode\n");
796     printf ("       -y          Suppress file overwrite prompts\n");
797     printf ("\n");
798     return;
799 }
800
801
802 /******************************************************************************
803  *
804  * FUNCTION:    main
805  *
806  * DESCRIPTION: C main function
807  *
808  ******************************************************************************/
809
810 int ACPI_SYSTEM_XFACE
811 main (
812     int                     argc,
813     char                    *argv[])
814 {
815     int                     j;
816     ACPI_CONVERSION_TABLE   *ConversionTable = NULL;
817     char                    *SourcePath;
818     char                    *TargetPath;
819     UINT32                  FileType;
820
821
822     printf ("ACPI Source Code Conversion Utility");
823     printf (" version %8.8X", ((UINT32) ACPI_CA_VERSION));
824     printf (" [%s]\n\n",  __DATE__);
825
826     if (argc < 2)
827     {
828         AsDisplayUsage ();
829         return 0;
830     }
831
832     /* Command line options */
833
834     while ((j = AcpiGetopt (argc, argv, "lcsuvyd")) != EOF) switch(j)
835     {
836     case 'l':
837         /* Linux code generation */
838
839         printf ("Creating Linux source code\n");
840         ConversionTable = &LinuxConversionTable;
841         Gbl_WidenDeclarations = TRUE;
842         Gbl_IgnoreLoneLineFeeds = TRUE;
843         break;
844
845     case 'c':
846         /* Cleanup code */
847
848         printf ("Code cleanup\n");
849         ConversionTable = &CleanupConversionTable;
850         break;
851
852     case 's':
853         /* Statistics only */
854
855         break;
856
857     case 'u':
858         /* custom conversion  */
859
860         printf ("Custom source translation\n");
861         ConversionTable = &CustomConversionTable;
862         break;
863
864     case 'v':
865         /* Verbose mode */
866
867         Gbl_VerboseMode = TRUE;
868         break;
869
870     case 'y':
871         /* Batch mode */
872
873         Gbl_BatchMode = TRUE;
874         break;
875
876     case 'd':
877         /* Leave debug statements in */
878
879         Gbl_DebugStatementsMode = TRUE;
880         break;
881
882     default:
883         AsDisplayUsage ();
884         return -1;
885     }
886
887
888     SourcePath = argv[AcpiGbl_Optind];
889     if (!SourcePath)
890     {
891         printf ("Missing source path\n");
892         AsDisplayUsage ();
893         return -1;
894     }
895
896     TargetPath = argv[AcpiGbl_Optind+1];
897
898     if (!ConversionTable)
899     {
900         /* Just generate statistics.  Ignore target path */
901
902         TargetPath = SourcePath;
903
904         printf ("Source code statistics only\n");
905         ConversionTable = &StatsConversionTable;
906     }
907     else if (!TargetPath)
908     {
909         TargetPath = SourcePath;
910     }
911
912     if (Gbl_DebugStatementsMode)
913     {
914         ConversionTable->SourceFunctions &= ~CVT_REMOVE_DEBUG_MACROS;
915     }
916
917     /* Check source and target paths and files */
918
919     if (AsExaminePaths (ConversionTable, SourcePath, TargetPath, &FileType))
920     {
921         return -1;
922     }
923
924     /* Source/target can be either directories or a files */
925
926     if (FileType == S_IFDIR)
927     {
928         /* Process the directory tree */
929
930         AsProcessTree (ConversionTable, SourcePath, TargetPath);
931     }
932     else
933     {
934         /* Process a single file */
935
936         /* Differentiate between source and header files */
937
938         if (strstr (SourcePath, ".h"))
939         {
940             AsProcessOneFile (ConversionTable, NULL, TargetPath, 0, SourcePath, FILE_TYPE_HEADER);
941         }
942         else
943         {
944             AsProcessOneFile (ConversionTable, NULL, TargetPath, 0, SourcePath, FILE_TYPE_SOURCE);
945         }
946     }
947
948     /* Always display final summary and stats */
949
950     AsDisplayStats ();
951
952     return 0;
953 }