]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - source/compiler/aslfiles.c
Import ACPICA 20120215.
[FreeBSD/FreeBSD.git] / source / compiler / aslfiles.c
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 "aslcompiler.h"
46 #include "acapps.h"
47
48 #define _COMPONENT          ACPI_COMPILER
49         ACPI_MODULE_NAME    ("aslfiles")
50
51 /* Local prototypes */
52
53 static 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_STDOUT);
85     if (Gbl_DebugFlag)
86     {
87         /* Print error summary to the debug file */
88
89         AePrintErrorLog (ASL_FILE_STDERR);
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     Gbl_Files[FileId].Handle = NULL;
367
368     if (Error)
369     {
370         FlFileError (FileId, ASL_MSG_CLOSE);
371         AslAbort ();
372     }
373
374     return;
375 }
376
377
378 /*******************************************************************************
379  *
380  * FUNCTION:    FlSetLineNumber
381  *
382  * PARAMETERS:  Op        - Parse node for the LINE asl statement
383  *
384  * RETURN:      None.
385  *
386  * DESCRIPTION: Set the current line number
387  *
388  ******************************************************************************/
389
390 void
391 FlSetLineNumber (
392     ACPI_PARSE_OBJECT       *Op)
393 {
394
395     Gbl_CurrentLineNumber = (UINT32) Op->Asl.Value.Integer;
396     Gbl_LogicalLineNumber = (UINT32) Op->Asl.Value.Integer;
397 }
398
399
400 /*******************************************************************************
401  *
402  * FUNCTION:    FlAddIncludeDirectory
403  *
404  * PARAMETERS:  Dir             - Directory pathname string
405  *
406  * RETURN:      None
407  *
408  * DESCRIPTION: Add a directory the list of include prefix directories.
409  *
410  ******************************************************************************/
411
412 void
413 FlAddIncludeDirectory (
414     char                    *Dir)
415 {
416     ASL_INCLUDE_DIR         *NewDir;
417     ASL_INCLUDE_DIR         *NextDir;
418     ASL_INCLUDE_DIR         *PrevDir = NULL;
419     UINT32                  NeedsSeparator = 0;
420     size_t                  DirLength;
421
422
423     DirLength = strlen (Dir);
424     if (!DirLength)
425     {
426         return;
427     }
428
429     /* Make sure that the pathname ends with a path separator */
430
431     if ((Dir[DirLength-1] != '/') &&
432         (Dir[DirLength-1] != '\\'))
433     {
434         NeedsSeparator = 1;
435     }
436
437     NewDir = ACPI_ALLOCATE_ZEROED (sizeof (ASL_INCLUDE_DIR));
438     NewDir->Dir = ACPI_ALLOCATE (DirLength + 1 + NeedsSeparator);
439     strcpy (NewDir->Dir, Dir);
440     if (NeedsSeparator)
441     {
442         strcat (NewDir->Dir, "/");
443     }
444
445     /*
446      * Preserve command line ordering of -I options by adding new elements
447      * at the end of the list
448      */
449     NextDir = Gbl_IncludeDirList;
450     while (NextDir)
451     {
452         PrevDir = NextDir;
453         NextDir = NextDir->Next;
454     }
455
456     if (PrevDir)
457     {
458         PrevDir->Next = NewDir;
459     }
460     else
461     {
462         Gbl_IncludeDirList = NewDir;
463     }
464 }
465
466
467 /*******************************************************************************
468  *
469  * FUNCTION:    FlOpenIncludeWithPrefix
470  *
471  * PARAMETERS:  PrefixDir       - Prefix directory pathname. Can be a zero
472  *                                length string.
473  *              Filename        - The include filename from the source ASL.
474  *
475  * RETURN:      Valid file descriptor if successful. Null otherwise.
476  *
477  * DESCRIPTION: Open an include file and push it on the input file stack.
478  *
479  ******************************************************************************/
480
481 static FILE *
482 FlOpenIncludeWithPrefix (
483     char                    *PrefixDir,
484     char                    *Filename)
485 {
486     FILE                    *IncludeFile;
487     char                    *Pathname;
488
489
490     /* Build the full pathname to the file */
491
492     Pathname = ACPI_ALLOCATE (strlen (PrefixDir) + strlen (Filename) + 1);
493
494     strcpy (Pathname, PrefixDir);
495     strcat (Pathname, Filename);
496
497     DbgPrint (ASL_PARSE_OUTPUT, "\nAttempt to open include file: path %s\n\n",
498         Pathname);
499
500     /* Attempt to open the file, push if successful */
501
502     IncludeFile = fopen (Pathname, "r");
503     if (IncludeFile)
504     {
505         /* Push the include file on the open input file stack */
506
507         AslPushInputFileStack (IncludeFile, Pathname);
508         return (IncludeFile);
509     }
510
511     ACPI_FREE (Pathname);
512     return (NULL);
513 }
514
515
516 /*******************************************************************************
517  *
518  * FUNCTION:    FlOpenIncludeFile
519  *
520  * PARAMETERS:  Op        - Parse node for the INCLUDE ASL statement
521  *
522  * RETURN:      None.
523  *
524  * DESCRIPTION: Open an include file and push it on the input file stack.
525  *
526  ******************************************************************************/
527
528 void
529 FlOpenIncludeFile (
530     ACPI_PARSE_OBJECT       *Op)
531 {
532     FILE                    *IncludeFile;
533     ASL_INCLUDE_DIR         *NextDir;
534
535
536     /* Op must be valid */
537
538     if (!Op)
539     {
540         AslCommonError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN,
541             Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
542             Gbl_InputByteCount, Gbl_CurrentColumn,
543             Gbl_Files[ASL_FILE_INPUT].Filename, " - Null parse node");
544
545         return;
546     }
547
548     /*
549      * Flush out the "include ()" statement on this line, start
550      * the actual include file on the next line
551      */
552     ResetCurrentLineBuffer ();
553     FlPrintFile (ASL_FILE_SOURCE_OUTPUT, "\n");
554     Gbl_CurrentLineOffset++;
555
556
557     /* Attempt to open the include file */
558
559     /* If the file specifies an absolute path, just open it */
560
561     if ((Op->Asl.Value.String[0] == '/')  ||
562         (Op->Asl.Value.String[0] == '\\') ||
563         (Op->Asl.Value.String[1] == ':'))
564     {
565         IncludeFile = FlOpenIncludeWithPrefix ("", Op->Asl.Value.String);
566         if (!IncludeFile)
567         {
568             goto ErrorExit;
569         }
570         return;
571     }
572
573     /*
574      * The include filename is not an absolute path.
575      *
576      * First, search for the file within the "local" directory -- meaning
577      * the same directory that contains the source file.
578      *
579      * Construct the file pathname from the global directory name.
580      */
581     IncludeFile = FlOpenIncludeWithPrefix (Gbl_DirectoryPath, Op->Asl.Value.String);
582     if (IncludeFile)
583     {
584         return;
585     }
586
587     /*
588      * Second, search for the file within the (possibly multiple) directories
589      * specified by the -I option on the command line.
590      */
591     NextDir = Gbl_IncludeDirList;
592     while (NextDir)
593     {
594         IncludeFile = FlOpenIncludeWithPrefix (NextDir->Dir, Op->Asl.Value.String);
595         if (IncludeFile)
596         {
597             return;
598         }
599
600         NextDir = NextDir->Next;
601     }
602
603     /* We could not open the include file after trying very hard */
604
605 ErrorExit:
606     sprintf (MsgBuffer, "%s, %s", Op->Asl.Value.String, strerror (errno));
607     AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, Op, MsgBuffer);
608 }
609
610
611 /*******************************************************************************
612  *
613  * FUNCTION:    FlOpenInputFile
614  *
615  * PARAMETERS:  InputFilename       - The user-specified ASL source file to be
616  *                                    compiled
617  *
618  * RETURN:      Status
619  *
620  * DESCRIPTION: Open the specified input file, and save the directory path to
621  *              the file so that include files can be opened in
622  *              the same directory.
623  *
624  ******************************************************************************/
625
626 ACPI_STATUS
627 FlOpenInputFile (
628     char                    *InputFilename)
629 {
630
631     /* Open the input ASL file, text mode */
632
633     FlOpenFile (ASL_FILE_INPUT, InputFilename, "r");
634     AslCompilerin = Gbl_Files[ASL_FILE_INPUT].Handle;
635
636     return (AE_OK);
637 }
638
639
640 /*******************************************************************************
641  *
642  * FUNCTION:    FlOpenAmlOutputFile
643  *
644  * PARAMETERS:  FilenamePrefix       - The user-specified ASL source file
645  *
646  * RETURN:      Status
647  *
648  * DESCRIPTION: Create the output filename (*.AML) and open the file.  The file
649  *              is created in the same directory as the parent input file.
650  *
651  ******************************************************************************/
652
653 ACPI_STATUS
654 FlOpenAmlOutputFile (
655     char                    *FilenamePrefix)
656 {
657     char                    *Filename;
658
659
660     /* Output filename usually comes from the ASL itself */
661
662     Filename = Gbl_Files[ASL_FILE_AML_OUTPUT].Filename;
663     if (!Filename)
664     {
665         /* Create the output AML filename */
666
667         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_AML_CODE);
668         if (!Filename)
669         {
670             AslCommonError (ASL_ERROR, ASL_MSG_OUTPUT_FILENAME,
671                 0, 0, 0, 0, NULL, NULL);
672             return (AE_ERROR);
673         }
674     }
675
676     /* Open the output AML file in binary mode */
677
678     FlOpenFile (ASL_FILE_AML_OUTPUT, Filename, "w+b");
679     return (AE_OK);
680 }
681
682
683 /*******************************************************************************
684  *
685  * FUNCTION:    FlOpenMiscOutputFiles
686  *
687  * PARAMETERS:  FilenamePrefix       - The user-specified ASL source file
688  *
689  * RETURN:      Status
690  *
691  * DESCRIPTION: Create and open the various output files needed, depending on
692  *              the command line options
693  *
694  ******************************************************************************/
695
696 ACPI_STATUS
697 FlOpenMiscOutputFiles (
698     char                    *FilenamePrefix)
699 {
700     char                    *Filename;
701
702
703     /* Create/Open a hex output file if asked */
704
705     if (Gbl_HexOutputFlag)
706     {
707         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_HEX_DUMP);
708         if (!Filename)
709         {
710             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
711                 0, 0, 0, 0, NULL, NULL);
712             return (AE_ERROR);
713         }
714
715         /* Open the hex file, text mode */
716
717         FlOpenFile (ASL_FILE_HEX_OUTPUT, Filename, "w+");
718
719         AslCompilerSignon (ASL_FILE_HEX_OUTPUT);
720         AslCompilerFileHeader (ASL_FILE_HEX_OUTPUT);
721     }
722
723     /* Create/Open a debug output file if asked */
724
725     if (Gbl_DebugFlag)
726     {
727         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_DEBUG);
728         if (!Filename)
729         {
730             AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME,
731                 0, 0, 0, 0, NULL, NULL);
732             return (AE_ERROR);
733         }
734
735         /* Open the debug file as STDERR, text mode */
736
737         /* TBD: hide this behind a FlReopenFile function */
738
739         Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Filename = Filename;
740         Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle =
741             freopen (Filename, "w+t", stderr);
742
743         AslCompilerSignon (ASL_FILE_DEBUG_OUTPUT);
744         AslCompilerFileHeader (ASL_FILE_DEBUG_OUTPUT);
745     }
746
747     /* Create/Open a listing output file if asked */
748
749     if (Gbl_ListingFlag)
750     {
751         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_LISTING);
752         if (!Filename)
753         {
754             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
755                 0, 0, 0, 0, NULL, NULL);
756             return (AE_ERROR);
757         }
758
759         /* Open the listing file, text mode */
760
761         FlOpenFile (ASL_FILE_LISTING_OUTPUT, Filename, "w+");
762
763         AslCompilerSignon (ASL_FILE_LISTING_OUTPUT);
764         AslCompilerFileHeader (ASL_FILE_LISTING_OUTPUT);
765     }
766
767     if (Gbl_FileType == ASL_INPUT_TYPE_ASCII_DATA)
768     {
769         return (AE_OK);
770     }
771
772     /* Create/Open a combined source output file */
773
774     Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_SOURCE);
775     if (!Filename)
776     {
777         AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
778             0, 0, 0, 0, NULL, NULL);
779         return (AE_ERROR);
780     }
781
782     /*
783      * Open the source output file, binary mode (so that LF does not get
784      * expanded to CR/LF on some systems, messing up our seek
785      * calculations.)
786      */
787     FlOpenFile (ASL_FILE_SOURCE_OUTPUT, Filename, "w+b");
788
789     /* Create/Open a assembly code source output file if asked */
790
791     if (Gbl_AsmOutputFlag)
792     {
793         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_SOURCE);
794         if (!Filename)
795         {
796             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
797                 0, 0, 0, 0, NULL, NULL);
798             return (AE_ERROR);
799         }
800
801         /* Open the assembly code source file, text mode */
802
803         FlOpenFile (ASL_FILE_ASM_SOURCE_OUTPUT, Filename, "w+");
804
805         AslCompilerSignon (ASL_FILE_ASM_SOURCE_OUTPUT);
806         AslCompilerFileHeader (ASL_FILE_ASM_SOURCE_OUTPUT);
807     }
808
809     /* Create/Open a C code source output file if asked */
810
811     if (Gbl_C_OutputFlag)
812     {
813         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_SOURCE);
814         if (!Filename)
815         {
816             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
817                 0, 0, 0, 0, NULL, NULL);
818             return (AE_ERROR);
819         }
820
821         /* Open the C code source file, text mode */
822
823         FlOpenFile (ASL_FILE_C_SOURCE_OUTPUT, Filename, "w+");
824
825         FlPrintFile (ASL_FILE_C_SOURCE_OUTPUT, "/*\n");
826         AslCompilerSignon (ASL_FILE_C_SOURCE_OUTPUT);
827         AslCompilerFileHeader (ASL_FILE_C_SOURCE_OUTPUT);
828     }
829
830     /* Create/Open a assembly include output file if asked */
831
832     if (Gbl_AsmIncludeOutputFlag)
833     {
834         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_INCLUDE);
835         if (!Filename)
836         {
837             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
838                 0, 0, 0, 0, NULL, NULL);
839             return (AE_ERROR);
840         }
841
842         /* Open the assembly include file, text mode */
843
844         FlOpenFile (ASL_FILE_ASM_INCLUDE_OUTPUT, Filename, "w+");
845
846         AslCompilerSignon (ASL_FILE_ASM_INCLUDE_OUTPUT);
847         AslCompilerFileHeader (ASL_FILE_ASM_INCLUDE_OUTPUT);
848     }
849
850     /* Create/Open a C include output file if asked */
851
852     if (Gbl_C_IncludeOutputFlag)
853     {
854         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_INCLUDE);
855         if (!Filename)
856         {
857             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
858                 0, 0, 0, 0, NULL, NULL);
859             return (AE_ERROR);
860         }
861
862         /* Open the C include file, text mode */
863
864         FlOpenFile (ASL_FILE_C_INCLUDE_OUTPUT, Filename, "w+");
865
866         FlPrintFile (ASL_FILE_C_INCLUDE_OUTPUT, "/*\n");
867         AslCompilerSignon (ASL_FILE_C_INCLUDE_OUTPUT);
868         AslCompilerFileHeader (ASL_FILE_C_INCLUDE_OUTPUT);
869     }
870
871     /* Create a namespace output file if asked */
872
873     if (Gbl_NsOutputFlag)
874     {
875         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_NAMESPACE);
876         if (!Filename)
877         {
878             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
879                 0, 0, 0, 0, NULL, NULL);
880             return (AE_ERROR);
881         }
882
883         /* Open the namespace file, text mode */
884
885         FlOpenFile (ASL_FILE_NAMESPACE_OUTPUT, Filename, "w+");
886
887         AslCompilerSignon (ASL_FILE_NAMESPACE_OUTPUT);
888         AslCompilerFileHeader (ASL_FILE_NAMESPACE_OUTPUT);
889     }
890
891     return (AE_OK);
892 }
893
894
895 #ifdef ACPI_OBSOLETE_FUNCTIONS
896 /*******************************************************************************
897  *
898  * FUNCTION:    FlParseInputPathname
899  *
900  * PARAMETERS:  InputFilename       - The user-specified ASL source file to be
901  *                                    compiled
902  *
903  * RETURN:      Status
904  *
905  * DESCRIPTION: Split the input path into a directory and filename part
906  *              1) Directory part used to open include files
907  *              2) Filename part used to generate output filenames
908  *
909  ******************************************************************************/
910
911 ACPI_STATUS
912 FlParseInputPathname (
913     char                    *InputFilename)
914 {
915     char                    *Substring;
916
917
918     if (!InputFilename)
919     {
920         return (AE_OK);
921     }
922
923     /* Get the path to the input filename's directory */
924
925     Gbl_DirectoryPath = strdup (InputFilename);
926     if (!Gbl_DirectoryPath)
927     {
928         return (AE_NO_MEMORY);
929     }
930
931     Substring = strrchr (Gbl_DirectoryPath, '\\');
932     if (!Substring)
933     {
934         Substring = strrchr (Gbl_DirectoryPath, '/');
935         if (!Substring)
936         {
937             Substring = strrchr (Gbl_DirectoryPath, ':');
938         }
939     }
940
941     if (!Substring)
942     {
943         Gbl_DirectoryPath[0] = 0;
944         if (Gbl_UseDefaultAmlFilename)
945         {
946             Gbl_OutputFilenamePrefix = strdup (InputFilename);
947         }
948     }
949     else
950     {
951         if (Gbl_UseDefaultAmlFilename)
952         {
953             Gbl_OutputFilenamePrefix = strdup (Substring + 1);
954         }
955         *(Substring+1) = 0;
956     }
957
958     return (AE_OK);
959 }
960 #endif
961
962