1 /******************************************************************************
2  *
3  * Module Name: aslfiles - File support functions
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2015, Intel Corp.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions, and the following disclaimer,
16  *    without modification.
17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18  *    substantially similar to the "NO WARRANTY" disclaimer below
19  *    ("Disclaimer") and any redistribution must be conditioned upon
20  *    including a substantially similar Disclaimer requirement for further
21  *    binary redistribution.
22  * 3. Neither the names of the above-listed copyright holders nor the names
23  *    of any contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * Alternatively, this software may be distributed under the terms of the
27  * GNU General Public License ("GPL") version 2 as published by the Free
28  * Software Foundation.
29  *
30  * NO WARRANTY
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41  * POSSIBILITY OF SUCH DAMAGES.
42  */
43 
44 #include "aslcompiler.h"
45 #include "acapps.h"
46 #include "dtcompiler.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     ACPI_PARSE_OBJECT       *Op,
57     char                    *Filename);
58 
59 #ifdef ACPI_OBSOLETE_FUNCTIONS
60 ACPI_STATUS
61 FlParseInputPathname (
62     char                    *InputFilename);
63 #endif
64 
65 
66 /*******************************************************************************
67  *
68  * FUNCTION:    FlSetLineNumber
69  *
70  * PARAMETERS:  Op        - Parse node for the LINE asl statement
71  *
72  * RETURN:      None.
73  *
74  * DESCRIPTION: Set the current line number
75  *
76  ******************************************************************************/
77 
78 void
79 FlSetLineNumber (
80     UINT32                  LineNumber)
81 {
82 
83     DbgPrint (ASL_PARSE_OUTPUT, "\n#line: New line number %u (old %u)\n",
84          LineNumber, Gbl_LogicalLineNumber);
85 
86     Gbl_CurrentLineNumber = LineNumber;
87 }
88 
89 
90 /*******************************************************************************
91  *
92  * FUNCTION:    FlSetFilename
93  *
94  * PARAMETERS:  Op        - Parse node for the LINE asl statement
95  *
96  * RETURN:      None.
97  *
98  * DESCRIPTION: Set the current filename
99  *
100  ******************************************************************************/
101 
102 void
103 FlSetFilename (
104     char                    *Filename)
105 {
106 
107     DbgPrint (ASL_PARSE_OUTPUT, "\n#line: New filename %s (old %s)\n",
108          Filename, Gbl_Files[ASL_FILE_INPUT].Filename);
109 
110     /* No need to free any existing filename */
111 
112     Gbl_Files[ASL_FILE_INPUT].Filename = Filename;
113 }
114 
115 
116 /*******************************************************************************
117  *
118  * FUNCTION:    FlAddIncludeDirectory
119  *
120  * PARAMETERS:  Dir             - Directory pathname string
121  *
122  * RETURN:      None
123  *
124  * DESCRIPTION: Add a directory the list of include prefix directories.
125  *
126  ******************************************************************************/
127 
128 void
129 FlAddIncludeDirectory (
130     char                    *Dir)
131 {
132     ASL_INCLUDE_DIR         *NewDir;
133     ASL_INCLUDE_DIR         *NextDir;
134     ASL_INCLUDE_DIR         *PrevDir = NULL;
135     UINT32                  NeedsSeparator = 0;
136     size_t                  DirLength;
137 
138 
139     DirLength = strlen (Dir);
140     if (!DirLength)
141     {
142         return;
143     }
144 
145     /* Make sure that the pathname ends with a path separator */
146 
147     if ((Dir[DirLength-1] != '/') &&
148         (Dir[DirLength-1] != '\\'))
149     {
150         NeedsSeparator = 1;
151     }
152 
153     NewDir = ACPI_ALLOCATE_ZEROED (sizeof (ASL_INCLUDE_DIR));
154     NewDir->Dir = ACPI_ALLOCATE (DirLength + 1 + NeedsSeparator);
155     strcpy (NewDir->Dir, Dir);
156     if (NeedsSeparator)
157     {
158         strcat (NewDir->Dir, "/");
159     }
160 
161     /*
162      * Preserve command line ordering of -I options by adding new elements
163      * at the end of the list
164      */
165     NextDir = Gbl_IncludeDirList;
166     while (NextDir)
167     {
168         PrevDir = NextDir;
169         NextDir = NextDir->Next;
170     }
171 
172     if (PrevDir)
173     {
174         PrevDir->Next = NewDir;
175     }
176     else
177     {
178         Gbl_IncludeDirList = NewDir;
179     }
180 }
181 
182 
183 /*******************************************************************************
184  *
185  * FUNCTION:    FlMergePathnames
186  *
187  * PARAMETERS:  PrefixDir       - Prefix directory pathname. Can be NULL or
188  *                                a zero length string.
189  *              FilePathname    - The include filename from the source ASL.
190  *
191  * RETURN:      Merged pathname string
192  *
193  * DESCRIPTION: Merge two pathnames that (probably) have common elements, to
194  *              arrive at a minimal length string. Merge can occur if the
195  *              FilePathname is relative to the PrefixDir.
196  *
197  ******************************************************************************/
198 
199 char *
200 FlMergePathnames (
201     char                    *PrefixDir,
202     char                    *FilePathname)
203 {
204     char                    *CommonPath;
205     char                    *Pathname;
206     char                    *LastElement;
207 
208 
209     DbgPrint (ASL_PARSE_OUTPUT, "Include: Prefix path - \"%s\"\n"
210         "Include: FilePathname - \"%s\"\n",
211          PrefixDir, FilePathname);
212 
213     /*
214      * If there is no prefix directory or if the file pathname is absolute,
215      * just return the original file pathname
216      */
217     if (!PrefixDir || (!*PrefixDir) ||
218         (*FilePathname == '/') ||
219          (FilePathname[1] == ':'))
220     {
221         Pathname = UtStringCacheCalloc (strlen (FilePathname) + 1);
222         strcpy (Pathname, FilePathname);
223         goto ConvertBackslashes;
224     }
225 
226     /* Need a local copy of the prefix directory path */
227 
228     CommonPath = UtStringCacheCalloc (strlen (PrefixDir) + 1);
229     strcpy (CommonPath, PrefixDir);
230 
231     /*
232      * Walk forward through the file path, and simultaneously backward
233      * through the prefix directory path until there are no more
234      * relative references at the start of the file path.
235      */
236     while (*FilePathname && (!strncmp (FilePathname, "../", 3)))
237     {
238         /* Remove last element of the prefix directory path */
239 
240         LastElement = strrchr (CommonPath, '/');
241         if (!LastElement)
242         {
243             goto ConcatenatePaths;
244         }
245 
246         *LastElement = 0;   /* Terminate CommonPath string */
247         FilePathname += 3;  /* Point to next path element */
248     }
249 
250     /*
251      * Remove the last element of the prefix directory path (it is the same as
252      * the first element of the file pathname), and build the final merged
253      * pathname.
254      */
255     LastElement = strrchr (CommonPath, '/');
256     if (LastElement)
257     {
258         *LastElement = 0;
259     }
260 
261     /* Build the final merged pathname */
262 
263 ConcatenatePaths:
264     Pathname = UtStringCacheCalloc (
265         strlen (CommonPath) + strlen (FilePathname) + 2);
266     if (LastElement && *CommonPath)
267     {
268         strcpy (Pathname, CommonPath);
269         strcat (Pathname, "/");
270     }
271     strcat (Pathname, FilePathname);
272 
273     /* Convert all backslashes to normal slashes */
274 
275 ConvertBackslashes:
276     UtConvertBackslashes (Pathname);
277 
278     DbgPrint (ASL_PARSE_OUTPUT, "Include: Merged Pathname - \"%s\"\n",
279          Pathname);
280     return (Pathname);
281 }
282 
283 
284 /*******************************************************************************
285  *
286  * FUNCTION:    FlOpenIncludeWithPrefix
287  *
288  * PARAMETERS:  PrefixDir       - Prefix directory pathname. Can be a zero
289  *                                length string.
290  *              Filename        - The include filename from the source ASL.
291  *
292  * RETURN:      Valid file descriptor if successful. Null otherwise.
293  *
294  * DESCRIPTION: Open an include file and push it on the input file stack.
295  *
296  ******************************************************************************/
297 
298 static FILE *
299 FlOpenIncludeWithPrefix (
300     char                    *PrefixDir,
301     ACPI_PARSE_OBJECT       *Op,
302     char                    *Filename)
303 {
304     FILE                    *IncludeFile;
305     char                    *Pathname;
306     UINT32                  OriginalLineNumber;
307 
308 
309     /* Build the full pathname to the file */
310 
311     Pathname = FlMergePathnames (PrefixDir, Filename);
312 
313     DbgPrint (ASL_PARSE_OUTPUT, "Include: Opening file - \"%s\"\n\n",
314         Pathname);
315 
316     /* Attempt to open the file, push if successful */
317 
318     IncludeFile = fopen (Pathname, "r");
319     if (!IncludeFile)
320     {
321         fprintf (stderr, "Could not open include file %s\n", Pathname);
322         ACPI_FREE (Pathname);
323         return (NULL);
324     }
325 
326     /*
327      * Check the entire include file for any # preprocessor directives.
328      * This is because there may be some confusion between the #include
329      * preprocessor directive and the ASL Include statement. A file included
330      * by the ASL include cannot contain preprocessor directives because
331      * the preprocessor has already run by the time the ASL include is
332      * recognized (by the compiler, not the preprocessor.)
333      *
334      * Note: DtGetNextLine strips/ignores comments.
335      * Save current line number since DtGetNextLine modifies it.
336      */
337     Gbl_CurrentLineNumber--;
338     OriginalLineNumber = Gbl_CurrentLineNumber;
339     while (DtGetNextLine (IncludeFile, DT_ALLOW_MULTILINE_QUOTES) != ASL_EOF)
340     {
341         if (Gbl_CurrentLineBuffer[0] == '#')
342         {
343             AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE,
344                 Op, "use #include instead");
345         }
346     }
347     Gbl_CurrentLineNumber = OriginalLineNumber;
348 
349     /* Must seek back to the start of the file */
350 
351     fseek (IncludeFile, 0, SEEK_SET);
352 
353     /* Push the include file on the open input file stack */
354 
355     AslPushInputFileStack (IncludeFile, Pathname);
356     return (IncludeFile);
357 }
358 
359 
360 /*******************************************************************************
361  *
362  * FUNCTION:    FlOpenIncludeFile
363  *
364  * PARAMETERS:  Op        - Parse node for the INCLUDE ASL statement
365  *
366  * RETURN:      None.
367  *
368  * DESCRIPTION: Open an include file and push it on the input file stack.
369  *
370  ******************************************************************************/
371 
372 void
373 FlOpenIncludeFile (
374     ACPI_PARSE_OBJECT       *Op)
375 {
376     FILE                    *IncludeFile;
377     ASL_INCLUDE_DIR         *NextDir;
378 
379 
380     /* Op must be valid */
381 
382     if (!Op)
383     {
384         AslCommonError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN,
385             Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
386             Gbl_InputByteCount, Gbl_CurrentColumn,
387             Gbl_Files[ASL_FILE_INPUT].Filename, " - Null parse node");
388 
389         return;
390     }
391 
392     /*
393      * Flush out the "include ()" statement on this line, start
394      * the actual include file on the next line
395      */
396     AslResetCurrentLineBuffer ();
397     FlPrintFile (ASL_FILE_SOURCE_OUTPUT, "\n");
398     Gbl_CurrentLineOffset++;
399 
400 
401     /* Attempt to open the include file */
402 
403     /* If the file specifies an absolute path, just open it */
404 
405     if ((Op->Asl.Value.String[0] == '/')  ||
406         (Op->Asl.Value.String[0] == '\\') ||
407         (Op->Asl.Value.String[1] == ':'))
408     {
409         IncludeFile = FlOpenIncludeWithPrefix ("", Op, Op->Asl.Value.String);
410         if (!IncludeFile)
411         {
412             goto ErrorExit;
413         }
414         return;
415     }
416 
417     /*
418      * The include filename is not an absolute path.
419      *
420      * First, search for the file within the "local" directory -- meaning
421      * the same directory that contains the source file.
422      *
423      * Construct the file pathname from the global directory name.
424      */
425     IncludeFile = FlOpenIncludeWithPrefix (
426         Gbl_DirectoryPath, Op, Op->Asl.Value.String);
427     if (IncludeFile)
428     {
429         return;
430     }
431 
432     /*
433      * Second, search for the file within the (possibly multiple) directories
434      * specified by the -I option on the command line.
435      */
436     NextDir = Gbl_IncludeDirList;
437     while (NextDir)
438     {
439         IncludeFile = FlOpenIncludeWithPrefix (
440             NextDir->Dir, Op, Op->Asl.Value.String);
441         if (IncludeFile)
442         {
443             return;
444         }
445 
446         NextDir = NextDir->Next;
447     }
448 
449     /* We could not open the include file after trying very hard */
450 
451 ErrorExit:
452     sprintf (MsgBuffer, "%s, %s", Op->Asl.Value.String, strerror (errno));
453     AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, Op, MsgBuffer);
454 }
455 
456 
457 /*******************************************************************************
458  *
459  * FUNCTION:    FlOpenInputFile
460  *
461  * PARAMETERS:  InputFilename       - The user-specified ASL source file to be
462  *                                    compiled
463  *
464  * RETURN:      Status
465  *
466  * DESCRIPTION: Open the specified input file, and save the directory path to
467  *              the file so that include files can be opened in
468  *              the same directory.
469  *
470  ******************************************************************************/
471 
472 ACPI_STATUS
473 FlOpenInputFile (
474     char                    *InputFilename)
475 {
476 
477     /* Open the input ASL file, text mode */
478 
479     FlOpenFile (ASL_FILE_INPUT, InputFilename, "rt");
480     AslCompilerin = Gbl_Files[ASL_FILE_INPUT].Handle;
481 
482     return (AE_OK);
483 }
484 
485 
486 /*******************************************************************************
487  *
488  * FUNCTION:    FlOpenAmlOutputFile
489  *
490  * PARAMETERS:  FilenamePrefix       - The user-specified ASL source file
491  *
492  * RETURN:      Status
493  *
494  * DESCRIPTION: Create the output filename (*.AML) and open the file. The file
495  *              is created in the same directory as the parent input file.
496  *
497  ******************************************************************************/
498 
499 ACPI_STATUS
500 FlOpenAmlOutputFile (
501     char                    *FilenamePrefix)
502 {
503     char                    *Filename;
504 
505 
506     /* Output filename usually comes from the ASL itself */
507 
508     Filename = Gbl_Files[ASL_FILE_AML_OUTPUT].Filename;
509     if (!Filename)
510     {
511         /* Create the output AML filename */
512 
513         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_AML_CODE);
514         if (!Filename)
515         {
516             AslCommonError (ASL_ERROR, ASL_MSG_OUTPUT_FILENAME,
517                 0, 0, 0, 0, NULL, NULL);
518             return (AE_ERROR);
519         }
520 
521         Gbl_Files[ASL_FILE_AML_OUTPUT].Filename = Filename;
522     }
523 
524     /* Open the output AML file in binary mode */
525 
526     FlOpenFile (ASL_FILE_AML_OUTPUT, Filename, "w+b");
527     return (AE_OK);
528 }
529 
530 
531 /*******************************************************************************
532  *
533  * FUNCTION:    FlOpenMiscOutputFiles
534  *
535  * PARAMETERS:  FilenamePrefix       - The user-specified ASL source file
536  *
537  * RETURN:      Status
538  *
539  * DESCRIPTION: Create and open the various output files needed, depending on
540  *              the command line options
541  *
542  ******************************************************************************/
543 
544 ACPI_STATUS
545 FlOpenMiscOutputFiles (
546     char                    *FilenamePrefix)
547 {
548     char                    *Filename;
549 
550 
551      /* Create/Open a map file if requested */
552 
553     if (Gbl_MapfileFlag)
554     {
555         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_MAP);
556         if (!Filename)
557         {
558             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
559                 0, 0, 0, 0, NULL, NULL);
560             return (AE_ERROR);
561         }
562 
563         /* Open the hex file, text mode (closed at compiler exit) */
564 
565         FlOpenFile (ASL_FILE_MAP_OUTPUT, Filename, "w+t");
566 
567         AslCompilerSignon (ASL_FILE_MAP_OUTPUT);
568         AslCompilerFileHeader (ASL_FILE_MAP_OUTPUT);
569     }
570 
571     /* All done for disassembler */
572 
573     if (Gbl_FileType == ASL_INPUT_TYPE_ACPI_TABLE)
574     {
575         return (AE_OK);
576     }
577 
578     /* Create/Open a hex output file if asked */
579 
580     if (Gbl_HexOutputFlag)
581     {
582         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_HEX_DUMP);
583         if (!Filename)
584         {
585             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
586                 0, 0, 0, 0, NULL, NULL);
587             return (AE_ERROR);
588         }
589 
590         /* Open the hex file, text mode */
591 
592         FlOpenFile (ASL_FILE_HEX_OUTPUT, Filename, "w+t");
593 
594         AslCompilerSignon (ASL_FILE_HEX_OUTPUT);
595         AslCompilerFileHeader (ASL_FILE_HEX_OUTPUT);
596     }
597 
598     /* Create/Open a debug output file if asked */
599 
600     if (Gbl_DebugFlag)
601     {
602         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_DEBUG);
603         if (!Filename)
604         {
605             AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME,
606                 0, 0, 0, 0, NULL, NULL);
607             return (AE_ERROR);
608         }
609 
610         /* Open the debug file as STDERR, text mode */
611 
612         Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Filename = Filename;
613         Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle =
614             freopen (Filename, "w+t", stderr);
615 
616         if (!Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle)
617         {
618             /*
619              * A problem with freopen is that on error, we no longer
620              * have stderr and cannot emit normal error messages.
621              * Emit error to stdout, close files, and exit.
622              */
623             fprintf (stdout,
624                 "\nCould not open debug output file: %s\n\n", Filename);
625 
626             CmCleanupAndExit ();
627             exit (1);
628         }
629 
630         AslCompilerSignon (ASL_FILE_DEBUG_OUTPUT);
631         AslCompilerFileHeader (ASL_FILE_DEBUG_OUTPUT);
632     }
633 
634     /* Create/Open a listing output file if asked */
635 
636     if (Gbl_ListingFlag)
637     {
638         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_LISTING);
639         if (!Filename)
640         {
641             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
642                 0, 0, 0, 0, NULL, NULL);
643             return (AE_ERROR);
644         }
645 
646         /* Open the listing file, text mode */
647 
648         FlOpenFile (ASL_FILE_LISTING_OUTPUT, Filename, "w+t");
649 
650         AslCompilerSignon (ASL_FILE_LISTING_OUTPUT);
651         AslCompilerFileHeader (ASL_FILE_LISTING_OUTPUT);
652     }
653 
654     /* Create the preprocessor output temp file if preprocessor enabled */
655 
656     if (Gbl_PreprocessFlag)
657     {
658         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_PREPROCESSOR);
659         if (!Filename)
660         {
661             AslCommonError (ASL_ERROR, ASL_MSG_PREPROCESSOR_FILENAME,
662                 0, 0, 0, 0, NULL, NULL);
663             return (AE_ERROR);
664         }
665 
666         FlOpenFile (ASL_FILE_PREPROCESSOR, Filename, "w+t");
667     }
668 
669     /*
670      * Create the "user" preprocessor output file if -li flag set.
671      * Note, this file contains no embedded #line directives.
672      */
673     if (Gbl_PreprocessorOutputFlag)
674     {
675         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_PREPROC_USER);
676         if (!Filename)
677         {
678             AslCommonError (ASL_ERROR, ASL_MSG_PREPROCESSOR_FILENAME,
679                 0, 0, 0, 0, NULL, NULL);
680             return (AE_ERROR);
681         }
682 
683         FlOpenFile (ASL_FILE_PREPROCESSOR_USER, Filename, "w+t");
684     }
685 
686     /* All done for data table compiler */
687 
688     if (Gbl_FileType == ASL_INPUT_TYPE_ASCII_DATA)
689     {
690         return (AE_OK);
691     }
692 
693     /* Create/Open a combined source output file */
694 
695     Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_SOURCE);
696     if (!Filename)
697     {
698         AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
699             0, 0, 0, 0, NULL, NULL);
700         return (AE_ERROR);
701     }
702 
703     /*
704      * Open the source output file, binary mode (so that LF does not get
705      * expanded to CR/LF on some systems, messing up our seek
706      * calculations.)
707      */
708     FlOpenFile (ASL_FILE_SOURCE_OUTPUT, Filename, "w+b");
709 
710 /*
711 // TBD: TEMP
712 //    AslCompilerin = Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle;
713 */
714     /* Create/Open a assembly code source output file if asked */
715 
716     if (Gbl_AsmOutputFlag)
717     {
718         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_SOURCE);
719         if (!Filename)
720         {
721             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
722                 0, 0, 0, 0, NULL, NULL);
723             return (AE_ERROR);
724         }
725 
726         /* Open the assembly code source file, text mode */
727 
728         FlOpenFile (ASL_FILE_ASM_SOURCE_OUTPUT, Filename, "w+t");
729 
730         AslCompilerSignon (ASL_FILE_ASM_SOURCE_OUTPUT);
731         AslCompilerFileHeader (ASL_FILE_ASM_SOURCE_OUTPUT);
732     }
733 
734     /* Create/Open a C code source output file if asked */
735 
736     if (Gbl_C_OutputFlag)
737     {
738         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_SOURCE);
739         if (!Filename)
740         {
741             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
742                 0, 0, 0, 0, NULL, NULL);
743             return (AE_ERROR);
744         }
745 
746         /* Open the C code source file, text mode */
747 
748         FlOpenFile (ASL_FILE_C_SOURCE_OUTPUT, Filename, "w+t");
749 
750         FlPrintFile (ASL_FILE_C_SOURCE_OUTPUT, "/*\n");
751         AslCompilerSignon (ASL_FILE_C_SOURCE_OUTPUT);
752         AslCompilerFileHeader (ASL_FILE_C_SOURCE_OUTPUT);
753     }
754 
755     /* Create/Open a C code source output file for the offset table if asked */
756 
757     if (Gbl_C_OffsetTableFlag)
758     {
759         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_OFFSET);
760         if (!Filename)
761         {
762             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
763                 0, 0, 0, 0, NULL, NULL);
764             return (AE_ERROR);
765         }
766 
767         /* Open the C code source file, text mode */
768 
769         FlOpenFile (ASL_FILE_C_OFFSET_OUTPUT, Filename, "w+t");
770 
771         FlPrintFile (ASL_FILE_C_OFFSET_OUTPUT, "/*\n");
772         AslCompilerSignon (ASL_FILE_C_OFFSET_OUTPUT);
773         AslCompilerFileHeader (ASL_FILE_C_OFFSET_OUTPUT);
774     }
775 
776     /* Create/Open a assembly include output file if asked */
777 
778     if (Gbl_AsmIncludeOutputFlag)
779     {
780         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_INCLUDE);
781         if (!Filename)
782         {
783             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
784                 0, 0, 0, 0, NULL, NULL);
785             return (AE_ERROR);
786         }
787 
788         /* Open the assembly include file, text mode */
789 
790         FlOpenFile (ASL_FILE_ASM_INCLUDE_OUTPUT, Filename, "w+t");
791 
792         AslCompilerSignon (ASL_FILE_ASM_INCLUDE_OUTPUT);
793         AslCompilerFileHeader (ASL_FILE_ASM_INCLUDE_OUTPUT);
794     }
795 
796     /* Create/Open a C include output file if asked */
797 
798     if (Gbl_C_IncludeOutputFlag)
799     {
800         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_INCLUDE);
801         if (!Filename)
802         {
803             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
804                 0, 0, 0, 0, NULL, NULL);
805             return (AE_ERROR);
806         }
807 
808         /* Open the C include file, text mode */
809 
810         FlOpenFile (ASL_FILE_C_INCLUDE_OUTPUT, Filename, "w+t");
811 
812         FlPrintFile (ASL_FILE_C_INCLUDE_OUTPUT, "/*\n");
813         AslCompilerSignon (ASL_FILE_C_INCLUDE_OUTPUT);
814         AslCompilerFileHeader (ASL_FILE_C_INCLUDE_OUTPUT);
815     }
816 
817     /* Create a namespace output file if asked */
818 
819     if (Gbl_NsOutputFlag)
820     {
821         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_NAMESPACE);
822         if (!Filename)
823         {
824             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
825                 0, 0, 0, 0, NULL, NULL);
826             return (AE_ERROR);
827         }
828 
829         /* Open the namespace file, text mode */
830 
831         FlOpenFile (ASL_FILE_NAMESPACE_OUTPUT, Filename, "w+t");
832 
833         AslCompilerSignon (ASL_FILE_NAMESPACE_OUTPUT);
834         AslCompilerFileHeader (ASL_FILE_NAMESPACE_OUTPUT);
835     }
836 
837     return (AE_OK);
838 }
839 
840 
841 #ifdef ACPI_OBSOLETE_FUNCTIONS
842 /*******************************************************************************
843  *
844  * FUNCTION:    FlParseInputPathname
845  *
846  * PARAMETERS:  InputFilename       - The user-specified ASL source file to be
847  *                                    compiled
848  *
849  * RETURN:      Status
850  *
851  * DESCRIPTION: Split the input path into a directory and filename part
852  *              1) Directory part used to open include files
853  *              2) Filename part used to generate output filenames
854  *
855  ******************************************************************************/
856 
857 ACPI_STATUS
858 FlParseInputPathname (
859     char                    *InputFilename)
860 {
861     char                    *Substring;
862 
863 
864     if (!InputFilename)
865     {
866         return (AE_OK);
867     }
868 
869     /* Get the path to the input filename's directory */
870 
871     Gbl_DirectoryPath = strdup (InputFilename);
872     if (!Gbl_DirectoryPath)
873     {
874         return (AE_NO_MEMORY);
875     }
876 
877     Substring = strrchr (Gbl_DirectoryPath, '\\');
878     if (!Substring)
879     {
880         Substring = strrchr (Gbl_DirectoryPath, '/');
881         if (!Substring)
882         {
883             Substring = strrchr (Gbl_DirectoryPath, ':');
884         }
885     }
886 
887     if (!Substring)
888     {
889         Gbl_DirectoryPath[0] = 0;
890         if (Gbl_UseDefaultAmlFilename)
891         {
892             Gbl_OutputFilenamePrefix = strdup (InputFilename);
893         }
894     }
895     else
896     {
897         if (Gbl_UseDefaultAmlFilename)
898         {
899             Gbl_OutputFilenamePrefix = strdup (Substring + 1);
900         }
901         *(Substring+1) = 0;
902     }
903 
904     UtConvertBackslashes (Gbl_OutputFilenamePrefix);
905     return (AE_OK);
906 }
907 #endif
908