xref: /freebsd/sys/contrib/dev/acpica/compiler/aslfiles.c (revision aa64588d28258aef88cc33b8043112e8856948d0)
1 
2 /******************************************************************************
3  *
4  * Module Name: aslfiles - file I/O suppoert
5  *
6  *****************************************************************************/
7 
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
13  * All rights reserved.
14  *
15  * 2. License
16  *
17  * 2.1. This is your license from Intel Corp. under its intellectual property
18  * rights.  You may have additional license terms from the party that provided
19  * you this software, covering your right to use that party's intellectual
20  * property rights.
21  *
22  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23  * copy of the source code appearing in this file ("Covered Code") an
24  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25  * base code distributed originally by Intel ("Original Intel Code") to copy,
26  * make derivatives, distribute, use and display any portion of the Covered
27  * Code in any form, with the right to sublicense such rights; and
28  *
29  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30  * license (with the right to sublicense), under only those claims of Intel
31  * patents that are infringed by the Original Intel Code, to make, use, sell,
32  * offer to sell, and import the Covered Code and derivative works thereof
33  * solely to the minimum extent necessary to exercise the above copyright
34  * license, and in no event shall the patent license extend to any additions
35  * to or modifications of the Original Intel Code.  No other license or right
36  * is granted directly or by implication, estoppel or otherwise;
37  *
38  * The above copyright and patent license is granted only if the following
39  * conditions are met:
40  *
41  * 3. Conditions
42  *
43  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44  * Redistribution of source code of any substantial portion of the Covered
45  * Code or modification with rights to further distribute source must include
46  * the above Copyright Notice, the above License, this list of Conditions,
47  * and the following Disclaimer and Export Compliance provision.  In addition,
48  * Licensee must cause all Covered Code to which Licensee contributes to
49  * contain a file documenting the changes Licensee made to create that Covered
50  * Code and the date of any change.  Licensee must include in that file the
51  * documentation of any changes made by any predecessor Licensee.  Licensee
52  * must include a prominent statement that the modification is derived,
53  * directly or indirectly, from Original Intel Code.
54  *
55  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56  * Redistribution of source code of any substantial portion of the Covered
57  * Code or modification without rights to further distribute source must
58  * include the following Disclaimer and Export Compliance provision in the
59  * documentation and/or other materials provided with distribution.  In
60  * addition, Licensee may not authorize further sublicense of source of any
61  * portion of the Covered Code, and must include terms to the effect that the
62  * license from Licensee to its licensee is limited to the intellectual
63  * property embodied in the software Licensee provides to its licensee, and
64  * not to intellectual property embodied in modifications its licensee may
65  * make.
66  *
67  * 3.3. Redistribution of Executable. Redistribution in executable form of any
68  * substantial portion of the Covered Code or modification must reproduce the
69  * above Copyright Notice, and the following Disclaimer and Export Compliance
70  * provision in the documentation and/or other materials provided with the
71  * distribution.
72  *
73  * 3.4. Intel retains all right, title, and interest in and to the Original
74  * Intel Code.
75  *
76  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77  * Intel shall be used in advertising or otherwise to promote the sale, use or
78  * other dealings in products derived from or relating to the Covered Code
79  * without prior written authorization from Intel.
80  *
81  * 4. Disclaimer and Export Compliance
82  *
83  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89  * PARTICULAR PURPOSE.
90  *
91  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98  * LIMITED REMEDY.
99  *
100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
101  * software or system incorporating such software without first obtaining any
102  * required license or other approval from the U. S. Department of Commerce or
103  * any other agency or department of the United States Government.  In the
104  * event Licensee exports any such software from the United States or
105  * re-exports any such software from a foreign destination, Licensee shall
106  * ensure that the distribution and export/re-export of the software is in
107  * compliance with all laws, regulations, orders, or other restrictions of the
108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109  * any of its subsidiaries will export/re-export any technical data, process,
110  * software, or service, directly or indirectly, to any country for which the
111  * United States government or any agency thereof requires an export license,
112  * other governmental approval, or letter of assurance, without first obtaining
113  * such license, approval or letter.
114  *
115  *****************************************************************************/
116 
117 #include <contrib/dev/acpica/compiler/aslcompiler.h>
118 #include <contrib/dev/acpica/include/acapps.h>
119 
120 #define _COMPONENT          ACPI_COMPILER
121         ACPI_MODULE_NAME    ("aslfiles")
122 
123 /* Local prototypes */
124 
125 static void
126 FlOpenFile (
127     UINT32                  FileId,
128     char                    *Filename,
129     char                    *Mode);
130 
131 FILE *
132 FlOpenIncludeWithPrefix (
133     char                    *PrefixDir,
134     char                    *Filename);
135 
136 
137 #ifdef ACPI_OBSOLETE_FUNCTIONS
138 ACPI_STATUS
139 FlParseInputPathname (
140     char                    *InputFilename);
141 #endif
142 
143 
144 /*******************************************************************************
145  *
146  * FUNCTION:    AslAbort
147  *
148  * PARAMETERS:  None
149  *
150  * RETURN:      None
151  *
152  * DESCRIPTION: Dump the error log and abort the compiler.  Used for serious
153  *              I/O errors
154  *
155  ******************************************************************************/
156 
157 void
158 AslAbort (
159     void)
160 {
161 
162     AePrintErrorLog (ASL_FILE_STDOUT);
163     if (Gbl_DebugFlag)
164     {
165         /* Print error summary to the debug file */
166 
167         AePrintErrorLog (ASL_FILE_STDERR);
168     }
169 
170     exit (1);
171 }
172 
173 
174 /*******************************************************************************
175  *
176  * FUNCTION:    FlFileError
177  *
178  * PARAMETERS:  FileId              - Index into file info array
179  *              ErrorId             - Index into error message array
180  *
181  * RETURN:      None
182  *
183  * DESCRIPTION: Decode errno to an error message and add the entire error
184  *              to the error log.
185  *
186  ******************************************************************************/
187 
188 void
189 FlFileError (
190     UINT32                  FileId,
191     UINT8                   ErrorId)
192 {
193 
194     sprintf (MsgBuffer, "\"%s\" (%s)", Gbl_Files[FileId].Filename,
195         strerror (errno));
196     AslCommonError (ASL_ERROR, ErrorId, 0, 0, 0, 0, NULL, MsgBuffer);
197 }
198 
199 
200 /*******************************************************************************
201  *
202  * FUNCTION:    FlOpenFile
203  *
204  * PARAMETERS:  FileId              - Index into file info array
205  *              Filename            - file pathname to open
206  *              Mode                - Open mode for fopen
207  *
208  * RETURN:      None
209  *
210  * DESCRIPTION: Open a file.
211  *              NOTE: Aborts compiler on any error.
212  *
213  ******************************************************************************/
214 
215 static void
216 FlOpenFile (
217     UINT32                  FileId,
218     char                    *Filename,
219     char                    *Mode)
220 {
221     FILE                    *File;
222 
223 
224     File = fopen (Filename, Mode);
225 
226     Gbl_Files[FileId].Filename = Filename;
227     Gbl_Files[FileId].Handle   = File;
228 
229     if (!File)
230     {
231         FlFileError (FileId, ASL_MSG_OPEN);
232         AslAbort ();
233     }
234 }
235 
236 
237 /*******************************************************************************
238  *
239  * FUNCTION:    FlGetFileSize
240  *
241  * PARAMETERS:  FileId              - Index into file info array
242  *
243  * RETURN:      File Size
244  *
245  * DESCRIPTION: Get current file size. Uses seek-to-EOF. File must be open.
246  *
247  ******************************************************************************/
248 
249 UINT32
250 FlGetFileSize (
251     UINT32                  FileId)
252 {
253     FILE                    *fp;
254     UINT32                  FileSize;
255 
256 
257     fp = Gbl_Files[FileId].Handle;
258 
259     fseek (fp, 0, SEEK_END);
260     FileSize = (UINT32) ftell (fp);
261     fseek (fp, 0, SEEK_SET);
262 
263     return (FileSize);
264 }
265 
266 
267 /*******************************************************************************
268  *
269  * FUNCTION:    FlReadFile
270  *
271  * PARAMETERS:  FileId              - Index into file info array
272  *              Buffer              - Where to place the data
273  *              Length              - Amount to read
274  *
275  * RETURN:      Status.  AE_ERROR indicates EOF.
276  *
277  * DESCRIPTION: Read data from an open file.
278  *              NOTE: Aborts compiler on any error.
279  *
280  ******************************************************************************/
281 
282 ACPI_STATUS
283 FlReadFile (
284     UINT32                  FileId,
285     void                    *Buffer,
286     UINT32                  Length)
287 {
288     UINT32                  Actual;
289 
290 
291     /* Read and check for error */
292 
293     Actual = fread (Buffer, 1, Length, Gbl_Files[FileId].Handle);
294     if (Actual != Length)
295     {
296         if (feof (Gbl_Files[FileId].Handle))
297         {
298             /* End-of-file, just return error */
299 
300             return (AE_ERROR);
301         }
302 
303         FlFileError (FileId, ASL_MSG_READ);
304         AslAbort ();
305     }
306 
307     return (AE_OK);
308 }
309 
310 
311 /*******************************************************************************
312  *
313  * FUNCTION:    FlWriteFile
314  *
315  * PARAMETERS:  FileId              - Index into file info array
316  *              Buffer              - Data to write
317  *              Length              - Amount of data to write
318  *
319  * RETURN:      None
320  *
321  * DESCRIPTION: Write data to an open file.
322  *              NOTE: Aborts compiler on any error.
323  *
324  ******************************************************************************/
325 
326 void
327 FlWriteFile (
328     UINT32                  FileId,
329     void                    *Buffer,
330     UINT32                  Length)
331 {
332     UINT32                  Actual;
333 
334 
335     /* Write and check for error */
336 
337     Actual = fwrite ((char *) Buffer, 1, Length, Gbl_Files[FileId].Handle);
338     if (Actual != Length)
339     {
340         FlFileError (FileId, ASL_MSG_WRITE);
341         AslAbort ();
342     }
343 }
344 
345 
346 /*******************************************************************************
347  *
348  * FUNCTION:    FlPrintFile
349  *
350  * PARAMETERS:  FileId              - Index into file info array
351  *              Format              - Printf format string
352  *              ...                 - Printf arguments
353  *
354  * RETURN:      None
355  *
356  * DESCRIPTION: Formatted write to an open file.
357  *              NOTE: Aborts compiler on any error.
358  *
359  ******************************************************************************/
360 
361 void
362 FlPrintFile (
363     UINT32                  FileId,
364     char                    *Format,
365     ...)
366 {
367     INT32                   Actual;
368     va_list                 Args;
369 
370 
371     va_start (Args, Format);
372 
373     Actual = vfprintf (Gbl_Files[FileId].Handle, Format, Args);
374     va_end (Args);
375 
376     if (Actual == -1)
377     {
378         FlFileError (FileId, ASL_MSG_WRITE);
379         AslAbort ();
380     }
381 }
382 
383 
384 /*******************************************************************************
385  *
386  * FUNCTION:    FlSeekFile
387  *
388  * PARAMETERS:  FileId              - Index into file info array
389  *              Offset              - Absolute byte offset in file
390  *
391  * RETURN:      None
392  *
393  * DESCRIPTION: Seek to absolute offset
394  *              NOTE: Aborts compiler on any error.
395  *
396  ******************************************************************************/
397 
398 void
399 FlSeekFile (
400     UINT32                  FileId,
401     long                    Offset)
402 {
403     int                     Error;
404 
405 
406     Error = fseek (Gbl_Files[FileId].Handle, Offset, SEEK_SET);
407     if (Error)
408     {
409         FlFileError (FileId, ASL_MSG_SEEK);
410         AslAbort ();
411     }
412 }
413 
414 
415 /*******************************************************************************
416  *
417  * FUNCTION:    FlCloseFile
418  *
419  * PARAMETERS:  FileId              - Index into file info array
420  *
421  * RETURN:      None
422  *
423  * DESCRIPTION: Close an open file.  Aborts compiler on error
424  *
425  ******************************************************************************/
426 
427 void
428 FlCloseFile (
429     UINT32                  FileId)
430 {
431     int                     Error;
432 
433 
434     if (!Gbl_Files[FileId].Handle)
435     {
436         return;
437     }
438 
439     Error = fclose (Gbl_Files[FileId].Handle);
440     Gbl_Files[FileId].Handle = NULL;
441 
442     if (Error)
443     {
444         FlFileError (FileId, ASL_MSG_CLOSE);
445         AslAbort ();
446     }
447 
448     return;
449 }
450 
451 
452 /*******************************************************************************
453  *
454  * FUNCTION:    FlSetLineNumber
455  *
456  * PARAMETERS:  Op        - Parse node for the LINE asl statement
457  *
458  * RETURN:      None.
459  *
460  * DESCRIPTION: Set the current line number
461  *
462  ******************************************************************************/
463 
464 void
465 FlSetLineNumber (
466     ACPI_PARSE_OBJECT       *Op)
467 {
468 
469     Gbl_CurrentLineNumber = (UINT32) Op->Asl.Value.Integer;
470     Gbl_LogicalLineNumber = (UINT32) Op->Asl.Value.Integer;
471 }
472 
473 
474 /*******************************************************************************
475  *
476  * FUNCTION:    FlAddIncludeDirectory
477  *
478  * PARAMETERS:  Dir             - Directory pathname string
479  *
480  * RETURN:      None
481  *
482  * DESCRIPTION: Add a directory the list of include prefix directories.
483  *
484  ******************************************************************************/
485 
486 void
487 FlAddIncludeDirectory (
488     char                    *Dir)
489 {
490     ASL_INCLUDE_DIR         *NewDir;
491     ASL_INCLUDE_DIR         *NextDir;
492     ASL_INCLUDE_DIR         *PrevDir = NULL;
493     UINT32                  NeedsSeparator = 0;
494     size_t                  DirLength;
495 
496 
497     DirLength = strlen (Dir);
498     if (!DirLength)
499     {
500         return;
501     }
502 
503     /* Make sure that the pathname ends with a path separator */
504 
505     if ((Dir[DirLength-1] != '/') &&
506         (Dir[DirLength-1] != '\\'))
507     {
508         NeedsSeparator = 1;
509     }
510 
511     NewDir = ACPI_ALLOCATE_ZEROED (sizeof (ASL_INCLUDE_DIR));
512     NewDir->Dir = ACPI_ALLOCATE (DirLength + 1 + NeedsSeparator);
513     strcpy (NewDir->Dir, Dir);
514     if (NeedsSeparator)
515     {
516         strcat (NewDir->Dir, "/");
517     }
518 
519     /*
520      * Preserve command line ordering of -I options by adding new elements
521      * at the end of the list
522      */
523     NextDir = Gbl_IncludeDirList;
524     while (NextDir)
525     {
526         PrevDir = NextDir;
527         NextDir = NextDir->Next;
528     }
529 
530     if (PrevDir)
531     {
532         PrevDir->Next = NewDir;
533     }
534     else
535     {
536         Gbl_IncludeDirList = NewDir;
537     }
538 }
539 
540 
541 /*******************************************************************************
542  *
543  * FUNCTION:    FlOpenIncludeWithPrefix
544  *
545  * PARAMETERS:  PrefixDir       - Prefix directory pathname. Can be a zero
546  *                                length string.
547  *              Filename        - The include filename from the source ASL.
548  *
549  * RETURN:      Valid file descriptor if successful. Null otherwise.
550  *
551  * DESCRIPTION: Open an include file and push it on the input file stack.
552  *
553  ******************************************************************************/
554 
555 FILE *
556 FlOpenIncludeWithPrefix (
557     char                    *PrefixDir,
558     char                    *Filename)
559 {
560     FILE                    *IncludeFile;
561     char                    *Pathname;
562 
563 
564     /* Build the full pathname to the file */
565 
566     Pathname = ACPI_ALLOCATE (strlen (PrefixDir) + strlen (Filename) + 1);
567 
568     strcpy (Pathname, PrefixDir);
569     strcat (Pathname, Filename);
570 
571     DbgPrint (ASL_PARSE_OUTPUT, "\nAttempt to open include file: path %s\n\n",
572         Pathname);
573 
574     /* Attempt to open the file, push if successful */
575 
576     IncludeFile = fopen (Pathname, "r");
577     if (IncludeFile)
578     {
579         /* Push the include file on the open input file stack */
580 
581         AslPushInputFileStack (IncludeFile, Pathname);
582         return (IncludeFile);
583     }
584 
585     ACPI_FREE (Pathname);
586     return (NULL);
587 }
588 
589 
590 /*******************************************************************************
591  *
592  * FUNCTION:    FlOpenIncludeFile
593  *
594  * PARAMETERS:  Op        - Parse node for the INCLUDE ASL statement
595  *
596  * RETURN:      None.
597  *
598  * DESCRIPTION: Open an include file and push it on the input file stack.
599  *
600  ******************************************************************************/
601 
602 void
603 FlOpenIncludeFile (
604     ACPI_PARSE_OBJECT       *Op)
605 {
606     FILE                    *IncludeFile;
607     ASL_INCLUDE_DIR         *NextDir;
608 
609 
610     /* Op must be valid */
611 
612     if (!Op)
613     {
614         AslCommonError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN,
615             Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
616             Gbl_InputByteCount, Gbl_CurrentColumn,
617             Gbl_Files[ASL_FILE_INPUT].Filename, " - Null parse node");
618 
619         return;
620     }
621 
622     /*
623      * Flush out the "include ()" statement on this line, start
624      * the actual include file on the next line
625      */
626     ResetCurrentLineBuffer ();
627     FlPrintFile (ASL_FILE_SOURCE_OUTPUT, "\n");
628     Gbl_CurrentLineOffset++;
629 
630 
631     /* Attempt to open the include file */
632 
633     /* If the file specifies an absolute path, just open it */
634 
635     if ((Op->Asl.Value.String[0] == '/')  ||
636         (Op->Asl.Value.String[0] == '\\') ||
637         (Op->Asl.Value.String[1] == ':'))
638     {
639         IncludeFile = FlOpenIncludeWithPrefix ("", Op->Asl.Value.String);
640         if (!IncludeFile)
641         {
642             goto ErrorExit;
643         }
644         return;
645     }
646 
647     /*
648      * The include filename is not an absolute path.
649      *
650      * First, search for the file within the "local" directory -- meaning
651      * the same directory that contains the source file.
652      *
653      * Construct the file pathname from the global directory name.
654      */
655     IncludeFile = FlOpenIncludeWithPrefix (Gbl_DirectoryPath, Op->Asl.Value.String);
656     if (IncludeFile)
657     {
658         return;
659     }
660 
661     /*
662      * Second, search for the file within the (possibly multiple) directories
663      * specified by the -I option on the command line.
664      */
665     NextDir = Gbl_IncludeDirList;
666     while (NextDir)
667     {
668         IncludeFile = FlOpenIncludeWithPrefix (NextDir->Dir, Op->Asl.Value.String);
669         if (IncludeFile)
670         {
671             return;
672         }
673 
674         NextDir = NextDir->Next;
675     }
676 
677     /* We could not open the include file after trying very hard */
678 
679 ErrorExit:
680     sprintf (MsgBuffer, "%s, %s", Op->Asl.Value.String, strerror (errno));
681     AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, Op, MsgBuffer);
682 }
683 
684 
685 /*******************************************************************************
686  *
687  * FUNCTION:    FlOpenInputFile
688  *
689  * PARAMETERS:  InputFilename       - The user-specified ASL source file to be
690  *                                    compiled
691  *
692  * RETURN:      Status
693  *
694  * DESCRIPTION: Open the specified input file, and save the directory path to
695  *              the file so that include files can be opened in
696  *              the same directory.
697  *
698  ******************************************************************************/
699 
700 ACPI_STATUS
701 FlOpenInputFile (
702     char                    *InputFilename)
703 {
704 
705     /* Open the input ASL file, text mode */
706 
707     FlOpenFile (ASL_FILE_INPUT, InputFilename, "r");
708     AslCompilerin = Gbl_Files[ASL_FILE_INPUT].Handle;
709 
710     return (AE_OK);
711 }
712 
713 
714 /*******************************************************************************
715  *
716  * FUNCTION:    FlOpenAmlOutputFile
717  *
718  * PARAMETERS:  FilenamePrefix       - The user-specified ASL source file
719  *
720  * RETURN:      Status
721  *
722  * DESCRIPTION: Create the output filename (*.AML) and open the file.  The file
723  *              is created in the same directory as the parent input file.
724  *
725  ******************************************************************************/
726 
727 ACPI_STATUS
728 FlOpenAmlOutputFile (
729     char                    *FilenamePrefix)
730 {
731     char                    *Filename;
732 
733 
734     /* Output filename usually comes from the ASL itself */
735 
736     Filename = Gbl_Files[ASL_FILE_AML_OUTPUT].Filename;
737     if (!Filename)
738     {
739         /* Create the output AML filename */
740 
741         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_AML_CODE);
742         if (!Filename)
743         {
744             AslCommonError (ASL_ERROR, ASL_MSG_OUTPUT_FILENAME,
745                 0, 0, 0, 0, NULL, NULL);
746             return (AE_ERROR);
747         }
748     }
749 
750     /* Open the output AML file in binary mode */
751 
752     FlOpenFile (ASL_FILE_AML_OUTPUT, Filename, "w+b");
753     return (AE_OK);
754 }
755 
756 
757 /*******************************************************************************
758  *
759  * FUNCTION:    FlOpenMiscOutputFiles
760  *
761  * PARAMETERS:  FilenamePrefix       - The user-specified ASL source file
762  *
763  * RETURN:      Status
764  *
765  * DESCRIPTION: Create and open the various output files needed, depending on
766  *              the command line options
767  *
768  ******************************************************************************/
769 
770 ACPI_STATUS
771 FlOpenMiscOutputFiles (
772     char                    *FilenamePrefix)
773 {
774     char                    *Filename;
775 
776 
777     /* Create/Open a combined source output file */
778 
779     Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_SOURCE);
780     if (!Filename)
781     {
782         AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
783             0, 0, 0, 0, NULL, NULL);
784         return (AE_ERROR);
785     }
786 
787     /*
788      * Open the source output file, binary mode (so that LF does not get
789      * expanded to CR/LF on some systems, messing up our seek
790      * calculations.)
791      */
792     FlOpenFile (ASL_FILE_SOURCE_OUTPUT, Filename, "w+b");
793 
794     /* Create/Open a listing output file if asked */
795 
796     if (Gbl_ListingFlag)
797     {
798         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_LISTING);
799         if (!Filename)
800         {
801             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
802                 0, 0, 0, 0, NULL, NULL);
803             return (AE_ERROR);
804         }
805 
806         /* Open the listing file, text mode */
807 
808         FlOpenFile (ASL_FILE_LISTING_OUTPUT, Filename, "w+");
809 
810         AslCompilerSignon (ASL_FILE_LISTING_OUTPUT);
811         AslCompilerFileHeader (ASL_FILE_LISTING_OUTPUT);
812     }
813 
814     /* Create/Open a assembly code source output file if asked */
815 
816     if (Gbl_AsmOutputFlag)
817     {
818         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_SOURCE);
819         if (!Filename)
820         {
821             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
822                 0, 0, 0, 0, NULL, NULL);
823             return (AE_ERROR);
824         }
825 
826         /* Open the assembly code source file, text mode */
827 
828         FlOpenFile (ASL_FILE_ASM_SOURCE_OUTPUT, Filename, "w+");
829 
830         AslCompilerSignon (ASL_FILE_ASM_SOURCE_OUTPUT);
831         AslCompilerFileHeader (ASL_FILE_ASM_SOURCE_OUTPUT);
832     }
833 
834     /* Create/Open a C code source output file if asked */
835 
836     if (Gbl_C_OutputFlag)
837     {
838         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_SOURCE);
839         if (!Filename)
840         {
841             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
842                 0, 0, 0, 0, NULL, NULL);
843             return (AE_ERROR);
844         }
845 
846         /* Open the C code source file, text mode */
847 
848         FlOpenFile (ASL_FILE_C_SOURCE_OUTPUT, Filename, "w+");
849 
850         FlPrintFile (ASL_FILE_C_SOURCE_OUTPUT, "/*\n");
851         AslCompilerSignon (ASL_FILE_C_SOURCE_OUTPUT);
852         AslCompilerFileHeader (ASL_FILE_C_SOURCE_OUTPUT);
853     }
854 
855     /* Create/Open a assembly include output file if asked */
856 
857     if (Gbl_AsmIncludeOutputFlag)
858     {
859         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_INCLUDE);
860         if (!Filename)
861         {
862             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
863                 0, 0, 0, 0, NULL, NULL);
864             return (AE_ERROR);
865         }
866 
867         /* Open the assembly include file, text mode */
868 
869         FlOpenFile (ASL_FILE_ASM_INCLUDE_OUTPUT, Filename, "w+");
870 
871         AslCompilerSignon (ASL_FILE_ASM_INCLUDE_OUTPUT);
872         AslCompilerFileHeader (ASL_FILE_ASM_INCLUDE_OUTPUT);
873     }
874 
875     /* Create/Open a C include output file if asked */
876 
877     if (Gbl_C_IncludeOutputFlag)
878     {
879         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_INCLUDE);
880         if (!Filename)
881         {
882             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
883                 0, 0, 0, 0, NULL, NULL);
884             return (AE_ERROR);
885         }
886 
887         /* Open the C include file, text mode */
888 
889         FlOpenFile (ASL_FILE_C_INCLUDE_OUTPUT, Filename, "w+");
890 
891         FlPrintFile (ASL_FILE_C_INCLUDE_OUTPUT, "/*\n");
892         AslCompilerSignon (ASL_FILE_C_INCLUDE_OUTPUT);
893         AslCompilerFileHeader (ASL_FILE_C_INCLUDE_OUTPUT);
894     }
895 
896     /* Create/Open a hex output file if asked */
897 
898     if (Gbl_HexOutputFlag)
899     {
900         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_HEX_DUMP);
901         if (!Filename)
902         {
903             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
904                 0, 0, 0, 0, NULL, NULL);
905             return (AE_ERROR);
906         }
907 
908         /* Open the hex file, text mode */
909 
910         FlOpenFile (ASL_FILE_HEX_OUTPUT, Filename, "w+");
911 
912         AslCompilerSignon (ASL_FILE_HEX_OUTPUT);
913         AslCompilerFileHeader (ASL_FILE_HEX_OUTPUT);
914     }
915 
916     /* Create a namespace output file if asked */
917 
918     if (Gbl_NsOutputFlag)
919     {
920         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_NAMESPACE);
921         if (!Filename)
922         {
923             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
924                 0, 0, 0, 0, NULL, NULL);
925             return (AE_ERROR);
926         }
927 
928         /* Open the namespace file, text mode */
929 
930         FlOpenFile (ASL_FILE_NAMESPACE_OUTPUT, Filename, "w+");
931 
932         AslCompilerSignon (ASL_FILE_NAMESPACE_OUTPUT);
933         AslCompilerFileHeader (ASL_FILE_NAMESPACE_OUTPUT);
934     }
935 
936     /* Create/Open a debug output file if asked */
937 
938     if (Gbl_DebugFlag)
939     {
940         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_DEBUG);
941         if (!Filename)
942         {
943             AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME,
944                 0, 0, 0, 0, NULL, NULL);
945             return (AE_ERROR);
946         }
947 
948         /* Open the debug file as STDERR, text mode */
949 
950         /* TBD: hide this behind a FlReopenFile function */
951 
952         Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Filename = Filename;
953         Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle =
954             freopen (Filename, "w+t", stderr);
955 
956         AslCompilerSignon (ASL_FILE_DEBUG_OUTPUT);
957         AslCompilerFileHeader (ASL_FILE_DEBUG_OUTPUT);
958     }
959 
960     return (AE_OK);
961 }
962 
963 
964 #ifdef ACPI_OBSOLETE_FUNCTIONS
965 /*******************************************************************************
966  *
967  * FUNCTION:    FlParseInputPathname
968  *
969  * PARAMETERS:  InputFilename       - The user-specified ASL source file to be
970  *                                    compiled
971  *
972  * RETURN:      Status
973  *
974  * DESCRIPTION: Split the input path into a directory and filename part
975  *              1) Directory part used to open include files
976  *              2) Filename part used to generate output filenames
977  *
978  ******************************************************************************/
979 
980 ACPI_STATUS
981 FlParseInputPathname (
982     char                    *InputFilename)
983 {
984     char                    *Substring;
985 
986 
987     if (!InputFilename)
988     {
989         return (AE_OK);
990     }
991 
992     /* Get the path to the input filename's directory */
993 
994     Gbl_DirectoryPath = strdup (InputFilename);
995     if (!Gbl_DirectoryPath)
996     {
997         return (AE_NO_MEMORY);
998     }
999 
1000     Substring = strrchr (Gbl_DirectoryPath, '\\');
1001     if (!Substring)
1002     {
1003         Substring = strrchr (Gbl_DirectoryPath, '/');
1004         if (!Substring)
1005         {
1006             Substring = strrchr (Gbl_DirectoryPath, ':');
1007         }
1008     }
1009 
1010     if (!Substring)
1011     {
1012         Gbl_DirectoryPath[0] = 0;
1013         if (Gbl_UseDefaultAmlFilename)
1014         {
1015             Gbl_OutputFilenamePrefix = strdup (InputFilename);
1016         }
1017     }
1018     else
1019     {
1020         if (Gbl_UseDefaultAmlFilename)
1021         {
1022             Gbl_OutputFilenamePrefix = strdup (Substring + 1);
1023         }
1024         *(Substring+1) = 0;
1025     }
1026 
1027     return (AE_OK);
1028 }
1029 #endif
1030 
1031 
1032