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