1 /******************************************************************************
2  *
3  * Module Name: asloptions - compiler command line processing
4  *
5  *****************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2021, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
16  * 2.1. This is your license from Intel Corp. under its intellectual property
17  * rights. You may have additional license terms from the party that provided
18  * you this software, covering your right to use that party's intellectual
19  * property rights.
20  *
21  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22  * copy of the source code appearing in this file ("Covered Code") an
23  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24  * base code distributed originally by Intel ("Original Intel Code") to copy,
25  * make derivatives, distribute, use and display any portion of the Covered
26  * Code in any form, with the right to sublicense such rights; and
27  *
28  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29  * license (with the right to sublicense), under only those claims of Intel
30  * patents that are infringed by the Original Intel Code, to make, use, sell,
31  * offer to sell, and import the Covered Code and derivative works thereof
32  * solely to the minimum extent necessary to exercise the above copyright
33  * license, and in no event shall the patent license extend to any additions
34  * to or modifications of the Original Intel Code. No other license or right
35  * is granted directly or by implication, estoppel or otherwise;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
42  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43  * Redistribution of source code of any substantial portion of the Covered
44  * Code or modification with rights to further distribute source must include
45  * the above Copyright Notice, the above License, this list of Conditions,
46  * and the following Disclaimer and Export Compliance provision. In addition,
47  * Licensee must cause all Covered Code to which Licensee contributes to
48  * contain a file documenting the changes Licensee made to create that Covered
49  * Code and the date of any change. Licensee must include in that file the
50  * documentation of any changes made by any predecessor Licensee. Licensee
51  * must include a prominent statement that the modification is derived,
52  * directly or indirectly, from Original Intel Code.
53  *
54  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55  * Redistribution of source code of any substantial portion of the Covered
56  * Code or modification without rights to further distribute source must
57  * include the following Disclaimer and Export Compliance provision in the
58  * documentation and/or other materials provided with distribution. In
59  * addition, Licensee may not authorize further sublicense of source of any
60  * portion of the Covered Code, and must include terms to the effect that the
61  * license from Licensee to its licensee is limited to the intellectual
62  * property embodied in the software Licensee provides to its licensee, and
63  * not to intellectual property embodied in modifications its licensee may
64  * make.
65  *
66  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67  * substantial portion of the Covered Code or modification must reproduce the
68  * above Copyright Notice, and the following Disclaimer and Export Compliance
69  * provision in the documentation and/or other materials provided with the
70  * distribution.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
75  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76  * Intel shall be used in advertising or otherwise to promote the sale, use or
77  * other dealings in products derived from or relating to the Covered Code
78  * without prior written authorization from Intel.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
82  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88  * PARTICULAR PURPOSE.
89  *
90  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97  * LIMITED REMEDY.
98  *
99  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100  * software or system incorporating such software without first obtaining any
101  * required license or other approval from the U. S. Department of Commerce or
102  * any other agency or department of the United States Government. In the
103  * event Licensee exports any such software from the United States or
104  * re-exports any such software from a foreign destination, Licensee shall
105  * ensure that the distribution and export/re-export of the software is in
106  * compliance with all laws, regulations, orders, or other restrictions of the
107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108  * any of its subsidiaries will export/re-export any technical data, process,
109  * software, or service, directly or indirectly, to any country for which the
110  * United States government or any agency thereof requires an export license,
111  * other governmental approval, or letter of assurance, without first obtaining
112  * such license, approval or letter.
113  *
114  *****************************************************************************
115  *
116  * Alternatively, you may choose to be licensed under the terms of the
117  * following license:
118  *
119  * Redistribution and use in source and binary forms, with or without
120  * modification, are permitted provided that the following conditions
121  * are met:
122  * 1. Redistributions of source code must retain the above copyright
123  *    notice, this list of conditions, and the following disclaimer,
124  *    without modification.
125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126  *    substantially similar to the "NO WARRANTY" disclaimer below
127  *    ("Disclaimer") and any redistribution must be conditioned upon
128  *    including a substantially similar Disclaimer requirement for further
129  *    binary redistribution.
130  * 3. Neither the names of the above-listed copyright holders nor the names
131  *    of any contributors may be used to endorse or promote products derived
132  *    from this software without specific prior written permission.
133  *
134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145  *
146  * Alternatively, you may choose to be licensed under the terms of the
147  * GNU General Public License ("GPL") version 2 as published by the Free
148  * Software Foundation.
149  *
150  *****************************************************************************/
151 
152 #include "aslcompiler.h"
153 #include "acapps.h"
154 #include "acdisasm.h"
155 
156 #define _COMPONENT          ACPI_COMPILER
157         ACPI_MODULE_NAME    ("asloption")
158 
159 
160 /* Local prototypes */
161 
162 static int
163 AslDoOptions (
164     int                     argc,
165     char                    **argv,
166     BOOLEAN                 IsResponseFile);
167 
168 static void
169 AslMergeOptionTokens (
170     char                    *InBuffer,
171     char                    *OutBuffer);
172 
173 static int
174 AslDoResponseFile (
175     char                    *Filename);
176 
177 
178 #define ASL_TOKEN_SEPARATORS    " \t\n"
179 #define ASL_SUPPORTED_OPTIONS   "@:a:b|c|d^D:e:f^gh^i|I:l^m:no|p:P^q^r:s|t|T+G^v^w|x:z"
180 
181 
182 /*******************************************************************************
183  *
184  * FUNCTION:    AslCommandLine
185  *
186  * PARAMETERS:  argc/argv
187  *
188  * RETURN:      Last argv index
189  *
190  * DESCRIPTION: Command line processing
191  *
192  ******************************************************************************/
193 
194 int
195 AslCommandLine (
196     int                     argc,
197     char                    **argv)
198 {
199     int                     BadCommandLine = 0;
200     ACPI_STATUS             Status;
201 
202 
203     /* Minimum command line contains at least the command and an input file */
204 
205     if (argc < 2)
206     {
207         Usage ();
208         exit (1);
209     }
210 
211     /* Process all command line options */
212 
213     BadCommandLine = AslDoOptions (argc, argv, FALSE);
214 
215     if (AslGbl_DoTemplates)
216     {
217         Status = DtCreateTemplates (argv);
218         if (ACPI_FAILURE (Status))
219         {
220             exit (-1);
221         }
222         exit (0);
223     }
224 
225     /* Next parameter must be the input filename */
226 
227     if (!argv[AcpiGbl_Optind] &&
228         !AcpiGbl_DisasmFlag)
229     {
230         printf ("Missing input filename\n");
231         BadCommandLine = TRUE;
232     }
233 
234     if (AslGbl_DoSignon)
235     {
236         printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
237         if (AslGbl_IgnoreErrors)
238         {
239             printf ("Ignoring all errors, forcing AML file generation\n\n");
240         }
241     }
242 
243     if (BadCommandLine)
244     {
245         printf ("Use -h option for help information\n");
246         exit (1);
247     }
248 
249     return (AcpiGbl_Optind);
250 }
251 
252 
253 /*******************************************************************************
254  *
255  * FUNCTION:    AslDoOptions
256  *
257  * PARAMETERS:  argc/argv           - Standard argc/argv
258  *              IsResponseFile      - TRUE if executing a response file.
259  *
260  * RETURN:      Status
261  *
262  * DESCRIPTION: Command line option processing
263  *
264  ******************************************************************************/
265 
266 static int
267 AslDoOptions (
268     int                     argc,
269     char                    **argv,
270     BOOLEAN                 IsResponseFile)
271 {
272     ACPI_STATUS             Status;
273     UINT32                  j;
274 
275 
276     /* Get the command line options */
277 
278     while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch (j)
279     {
280     case '@':   /* Begin a response file */
281 
282         if (IsResponseFile)
283         {
284             printf ("Nested command files are not supported\n");
285             return (-1);
286         }
287 
288         if (AslDoResponseFile (AcpiGbl_Optarg))
289         {
290             return (-1);
291         }
292         break;
293 
294     case 'a':   /* Debug options */
295 
296         switch (AcpiGbl_Optarg[0])
297         {
298         case 'r':
299 
300             AslGbl_EnableReferenceTypechecking = TRUE;
301             break;
302 
303         default:
304 
305             printf ("Unknown option: -a%s\n", AcpiGbl_Optarg);
306             return (-1);
307         }
308 
309         break;
310 
311 
312     case 'b':   /* Debug options */
313 
314         switch (AcpiGbl_Optarg[0])
315         {
316 
317         case 'c':
318 
319             printf ("Debug ASL to ASL+ conversion\n");
320 
321             AslGbl_DoAslConversion = TRUE;
322             AslGbl_FoldConstants = FALSE;
323             AslGbl_IntegerOptimizationFlag = FALSE;
324             AslGbl_ReferenceOptimizationFlag = FALSE;
325             AslGbl_OptimizeTrivialParseNodes = FALSE;
326             AcpiGbl_CaptureComments = TRUE;
327             AcpiGbl_DoDisassemblerOptimizations = FALSE;
328             AcpiGbl_DebugAslConversion = TRUE;
329             AcpiGbl_DmEmitExternalOpcodes = TRUE;
330             AslGbl_DoExternalsInPlace = TRUE;
331 
332             return (0);
333 
334         case 'f':
335 
336             AslCompilerdebug = 1; /* same as yydebug */
337             DtParserdebug = 1;
338             PrParserdebug = 1;
339             AslGbl_DebugFlag = TRUE;
340             AslGbl_KeepPreprocessorTempFile = TRUE;
341             break;
342 
343         case 'p':   /* Prune ASL parse tree */
344 
345             /* Get the required argument */
346 
347             if (AcpiGetoptArgument (argc, argv))
348             {
349                 return (-1);
350             }
351 
352             AslGbl_PruneParseTree = TRUE;
353             AslGbl_PruneDepth = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
354             break;
355 
356         case 's':
357 
358             AslGbl_DebugFlag = TRUE;
359             break;
360 
361         case 't':
362 
363             /* Get the required argument */
364 
365             if (AcpiGetoptArgument (argc, argv))
366             {
367                 return (-1);
368             }
369 
370             AslGbl_PruneType = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
371             break;
372 
373         default:
374 
375             printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
376             return (-1);
377         }
378 
379         break;
380 
381     case 'c':
382 
383         switch (AcpiGbl_Optarg[0])
384         {
385 
386         case 'a':
387 
388             printf ("Convert ASL to ASL+ with comments\n");
389             AslGbl_DoAslConversion = TRUE;
390             AslGbl_FoldConstants = FALSE;
391             AslGbl_IntegerOptimizationFlag = FALSE;
392             AslGbl_ReferenceOptimizationFlag = FALSE;
393             AslGbl_OptimizeTrivialParseNodes = FALSE;
394             AcpiGbl_CaptureComments = TRUE;
395             AcpiGbl_DoDisassemblerOptimizations = FALSE;
396             AcpiGbl_DmEmitExternalOpcodes = TRUE;
397             AslGbl_DoExternalsInPlace = TRUE;
398 
399             return (0);
400 
401         case 'r':
402 
403             AslGbl_NoResourceChecking = TRUE;
404             break;
405 
406         default:
407 
408             printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
409             return (-1);
410         }
411         break;
412 
413     case 'd':   /* Disassembler */
414 
415         switch (AcpiGbl_Optarg[0])
416         {
417         case '^':
418 
419             AslGbl_DoCompile = FALSE;
420             break;
421 
422         case 'a':
423 
424             AslGbl_DoCompile = FALSE;
425             AslGbl_DisassembleAll = TRUE;
426             break;
427 
428         case 'b':   /* Do not convert buffers to resource descriptors */
429 
430             AcpiGbl_NoResourceDisassembly = TRUE;
431             break;
432 
433         case 'c':
434 
435             break;
436 
437         case 'f':
438 
439             AcpiGbl_ForceAmlDisassembly = TRUE;
440             break;
441 
442         case 'l':   /* Use legacy ASL code (not ASL+) for disassembly */
443 
444             AslGbl_DoCompile = FALSE;
445             AcpiGbl_CstyleDisassembly = FALSE;
446             break;
447 
448         default:
449 
450             printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
451             return (-1);
452         }
453 
454         AcpiGbl_DisasmFlag = TRUE;
455         break;
456 
457     case 'D':   /* Define a symbol */
458 
459         PrAddDefine (AcpiGbl_Optarg, NULL, TRUE);
460         break;
461 
462     case 'e':   /* External files for disassembler */
463 
464         /* Get entire list of external files */
465 
466         AcpiGbl_Optind--;
467         argv[AcpiGbl_Optind] = AcpiGbl_Optarg;
468 
469         while (argv[AcpiGbl_Optind] &&
470               (argv[AcpiGbl_Optind][0] != '-'))
471         {
472             Status = AcpiDmAddToExternalFileList (argv[AcpiGbl_Optind]);
473             if (ACPI_FAILURE (Status))
474             {
475                 printf ("Could not add %s to external list\n",
476                     argv[AcpiGbl_Optind]);
477                 return (-1);
478             }
479 
480             AcpiGbl_Optind++;
481         }
482         break;
483 
484     case 'f':
485 
486         switch (AcpiGbl_Optarg[0])
487         {
488         case '^':   /* Ignore errors and force creation of aml file */
489 
490             AslGbl_IgnoreErrors = TRUE;
491             break;
492 
493         case 'e':   /* Disassembler: Get external declaration file */
494 
495             if (AcpiGetoptArgument (argc, argv))
496             {
497                 return (-1);
498             }
499 
500             AslGbl_ExternalRefFilename = AcpiGbl_Optarg;
501             break;
502 
503         default:
504 
505             printf ("Unknown option: -f%s\n", AcpiGbl_Optarg);
506             return (-1);
507         }
508         break;
509 
510     case 'G':
511 
512         AslGbl_CompileGeneric = TRUE;
513         break;
514 
515     case 'g':   /* Get all ACPI tables */
516 
517         printf ("-g option is deprecated, use acpidump utility instead\n");
518         exit (1);
519 
520     case 'h':
521 
522         switch (AcpiGbl_Optarg[0])
523         {
524         case '^':
525 
526             Usage ();
527             exit (0);
528 
529         case 'c':
530 
531             UtDisplayConstantOpcodes ();
532             exit (0);
533 
534         case 'd':
535 
536             AslDisassemblyHelp ();
537             exit (0);
538 
539         case 'f':
540 
541             AslFilenameHelp ();
542             exit (0);
543 
544         case 'r':
545 
546             /* reserved names */
547 
548             ApDisplayReservedNames ();
549             exit (0);
550 
551         case 't':
552 
553             UtDisplaySupportedTables ();
554             exit (0);
555 
556         default:
557 
558             printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
559             return (-1);
560         }
561 
562     case 'I':   /* Add an include file search directory */
563 
564         FlAddIncludeDirectory (AcpiGbl_Optarg);
565         break;
566 
567     case 'i':   /* Output AML as an include file */
568 
569         switch (AcpiGbl_Optarg[0])
570         {
571         case 'a':
572 
573             /* Produce assembly code include file */
574 
575             AslGbl_AsmIncludeOutputFlag = TRUE;
576             break;
577 
578         case 'c':
579 
580             /* Produce C include file */
581 
582             AslGbl_C_IncludeOutputFlag = TRUE;
583             break;
584 
585         case 'n':
586 
587             /* Compiler/Disassembler: Ignore the NOOP operator */
588 
589             AcpiGbl_IgnoreNoopOperator = TRUE;
590             break;
591 
592         default:
593 
594             printf ("Unknown option: -i%s\n", AcpiGbl_Optarg);
595             return (-1);
596         }
597         break;
598 
599     case 'l':   /* Listing files */
600 
601         switch (AcpiGbl_Optarg[0])
602         {
603         case '^':
604 
605             /* Produce listing file (Mixed source/aml) */
606 
607             AslGbl_ListingFlag = TRUE;
608             AcpiGbl_DmOpt_Listing = TRUE;
609             break;
610 
611         case 'i':
612 
613             /* Produce preprocessor output file */
614 
615             AslGbl_PreprocessorOutputFlag = TRUE;
616             break;
617 
618         case 'm':
619 
620             /* Produce hardware map summary file */
621 
622             AslGbl_MapfileFlag = TRUE;
623             break;
624 
625         case 'n':
626 
627             /* Produce namespace file */
628 
629             AslGbl_NsOutputFlag = TRUE;
630             break;
631 
632         case 's':
633 
634             /* Produce combined source file */
635 
636             AslGbl_SourceOutputFlag = TRUE;
637             break;
638 
639         case 'x':
640 
641             /* Produce cross-reference file */
642 
643             AslGbl_CrossReferenceOutput = TRUE;
644             break;
645 
646         default:
647 
648             printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
649             return (-1);
650         }
651         break;
652 
653     case 'm':   /* Set line buffer size */
654 
655         AslGbl_LineBufferSize = (UINT32) strtoul (AcpiGbl_Optarg, NULL, 0) * 1024;
656         if (AslGbl_LineBufferSize < ASL_DEFAULT_LINE_BUFFER_SIZE)
657         {
658             AslGbl_LineBufferSize = ASL_DEFAULT_LINE_BUFFER_SIZE;
659         }
660         printf ("Line Buffer Size: %u\n", AslGbl_LineBufferSize);
661         break;
662 
663     case 'n':   /* Parse only */
664 
665         AslGbl_ParseOnlyFlag = TRUE;
666         break;
667 
668     case 'o':   /* Control compiler AML optimizations */
669 
670         switch (AcpiGbl_Optarg[0])
671         {
672         case 'a':
673 
674             /* Disable all optimizations */
675 
676             AslGbl_FoldConstants = FALSE;
677             AslGbl_IntegerOptimizationFlag = FALSE;
678             AslGbl_ReferenceOptimizationFlag = FALSE;
679             AslGbl_OptimizeTrivialParseNodes = FALSE;
680 
681             break;
682 
683         case 'c':
684 
685             /* Display compile time(s) */
686 
687             AslGbl_CompileTimesFlag = TRUE;
688             break;
689 
690         case 'd':
691 
692             /* Disable disassembler code optimizations */
693 
694             AcpiGbl_DoDisassemblerOptimizations = FALSE;
695             break;
696 
697         case 'e':
698 
699             /* Disassembler: Emit embedded external operators */
700 
701             AcpiGbl_DmEmitExternalOpcodes = TRUE;
702             break;
703 
704         case 'E':
705 
706             /*
707              * iASL: keep External opcodes in place.
708              * No affect if Gbl_DoExternals is false.
709              */
710 
711             AslGbl_DoExternalsInPlace = TRUE;
712             break;
713 
714         case 'f':
715 
716             /* Disable folding on "normal" expressions */
717 
718             AslGbl_FoldConstants = FALSE;
719             break;
720 
721         case 'i':
722 
723             /* Disable integer optimization to constants */
724 
725             AslGbl_IntegerOptimizationFlag = FALSE;
726             break;
727 
728         case 'n':
729 
730             /* Disable named reference optimization */
731 
732             AslGbl_ReferenceOptimizationFlag = FALSE;
733             break;
734 
735         case 't':
736 
737             /* Disable heavy typechecking */
738 
739             AslGbl_DoTypechecking = FALSE;
740             break;
741 
742         default:
743 
744             printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
745             return (-1);
746         }
747         break;
748 
749     case 'P':   /* Preprocessor options */
750 
751         switch (AcpiGbl_Optarg[0])
752         {
753         case '^':   /* Proprocess only, emit (.i) file */
754 
755             AslGbl_PreprocessOnly = TRUE;
756             AslGbl_PreprocessorOutputFlag = TRUE;
757             break;
758 
759         case 'n':   /* Disable preprocessor */
760 
761             AslGbl_PreprocessFlag = FALSE;
762             break;
763 
764         default:
765 
766             printf ("Unknown option: -P%s\n", AcpiGbl_Optarg);
767             return (-1);
768         }
769         break;
770 
771     case 'p':   /* Override default AML output filename */
772 
773         AslGbl_OutputFilenamePrefix = AcpiGbl_Optarg;
774         UtConvertBackslashes (AslGbl_OutputFilenamePrefix);
775         AslGbl_UseDefaultAmlFilename = FALSE;
776         break;
777 
778     case 'q':   /* ASL/ASl+ converter: compile only and leave badaml. */
779 
780         printf ("Convert ASL to ASL+ with comments\n");
781         AslGbl_FoldConstants = FALSE;
782         AslGbl_IntegerOptimizationFlag = FALSE;
783         AslGbl_ReferenceOptimizationFlag = FALSE;
784         AslGbl_OptimizeTrivialParseNodes = FALSE;
785         AslGbl_DoExternalsInPlace = TRUE;
786         AcpiGbl_CaptureComments = TRUE;
787         return (0);
788 
789     case 'r':   /* Override revision found in table header */
790 
791         AslGbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
792         break;
793 
794     case 's':   /* Create AML in a source code file */
795 
796         switch (AcpiGbl_Optarg[0])
797         {
798         case 'a':
799 
800             /* Produce assembly code output file */
801 
802             AslGbl_AsmOutputFlag = TRUE;
803             break;
804 
805         case 'c':
806 
807             /* Produce C hex output file */
808 
809             AslGbl_C_OutputFlag = TRUE;
810             break;
811 
812         case 'o':
813 
814             /* Produce AML offset table in C */
815 
816             AslGbl_C_OffsetTableFlag = TRUE;
817             break;
818 
819         default:
820 
821             printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
822             return (-1);
823         }
824         break;
825 
826     case 't':   /* Produce hex table output file */
827 
828         switch (AcpiGbl_Optarg[0])
829         {
830         case 'a':
831 
832             AslGbl_HexOutputFlag = HEX_OUTPUT_ASM;
833             break;
834 
835         case 'c':
836 
837             AslGbl_HexOutputFlag = HEX_OUTPUT_C;
838             break;
839 
840     case 'p': /* data table flex/bison prototype */
841 
842             AslGbl_DtLexBisonPrototype = TRUE;
843             break;
844 
845         case 's':
846 
847             AslGbl_HexOutputFlag = HEX_OUTPUT_ASL;
848             break;
849 
850         default:
851 
852             printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
853             return (-1);
854         }
855         break;
856 
857     case 'T':   /* Create a ACPI table template file */
858 
859         AslGbl_DoTemplates = TRUE;
860         break;
861 
862     case 'v':   /* Version and verbosity settings */
863 
864         switch (AcpiGbl_Optarg[0])
865         {
866         case '^':
867 
868             printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
869             exit (0);
870 
871         case 'a':
872 
873             /* Disable all error/warning/remark messages */
874 
875             AslGbl_NoErrors = TRUE;
876             break;
877 
878         case 'd':
879 
880             printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
881             printf (ACPI_COMMON_BUILD_TIME);
882             exit (0);
883 
884         case 'e':
885 
886             /* Disable all warning/remark messages (errors only) */
887 
888             AslGbl_DisplayRemarks = FALSE;
889             AslGbl_DisplayWarnings = FALSE;
890             break;
891 
892         case 'i':
893             /*
894              * Support for integrated development environment(s).
895              *
896              * 1) No compiler signon
897              * 2) Send stderr messages to stdout
898              * 3) Less verbose error messages (single line only for each)
899              * 4) Error/warning messages are formatted appropriately to
900              *    be recognized by MS Visual Studio
901              */
902             AslGbl_VerboseErrors = FALSE;
903             AslGbl_DoSignon = FALSE;
904             break;
905 
906         case 'o':
907 
908             AslGbl_DisplayOptimizations = TRUE;
909             break;
910 
911         case 'r':
912 
913             AslGbl_DisplayRemarks = FALSE;
914             break;
915 
916         case 's':
917 
918             AslGbl_DoSignon = FALSE;
919             break;
920 
921         case 't':
922 
923             AslGbl_VerboseTemplates = TRUE;
924             break;
925 
926         case 'w':
927 
928             /* Get the required argument */
929 
930             if (AcpiGetoptArgument (argc, argv))
931             {
932                 return (-1);
933             }
934 
935             Status = AslDisableException (AcpiGbl_Optarg);
936             if (ACPI_FAILURE (Status))
937             {
938                 return (-1);
939             }
940             break;
941 
942         case 'x':
943 
944             /* Get the required argument */
945 
946             if (AcpiGetoptArgument (argc, argv))
947             {
948                 return (-1);
949             }
950 
951             Status = AslLogExpectedException (AcpiGbl_Optarg);
952             if (ACPI_FAILURE (Status))
953             {
954                 return (-1);
955             }
956             break;
957 
958         default:
959 
960             printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
961             return (-1);
962         }
963         break;
964 
965     case 'w': /* Set warning levels */
966 
967         switch (AcpiGbl_Optarg[0])
968         {
969         case '1':
970 
971             AslGbl_WarningLevel = ASL_WARNING;
972             break;
973 
974         case '2':
975 
976             AslGbl_WarningLevel = ASL_WARNING2;
977             break;
978 
979         case '3':
980 
981             AslGbl_WarningLevel = ASL_WARNING3;
982             break;
983 
984         case 'e':
985 
986             AslGbl_WarningsAsErrors = TRUE;
987             break;
988 
989         case 'w':
990 
991             /* Get the required argument */
992 
993             if (AcpiGetoptArgument (argc, argv))
994             {
995                 return (-1);
996             }
997 
998             Status = AslElevateException (AcpiGbl_Optarg);
999             if (ACPI_FAILURE (Status))
1000             {
1001                 return (-1);
1002             }
1003             break;
1004 
1005 
1006         default:
1007 
1008             printf ("Unknown option: -w%s\n", AcpiGbl_Optarg);
1009             return (-1);
1010         }
1011         break;
1012 
1013     case 'x':   /* Set debug print output level */
1014 
1015         AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
1016         break;
1017 
1018     case 'z':
1019 
1020         AslGbl_UseOriginalCompilerId = TRUE;
1021         break;
1022 
1023     default:
1024 
1025         return (-1);
1026     }
1027 
1028     return (0);
1029 }
1030 
1031 
1032 /*******************************************************************************
1033  *
1034  * FUNCTION:    AslMergeOptionTokens
1035  *
1036  * PARAMETERS:  InBuffer            - Input containing an option string
1037  *              OutBuffer           - Merged output buffer
1038  *
1039  * RETURN:      None
1040  *
1041  * DESCRIPTION: Remove all whitespace from an option string.
1042  *
1043  ******************************************************************************/
1044 
1045 static void
1046 AslMergeOptionTokens (
1047     char                    *InBuffer,
1048     char                    *OutBuffer)
1049 {
1050     char                    *Token;
1051 
1052 
1053     *OutBuffer = 0;
1054 
1055     Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS);
1056     while (Token)
1057     {
1058         strcat (OutBuffer, Token);
1059         Token = strtok (NULL, ASL_TOKEN_SEPARATORS);
1060     }
1061 }
1062 
1063 
1064 /*******************************************************************************
1065  *
1066  * FUNCTION:    AslDoResponseFile
1067  *
1068  * PARAMETERS:  Filename        - Name of the response file
1069  *
1070  * RETURN:      Status
1071  *
1072  * DESCRIPTION: Open a response file and process all options within.
1073  *
1074  ******************************************************************************/
1075 
1076 static int
1077 AslDoResponseFile (
1078     char                    *Filename)
1079 {
1080     char                    *argv = AslGbl_StringBuffer2;
1081     FILE                    *ResponseFile;
1082     int                     OptStatus = 0;
1083     int                     Opterr;
1084     int                     Optind;
1085 
1086 
1087     ResponseFile = fopen (Filename, "r");
1088     if (!ResponseFile)
1089     {
1090         printf ("Could not open command file %s, %s\n",
1091             Filename, strerror (errno));
1092         return (-1);
1093     }
1094 
1095     /* Must save the current GetOpt globals */
1096 
1097     Opterr = AcpiGbl_Opterr;
1098     Optind = AcpiGbl_Optind;
1099 
1100     /*
1101      * Process all lines in the response file. There must be one complete
1102      * option per line
1103      */
1104     while (fgets (AslGbl_StringBuffer, ASL_STRING_BUFFER_SIZE, ResponseFile))
1105     {
1106         /* Compress all tokens, allowing us to use a single argv entry */
1107 
1108         AslMergeOptionTokens (AslGbl_StringBuffer, AslGbl_StringBuffer2);
1109 
1110         /* Process the option */
1111 
1112         AcpiGbl_Opterr = 0;
1113         AcpiGbl_Optind = 0;
1114 
1115         OptStatus = AslDoOptions (1, &argv, TRUE);
1116         if (OptStatus)
1117         {
1118             printf ("Invalid option in command file %s: %s\n",
1119                 Filename, AslGbl_StringBuffer);
1120             break;
1121         }
1122     }
1123 
1124     /* Restore the GetOpt globals */
1125 
1126     AcpiGbl_Opterr = Opterr;
1127     AcpiGbl_Optind = Optind;
1128 
1129     fclose (ResponseFile);
1130     return (OptStatus);
1131 }
1132