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 - 2017, 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 static char ASL_BUILD_DATE[] = __DATE__;
182 static char ASL_BUILD_TIME[] = __TIME__;
183 
184 
185 /*******************************************************************************
186  *
187  * FUNCTION:    AslCommandLine
188  *
189  * PARAMETERS:  argc/argv
190  *
191  * RETURN:      Last argv index
192  *
193  * DESCRIPTION: Command line processing
194  *
195  ******************************************************************************/
196 
197 int
198 AslCommandLine (
199     int                     argc,
200     char                    **argv)
201 {
202     int                     BadCommandLine = 0;
203     ACPI_STATUS             Status;
204 
205 
206     /* Minimum command line contains at least the command and an input file */
207 
208     if (argc < 2)
209     {
210         printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
211         Usage ();
212         exit (1);
213     }
214 
215     /* Process all command line options */
216 
217     BadCommandLine = AslDoOptions (argc, argv, FALSE);
218 
219     if (Gbl_DoTemplates)
220     {
221         Status = DtCreateTemplates (argv);
222         if (ACPI_FAILURE (Status))
223         {
224             exit (-1);
225         }
226         exit (1);
227     }
228 
229     /* Next parameter must be the input filename */
230 
231     if (!argv[AcpiGbl_Optind] &&
232         !AcpiGbl_DisasmFlag)
233     {
234         printf ("Missing input filename\n");
235         BadCommandLine = TRUE;
236     }
237 
238     if (Gbl_DoSignon)
239     {
240         printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
241         if (Gbl_IgnoreErrors)
242         {
243             printf ("Ignoring all errors, forcing AML file generation\n\n");
244         }
245     }
246 
247     if (BadCommandLine)
248     {
249         printf ("Use -h option for help information\n");
250         exit (1);
251     }
252 
253     return (AcpiGbl_Optind);
254 }
255 
256 
257 /*******************************************************************************
258  *
259  * FUNCTION:    AslDoOptions
260  *
261  * PARAMETERS:  argc/argv           - Standard argc/argv
262  *              IsResponseFile      - TRUE if executing a response file.
263  *
264  * RETURN:      Status
265  *
266  * DESCRIPTION: Command line option processing
267  *
268  ******************************************************************************/
269 
270 static int
271 AslDoOptions (
272     int                     argc,
273     char                    **argv,
274     BOOLEAN                 IsResponseFile)
275 {
276     ACPI_STATUS             Status;
277     UINT32                  j;
278 
279 
280     /* Get the command line options */
281 
282     while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch (j)
283     {
284     case '@':   /* Begin a response file */
285 
286         if (IsResponseFile)
287         {
288             printf ("Nested command files are not supported\n");
289             return (-1);
290         }
291 
292         if (AslDoResponseFile (AcpiGbl_Optarg))
293         {
294             return (-1);
295         }
296         break;
297 
298     case 'a':   /* Debug options */
299 
300         switch (AcpiGbl_Optarg[0])
301         {
302         case 'r':
303 
304             Gbl_EnableReferenceTypechecking = TRUE;
305             break;
306 
307         default:
308 
309             printf ("Unknown option: -a%s\n", AcpiGbl_Optarg);
310             return (-1);
311         }
312 
313         break;
314 
315 
316     case 'b':   /* Debug options */
317 
318         switch (AcpiGbl_Optarg[0])
319         {
320 
321         case 'c':
322 
323             printf ("Debug ASL to ASL+ conversion\n");
324 
325             Gbl_DoAslConversion = TRUE;
326             Gbl_FoldConstants = FALSE;
327             Gbl_IntegerOptimizationFlag = FALSE;
328             Gbl_ReferenceOptimizationFlag = FALSE;
329             Gbl_OptimizeTrivialParseNodes = FALSE;
330             Gbl_CaptureComments = TRUE;
331             AcpiGbl_DoDisassemblerOptimizations = FALSE;
332             AcpiGbl_DebugAslConversion = TRUE;
333             AcpiGbl_DmEmitExternalOpcodes = TRUE;
334             Gbl_DoExternalsInPlace = TRUE;
335 
336             return (0);
337 
338         case 'f':
339 
340             AslCompilerdebug = 1; /* same as yydebug */
341             DtParserdebug = 1;
342             PrParserdebug = 1;
343             Gbl_DebugFlag = TRUE;
344             Gbl_KeepPreprocessorTempFile = TRUE;
345             break;
346 
347         case 'p':   /* Prune ASL parse tree */
348 
349             /* Get the required argument */
350 
351             if (AcpiGetoptArgument (argc, argv))
352             {
353                 return (-1);
354             }
355 
356             Gbl_PruneParseTree = TRUE;
357             Gbl_PruneDepth = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
358             break;
359 
360         case 's':
361 
362             Gbl_DebugFlag = TRUE;
363             break;
364 
365         case 't':
366 
367             /* Get the required argument */
368 
369             if (AcpiGetoptArgument (argc, argv))
370             {
371                 return (-1);
372             }
373 
374             Gbl_PruneType = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
375             break;
376 
377         default:
378 
379             printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
380             return (-1);
381         }
382 
383         break;
384 
385     case 'c':
386 
387         switch (AcpiGbl_Optarg[0])
388         {
389 
390         case 'a':
391 
392             printf ("Convert ASL to ASL+ with comments\n");
393             Gbl_DoAslConversion = TRUE;
394             Gbl_FoldConstants = FALSE;
395             Gbl_IntegerOptimizationFlag = FALSE;
396             Gbl_ReferenceOptimizationFlag = FALSE;
397             Gbl_OptimizeTrivialParseNodes = FALSE;
398             Gbl_CaptureComments = TRUE;
399             AcpiGbl_DoDisassemblerOptimizations = FALSE;
400             AcpiGbl_DmEmitExternalOpcodes = TRUE;
401             Gbl_DoExternalsInPlace = TRUE;
402 
403             return (0);
404 
405         case 'r':
406 
407             Gbl_NoResourceChecking = TRUE;
408             break;
409 
410         default:
411 
412             printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
413             return (-1);
414         }
415         break;
416 
417     case 'd':   /* Disassembler */
418 
419         switch (AcpiGbl_Optarg[0])
420         {
421         case '^':
422 
423             /* Get the required argument */
424 
425             if (AcpiGetoptArgument (argc, argv))
426             {
427                 return (-1);
428             }
429 
430             Gbl_DoCompile = FALSE;
431             break;
432 
433         case 'a':
434 
435             /* Get the required argument */
436 
437             if (AcpiGetoptArgument (argc, argv))
438             {
439                 return (-1);
440             }
441 
442             Gbl_DoCompile = FALSE;
443             Gbl_DisassembleAll = TRUE;
444             break;
445 
446         case 'b':   /* Do not convert buffers to resource descriptors */
447 
448             AcpiGbl_NoResourceDisassembly = TRUE;
449             break;
450 
451         case 'c':
452 
453             break;
454 
455         case 'f':
456 
457             AcpiGbl_ForceAmlDisassembly = TRUE;
458             break;
459 
460         case 'l':   /* Use legacy ASL code (not ASL+) for disassembly */
461 
462             Gbl_DoCompile = FALSE;
463             AcpiGbl_CstyleDisassembly = FALSE;
464             break;
465 
466         default:
467 
468             printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
469             return (-1);
470         }
471 
472         AcpiGbl_DisasmFlag = TRUE;
473         break;
474 
475     case 'D':   /* Define a symbol */
476 
477         PrAddDefine (AcpiGbl_Optarg, NULL, TRUE);
478         break;
479 
480     case 'e':   /* External files for disassembler */
481 
482         /* Get entire list of external files */
483 
484         AcpiGbl_Optind--;
485         argv[AcpiGbl_Optind] = AcpiGbl_Optarg;
486 
487         while (argv[AcpiGbl_Optind] &&
488               (argv[AcpiGbl_Optind][0] != '-'))
489         {
490             Status = AcpiDmAddToExternalFileList (argv[AcpiGbl_Optind]);
491             if (ACPI_FAILURE (Status))
492             {
493                 printf ("Could not add %s to external list\n",
494                     argv[AcpiGbl_Optind]);
495                 return (-1);
496             }
497 
498             AcpiGbl_Optind++;
499         }
500         break;
501 
502     case 'f':
503 
504         switch (AcpiGbl_Optarg[0])
505         {
506         case '^':   /* Ignore errors and force creation of aml file */
507 
508             Gbl_IgnoreErrors = TRUE;
509             break;
510 
511         case 'e':   /* Disassembler: Get external declaration file */
512 
513             if (AcpiGetoptArgument (argc, argv))
514             {
515                 return (-1);
516             }
517 
518             Gbl_ExternalRefFilename = AcpiGbl_Optarg;
519             break;
520 
521         default:
522 
523             printf ("Unknown option: -f%s\n", AcpiGbl_Optarg);
524             return (-1);
525         }
526         break;
527 
528     case 'G':
529 
530         Gbl_CompileGeneric = TRUE;
531         break;
532 
533     case 'g':   /* Get all ACPI tables */
534 
535         printf ("-g option is deprecated, use acpidump utility instead\n");
536         exit (1);
537 
538     case 'h':
539 
540         switch (AcpiGbl_Optarg[0])
541         {
542         case '^':
543 
544             printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
545             Usage ();
546             exit (0);
547 
548         case 'c':
549 
550             UtDisplayConstantOpcodes ();
551             exit (0);
552 
553         case 'd':
554 
555             AslDisassemblyHelp ();
556             exit (0);
557 
558         case 'f':
559 
560             AslFilenameHelp ();
561             exit (0);
562 
563         case 'r':
564 
565             /* reserved names */
566 
567             ApDisplayReservedNames ();
568             exit (0);
569 
570         case 't':
571 
572             UtDisplaySupportedTables ();
573             exit (0);
574 
575         default:
576 
577             printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
578             return (-1);
579         }
580 
581     case 'I':   /* Add an include file search directory */
582 
583         FlAddIncludeDirectory (AcpiGbl_Optarg);
584         break;
585 
586     case 'i':   /* Output AML as an include file */
587 
588         switch (AcpiGbl_Optarg[0])
589         {
590         case 'a':
591 
592             /* Produce assembly code include file */
593 
594             Gbl_AsmIncludeOutputFlag = TRUE;
595             break;
596 
597         case 'c':
598 
599             /* Produce C include file */
600 
601             Gbl_C_IncludeOutputFlag = TRUE;
602             break;
603 
604         case 'n':
605 
606             /* Compiler/Disassembler: Ignore the NOOP operator */
607 
608             AcpiGbl_IgnoreNoopOperator = TRUE;
609             break;
610 
611         default:
612 
613             printf ("Unknown option: -i%s\n", AcpiGbl_Optarg);
614             return (-1);
615         }
616         break;
617 
618     case 'l':   /* Listing files */
619 
620         switch (AcpiGbl_Optarg[0])
621         {
622         case '^':
623 
624             /* Produce listing file (Mixed source/aml) */
625 
626             Gbl_ListingFlag = TRUE;
627             AcpiGbl_DmOpt_Listing = TRUE;
628             break;
629 
630         case 'i':
631 
632             /* Produce preprocessor output file */
633 
634             Gbl_PreprocessorOutputFlag = TRUE;
635             break;
636 
637         case 'm':
638 
639             /* Produce hardware map summary file */
640 
641             Gbl_MapfileFlag = TRUE;
642             break;
643 
644         case 'n':
645 
646             /* Produce namespace file */
647 
648             Gbl_NsOutputFlag = TRUE;
649             break;
650 
651         case 's':
652 
653             /* Produce combined source file */
654 
655             Gbl_SourceOutputFlag = TRUE;
656             break;
657 
658         case 'x':
659 
660             /* Produce cross-reference file */
661 
662             Gbl_CrossReferenceOutput = TRUE;
663             break;
664 
665         default:
666 
667             printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
668             return (-1);
669         }
670         break;
671 
672     case 'm':   /* Set line buffer size */
673 
674         Gbl_LineBufferSize = (UINT32) strtoul (AcpiGbl_Optarg, NULL, 0) * 1024;
675         if (Gbl_LineBufferSize < ASL_DEFAULT_LINE_BUFFER_SIZE)
676         {
677             Gbl_LineBufferSize = ASL_DEFAULT_LINE_BUFFER_SIZE;
678         }
679         printf ("Line Buffer Size: %u\n", Gbl_LineBufferSize);
680         break;
681 
682     case 'n':   /* Parse only */
683 
684         Gbl_ParseOnlyFlag = TRUE;
685         break;
686 
687     case 'o':   /* Control compiler AML optimizations */
688 
689         switch (AcpiGbl_Optarg[0])
690         {
691         case 'a':
692 
693             /* Disable all optimizations */
694 
695             Gbl_FoldConstants = FALSE;
696             Gbl_IntegerOptimizationFlag = FALSE;
697             Gbl_ReferenceOptimizationFlag = FALSE;
698             Gbl_OptimizeTrivialParseNodes = FALSE;
699 
700             break;
701 
702         case 'c':
703 
704             /* Display compile time(s) */
705 
706             Gbl_CompileTimesFlag = TRUE;
707             break;
708 
709         case 'd':
710 
711             /* Disable disassembler code optimizations */
712 
713             AcpiGbl_DoDisassemblerOptimizations = FALSE;
714             break;
715 
716         case 'e':
717 
718             /* Disassembler: Emit embedded external operators */
719 
720             AcpiGbl_DmEmitExternalOpcodes = TRUE;
721             break;
722 
723         case 'E':
724 
725             /*
726              * iASL: keep External opcodes in place.
727              * No affect if Gbl_DoExternals is false.
728              */
729 
730             Gbl_DoExternalsInPlace = TRUE;
731             break;
732 
733         case 'f':
734 
735             /* Disable folding on "normal" expressions */
736 
737             Gbl_FoldConstants = FALSE;
738             break;
739 
740         case 'i':
741 
742             /* Disable integer optimization to constants */
743 
744             Gbl_IntegerOptimizationFlag = FALSE;
745             break;
746 
747         case 'n':
748 
749             /* Disable named reference optimization */
750 
751             Gbl_ReferenceOptimizationFlag = FALSE;
752             break;
753 
754         case 't':
755 
756             /* Disable heavy typechecking */
757 
758             Gbl_DoTypechecking = FALSE;
759             break;
760 
761         default:
762 
763             printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
764             return (-1);
765         }
766         break;
767 
768     case 'P':   /* Preprocessor options */
769 
770         switch (AcpiGbl_Optarg[0])
771         {
772         case '^':   /* Proprocess only, emit (.i) file */
773 
774             Gbl_PreprocessOnly = TRUE;
775             Gbl_PreprocessorOutputFlag = TRUE;
776             break;
777 
778         case 'n':   /* Disable preprocessor */
779 
780             Gbl_PreprocessFlag = FALSE;
781             break;
782 
783         default:
784 
785             printf ("Unknown option: -P%s\n", AcpiGbl_Optarg);
786             return (-1);
787         }
788         break;
789 
790     case 'p':   /* Override default AML output filename */
791 
792         Gbl_OutputFilenamePrefix = AcpiGbl_Optarg;
793         UtConvertBackslashes (Gbl_OutputFilenamePrefix);
794         Gbl_UseDefaultAmlFilename = FALSE;
795         break;
796 
797     case 'q':   /* ASL/ASl+ converter: compile only and leave badaml. */
798 
799         printf ("Convert ASL to ASL+ with comments\n");
800         Gbl_FoldConstants = FALSE;
801         Gbl_IntegerOptimizationFlag = FALSE;
802         Gbl_ReferenceOptimizationFlag = FALSE;
803         Gbl_OptimizeTrivialParseNodes = FALSE;
804         Gbl_CaptureComments = TRUE;
805         Gbl_DoExternalsInPlace = TRUE;
806         return (0);
807 
808     case 'r':   /* Override revision found in table header */
809 
810         Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
811         break;
812 
813     case 's':   /* Create AML in a source code file */
814 
815         switch (AcpiGbl_Optarg[0])
816         {
817         case 'a':
818 
819             /* Produce assembly code output file */
820 
821             Gbl_AsmOutputFlag = TRUE;
822             break;
823 
824         case 'c':
825 
826             /* Produce C hex output file */
827 
828             Gbl_C_OutputFlag = TRUE;
829             break;
830 
831         case 'o':
832 
833             /* Produce AML offset table in C */
834 
835             Gbl_C_OffsetTableFlag = TRUE;
836             break;
837 
838         default:
839 
840             printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
841             return (-1);
842         }
843         break;
844 
845     case 't':   /* Produce hex table output file */
846 
847         switch (AcpiGbl_Optarg[0])
848         {
849         case 'a':
850 
851             Gbl_HexOutputFlag = HEX_OUTPUT_ASM;
852             break;
853 
854         case 'c':
855 
856             Gbl_HexOutputFlag = HEX_OUTPUT_C;
857             break;
858 
859         case 's':
860 
861             Gbl_HexOutputFlag = HEX_OUTPUT_ASL;
862             break;
863 
864         default:
865 
866             printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
867             return (-1);
868         }
869         break;
870 
871     case 'T':   /* Create a ACPI table template file */
872 
873         Gbl_DoTemplates = TRUE;
874         break;
875 
876     case 'v':   /* Version and verbosity settings */
877 
878         switch (AcpiGbl_Optarg[0])
879         {
880         case '^':
881 
882             printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
883             exit (0);
884 
885         case 'a':
886 
887             /* Disable all error/warning/remark messages */
888 
889             Gbl_NoErrors = TRUE;
890             break;
891 
892         case 'd':
893 
894             printf ("%s Build date/time: %s %s\n",
895                 ASL_COMPILER_NAME, ASL_BUILD_DATE, ASL_BUILD_TIME);
896             exit (0);
897 
898         case 'e':
899 
900             /* Disable all warning/remark messages (errors only) */
901 
902             Gbl_DisplayRemarks = FALSE;
903             Gbl_DisplayWarnings = FALSE;
904             break;
905 
906         case 'i':
907             /*
908              * Support for integrated development environment(s).
909              *
910              * 1) No compiler signon
911              * 2) Send stderr messages to stdout
912              * 3) Less verbose error messages (single line only for each)
913              * 4) Error/warning messages are formatted appropriately to
914              *    be recognized by MS Visual Studio
915              */
916             Gbl_VerboseErrors = FALSE;
917             Gbl_DoSignon = FALSE;
918             Gbl_Files[ASL_FILE_STDERR].Handle = stdout;
919             break;
920 
921         case 'o':
922 
923             Gbl_DisplayOptimizations = TRUE;
924             break;
925 
926         case 'r':
927 
928             Gbl_DisplayRemarks = FALSE;
929             break;
930 
931         case 's':
932 
933             Gbl_DoSignon = FALSE;
934             break;
935 
936         case 't':
937 
938             Gbl_VerboseTemplates = TRUE;
939             break;
940 
941         case 'w':
942 
943             /* Get the required argument */
944 
945             if (AcpiGetoptArgument (argc, argv))
946             {
947                 return (-1);
948             }
949 
950             Status = AslDisableException (AcpiGbl_Optarg);
951             if (ACPI_FAILURE (Status))
952             {
953                 return (-1);
954             }
955             break;
956 
957         case 'x':
958 
959             /* Get the required argument */
960 
961             if (AcpiGetoptArgument (argc, argv))
962             {
963                 return (-1);
964             }
965 
966             Status = AslExpectException (AcpiGbl_Optarg);
967             if (ACPI_FAILURE (Status))
968             {
969                 return (-1);
970             }
971             break;
972 
973         default:
974 
975             printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
976             return (-1);
977         }
978         break;
979 
980     case 'w': /* Set warning levels */
981 
982         switch (AcpiGbl_Optarg[0])
983         {
984         case '1':
985 
986             Gbl_WarningLevel = ASL_WARNING;
987             break;
988 
989         case '2':
990 
991             Gbl_WarningLevel = ASL_WARNING2;
992             break;
993 
994         case '3':
995 
996             Gbl_WarningLevel = ASL_WARNING3;
997             break;
998 
999         case 'e':
1000 
1001             Gbl_WarningsAsErrors = TRUE;
1002             break;
1003 
1004         default:
1005 
1006             printf ("Unknown option: -w%s\n", AcpiGbl_Optarg);
1007             return (-1);
1008         }
1009         break;
1010 
1011     case 'x':   /* Set debug print output level */
1012 
1013         AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
1014         break;
1015 
1016     case 'z':
1017 
1018         Gbl_UseOriginalCompilerId = TRUE;
1019         break;
1020 
1021     default:
1022 
1023         return (-1);
1024     }
1025 
1026     return (0);
1027 }
1028 
1029 
1030 /*******************************************************************************
1031  *
1032  * FUNCTION:    AslMergeOptionTokens
1033  *
1034  * PARAMETERS:  InBuffer            - Input containing an option string
1035  *              OutBuffer           - Merged output buffer
1036  *
1037  * RETURN:      None
1038  *
1039  * DESCRIPTION: Remove all whitespace from an option string.
1040  *
1041  ******************************************************************************/
1042 
1043 static void
1044 AslMergeOptionTokens (
1045     char                    *InBuffer,
1046     char                    *OutBuffer)
1047 {
1048     char                    *Token;
1049 
1050 
1051     *OutBuffer = 0;
1052 
1053     Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS);
1054     while (Token)
1055     {
1056         strcat (OutBuffer, Token);
1057         Token = strtok (NULL, ASL_TOKEN_SEPARATORS);
1058     }
1059 }
1060 
1061 
1062 /*******************************************************************************
1063  *
1064  * FUNCTION:    AslDoResponseFile
1065  *
1066  * PARAMETERS:  Filename        - Name of the response file
1067  *
1068  * RETURN:      Status
1069  *
1070  * DESCRIPTION: Open a response file and process all options within.
1071  *
1072  ******************************************************************************/
1073 
1074 static int
1075 AslDoResponseFile (
1076     char                    *Filename)
1077 {
1078     char                    *argv = StringBuffer2;
1079     FILE                    *ResponseFile;
1080     int                     OptStatus = 0;
1081     int                     Opterr;
1082     int                     Optind;
1083 
1084 
1085     ResponseFile = fopen (Filename, "r");
1086     if (!ResponseFile)
1087     {
1088         printf ("Could not open command file %s, %s\n",
1089             Filename, strerror (errno));
1090         return (-1);
1091     }
1092 
1093     /* Must save the current GetOpt globals */
1094 
1095     Opterr = AcpiGbl_Opterr;
1096     Optind = AcpiGbl_Optind;
1097 
1098     /*
1099      * Process all lines in the response file. There must be one complete
1100      * option per line
1101      */
1102     while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ResponseFile))
1103     {
1104         /* Compress all tokens, allowing us to use a single argv entry */
1105 
1106         AslMergeOptionTokens (StringBuffer, StringBuffer2);
1107 
1108         /* Process the option */
1109 
1110         AcpiGbl_Opterr = 0;
1111         AcpiGbl_Optind = 0;
1112 
1113         OptStatus = AslDoOptions (1, &argv, TRUE);
1114         if (OptStatus)
1115         {
1116             printf ("Invalid option in command file %s: %s\n",
1117                 Filename, StringBuffer);
1118             break;
1119         }
1120     }
1121 
1122     /* Restore the GetOpt globals */
1123 
1124     AcpiGbl_Opterr = Opterr;
1125     AcpiGbl_Optind = Optind;
1126 
1127     fclose (ResponseFile);
1128     return (OptStatus);
1129 }
1130