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