Sync ACPICA with Intel's version 20150717.
[dragonfly.git] / sys / contrib / dev / acpica / source / compiler / aslfiles.c
blob1b738ccf15d8829b51af8d474e99138299f9a7bb
1 /******************************************************************************
3 * Module Name: aslfiles - File support functions
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2015, Intel Corp.
9 * All rights reserved.
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.
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.
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.
44 #include "aslcompiler.h"
45 #include "acapps.h"
46 #include "dtcompiler.h"
48 #define _COMPONENT ACPI_COMPILER
49 ACPI_MODULE_NAME ("aslfiles")
51 /* Local prototypes */
53 static FILE *
54 FlOpenIncludeWithPrefix (
55 char *PrefixDir,
56 ACPI_PARSE_OBJECT *Op,
57 char *Filename);
60 #ifdef ACPI_OBSOLETE_FUNCTIONS
61 ACPI_STATUS
62 FlParseInputPathname (
63 char *InputFilename);
64 #endif
67 /*******************************************************************************
69 * FUNCTION: FlSetLineNumber
71 * PARAMETERS: Op - Parse node for the LINE asl statement
73 * RETURN: None.
75 * DESCRIPTION: Set the current line number
77 ******************************************************************************/
79 void
80 FlSetLineNumber (
81 UINT32 LineNumber)
84 DbgPrint (ASL_PARSE_OUTPUT, "\n#line: New line number %u (old %u)\n",
85 LineNumber, Gbl_LogicalLineNumber);
87 Gbl_CurrentLineNumber = LineNumber;
91 /*******************************************************************************
93 * FUNCTION: FlSetFilename
95 * PARAMETERS: Op - Parse node for the LINE asl statement
97 * RETURN: None.
99 * DESCRIPTION: Set the current filename
101 ******************************************************************************/
103 void
104 FlSetFilename (
105 char *Filename)
108 DbgPrint (ASL_PARSE_OUTPUT, "\n#line: New filename %s (old %s)\n",
109 Filename, Gbl_Files[ASL_FILE_INPUT].Filename);
111 /* No need to free any existing filename */
113 Gbl_Files[ASL_FILE_INPUT].Filename = Filename;
117 /*******************************************************************************
119 * FUNCTION: FlAddIncludeDirectory
121 * PARAMETERS: Dir - Directory pathname string
123 * RETURN: None
125 * DESCRIPTION: Add a directory the list of include prefix directories.
127 ******************************************************************************/
129 void
130 FlAddIncludeDirectory (
131 char *Dir)
133 ASL_INCLUDE_DIR *NewDir;
134 ASL_INCLUDE_DIR *NextDir;
135 ASL_INCLUDE_DIR *PrevDir = NULL;
136 UINT32 NeedsSeparator = 0;
137 size_t DirLength;
140 DirLength = strlen (Dir);
141 if (!DirLength)
143 return;
146 /* Make sure that the pathname ends with a path separator */
148 if ((Dir[DirLength-1] != '/') &&
149 (Dir[DirLength-1] != '\\'))
151 NeedsSeparator = 1;
154 NewDir = ACPI_ALLOCATE_ZEROED (sizeof (ASL_INCLUDE_DIR));
155 NewDir->Dir = ACPI_ALLOCATE (DirLength + 1 + NeedsSeparator);
156 strcpy (NewDir->Dir, Dir);
157 if (NeedsSeparator)
159 strcat (NewDir->Dir, "/");
163 * Preserve command line ordering of -I options by adding new elements
164 * at the end of the list
166 NextDir = Gbl_IncludeDirList;
167 while (NextDir)
169 PrevDir = NextDir;
170 NextDir = NextDir->Next;
173 if (PrevDir)
175 PrevDir->Next = NewDir;
177 else
179 Gbl_IncludeDirList = NewDir;
184 /*******************************************************************************
186 * FUNCTION: FlMergePathnames
188 * PARAMETERS: PrefixDir - Prefix directory pathname. Can be NULL or
189 * a zero length string.
190 * FilePathname - The include filename from the source ASL.
192 * RETURN: Merged pathname string
194 * DESCRIPTION: Merge two pathnames that (probably) have common elements, to
195 * arrive at a minimal length string. Merge can occur if the
196 * FilePathname is relative to the PrefixDir.
198 ******************************************************************************/
200 char *
201 FlMergePathnames (
202 char *PrefixDir,
203 char *FilePathname)
205 char *CommonPath;
206 char *Pathname;
207 char *LastElement;
210 DbgPrint (ASL_PARSE_OUTPUT, "Include: Prefix path - \"%s\"\n"
211 "Include: FilePathname - \"%s\"\n",
212 PrefixDir, FilePathname);
215 * If there is no prefix directory or if the file pathname is absolute,
216 * just return the original file pathname
218 if (!PrefixDir || (!*PrefixDir) ||
219 (*FilePathname == '/') ||
220 (FilePathname[1] == ':'))
222 Pathname = UtStringCacheCalloc (strlen (FilePathname) + 1);
223 strcpy (Pathname, FilePathname);
224 goto ConvertBackslashes;
227 /* Need a local copy of the prefix directory path */
229 CommonPath = UtStringCacheCalloc (strlen (PrefixDir) + 1);
230 strcpy (CommonPath, PrefixDir);
233 * Walk forward through the file path, and simultaneously backward
234 * through the prefix directory path until there are no more
235 * relative references at the start of the file path.
237 while (*FilePathname && (!strncmp (FilePathname, "../", 3)))
239 /* Remove last element of the prefix directory path */
241 LastElement = strrchr (CommonPath, '/');
242 if (!LastElement)
244 goto ConcatenatePaths;
247 *LastElement = 0; /* Terminate CommonPath string */
248 FilePathname += 3; /* Point to next path element */
252 * Remove the last element of the prefix directory path (it is the same as
253 * the first element of the file pathname), and build the final merged
254 * pathname.
256 LastElement = strrchr (CommonPath, '/');
257 if (LastElement)
259 *LastElement = 0;
262 /* Build the final merged pathname */
264 ConcatenatePaths:
265 Pathname = UtStringCacheCalloc (strlen (CommonPath) + strlen (FilePathname) + 2);
266 if (LastElement && *CommonPath)
268 strcpy (Pathname, CommonPath);
269 strcat (Pathname, "/");
271 strcat (Pathname, FilePathname);
273 /* Convert all backslashes to normal slashes */
275 ConvertBackslashes:
276 UtConvertBackslashes (Pathname);
278 DbgPrint (ASL_PARSE_OUTPUT, "Include: Merged Pathname - \"%s\"\n",
279 Pathname);
280 return (Pathname);
284 /*******************************************************************************
286 * FUNCTION: FlOpenIncludeWithPrefix
288 * PARAMETERS: PrefixDir - Prefix directory pathname. Can be a zero
289 * length string.
290 * Filename - The include filename from the source ASL.
292 * RETURN: Valid file descriptor if successful. Null otherwise.
294 * DESCRIPTION: Open an include file and push it on the input file stack.
296 ******************************************************************************/
298 static FILE *
299 FlOpenIncludeWithPrefix (
300 char *PrefixDir,
301 ACPI_PARSE_OBJECT *Op,
302 char *Filename)
304 FILE *IncludeFile;
305 char *Pathname;
306 UINT32 OriginalLineNumber;
309 /* Build the full pathname to the file */
311 Pathname = FlMergePathnames (PrefixDir, Filename);
313 DbgPrint (ASL_PARSE_OUTPUT, "Include: Opening file - \"%s\"\n\n",
314 Pathname);
316 /* Attempt to open the file, push if successful */
318 IncludeFile = fopen (Pathname, "r");
319 if (!IncludeFile)
321 fprintf (stderr, "Could not open include file %s\n", Pathname);
322 ACPI_FREE (Pathname);
323 return (NULL);
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.)
334 * Note: DtGetNextLine strips/ignores comments.
335 * Save current line number since DtGetNextLine modifies it.
337 Gbl_CurrentLineNumber--;
338 OriginalLineNumber = Gbl_CurrentLineNumber;
339 while (DtGetNextLine (IncludeFile, DT_ALLOW_MULTILINE_QUOTES) != ASL_EOF)
341 if (Gbl_CurrentLineBuffer[0] == '#')
343 AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE,
344 Op, "use #include instead");
347 Gbl_CurrentLineNumber = OriginalLineNumber;
349 /* Must seek back to the start of the file */
351 fseek (IncludeFile, 0, SEEK_SET);
353 /* Push the include file on the open input file stack */
355 AslPushInputFileStack (IncludeFile, Pathname);
356 return (IncludeFile);
360 /*******************************************************************************
362 * FUNCTION: FlOpenIncludeFile
364 * PARAMETERS: Op - Parse node for the INCLUDE ASL statement
366 * RETURN: None.
368 * DESCRIPTION: Open an include file and push it on the input file stack.
370 ******************************************************************************/
372 void
373 FlOpenIncludeFile (
374 ACPI_PARSE_OBJECT *Op)
376 FILE *IncludeFile;
377 ASL_INCLUDE_DIR *NextDir;
380 /* Op must be valid */
382 if (!Op)
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");
389 return;
393 * Flush out the "include ()" statement on this line, start
394 * the actual include file on the next line
396 AslResetCurrentLineBuffer ();
397 FlPrintFile (ASL_FILE_SOURCE_OUTPUT, "\n");
398 Gbl_CurrentLineOffset++;
401 /* Attempt to open the include file */
403 /* If the file specifies an absolute path, just open it */
405 if ((Op->Asl.Value.String[0] == '/') ||
406 (Op->Asl.Value.String[0] == '\\') ||
407 (Op->Asl.Value.String[1] == ':'))
409 IncludeFile = FlOpenIncludeWithPrefix ("", Op, Op->Asl.Value.String);
410 if (!IncludeFile)
412 goto ErrorExit;
414 return;
418 * The include filename is not an absolute path.
420 * First, search for the file within the "local" directory -- meaning
421 * the same directory that contains the source file.
423 * Construct the file pathname from the global directory name.
425 IncludeFile = FlOpenIncludeWithPrefix (Gbl_DirectoryPath, Op, Op->Asl.Value.String);
426 if (IncludeFile)
428 return;
432 * Second, search for the file within the (possibly multiple) directories
433 * specified by the -I option on the command line.
435 NextDir = Gbl_IncludeDirList;
436 while (NextDir)
438 IncludeFile = FlOpenIncludeWithPrefix (NextDir->Dir, Op, Op->Asl.Value.String);
439 if (IncludeFile)
441 return;
444 NextDir = NextDir->Next;
447 /* We could not open the include file after trying very hard */
449 ErrorExit:
450 sprintf (MsgBuffer, "%s, %s", Op->Asl.Value.String, strerror (errno));
451 AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, Op, MsgBuffer);
455 /*******************************************************************************
457 * FUNCTION: FlOpenInputFile
459 * PARAMETERS: InputFilename - The user-specified ASL source file to be
460 * compiled
462 * RETURN: Status
464 * DESCRIPTION: Open the specified input file, and save the directory path to
465 * the file so that include files can be opened in
466 * the same directory.
468 ******************************************************************************/
470 ACPI_STATUS
471 FlOpenInputFile (
472 char *InputFilename)
475 /* Open the input ASL file, text mode */
477 FlOpenFile (ASL_FILE_INPUT, InputFilename, "rt");
478 AslCompilerin = Gbl_Files[ASL_FILE_INPUT].Handle;
480 return (AE_OK);
484 /*******************************************************************************
486 * FUNCTION: FlOpenAmlOutputFile
488 * PARAMETERS: FilenamePrefix - The user-specified ASL source file
490 * RETURN: Status
492 * DESCRIPTION: Create the output filename (*.AML) and open the file. The file
493 * is created in the same directory as the parent input file.
495 ******************************************************************************/
497 ACPI_STATUS
498 FlOpenAmlOutputFile (
499 char *FilenamePrefix)
501 char *Filename;
504 /* Output filename usually comes from the ASL itself */
506 Filename = Gbl_Files[ASL_FILE_AML_OUTPUT].Filename;
507 if (!Filename)
509 /* Create the output AML filename */
511 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_AML_CODE);
512 if (!Filename)
514 AslCommonError (ASL_ERROR, ASL_MSG_OUTPUT_FILENAME,
515 0, 0, 0, 0, NULL, NULL);
516 return (AE_ERROR);
519 Gbl_Files[ASL_FILE_AML_OUTPUT].Filename = Filename;
522 /* Open the output AML file in binary mode */
524 FlOpenFile (ASL_FILE_AML_OUTPUT, Filename, "w+b");
525 return (AE_OK);
529 /*******************************************************************************
531 * FUNCTION: FlOpenMiscOutputFiles
533 * PARAMETERS: FilenamePrefix - The user-specified ASL source file
535 * RETURN: Status
537 * DESCRIPTION: Create and open the various output files needed, depending on
538 * the command line options
540 ******************************************************************************/
542 ACPI_STATUS
543 FlOpenMiscOutputFiles (
544 char *FilenamePrefix)
546 char *Filename;
549 /* Create/Open a map file if requested */
551 if (Gbl_MapfileFlag)
553 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_MAP);
554 if (!Filename)
556 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
557 0, 0, 0, 0, NULL, NULL);
558 return (AE_ERROR);
561 /* Open the hex file, text mode (closed at compiler exit) */
563 FlOpenFile (ASL_FILE_MAP_OUTPUT, Filename, "w+t");
565 AslCompilerSignon (ASL_FILE_MAP_OUTPUT);
566 AslCompilerFileHeader (ASL_FILE_MAP_OUTPUT);
569 /* All done for disassembler */
571 if (Gbl_FileType == ASL_INPUT_TYPE_ACPI_TABLE)
573 return (AE_OK);
576 /* Create/Open a hex output file if asked */
578 if (Gbl_HexOutputFlag)
580 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_HEX_DUMP);
581 if (!Filename)
583 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
584 0, 0, 0, 0, NULL, NULL);
585 return (AE_ERROR);
588 /* Open the hex file, text mode */
590 FlOpenFile (ASL_FILE_HEX_OUTPUT, Filename, "w+t");
592 AslCompilerSignon (ASL_FILE_HEX_OUTPUT);
593 AslCompilerFileHeader (ASL_FILE_HEX_OUTPUT);
596 /* Create/Open a debug output file if asked */
598 if (Gbl_DebugFlag)
600 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_DEBUG);
601 if (!Filename)
603 AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME,
604 0, 0, 0, 0, NULL, NULL);
605 return (AE_ERROR);
608 /* Open the debug file as STDERR, text mode */
610 Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Filename = Filename;
611 Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle =
612 freopen (Filename, "w+t", stderr);
614 if (!Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle)
617 * A problem with freopen is that on error, we no longer
618 * have stderr and cannot emit normal error messages.
619 * Emit error to stdout, close files, and exit.
621 fprintf (stdout,
622 "\nCould not open debug output file: %s\n\n", Filename);
624 CmCleanupAndExit ();
625 exit (1);
628 AslCompilerSignon (ASL_FILE_DEBUG_OUTPUT);
629 AslCompilerFileHeader (ASL_FILE_DEBUG_OUTPUT);
632 /* Create/Open a listing output file if asked */
634 if (Gbl_ListingFlag)
636 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_LISTING);
637 if (!Filename)
639 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
640 0, 0, 0, 0, NULL, NULL);
641 return (AE_ERROR);
644 /* Open the listing file, text mode */
646 FlOpenFile (ASL_FILE_LISTING_OUTPUT, Filename, "w+t");
648 AslCompilerSignon (ASL_FILE_LISTING_OUTPUT);
649 AslCompilerFileHeader (ASL_FILE_LISTING_OUTPUT);
652 /* Create the preprocessor output temp file if preprocessor enabled */
654 if (Gbl_PreprocessFlag)
656 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_PREPROCESSOR);
657 if (!Filename)
659 AslCommonError (ASL_ERROR, ASL_MSG_PREPROCESSOR_FILENAME,
660 0, 0, 0, 0, NULL, NULL);
661 return (AE_ERROR);
664 FlOpenFile (ASL_FILE_PREPROCESSOR, Filename, "w+t");
668 * Create the "user" preprocessor output file if -li flag set.
669 * Note, this file contains no embedded #line directives.
671 if (Gbl_PreprocessorOutputFlag)
673 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_PREPROC_USER);
674 if (!Filename)
676 AslCommonError (ASL_ERROR, ASL_MSG_PREPROCESSOR_FILENAME,
677 0, 0, 0, 0, NULL, NULL);
678 return (AE_ERROR);
681 FlOpenFile (ASL_FILE_PREPROCESSOR_USER, Filename, "w+t");
684 /* All done for data table compiler */
686 if (Gbl_FileType == ASL_INPUT_TYPE_ASCII_DATA)
688 return (AE_OK);
691 /* Create/Open a combined source output file */
693 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_SOURCE);
694 if (!Filename)
696 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
697 0, 0, 0, 0, NULL, NULL);
698 return (AE_ERROR);
702 * Open the source output file, binary mode (so that LF does not get
703 * expanded to CR/LF on some systems, messing up our seek
704 * calculations.)
706 FlOpenFile (ASL_FILE_SOURCE_OUTPUT, Filename, "w+b");
709 // TBD: TEMP
710 // AslCompilerin = Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle;
712 /* Create/Open a assembly code source output file if asked */
714 if (Gbl_AsmOutputFlag)
716 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_SOURCE);
717 if (!Filename)
719 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
720 0, 0, 0, 0, NULL, NULL);
721 return (AE_ERROR);
724 /* Open the assembly code source file, text mode */
726 FlOpenFile (ASL_FILE_ASM_SOURCE_OUTPUT, Filename, "w+t");
728 AslCompilerSignon (ASL_FILE_ASM_SOURCE_OUTPUT);
729 AslCompilerFileHeader (ASL_FILE_ASM_SOURCE_OUTPUT);
732 /* Create/Open a C code source output file if asked */
734 if (Gbl_C_OutputFlag)
736 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_SOURCE);
737 if (!Filename)
739 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
740 0, 0, 0, 0, NULL, NULL);
741 return (AE_ERROR);
744 /* Open the C code source file, text mode */
746 FlOpenFile (ASL_FILE_C_SOURCE_OUTPUT, Filename, "w+t");
748 FlPrintFile (ASL_FILE_C_SOURCE_OUTPUT, "/*\n");
749 AslCompilerSignon (ASL_FILE_C_SOURCE_OUTPUT);
750 AslCompilerFileHeader (ASL_FILE_C_SOURCE_OUTPUT);
753 /* Create/Open a C code source output file for the offset table if asked */
755 if (Gbl_C_OffsetTableFlag)
757 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_OFFSET);
758 if (!Filename)
760 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
761 0, 0, 0, 0, NULL, NULL);
762 return (AE_ERROR);
765 /* Open the C code source file, text mode */
767 FlOpenFile (ASL_FILE_C_OFFSET_OUTPUT, Filename, "w+t");
769 FlPrintFile (ASL_FILE_C_OFFSET_OUTPUT, "/*\n");
770 AslCompilerSignon (ASL_FILE_C_OFFSET_OUTPUT);
771 AslCompilerFileHeader (ASL_FILE_C_OFFSET_OUTPUT);
774 /* Create/Open a assembly include output file if asked */
776 if (Gbl_AsmIncludeOutputFlag)
778 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_INCLUDE);
779 if (!Filename)
781 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
782 0, 0, 0, 0, NULL, NULL);
783 return (AE_ERROR);
786 /* Open the assembly include file, text mode */
788 FlOpenFile (ASL_FILE_ASM_INCLUDE_OUTPUT, Filename, "w+t");
790 AslCompilerSignon (ASL_FILE_ASM_INCLUDE_OUTPUT);
791 AslCompilerFileHeader (ASL_FILE_ASM_INCLUDE_OUTPUT);
794 /* Create/Open a C include output file if asked */
796 if (Gbl_C_IncludeOutputFlag)
798 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_INCLUDE);
799 if (!Filename)
801 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
802 0, 0, 0, 0, NULL, NULL);
803 return (AE_ERROR);
806 /* Open the C include file, text mode */
808 FlOpenFile (ASL_FILE_C_INCLUDE_OUTPUT, Filename, "w+t");
810 FlPrintFile (ASL_FILE_C_INCLUDE_OUTPUT, "/*\n");
811 AslCompilerSignon (ASL_FILE_C_INCLUDE_OUTPUT);
812 AslCompilerFileHeader (ASL_FILE_C_INCLUDE_OUTPUT);
815 /* Create a namespace output file if asked */
817 if (Gbl_NsOutputFlag)
819 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_NAMESPACE);
820 if (!Filename)
822 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
823 0, 0, 0, 0, NULL, NULL);
824 return (AE_ERROR);
827 /* Open the namespace file, text mode */
829 FlOpenFile (ASL_FILE_NAMESPACE_OUTPUT, Filename, "w+t");
831 AslCompilerSignon (ASL_FILE_NAMESPACE_OUTPUT);
832 AslCompilerFileHeader (ASL_FILE_NAMESPACE_OUTPUT);
835 return (AE_OK);
839 #ifdef ACPI_OBSOLETE_FUNCTIONS
840 /*******************************************************************************
842 * FUNCTION: FlParseInputPathname
844 * PARAMETERS: InputFilename - The user-specified ASL source file to be
845 * compiled
847 * RETURN: Status
849 * DESCRIPTION: Split the input path into a directory and filename part
850 * 1) Directory part used to open include files
851 * 2) Filename part used to generate output filenames
853 ******************************************************************************/
855 ACPI_STATUS
856 FlParseInputPathname (
857 char *InputFilename)
859 char *Substring;
862 if (!InputFilename)
864 return (AE_OK);
867 /* Get the path to the input filename's directory */
869 Gbl_DirectoryPath = strdup (InputFilename);
870 if (!Gbl_DirectoryPath)
872 return (AE_NO_MEMORY);
875 Substring = strrchr (Gbl_DirectoryPath, '\\');
876 if (!Substring)
878 Substring = strrchr (Gbl_DirectoryPath, '/');
879 if (!Substring)
881 Substring = strrchr (Gbl_DirectoryPath, ':');
885 if (!Substring)
887 Gbl_DirectoryPath[0] = 0;
888 if (Gbl_UseDefaultAmlFilename)
890 Gbl_OutputFilenamePrefix = strdup (InputFilename);
893 else
895 if (Gbl_UseDefaultAmlFilename)
897 Gbl_OutputFilenamePrefix = strdup (Substring + 1);
899 *(Substring+1) = 0;
902 UtConvertBackslashes (Gbl_OutputFilenamePrefix);
903 return (AE_OK);
905 #endif