1 /******************************************************************************
3 * Module Name: aslfiles - File support functions
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2019, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
152 #include <contrib/dev/acpica/compiler/aslcompiler.h>
153 #include <contrib/dev/acpica/include/acapps.h>
155 #define _COMPONENT ACPI_COMPILER
156 ACPI_MODULE_NAME ("aslfiles")
158 /* Local prototypes */
161 FlOpenIncludeWithPrefix (
163 ACPI_PARSE_OBJECT *Op,
168 char *InputFilename);
170 #ifdef ACPI_OBSOLETE_FUNCTIONS
172 FlParseInputPathname (
173 char *InputFilename);
177 /*******************************************************************************
179 * FUNCTION: FlInitOneFile
181 * PARAMETERS: InputFilename - The user-specified ASL source file to be
186 * DESCRIPTION: Initialize global file structure for one input file. This file
187 * structure contains references to input, output, debugging, and
188 * other miscellaneous files that are associated for a single
191 ******************************************************************************/
198 ASL_GLOBAL_FILE_NODE *NewFileNode;
201 if (FlInputFileExists (InputFilename))
203 AslError (ASL_ERROR, ASL_MSG_DUPLICATE_INPUT_FILE, NULL, InputFilename);
204 return (AE_ALREADY_EXISTS);
207 NewFileNode = ACPI_CAST_PTR (ASL_GLOBAL_FILE_NODE,
208 UtLocalCacheCalloc (sizeof (ASL_GLOBAL_FILE_NODE)));
212 AslError (ASL_ERROR, ASL_MSG_MEMORY_ALLOCATION, NULL, NULL);
213 return (AE_NO_MEMORY);
216 NewFileNode->ParserErrorDetected = FALSE;
217 NewFileNode->Next = AslGbl_FilesList;
219 AslGbl_FilesList = NewFileNode;
220 AslGbl_Files = NewFileNode->Files;
222 for (i = 0; i < ASL_NUM_FILES; i++)
224 AslGbl_Files[i].Handle = NULL;
225 AslGbl_Files[i].Filename = NULL;
228 AslGbl_Files[ASL_FILE_STDOUT].Handle = stdout;
229 AslGbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT";
231 if (AslGbl_VerboseErrors)
233 AslGbl_Files[ASL_FILE_STDERR].Handle = stderr;
237 AslGbl_Files[ASL_FILE_STDERR].Handle = stdout;
240 AslGbl_Files[ASL_FILE_STDERR].Filename = "STDERR";
245 /*******************************************************************************
247 * FUNCTION: FlInputFileExists
249 * PARAMETERS: Filename - File name to be searched
253 * DESCRIPTION: Returns true if the file name already exists.
255 ******************************************************************************/
261 ASL_GLOBAL_FILE_NODE *Current = AslGbl_FilesList;
266 if (!strcmp (Filename, Current->Files[ASL_FILE_INPUT].Filename))
271 Current = Current->Next;
278 /*******************************************************************************
280 * FUNCTION: FlSwitchFileSet
282 * PARAMETERS: Op - Parse node for the LINE asl statement
286 * DESCRIPTION: Set the current line number
288 ******************************************************************************/
290 ASL_FILE_SWITCH_STATUS
294 ASL_GLOBAL_FILE_NODE *Current = AslGbl_FilesList;
295 char *PrevFilename = Current->Files[ASL_FILE_INPUT].Filename;
300 if (!strcmp(Current->Files[ASL_FILE_INPUT].Filename, InputFilename))
302 AslGbl_Files = Current->Files;
303 AslGbl_TableSignature = Current->TableSignature;
304 AslGbl_TableId = Current->TableId;
306 if (!strcmp (InputFilename, PrevFilename))
308 return (SWITCH_TO_SAME_FILE);
312 return (SWITCH_TO_DIFFERENT_FILE);
316 Current = Current->Next;
319 return (FILE_NOT_FOUND);
323 /*******************************************************************************
325 * FUNCTION: FlGetFileHandle
327 * PARAMETERS: OutFileId - denotes file type of output handle
328 * InFileId - denotes file type of the input Filename
331 * RETURN: File handle
333 * DESCRIPTION: Get the file handle for a particular filename/FileId. This
334 * function also allows the caller to specify the file Id of the
337 ******************************************************************************/
345 ASL_GLOBAL_FILE_NODE *Current = AslGbl_FilesList;
355 if (!strcmp (Current->Files[InFileId].Filename, Filename))
357 return (Current->Files[OutFileId].Handle);
360 Current = Current->Next;
367 /*******************************************************************************
369 * FUNCTION: FlGetFileNode
371 * PARAMETERS: FileId - File type (ID) of the input Filename
372 * Filename - File to search for
374 * RETURN: A global file node
376 * DESCRIPTION: Get the file node for a particular filename/FileId.
378 ******************************************************************************/
380 ASL_GLOBAL_FILE_NODE *
385 ASL_GLOBAL_FILE_NODE *Current = AslGbl_FilesList;
395 if (!strcmp (Current->Files[FileId].Filename, Filename))
400 Current = Current->Next;
407 /*******************************************************************************
409 * FUNCTION: FlGetCurrentFileNode
413 * RETURN: Global file node
415 * DESCRIPTION: Get the current input file node
417 ******************************************************************************/
419 ASL_GLOBAL_FILE_NODE *
420 FlGetCurrentFileNode (
423 return (FlGetFileNode (
424 ASL_FILE_INPUT,AslGbl_Files[ASL_FILE_INPUT].Filename));
428 /*******************************************************************************
430 * FUNCTION: FlSetLineNumber
432 * PARAMETERS: Op - Parse node for the LINE asl statement
436 * DESCRIPTION: Set the current line number
438 ******************************************************************************/
445 DbgPrint (ASL_PARSE_OUTPUT, "\n#line: New line number %u (old %u)\n",
446 LineNumber, AslGbl_LogicalLineNumber);
448 AslGbl_CurrentLineNumber = LineNumber;
452 /*******************************************************************************
454 * FUNCTION: FlSetFilename
456 * PARAMETERS: Op - Parse node for the LINE asl statement
460 * DESCRIPTION: Set the current filename
462 ******************************************************************************/
469 DbgPrint (ASL_PARSE_OUTPUT, "\n#line: New filename %s (old %s)\n",
470 Filename, AslGbl_Files[ASL_FILE_INPUT].Filename);
472 /* No need to free any existing filename */
474 AslGbl_Files[ASL_FILE_INPUT].Filename = Filename;
478 /*******************************************************************************
480 * FUNCTION: FlAddIncludeDirectory
482 * PARAMETERS: Dir - Directory pathname string
486 * DESCRIPTION: Add a directory the list of include prefix directories.
488 ******************************************************************************/
491 FlAddIncludeDirectory (
494 ASL_INCLUDE_DIR *NewDir;
495 ASL_INCLUDE_DIR *NextDir;
496 ASL_INCLUDE_DIR *PrevDir = NULL;
497 UINT32 NeedsSeparator = 0;
501 DirLength = strlen (Dir);
507 /* Make sure that the pathname ends with a path separator */
509 if ((Dir[DirLength-1] != '/') &&
510 (Dir[DirLength-1] != '\\'))
515 NewDir = ACPI_CAST_PTR (ASL_INCLUDE_DIR,
516 UtLocalCacheCalloc (sizeof (ASL_INCLUDE_DIR)));
517 NewDir->Dir = UtLocalCacheCalloc (DirLength + 1 + NeedsSeparator);
518 strcpy (NewDir->Dir, Dir);
521 strcat (NewDir->Dir, "/");
525 * Preserve command line ordering of -I options by adding new elements
526 * at the end of the list
528 NextDir = AslGbl_IncludeDirList;
532 NextDir = NextDir->Next;
537 PrevDir->Next = NewDir;
541 AslGbl_IncludeDirList = NewDir;
546 /*******************************************************************************
548 * FUNCTION: FlMergePathnames
550 * PARAMETERS: PrefixDir - Prefix directory pathname. Can be NULL or
551 * a zero length string.
552 * FilePathname - The include filename from the source ASL.
554 * RETURN: Merged pathname string
556 * DESCRIPTION: Merge two pathnames that (probably) have common elements, to
557 * arrive at a minimal length string. Merge can occur if the
558 * FilePathname is relative to the PrefixDir.
560 ******************************************************************************/
572 DbgPrint (ASL_PARSE_OUTPUT, "Include: Prefix path - \"%s\"\n"
573 "Include: FilePathname - \"%s\"\n",
574 PrefixDir, FilePathname);
577 * If there is no prefix directory or if the file pathname is absolute,
578 * just return the original file pathname
580 if (!PrefixDir || (!*PrefixDir) ||
581 (*FilePathname == '/') ||
582 (FilePathname[1] == ':'))
584 Pathname = UtLocalCacheCalloc (strlen (FilePathname) + 1);
585 strcpy (Pathname, FilePathname);
586 goto ConvertBackslashes;
589 /* Need a local copy of the prefix directory path */
591 CommonPath = UtLocalCacheCalloc (strlen (PrefixDir) + 1);
592 strcpy (CommonPath, PrefixDir);
595 * Walk forward through the file path, and simultaneously backward
596 * through the prefix directory path until there are no more
597 * relative references at the start of the file path.
599 while (*FilePathname && (!strncmp (FilePathname, "../", 3)))
601 /* Remove last element of the prefix directory path */
603 LastElement = strrchr (CommonPath, '/');
606 goto ConcatenatePaths;
609 *LastElement = 0; /* Terminate CommonPath string */
610 FilePathname += 3; /* Point to next path element */
614 * Remove the last element of the prefix directory path (it is the same as
615 * the first element of the file pathname), and build the final merged
618 LastElement = strrchr (CommonPath, '/');
624 /* Build the final merged pathname */
627 Pathname = UtLocalCacheCalloc (
628 strlen (CommonPath) + strlen (FilePathname) + 2);
629 if (LastElement && *CommonPath)
631 strcpy (Pathname, CommonPath);
632 strcat (Pathname, "/");
634 strcat (Pathname, FilePathname);
636 /* Convert all backslashes to normal slashes */
639 UtConvertBackslashes (Pathname);
641 DbgPrint (ASL_PARSE_OUTPUT, "Include: Merged Pathname - \"%s\"\n",
647 /*******************************************************************************
649 * FUNCTION: FlOpenIncludeWithPrefix
651 * PARAMETERS: PrefixDir - Prefix directory pathname. Can be a zero
653 * Filename - The include filename from the source ASL.
655 * RETURN: Valid file descriptor if successful. Null otherwise.
657 * DESCRIPTION: Open an include file and push it on the input file stack.
659 ******************************************************************************/
662 FlOpenIncludeWithPrefix (
664 ACPI_PARSE_OBJECT *Op,
669 UINT32 OriginalLineNumber;
672 /* Build the full pathname to the file */
674 Pathname = FlMergePathnames (PrefixDir, Filename);
676 DbgPrint (ASL_PARSE_OUTPUT, "Include: Opening file - \"%s\"\n\n",
679 /* Attempt to open the file, push if successful */
681 IncludeFile = fopen (Pathname, "r");
688 * Check the entire include file for any # preprocessor directives.
689 * This is because there may be some confusion between the #include
690 * preprocessor directive and the ASL Include statement. A file included
691 * by the ASL include cannot contain preprocessor directives because
692 * the preprocessor has already run by the time the ASL include is
693 * recognized (by the compiler, not the preprocessor.)
695 * Note: DtGetNextLine strips/ignores comments.
696 * Save current line number since DtGetNextLine modifies it.
698 AslGbl_CurrentLineNumber--;
699 OriginalLineNumber = AslGbl_CurrentLineNumber;
701 while (DtGetNextLine (IncludeFile, DT_ALLOW_MULTILINE_QUOTES) != ASL_EOF)
703 if (AslGbl_CurrentLineBuffer[0] == '#')
705 AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE,
706 Op, "use #include instead");
710 AslGbl_CurrentLineNumber = OriginalLineNumber;
712 /* Must seek back to the start of the file */
714 fseek (IncludeFile, 0, SEEK_SET);
716 /* Push the include file on the open input file stack */
718 AslPushInputFileStack (IncludeFile, Pathname);
719 return (IncludeFile);
723 /*******************************************************************************
725 * FUNCTION: FlOpenIncludeFile
727 * PARAMETERS: Op - Parse node for the INCLUDE ASL statement
731 * DESCRIPTION: Open an include file and push it on the input file stack.
733 ******************************************************************************/
737 ACPI_PARSE_OBJECT *Op)
740 ASL_INCLUDE_DIR *NextDir;
743 /* Op must be valid */
747 AslCommonError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN,
748 AslGbl_CurrentLineNumber, AslGbl_LogicalLineNumber,
749 AslGbl_InputByteCount, AslGbl_CurrentColumn,
750 AslGbl_Files[ASL_FILE_INPUT].Filename, " - Null parse node");
756 * Flush out the "include ()" statement on this line, start
757 * the actual include file on the next line
759 AslResetCurrentLineBuffer ();
760 FlPrintFile (ASL_FILE_SOURCE_OUTPUT, "\n");
761 AslGbl_CurrentLineOffset++;
764 /* Attempt to open the include file */
766 /* If the file specifies an absolute path, just open it */
768 if ((Op->Asl.Value.String[0] == '/') ||
769 (Op->Asl.Value.String[0] == '\\') ||
770 (Op->Asl.Value.String[1] == ':'))
772 IncludeFile = FlOpenIncludeWithPrefix ("", Op, Op->Asl.Value.String);
781 * The include filename is not an absolute path.
783 * First, search for the file within the "local" directory -- meaning
784 * the same directory that contains the source file.
786 * Construct the file pathname from the global directory name.
788 IncludeFile = FlOpenIncludeWithPrefix (
789 AslGbl_DirectoryPath, Op, Op->Asl.Value.String);
796 * Second, search for the file within the (possibly multiple) directories
797 * specified by the -I option on the command line.
799 NextDir = AslGbl_IncludeDirList;
802 IncludeFile = FlOpenIncludeWithPrefix (
803 NextDir->Dir, Op, Op->Asl.Value.String);
809 NextDir = NextDir->Next;
812 /* We could not open the include file after trying very hard */
815 sprintf (AslGbl_MsgBuffer, "%s, %s", Op->Asl.Value.String, strerror (errno));
816 AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, Op, AslGbl_MsgBuffer);
820 /*******************************************************************************
822 * FUNCTION: FlOpenInputFile
824 * PARAMETERS: InputFilename - The user-specified ASL source file to be
829 * DESCRIPTION: Open the specified input file, and save the directory path to
830 * the file so that include files can be opened in
831 * the same directory.
833 ******************************************************************************/
840 /* Open the input ASL file, text mode */
842 FlOpenFile (ASL_FILE_INPUT, InputFilename, "rt");
843 AslCompilerin = AslGbl_Files[ASL_FILE_INPUT].Handle;
849 /*******************************************************************************
851 * FUNCTION: FlOpenAmlOutputFile
853 * PARAMETERS: FilenamePrefix - The user-specified ASL source file
857 * DESCRIPTION: Create the output filename (*.AML) and open the file. The file
858 * is created in the same directory as the parent input file.
860 ******************************************************************************/
863 FlOpenAmlOutputFile (
864 char *FilenamePrefix)
869 /* Output filename usually comes from the ASL itself */
871 Filename = AslGbl_Files[ASL_FILE_AML_OUTPUT].Filename;
874 /* Create the output AML filename */
875 if (!AcpiGbl_CaptureComments)
877 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_AML_CODE);
881 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_CONVERT_AML);
885 AslCommonError (ASL_ERROR, ASL_MSG_OUTPUT_FILENAME,
886 0, 0, 0, 0, NULL, NULL);
890 AslGbl_Files[ASL_FILE_AML_OUTPUT].Filename = Filename;
893 /* Open the output AML file in binary mode */
895 FlOpenFile (ASL_FILE_AML_OUTPUT, Filename, "w+b");
900 /*******************************************************************************
902 * FUNCTION: FlOpenMiscOutputFiles
904 * PARAMETERS: FilenamePrefix - The user-specified ASL source file
908 * DESCRIPTION: Create and open the various output files needed, depending on
909 * the command line options
911 ******************************************************************************/
914 FlOpenMiscOutputFiles (
915 char *FilenamePrefix)
920 /* Create/Open a map file if requested */
922 if (AslGbl_MapfileFlag)
924 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_MAP);
927 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
928 0, 0, 0, 0, NULL, NULL);
932 /* Open the hex file, text mode (closed at compiler exit) */
934 FlOpenFile (ASL_FILE_MAP_OUTPUT, Filename, "w+t");
936 AslCompilerSignon (ASL_FILE_MAP_OUTPUT);
937 AslCompilerFileHeader (ASL_FILE_MAP_OUTPUT);
940 /* All done for disassembler */
942 if (AslGbl_FileType == ASL_INPUT_TYPE_BINARY_ACPI_TABLE)
947 /* Create/Open a hex output file if asked */
949 if (AslGbl_HexOutputFlag)
951 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_HEX_DUMP);
954 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
955 0, 0, 0, 0, NULL, NULL);
959 /* Open the hex file, text mode */
961 FlOpenFile (ASL_FILE_HEX_OUTPUT, Filename, "w+t");
963 AslCompilerSignon (ASL_FILE_HEX_OUTPUT);
964 AslCompilerFileHeader (ASL_FILE_HEX_OUTPUT);
967 /* Create/Open a debug output file if asked */
969 if (AslGbl_DebugFlag)
971 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_DEBUG);
974 AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME,
975 0, 0, 0, 0, NULL, NULL);
979 /* Open the debug file as STDERR, text mode */
981 AslGbl_Files[ASL_FILE_DEBUG_OUTPUT].Filename = Filename;
982 AslGbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle =
983 freopen (Filename, "w+t", stderr);
985 if (!AslGbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle)
988 * A problem with freopen is that on error, we no longer
989 * have stderr and cannot emit normal error messages.
990 * Emit error to stdout, close files, and exit.
993 "\nCould not open debug output file: %s\n\n", Filename);
999 AslCompilerSignon (ASL_FILE_DEBUG_OUTPUT);
1000 AslCompilerFileHeader (ASL_FILE_DEBUG_OUTPUT);
1003 /* Create/Open a cross-reference output file if asked */
1005 if (AslGbl_CrossReferenceOutput)
1007 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_XREF);
1010 AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME,
1011 0, 0, 0, 0, NULL, NULL);
1015 FlOpenFile (ASL_FILE_XREF_OUTPUT, Filename, "w+t");
1017 AslCompilerSignon (ASL_FILE_XREF_OUTPUT);
1018 AslCompilerFileHeader (ASL_FILE_XREF_OUTPUT);
1021 /* Create/Open a listing output file if asked */
1023 if (AslGbl_ListingFlag)
1025 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_LISTING);
1028 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
1029 0, 0, 0, 0, NULL, NULL);
1033 /* Open the listing file, text mode */
1035 FlOpenFile (ASL_FILE_LISTING_OUTPUT, Filename, "w+t");
1037 AslCompilerSignon (ASL_FILE_LISTING_OUTPUT);
1038 AslCompilerFileHeader (ASL_FILE_LISTING_OUTPUT);
1041 /* Create the preprocessor output temp file if preprocessor enabled */
1043 if (AslGbl_PreprocessFlag)
1045 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_PREPROCESSOR);
1048 AslCommonError (ASL_ERROR, ASL_MSG_PREPROCESSOR_FILENAME,
1049 0, 0, 0, 0, NULL, NULL);
1053 FlOpenFile (ASL_FILE_PREPROCESSOR, Filename, "w+t");
1057 * Create the "user" preprocessor output file if -li flag set.
1058 * Note, this file contains no embedded #line directives.
1060 if (AslGbl_PreprocessorOutputFlag)
1062 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_PREPROC_USER);
1065 AslCommonError (ASL_ERROR, ASL_MSG_PREPROCESSOR_FILENAME,
1066 0, 0, 0, 0, NULL, NULL);
1070 FlOpenFile (ASL_FILE_PREPROCESSOR_USER, Filename, "w+t");
1073 /* All done for data table compiler */
1075 if (AslGbl_FileType == ASL_INPUT_TYPE_ASCII_DATA)
1080 /* Create/Open a combined source output file */
1082 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_SOURCE);
1085 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
1086 0, 0, 0, 0, NULL, NULL);
1091 * Open the source output file, binary mode (so that LF does not get
1092 * expanded to CR/LF on some systems, messing up our seek
1095 FlOpenFile (ASL_FILE_SOURCE_OUTPUT, Filename, "w+b");
1099 // AslCompilerin = AslGbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle;
1101 /* Create/Open a assembly code source output file if asked */
1103 if (AslGbl_AsmOutputFlag)
1105 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_SOURCE);
1108 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
1109 0, 0, 0, 0, NULL, NULL);
1113 /* Open the assembly code source file, text mode */
1115 FlOpenFile (ASL_FILE_ASM_SOURCE_OUTPUT, Filename, "w+t");
1117 AslCompilerSignon (ASL_FILE_ASM_SOURCE_OUTPUT);
1118 AslCompilerFileHeader (ASL_FILE_ASM_SOURCE_OUTPUT);
1121 /* Create/Open a C code source output file if asked */
1123 if (AslGbl_C_OutputFlag)
1125 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_SOURCE);
1128 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
1129 0, 0, 0, 0, NULL, NULL);
1133 /* Open the C code source file, text mode */
1135 FlOpenFile (ASL_FILE_C_SOURCE_OUTPUT, Filename, "w+t");
1137 FlPrintFile (ASL_FILE_C_SOURCE_OUTPUT, "/*\n");
1138 AslCompilerSignon (ASL_FILE_C_SOURCE_OUTPUT);
1139 AslCompilerFileHeader (ASL_FILE_C_SOURCE_OUTPUT);
1142 /* Create/Open a C code source output file for the offset table if asked */
1144 if (AslGbl_C_OffsetTableFlag)
1146 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_OFFSET);
1149 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
1150 0, 0, 0, 0, NULL, NULL);
1154 /* Open the C code source file, text mode */
1156 FlOpenFile (ASL_FILE_C_OFFSET_OUTPUT, Filename, "w+t");
1158 FlPrintFile (ASL_FILE_C_OFFSET_OUTPUT, "/*\n");
1159 AslCompilerSignon (ASL_FILE_C_OFFSET_OUTPUT);
1160 AslCompilerFileHeader (ASL_FILE_C_OFFSET_OUTPUT);
1163 /* Create/Open a assembly include output file if asked */
1165 if (AslGbl_AsmIncludeOutputFlag)
1167 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_INCLUDE);
1170 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
1171 0, 0, 0, 0, NULL, NULL);
1175 /* Open the assembly include file, text mode */
1177 FlOpenFile (ASL_FILE_ASM_INCLUDE_OUTPUT, Filename, "w+t");
1179 AslCompilerSignon (ASL_FILE_ASM_INCLUDE_OUTPUT);
1180 AslCompilerFileHeader (ASL_FILE_ASM_INCLUDE_OUTPUT);
1183 /* Create/Open a C include output file if asked */
1185 if (AslGbl_C_IncludeOutputFlag)
1187 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_INCLUDE);
1190 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
1191 0, 0, 0, 0, NULL, NULL);
1195 /* Open the C include file, text mode */
1197 FlOpenFile (ASL_FILE_C_INCLUDE_OUTPUT, Filename, "w+t");
1199 FlPrintFile (ASL_FILE_C_INCLUDE_OUTPUT, "/*\n");
1200 AslCompilerSignon (ASL_FILE_C_INCLUDE_OUTPUT);
1201 AslCompilerFileHeader (ASL_FILE_C_INCLUDE_OUTPUT);
1204 /* Create a namespace output file if asked */
1206 if (AslGbl_NsOutputFlag)
1208 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_NAMESPACE);
1211 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
1212 0, 0, 0, 0, NULL, NULL);
1216 /* Open the namespace file, text mode */
1218 FlOpenFile (ASL_FILE_NAMESPACE_OUTPUT, Filename, "w+t");
1220 AslCompilerSignon (ASL_FILE_NAMESPACE_OUTPUT);
1221 AslCompilerFileHeader (ASL_FILE_NAMESPACE_OUTPUT);
1224 /* Create a debug file for the converter */
1226 if (AcpiGbl_DebugAslConversion)
1228 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_CONVERT_DEBUG);
1231 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
1232 0, 0, 0, 0, NULL, NULL);
1236 /* Open the converter debug file, text mode */
1238 FlOpenFile (ASL_FILE_CONV_DEBUG_OUTPUT, Filename, "w+t");
1240 AslCompilerSignon (ASL_FILE_CONV_DEBUG_OUTPUT);
1241 AslCompilerFileHeader (ASL_FILE_CONV_DEBUG_OUTPUT);
1243 AcpiGbl_ConvDebugFile = AslGbl_Files[ASL_FILE_CONV_DEBUG_OUTPUT].Handle;
1250 #ifdef ACPI_OBSOLETE_FUNCTIONS
1251 /*******************************************************************************
1253 * FUNCTION: FlParseInputPathname
1255 * PARAMETERS: InputFilename - The user-specified ASL source file to be
1260 * DESCRIPTION: Split the input path into a directory and filename part
1261 * 1) Directory part used to open include files
1262 * 2) Filename part used to generate output filenames
1264 ******************************************************************************/
1267 FlParseInputPathname (
1268 char *InputFilename)
1278 /* Get the path to the input filename's directory */
1280 AslGbl_DirectoryPath = strdup (InputFilename);
1281 if (!AslGbl_DirectoryPath)
1283 return (AE_NO_MEMORY);
1286 Substring = strrchr (AslGbl_DirectoryPath, '\\');
1289 Substring = strrchr (AslGbl_DirectoryPath, '/');
1292 Substring = strrchr (AslGbl_DirectoryPath, ':');
1298 AslGbl_DirectoryPath[0] = 0;
1299 if (AslGbl_UseDefaultAmlFilename)
1301 AslGbl_OutputFilenamePrefix = strdup (InputFilename);
1306 if (AslGbl_UseDefaultAmlFilename)
1308 AslGbl_OutputFilenamePrefix = strdup (Substring + 1);
1313 UtConvertBackslashes (AslGbl_OutputFilenamePrefix);