xref: /freebsd/sys/contrib/dev/acpica/compiler/aslfiles.c (revision 8a166cafe0965f6bd72cd3d2f5372704f05cb5e8)
1 /******************************************************************************
2  *
3  * Module Name: aslfiles - File support functions
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2013, 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 <contrib/dev/acpica/compiler/aslcompiler.h>
45 #include <contrib/dev/acpica/include/acapps.h>
46 
47 #define _COMPONENT          ACPI_COMPILER
48         ACPI_MODULE_NAME    ("aslfiles")
49 
50 /* Local prototypes */
51 
52 FILE *
53 FlOpenIncludeWithPrefix (
54     char                    *PrefixDir,
55     char                    *Filename);
56 
57 
58 #ifdef ACPI_OBSOLETE_FUNCTIONS
59 ACPI_STATUS
60 FlParseInputPathname (
61     char                    *InputFilename);
62 #endif
63 
64 
65 /*******************************************************************************
66  *
67  * FUNCTION:    FlSetLineNumber
68  *
69  * PARAMETERS:  Op        - Parse node for the LINE asl statement
70  *
71  * RETURN:      None.
72  *
73  * DESCRIPTION: Set the current line number
74  *
75  ******************************************************************************/
76 
77 void
78 FlSetLineNumber (
79     UINT32                  LineNumber)
80 {
81 
82     DbgPrint (ASL_PARSE_OUTPUT, "\n#line: New line number %u (old %u)\n",
83          LineNumber, Gbl_LogicalLineNumber);
84 
85     Gbl_CurrentLineNumber = LineNumber;
86     Gbl_LogicalLineNumber = 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     Gbl_Files[ASL_FILE_INPUT].Filename = Filename;
111 }
112 
113 
114 /*******************************************************************************
115  *
116  * FUNCTION:    FlAddIncludeDirectory
117  *
118  * PARAMETERS:  Dir             - Directory pathname string
119  *
120  * RETURN:      None
121  *
122  * DESCRIPTION: Add a directory the list of include prefix directories.
123  *
124  ******************************************************************************/
125 
126 void
127 FlAddIncludeDirectory (
128     char                    *Dir)
129 {
130     ASL_INCLUDE_DIR         *NewDir;
131     ASL_INCLUDE_DIR         *NextDir;
132     ASL_INCLUDE_DIR         *PrevDir = NULL;
133     UINT32                  NeedsSeparator = 0;
134     size_t                  DirLength;
135 
136 
137     DirLength = strlen (Dir);
138     if (!DirLength)
139     {
140         return;
141     }
142 
143     /* Make sure that the pathname ends with a path separator */
144 
145     if ((Dir[DirLength-1] != '/') &&
146         (Dir[DirLength-1] != '\\'))
147     {
148         NeedsSeparator = 1;
149     }
150 
151     NewDir = ACPI_ALLOCATE_ZEROED (sizeof (ASL_INCLUDE_DIR));
152     NewDir->Dir = ACPI_ALLOCATE (DirLength + 1 + NeedsSeparator);
153     strcpy (NewDir->Dir, Dir);
154     if (NeedsSeparator)
155     {
156         strcat (NewDir->Dir, "/");
157     }
158 
159     /*
160      * Preserve command line ordering of -I options by adding new elements
161      * at the end of the list
162      */
163     NextDir = Gbl_IncludeDirList;
164     while (NextDir)
165     {
166         PrevDir = NextDir;
167         NextDir = NextDir->Next;
168     }
169 
170     if (PrevDir)
171     {
172         PrevDir->Next = NewDir;
173     }
174     else
175     {
176         Gbl_IncludeDirList = NewDir;
177     }
178 }
179 
180 
181 /*******************************************************************************
182  *
183  * FUNCTION:    FlMergePathnames
184  *
185  * PARAMETERS:  PrefixDir       - Prefix directory pathname. Can be NULL or
186  *                                a zero length string.
187  *              FilePathname    - The include filename from the source ASL.
188  *
189  * RETURN:      Merged pathname string
190  *
191  * DESCRIPTION: Merge two pathnames that (probably) have common elements, to
192  *              arrive at a minimal length string. Merge can occur if the
193  *              FilePathname is relative to the PrefixDir.
194  *
195  ******************************************************************************/
196 
197 char *
198 FlMergePathnames (
199     char                    *PrefixDir,
200     char                    *FilePathname)
201 {
202     char                    *CommonPath;
203     char                    *Pathname;
204     char                    *LastElement;
205 
206 
207     DbgPrint (ASL_PARSE_OUTPUT, "Include: Prefix path - \"%s\"\n"
208         "Include: FilePathname - \"%s\"\n",
209          PrefixDir, FilePathname);
210 
211     /*
212      * If there is no prefix directory or if the file pathname is absolute,
213      * just return the original file pathname
214      */
215     if (!PrefixDir || (!*PrefixDir) ||
216         (*FilePathname == '/') ||
217          (FilePathname[1] == ':'))
218     {
219         Pathname = ACPI_ALLOCATE (strlen (FilePathname) + 1);
220         strcpy (Pathname, FilePathname);
221         goto ConvertBackslashes;
222     }
223 
224     /* Need a local copy of the prefix directory path */
225 
226     CommonPath = ACPI_ALLOCATE (strlen (PrefixDir) + 1);
227     strcpy (CommonPath, PrefixDir);
228 
229     /*
230      * Walk forward through the file path, and simultaneously backward
231      * through the prefix directory path until there are no more
232      * relative references at the start of the file path.
233      */
234     while (*FilePathname && (!strncmp (FilePathname, "../", 3)))
235     {
236         /* Remove last element of the prefix directory path */
237 
238         LastElement = strrchr (CommonPath, '/');
239         if (!LastElement)
240         {
241             goto ConcatenatePaths;
242         }
243 
244         *LastElement = 0;   /* Terminate CommonPath string */
245         FilePathname += 3;  /* Point to next path element */
246     }
247 
248     /*
249      * Remove the last element of the prefix directory path (it is the same as
250      * the first element of the file pathname), and build the final merged
251      * pathname.
252      */
253     LastElement = strrchr (CommonPath, '/');
254     if (LastElement)
255     {
256         *LastElement = 0;
257     }
258 
259     /* Build the final merged pathname */
260 
261 ConcatenatePaths:
262     Pathname = ACPI_ALLOCATE_ZEROED (strlen (CommonPath) + strlen (FilePathname) + 2);
263     if (LastElement && *CommonPath)
264     {
265         strcpy (Pathname, CommonPath);
266         strcat (Pathname, "/");
267     }
268     strcat (Pathname, FilePathname);
269     ACPI_FREE (CommonPath);
270 
271     /* Convert all backslashes to normal slashes */
272 
273 ConvertBackslashes:
274     UtConvertBackslashes (Pathname);
275 
276     DbgPrint (ASL_PARSE_OUTPUT, "Include: Merged Pathname - \"%s\"\n",
277          Pathname);
278     return (Pathname);
279 }
280 
281 
282 /*******************************************************************************
283  *
284  * FUNCTION:    FlOpenIncludeWithPrefix
285  *
286  * PARAMETERS:  PrefixDir       - Prefix directory pathname. Can be a zero
287  *                                length string.
288  *              Filename        - The include filename from the source ASL.
289  *
290  * RETURN:      Valid file descriptor if successful. Null otherwise.
291  *
292  * DESCRIPTION: Open an include file and push it on the input file stack.
293  *
294  ******************************************************************************/
295 
296 FILE *
297 FlOpenIncludeWithPrefix (
298     char                    *PrefixDir,
299     char                    *Filename)
300 {
301     FILE                    *IncludeFile;
302     char                    *Pathname;
303 
304 
305     /* Build the full pathname to the file */
306 
307     Pathname = FlMergePathnames (PrefixDir, Filename);
308 
309     DbgPrint (ASL_PARSE_OUTPUT, "Include: Opening file - \"%s\"\n\n",
310         Pathname);
311 
312     /* Attempt to open the file, push if successful */
313 
314     IncludeFile = fopen (Pathname, "r");
315     if (!IncludeFile)
316     {
317         fprintf (stderr, "Could not open include file %s\n", Pathname);
318         ACPI_FREE (Pathname);
319         return (NULL);
320     }
321 
322     /* Push the include file on the open input file stack */
323 
324     AslPushInputFileStack (IncludeFile, Pathname);
325     return (IncludeFile);
326 }
327 
328 
329 /*******************************************************************************
330  *
331  * FUNCTION:    FlOpenIncludeFile
332  *
333  * PARAMETERS:  Op        - Parse node for the INCLUDE ASL statement
334  *
335  * RETURN:      None.
336  *
337  * DESCRIPTION: Open an include file and push it on the input file stack.
338  *
339  ******************************************************************************/
340 
341 void
342 FlOpenIncludeFile (
343     ACPI_PARSE_OBJECT       *Op)
344 {
345     FILE                    *IncludeFile;
346     ASL_INCLUDE_DIR         *NextDir;
347 
348 
349     /* Op must be valid */
350 
351     if (!Op)
352     {
353         AslCommonError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN,
354             Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
355             Gbl_InputByteCount, Gbl_CurrentColumn,
356             Gbl_Files[ASL_FILE_INPUT].Filename, " - Null parse node");
357 
358         return;
359     }
360 
361     /*
362      * Flush out the "include ()" statement on this line, start
363      * the actual include file on the next line
364      */
365     AslResetCurrentLineBuffer ();
366     FlPrintFile (ASL_FILE_SOURCE_OUTPUT, "\n");
367     Gbl_CurrentLineOffset++;
368 
369 
370     /* Attempt to open the include file */
371 
372     /* If the file specifies an absolute path, just open it */
373 
374     if ((Op->Asl.Value.String[0] == '/')  ||
375         (Op->Asl.Value.String[0] == '\\') ||
376         (Op->Asl.Value.String[1] == ':'))
377     {
378         IncludeFile = FlOpenIncludeWithPrefix ("", Op->Asl.Value.String);
379         if (!IncludeFile)
380         {
381             goto ErrorExit;
382         }
383         return;
384     }
385 
386     /*
387      * The include filename is not an absolute path.
388      *
389      * First, search for the file within the "local" directory -- meaning
390      * the same directory that contains the source file.
391      *
392      * Construct the file pathname from the global directory name.
393      */
394     IncludeFile = FlOpenIncludeWithPrefix (Gbl_DirectoryPath, Op->Asl.Value.String);
395     if (IncludeFile)
396     {
397         return;
398     }
399 
400     /*
401      * Second, search for the file within the (possibly multiple) directories
402      * specified by the -I option on the command line.
403      */
404     NextDir = Gbl_IncludeDirList;
405     while (NextDir)
406     {
407         IncludeFile = FlOpenIncludeWithPrefix (NextDir->Dir, Op->Asl.Value.String);
408         if (IncludeFile)
409         {
410             return;
411         }
412 
413         NextDir = NextDir->Next;
414     }
415 
416     /* We could not open the include file after trying very hard */
417 
418 ErrorExit:
419     sprintf (MsgBuffer, "%s, %s", Op->Asl.Value.String, strerror (errno));
420     AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, Op, MsgBuffer);
421 }
422 
423 
424 /*******************************************************************************
425  *
426  * FUNCTION:    FlOpenInputFile
427  *
428  * PARAMETERS:  InputFilename       - The user-specified ASL source file to be
429  *                                    compiled
430  *
431  * RETURN:      Status
432  *
433  * DESCRIPTION: Open the specified input file, and save the directory path to
434  *              the file so that include files can be opened in
435  *              the same directory.
436  *
437  ******************************************************************************/
438 
439 ACPI_STATUS
440 FlOpenInputFile (
441     char                    *InputFilename)
442 {
443 
444     /* Open the input ASL file, text mode */
445 
446     FlOpenFile (ASL_FILE_INPUT, InputFilename, "rt");
447     AslCompilerin = Gbl_Files[ASL_FILE_INPUT].Handle;
448 
449     return (AE_OK);
450 }
451 
452 
453 /*******************************************************************************
454  *
455  * FUNCTION:    FlOpenAmlOutputFile
456  *
457  * PARAMETERS:  FilenamePrefix       - The user-specified ASL source file
458  *
459  * RETURN:      Status
460  *
461  * DESCRIPTION: Create the output filename (*.AML) and open the file. The file
462  *              is created in the same directory as the parent input file.
463  *
464  ******************************************************************************/
465 
466 ACPI_STATUS
467 FlOpenAmlOutputFile (
468     char                    *FilenamePrefix)
469 {
470     char                    *Filename;
471 
472 
473     /* Output filename usually comes from the ASL itself */
474 
475     Filename = Gbl_Files[ASL_FILE_AML_OUTPUT].Filename;
476     if (!Filename)
477     {
478         /* Create the output AML filename */
479 
480         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_AML_CODE);
481         if (!Filename)
482         {
483             AslCommonError (ASL_ERROR, ASL_MSG_OUTPUT_FILENAME,
484                 0, 0, 0, 0, NULL, NULL);
485             return (AE_ERROR);
486         }
487     }
488 
489     /* Open the output AML file in binary mode */
490 
491     FlOpenFile (ASL_FILE_AML_OUTPUT, Filename, "w+b");
492     return (AE_OK);
493 }
494 
495 
496 /*******************************************************************************
497  *
498  * FUNCTION:    FlOpenMiscOutputFiles
499  *
500  * PARAMETERS:  FilenamePrefix       - The user-specified ASL source file
501  *
502  * RETURN:      Status
503  *
504  * DESCRIPTION: Create and open the various output files needed, depending on
505  *              the command line options
506  *
507  ******************************************************************************/
508 
509 ACPI_STATUS
510 FlOpenMiscOutputFiles (
511     char                    *FilenamePrefix)
512 {
513     char                    *Filename;
514 
515 
516     /* Create/Open a hex output file if asked */
517 
518     if (Gbl_HexOutputFlag)
519     {
520         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_HEX_DUMP);
521         if (!Filename)
522         {
523             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
524                 0, 0, 0, 0, NULL, NULL);
525             return (AE_ERROR);
526         }
527 
528         /* Open the hex file, text mode */
529 
530         FlOpenFile (ASL_FILE_HEX_OUTPUT, Filename, "w+t");
531 
532         AslCompilerSignon (ASL_FILE_HEX_OUTPUT);
533         AslCompilerFileHeader (ASL_FILE_HEX_OUTPUT);
534     }
535 
536     /* Create/Open a debug output file if asked */
537 
538     if (Gbl_DebugFlag)
539     {
540         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_DEBUG);
541         if (!Filename)
542         {
543             AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME,
544                 0, 0, 0, 0, NULL, NULL);
545             return (AE_ERROR);
546         }
547 
548         /* Open the debug file as STDERR, text mode */
549 
550         /* TBD: hide this behind a FlReopenFile function */
551 
552         Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Filename = Filename;
553         Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle =
554             freopen (Filename, "w+t", stderr);
555 
556         if (!Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle)
557         {
558             AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME,
559                 0, 0, 0, 0, NULL, NULL);
560             return (AE_ERROR);
561         }
562 
563         AslCompilerSignon (ASL_FILE_DEBUG_OUTPUT);
564         AslCompilerFileHeader (ASL_FILE_DEBUG_OUTPUT);
565     }
566 
567     /* Create/Open a listing output file if asked */
568 
569     if (Gbl_ListingFlag)
570     {
571         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_LISTING);
572         if (!Filename)
573         {
574             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
575                 0, 0, 0, 0, NULL, NULL);
576             return (AE_ERROR);
577         }
578 
579         /* Open the listing file, text mode */
580 
581         FlOpenFile (ASL_FILE_LISTING_OUTPUT, Filename, "w+t");
582 
583         AslCompilerSignon (ASL_FILE_LISTING_OUTPUT);
584         AslCompilerFileHeader (ASL_FILE_LISTING_OUTPUT);
585     }
586 
587     /* Create the preprocessor output file if preprocessor enabled */
588 
589     if (Gbl_PreprocessFlag)
590     {
591         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_PREPROCESSOR);
592         if (!Filename)
593         {
594             AslCommonError (ASL_ERROR, ASL_MSG_PREPROCESSOR_FILENAME,
595                 0, 0, 0, 0, NULL, NULL);
596             return (AE_ERROR);
597         }
598 
599         FlOpenFile (ASL_FILE_PREPROCESSOR, Filename, "w+t");
600     }
601 
602     /* All done for data table compiler */
603 
604     if (Gbl_FileType == ASL_INPUT_TYPE_ASCII_DATA)
605     {
606         return (AE_OK);
607     }
608 
609     /* Create/Open a combined source output file */
610 
611     Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_SOURCE);
612     if (!Filename)
613     {
614         AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
615             0, 0, 0, 0, NULL, NULL);
616         return (AE_ERROR);
617     }
618 
619     /*
620      * Open the source output file, binary mode (so that LF does not get
621      * expanded to CR/LF on some systems, messing up our seek
622      * calculations.)
623      */
624     FlOpenFile (ASL_FILE_SOURCE_OUTPUT, Filename, "w+b");
625 
626 /*
627 // TBD: TEMP
628 //    AslCompilerin = Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle;
629 */
630     /* Create/Open a assembly code source output file if asked */
631 
632     if (Gbl_AsmOutputFlag)
633     {
634         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_SOURCE);
635         if (!Filename)
636         {
637             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
638                 0, 0, 0, 0, NULL, NULL);
639             return (AE_ERROR);
640         }
641 
642         /* Open the assembly code source file, text mode */
643 
644         FlOpenFile (ASL_FILE_ASM_SOURCE_OUTPUT, Filename, "w+t");
645 
646         AslCompilerSignon (ASL_FILE_ASM_SOURCE_OUTPUT);
647         AslCompilerFileHeader (ASL_FILE_ASM_SOURCE_OUTPUT);
648     }
649 
650     /* Create/Open a C code source output file if asked */
651 
652     if (Gbl_C_OutputFlag)
653     {
654         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_SOURCE);
655         if (!Filename)
656         {
657             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
658                 0, 0, 0, 0, NULL, NULL);
659             return (AE_ERROR);
660         }
661 
662         /* Open the C code source file, text mode */
663 
664         FlOpenFile (ASL_FILE_C_SOURCE_OUTPUT, Filename, "w+t");
665 
666         FlPrintFile (ASL_FILE_C_SOURCE_OUTPUT, "/*\n");
667         AslCompilerSignon (ASL_FILE_C_SOURCE_OUTPUT);
668         AslCompilerFileHeader (ASL_FILE_C_SOURCE_OUTPUT);
669     }
670 
671     /* Create/Open a assembly include output file if asked */
672 
673     if (Gbl_AsmIncludeOutputFlag)
674     {
675         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_INCLUDE);
676         if (!Filename)
677         {
678             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
679                 0, 0, 0, 0, NULL, NULL);
680             return (AE_ERROR);
681         }
682 
683         /* Open the assembly include file, text mode */
684 
685         FlOpenFile (ASL_FILE_ASM_INCLUDE_OUTPUT, Filename, "w+t");
686 
687         AslCompilerSignon (ASL_FILE_ASM_INCLUDE_OUTPUT);
688         AslCompilerFileHeader (ASL_FILE_ASM_INCLUDE_OUTPUT);
689     }
690 
691     /* Create/Open a C include output file if asked */
692 
693     if (Gbl_C_IncludeOutputFlag)
694     {
695         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_INCLUDE);
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         /* Open the C include file, text mode */
704 
705         FlOpenFile (ASL_FILE_C_INCLUDE_OUTPUT, Filename, "w+t");
706 
707         FlPrintFile (ASL_FILE_C_INCLUDE_OUTPUT, "/*\n");
708         AslCompilerSignon (ASL_FILE_C_INCLUDE_OUTPUT);
709         AslCompilerFileHeader (ASL_FILE_C_INCLUDE_OUTPUT);
710     }
711 
712     /* Create a namespace output file if asked */
713 
714     if (Gbl_NsOutputFlag)
715     {
716         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_NAMESPACE);
717         if (!Filename)
718         {
719             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
720                 0, 0, 0, 0, NULL, NULL);
721             return (AE_ERROR);
722         }
723 
724         /* Open the namespace file, text mode */
725 
726         FlOpenFile (ASL_FILE_NAMESPACE_OUTPUT, Filename, "w+t");
727 
728         AslCompilerSignon (ASL_FILE_NAMESPACE_OUTPUT);
729         AslCompilerFileHeader (ASL_FILE_NAMESPACE_OUTPUT);
730     }
731 
732     return (AE_OK);
733 }
734 
735 
736 #ifdef ACPI_OBSOLETE_FUNCTIONS
737 /*******************************************************************************
738  *
739  * FUNCTION:    FlParseInputPathname
740  *
741  * PARAMETERS:  InputFilename       - The user-specified ASL source file to be
742  *                                    compiled
743  *
744  * RETURN:      Status
745  *
746  * DESCRIPTION: Split the input path into a directory and filename part
747  *              1) Directory part used to open include files
748  *              2) Filename part used to generate output filenames
749  *
750  ******************************************************************************/
751 
752 ACPI_STATUS
753 FlParseInputPathname (
754     char                    *InputFilename)
755 {
756     char                    *Substring;
757 
758 
759     if (!InputFilename)
760     {
761         return (AE_OK);
762     }
763 
764     /* Get the path to the input filename's directory */
765 
766     Gbl_DirectoryPath = strdup (InputFilename);
767     if (!Gbl_DirectoryPath)
768     {
769         return (AE_NO_MEMORY);
770     }
771 
772     Substring = strrchr (Gbl_DirectoryPath, '\\');
773     if (!Substring)
774     {
775         Substring = strrchr (Gbl_DirectoryPath, '/');
776         if (!Substring)
777         {
778             Substring = strrchr (Gbl_DirectoryPath, ':');
779         }
780     }
781 
782     if (!Substring)
783     {
784         Gbl_DirectoryPath[0] = 0;
785         if (Gbl_UseDefaultAmlFilename)
786         {
787             Gbl_OutputFilenamePrefix = strdup (InputFilename);
788         }
789     }
790     else
791     {
792         if (Gbl_UseDefaultAmlFilename)
793         {
794             Gbl_OutputFilenamePrefix = strdup (Substring + 1);
795         }
796         *(Substring+1) = 0;
797     }
798 
799     return (AE_OK);
800 }
801 #endif
802