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)));
210 NewFileNode->ParserErrorDetected = FALSE;
211 NewFileNode->Next = AslGbl_FilesList;
213 AslGbl_FilesList = NewFileNode;
214 AslGbl_Files = NewFileNode->Files;
216 for (i = 0; i < ASL_NUM_FILES; i++)
218 AslGbl_Files[i].Handle = NULL;
219 AslGbl_Files[i].Filename = NULL;
222 AslGbl_Files[ASL_FILE_STDOUT].Handle = stdout;
223 AslGbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT";
225 if (AslGbl_VerboseErrors)
227 AslGbl_Files[ASL_FILE_STDERR].Handle = stderr;
231 AslGbl_Files[ASL_FILE_STDERR].Handle = stdout;
234 AslGbl_Files[ASL_FILE_STDERR].Filename = "STDERR";
239 /*******************************************************************************
241 * FUNCTION: FlInputFileExists
243 * PARAMETERS: Filename - File name to be searched
247 * DESCRIPTION: Returns true if the file name already exists.
249 ******************************************************************************/
255 ASL_GLOBAL_FILE_NODE *Current = AslGbl_FilesList;
260 if (!strcmp (Filename, Current->Files[ASL_FILE_INPUT].Filename))
265 Current = Current->Next;
272 /*******************************************************************************
274 * FUNCTION: FlSwitchFileSet
276 * PARAMETERS: Op - Parse node for the LINE asl statement
280 * DESCRIPTION: Set the current line number
282 ******************************************************************************/
284 ASL_FILE_SWITCH_STATUS
288 ASL_GLOBAL_FILE_NODE *Current = AslGbl_FilesList;
289 char *PrevFilename = Current->Files[ASL_FILE_INPUT].Filename;
294 if (!strcmp(Current->Files[ASL_FILE_INPUT].Filename, InputFilename))
296 AslGbl_Files = Current->Files;
297 AslGbl_TableSignature = Current->TableSignature;
298 AslGbl_TableId = Current->TableId;
300 if (!strcmp (InputFilename, PrevFilename))
302 return (SWITCH_TO_SAME_FILE);
306 return (SWITCH_TO_DIFFERENT_FILE);
310 Current = Current->Next;
313 return (FILE_NOT_FOUND);
317 /*******************************************************************************
319 * FUNCTION: FlGetFileHandle
321 * PARAMETERS: OutFileId - denotes file type of output handle
322 * InFileId - denotes file type of the input Filename
325 * RETURN: File handle
327 * DESCRIPTION: Get the file handle for a particular filename/FileId. This
328 * function also allows the caller to specify the file Id of the
331 ******************************************************************************/
339 ASL_GLOBAL_FILE_NODE *Current = AslGbl_FilesList;
349 if (!strcmp (Current->Files[InFileId].Filename, Filename))
351 return (Current->Files[OutFileId].Handle);
354 Current = Current->Next;
361 /*******************************************************************************
363 * FUNCTION: FlGetFileNode
365 * PARAMETERS: FileId - File type (ID) of the input Filename
366 * Filename - File to search for
368 * RETURN: A global file node
370 * DESCRIPTION: Get the file node for a particular filename/FileId.
372 ******************************************************************************/
374 ASL_GLOBAL_FILE_NODE *
379 ASL_GLOBAL_FILE_NODE *Current = AslGbl_FilesList;
389 if (!strcmp (Current->Files[FileId].Filename, Filename))
394 Current = Current->Next;
401 /*******************************************************************************
403 * FUNCTION: FlGetCurrentFileNode
407 * RETURN: Global file node
409 * DESCRIPTION: Get the current input file node
411 ******************************************************************************/
413 ASL_GLOBAL_FILE_NODE *
414 FlGetCurrentFileNode (
417 ASL_GLOBAL_FILE_NODE *FileNode =
418 FlGetFileNode (ASL_FILE_INPUT,AslGbl_Files[ASL_FILE_INPUT].Filename);
424 * If the current file node does not exist after initializing the file
425 * node structures, something went wrong and this is an unrecoverable
428 FlFileError (ASL_FILE_INPUT, ASL_MSG_COMPILER_INTERNAL);
436 /*******************************************************************************
438 * FUNCTION: FlSetLineNumber
440 * PARAMETERS: Op - Parse node for the LINE asl statement
444 * DESCRIPTION: Set the current line number
446 ******************************************************************************/
453 DbgPrint (ASL_PARSE_OUTPUT, "\n#line: New line number %u (old %u)\n",
454 LineNumber, AslGbl_LogicalLineNumber);
456 AslGbl_CurrentLineNumber = LineNumber;
460 /*******************************************************************************
462 * FUNCTION: FlSetFilename
464 * PARAMETERS: Op - Parse node for the LINE asl statement
468 * DESCRIPTION: Set the current filename
470 ******************************************************************************/
477 DbgPrint (ASL_PARSE_OUTPUT, "\n#line: New filename %s (old %s)\n",
478 Filename, AslGbl_Files[ASL_FILE_INPUT].Filename);
480 /* No need to free any existing filename */
482 AslGbl_Files[ASL_FILE_INPUT].Filename = Filename;
486 /*******************************************************************************
488 * FUNCTION: FlAddIncludeDirectory
490 * PARAMETERS: Dir - Directory pathname string
494 * DESCRIPTION: Add a directory the list of include prefix directories.
496 ******************************************************************************/
499 FlAddIncludeDirectory (
502 ASL_INCLUDE_DIR *NewDir;
503 ASL_INCLUDE_DIR *NextDir;
504 ASL_INCLUDE_DIR *PrevDir = NULL;
505 UINT32 NeedsSeparator = 0;
509 DirLength = strlen (Dir);
515 /* Make sure that the pathname ends with a path separator */
517 if ((Dir[DirLength-1] != '/') &&
518 (Dir[DirLength-1] != '\\'))
523 NewDir = ACPI_CAST_PTR (ASL_INCLUDE_DIR,
524 UtLocalCacheCalloc (sizeof (ASL_INCLUDE_DIR)));
525 NewDir->Dir = UtLocalCacheCalloc (DirLength + 1 + NeedsSeparator);
526 strcpy (NewDir->Dir, Dir);
529 strcat (NewDir->Dir, "/");
533 * Preserve command line ordering of -I options by adding new elements
534 * at the end of the list
536 NextDir = AslGbl_IncludeDirList;
540 NextDir = NextDir->Next;
545 PrevDir->Next = NewDir;
549 AslGbl_IncludeDirList = NewDir;
554 /*******************************************************************************
556 * FUNCTION: FlMergePathnames
558 * PARAMETERS: PrefixDir - Prefix directory pathname. Can be NULL or
559 * a zero length string.
560 * FilePathname - The include filename from the source ASL.
562 * RETURN: Merged pathname string
564 * DESCRIPTION: Merge two pathnames that (probably) have common elements, to
565 * arrive at a minimal length string. Merge can occur if the
566 * FilePathname is relative to the PrefixDir.
568 ******************************************************************************/
580 DbgPrint (ASL_PARSE_OUTPUT, "Include: Prefix path - \"%s\"\n"
581 "Include: FilePathname - \"%s\"\n",
582 PrefixDir, FilePathname);
585 * If there is no prefix directory or if the file pathname is absolute,
586 * just return the original file pathname
588 if (!PrefixDir || (!*PrefixDir) ||
589 (*FilePathname == '/') ||
590 (FilePathname[1] == ':'))
592 Pathname = UtLocalCacheCalloc (strlen (FilePathname) + 1);
593 strcpy (Pathname, FilePathname);
594 goto ConvertBackslashes;
597 /* Need a local copy of the prefix directory path */
599 CommonPath = UtLocalCacheCalloc (strlen (PrefixDir) + 1);
600 strcpy (CommonPath, PrefixDir);
603 * Walk forward through the file path, and simultaneously backward
604 * through the prefix directory path until there are no more
605 * relative references at the start of the file path.
607 while (*FilePathname && (!strncmp (FilePathname, "../", 3)))
609 /* Remove last element of the prefix directory path */
611 LastElement = strrchr (CommonPath, '/');
614 goto ConcatenatePaths;
617 *LastElement = 0; /* Terminate CommonPath string */
618 FilePathname += 3; /* Point to next path element */
622 * Remove the last element of the prefix directory path (it is the same as
623 * the first element of the file pathname), and build the final merged
626 LastElement = strrchr (CommonPath, '/');
632 /* Build the final merged pathname */
635 Pathname = UtLocalCacheCalloc (
636 strlen (CommonPath) + strlen (FilePathname) + 2);
637 if (LastElement && *CommonPath)
639 strcpy (Pathname, CommonPath);
640 strcat (Pathname, "/");
642 strcat (Pathname, FilePathname);
644 /* Convert all backslashes to normal slashes */
647 UtConvertBackslashes (Pathname);
649 DbgPrint (ASL_PARSE_OUTPUT, "Include: Merged Pathname - \"%s\"\n",
655 /*******************************************************************************
657 * FUNCTION: FlOpenIncludeWithPrefix
659 * PARAMETERS: PrefixDir - Prefix directory pathname. Can be a zero
661 * Filename - The include filename from the source ASL.
663 * RETURN: Valid file descriptor if successful. Null otherwise.
665 * DESCRIPTION: Open an include file and push it on the input file stack.
667 ******************************************************************************/
670 FlOpenIncludeWithPrefix (
672 ACPI_PARSE_OBJECT *Op,
677 UINT32 OriginalLineNumber;
680 /* Build the full pathname to the file */
682 Pathname = FlMergePathnames (PrefixDir, Filename);
684 DbgPrint (ASL_PARSE_OUTPUT, "Include: Opening file - \"%s\"\n\n",
687 /* Attempt to open the file, push if successful */
689 IncludeFile = fopen (Pathname, "r");
696 * Check the entire include file for any # preprocessor directives.
697 * This is because there may be some confusion between the #include
698 * preprocessor directive and the ASL Include statement. A file included
699 * by the ASL include cannot contain preprocessor directives because
700 * the preprocessor has already run by the time the ASL include is
701 * recognized (by the compiler, not the preprocessor.)
703 * Note: DtGetNextLine strips/ignores comments.
704 * Save current line number since DtGetNextLine modifies it.
706 AslGbl_CurrentLineNumber--;
707 OriginalLineNumber = AslGbl_CurrentLineNumber;
709 while (DtGetNextLine (IncludeFile, DT_ALLOW_MULTILINE_QUOTES) != ASL_EOF)
711 if (AslGbl_CurrentLineBuffer[0] == '#')
713 AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE,
714 Op, "use #include instead");
718 AslGbl_CurrentLineNumber = OriginalLineNumber;
720 /* Must seek back to the start of the file */
722 fseek (IncludeFile, 0, SEEK_SET);
724 /* Push the include file on the open input file stack */
726 AslPushInputFileStack (IncludeFile, Pathname);
727 return (IncludeFile);
731 /*******************************************************************************
733 * FUNCTION: FlOpenIncludeFile
735 * PARAMETERS: Op - Parse node for the INCLUDE ASL statement
739 * DESCRIPTION: Open an include file and push it on the input file stack.
741 ******************************************************************************/
745 ACPI_PARSE_OBJECT *Op)
748 ASL_INCLUDE_DIR *NextDir;
751 /* Op must be valid */
755 AslCommonError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN,
756 AslGbl_CurrentLineNumber, AslGbl_LogicalLineNumber,
757 AslGbl_InputByteCount, AslGbl_CurrentColumn,
758 AslGbl_Files[ASL_FILE_INPUT].Filename, " - Null parse node");
764 * Flush out the "include ()" statement on this line, start
765 * the actual include file on the next line
767 AslResetCurrentLineBuffer ();
768 FlPrintFile (ASL_FILE_SOURCE_OUTPUT, "\n");
769 AslGbl_CurrentLineOffset++;
772 /* Attempt to open the include file */
774 /* If the file specifies an absolute path, just open it */
776 if ((Op->Asl.Value.String[0] == '/') ||
777 (Op->Asl.Value.String[0] == '\\') ||
778 (Op->Asl.Value.String[1] == ':'))
780 IncludeFile = FlOpenIncludeWithPrefix ("", Op, Op->Asl.Value.String);
789 * The include filename is not an absolute path.
791 * First, search for the file within the "local" directory -- meaning
792 * the same directory that contains the source file.
794 * Construct the file pathname from the global directory name.
796 IncludeFile = FlOpenIncludeWithPrefix (
797 AslGbl_DirectoryPath, Op, Op->Asl.Value.String);
804 * Second, search for the file within the (possibly multiple) directories
805 * specified by the -I option on the command line.
807 NextDir = AslGbl_IncludeDirList;
810 IncludeFile = FlOpenIncludeWithPrefix (
811 NextDir->Dir, Op, Op->Asl.Value.String);
817 NextDir = NextDir->Next;
820 /* We could not open the include file after trying very hard */
823 sprintf (AslGbl_MsgBuffer, "%s, %s", Op->Asl.Value.String, strerror (errno));
824 AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, Op, AslGbl_MsgBuffer);
828 /*******************************************************************************
830 * FUNCTION: FlOpenInputFile
832 * PARAMETERS: InputFilename - The user-specified ASL source file to be
837 * DESCRIPTION: Open the specified input file, and save the directory path to
838 * the file so that include files can be opened in
839 * the same directory.
841 ******************************************************************************/
848 /* Open the input ASL file, text mode */
850 FlOpenFile (ASL_FILE_INPUT, InputFilename, "rt");
851 AslCompilerin = AslGbl_Files[ASL_FILE_INPUT].Handle;
857 /*******************************************************************************
859 * FUNCTION: FlOpenAmlOutputFile
861 * PARAMETERS: FilenamePrefix - The user-specified ASL source file
865 * DESCRIPTION: Create the output filename (*.AML) and open the file. The file
866 * is created in the same directory as the parent input file.
868 ******************************************************************************/
871 FlOpenAmlOutputFile (
872 char *FilenamePrefix)
877 /* Output filename usually comes from the ASL itself */
879 Filename = AslGbl_Files[ASL_FILE_AML_OUTPUT].Filename;
882 /* Create the output AML filename */
883 if (!AcpiGbl_CaptureComments)
885 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_AML_CODE);
889 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_CONVERT_AML);
893 AslCommonError (ASL_ERROR, ASL_MSG_OUTPUT_FILENAME,
894 0, 0, 0, 0, NULL, NULL);
898 AslGbl_Files[ASL_FILE_AML_OUTPUT].Filename = Filename;
901 /* Open the output AML file in binary mode */
903 FlOpenFile (ASL_FILE_AML_OUTPUT, Filename, "w+b");
908 /*******************************************************************************
910 * FUNCTION: FlOpenMiscOutputFiles
912 * PARAMETERS: FilenamePrefix - The user-specified ASL source file
916 * DESCRIPTION: Create and open the various output files needed, depending on
917 * the command line options
919 ******************************************************************************/
922 FlOpenMiscOutputFiles (
923 char *FilenamePrefix)
928 /* Create/Open a map file if requested */
930 if (AslGbl_MapfileFlag)
932 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_MAP);
935 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
936 0, 0, 0, 0, NULL, NULL);
940 /* Open the hex file, text mode (closed at compiler exit) */
942 FlOpenFile (ASL_FILE_MAP_OUTPUT, Filename, "w+t");
944 AslCompilerSignon (ASL_FILE_MAP_OUTPUT);
945 AslCompilerFileHeader (ASL_FILE_MAP_OUTPUT);
948 /* All done for disassembler */
950 if (AslGbl_FileType == ASL_INPUT_TYPE_BINARY_ACPI_TABLE)
955 /* Create/Open a hex output file if asked */
957 if (AslGbl_HexOutputFlag)
959 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_HEX_DUMP);
962 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
963 0, 0, 0, 0, NULL, NULL);
967 /* Open the hex file, text mode */
969 FlOpenFile (ASL_FILE_HEX_OUTPUT, Filename, "w+t");
971 AslCompilerSignon (ASL_FILE_HEX_OUTPUT);
972 AslCompilerFileHeader (ASL_FILE_HEX_OUTPUT);
975 /* Create/Open a debug output file if asked */
977 if (AslGbl_DebugFlag)
979 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_DEBUG);
982 AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME,
983 0, 0, 0, 0, NULL, NULL);
987 /* Open the debug file as STDERR, text mode */
989 AslGbl_Files[ASL_FILE_DEBUG_OUTPUT].Filename = Filename;
990 AslGbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle =
991 freopen (Filename, "w+t", stderr);
993 if (!AslGbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle)
996 * A problem with freopen is that on error, we no longer
997 * have stderr and cannot emit normal error messages.
998 * Emit error to stdout, close files, and exit.
1001 "\nCould not open debug output file: %s\n\n", Filename);
1003 CmCleanupAndExit ();
1007 AslCompilerSignon (ASL_FILE_DEBUG_OUTPUT);
1008 AslCompilerFileHeader (ASL_FILE_DEBUG_OUTPUT);
1011 /* Create/Open a cross-reference output file if asked */
1013 if (AslGbl_CrossReferenceOutput)
1015 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_XREF);
1018 AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME,
1019 0, 0, 0, 0, NULL, NULL);
1023 FlOpenFile (ASL_FILE_XREF_OUTPUT, Filename, "w+t");
1025 AslCompilerSignon (ASL_FILE_XREF_OUTPUT);
1026 AslCompilerFileHeader (ASL_FILE_XREF_OUTPUT);
1029 /* Create/Open a listing output file if asked */
1031 if (AslGbl_ListingFlag)
1033 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_LISTING);
1036 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
1037 0, 0, 0, 0, NULL, NULL);
1041 /* Open the listing file, text mode */
1043 FlOpenFile (ASL_FILE_LISTING_OUTPUT, Filename, "w+t");
1045 AslCompilerSignon (ASL_FILE_LISTING_OUTPUT);
1046 AslCompilerFileHeader (ASL_FILE_LISTING_OUTPUT);
1049 /* Create the preprocessor output temp file if preprocessor enabled */
1051 if (AslGbl_PreprocessFlag)
1053 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_PREPROCESSOR);
1056 AslCommonError (ASL_ERROR, ASL_MSG_PREPROCESSOR_FILENAME,
1057 0, 0, 0, 0, NULL, NULL);
1061 FlOpenFile (ASL_FILE_PREPROCESSOR, Filename, "w+t");
1065 * Create the "user" preprocessor output file if -li flag set.
1066 * Note, this file contains no embedded #line directives.
1068 if (AslGbl_PreprocessorOutputFlag)
1070 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_PREPROC_USER);
1073 AslCommonError (ASL_ERROR, ASL_MSG_PREPROCESSOR_FILENAME,
1074 0, 0, 0, 0, NULL, NULL);
1078 FlOpenFile (ASL_FILE_PREPROCESSOR_USER, Filename, "w+t");
1081 /* All done for data table compiler */
1083 if (AslGbl_FileType == ASL_INPUT_TYPE_ASCII_DATA)
1088 /* Create/Open a combined source output file */
1090 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_SOURCE);
1093 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
1094 0, 0, 0, 0, NULL, NULL);
1099 * Open the source output file, binary mode (so that LF does not get
1100 * expanded to CR/LF on some systems, messing up our seek
1103 FlOpenFile (ASL_FILE_SOURCE_OUTPUT, Filename, "w+b");
1107 // AslCompilerin = AslGbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle;
1109 /* Create/Open a assembly code source output file if asked */
1111 if (AslGbl_AsmOutputFlag)
1113 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_SOURCE);
1116 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
1117 0, 0, 0, 0, NULL, NULL);
1121 /* Open the assembly code source file, text mode */
1123 FlOpenFile (ASL_FILE_ASM_SOURCE_OUTPUT, Filename, "w+t");
1125 AslCompilerSignon (ASL_FILE_ASM_SOURCE_OUTPUT);
1126 AslCompilerFileHeader (ASL_FILE_ASM_SOURCE_OUTPUT);
1129 /* Create/Open a C code source output file if asked */
1131 if (AslGbl_C_OutputFlag)
1133 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_SOURCE);
1136 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
1137 0, 0, 0, 0, NULL, NULL);
1141 /* Open the C code source file, text mode */
1143 FlOpenFile (ASL_FILE_C_SOURCE_OUTPUT, Filename, "w+t");
1145 FlPrintFile (ASL_FILE_C_SOURCE_OUTPUT, "/*\n");
1146 AslCompilerSignon (ASL_FILE_C_SOURCE_OUTPUT);
1147 AslCompilerFileHeader (ASL_FILE_C_SOURCE_OUTPUT);
1150 /* Create/Open a C code source output file for the offset table if asked */
1152 if (AslGbl_C_OffsetTableFlag)
1154 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_OFFSET);
1157 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
1158 0, 0, 0, 0, NULL, NULL);
1162 /* Open the C code source file, text mode */
1164 FlOpenFile (ASL_FILE_C_OFFSET_OUTPUT, Filename, "w+t");
1166 FlPrintFile (ASL_FILE_C_OFFSET_OUTPUT, "/*\n");
1167 AslCompilerSignon (ASL_FILE_C_OFFSET_OUTPUT);
1168 AslCompilerFileHeader (ASL_FILE_C_OFFSET_OUTPUT);
1171 /* Create/Open a assembly include output file if asked */
1173 if (AslGbl_AsmIncludeOutputFlag)
1175 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_INCLUDE);
1178 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
1179 0, 0, 0, 0, NULL, NULL);
1183 /* Open the assembly include file, text mode */
1185 FlOpenFile (ASL_FILE_ASM_INCLUDE_OUTPUT, Filename, "w+t");
1187 AslCompilerSignon (ASL_FILE_ASM_INCLUDE_OUTPUT);
1188 AslCompilerFileHeader (ASL_FILE_ASM_INCLUDE_OUTPUT);
1191 /* Create/Open a C include output file if asked */
1193 if (AslGbl_C_IncludeOutputFlag)
1195 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_INCLUDE);
1198 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
1199 0, 0, 0, 0, NULL, NULL);
1203 /* Open the C include file, text mode */
1205 FlOpenFile (ASL_FILE_C_INCLUDE_OUTPUT, Filename, "w+t");
1207 FlPrintFile (ASL_FILE_C_INCLUDE_OUTPUT, "/*\n");
1208 AslCompilerSignon (ASL_FILE_C_INCLUDE_OUTPUT);
1209 AslCompilerFileHeader (ASL_FILE_C_INCLUDE_OUTPUT);
1212 /* Create a namespace output file if asked */
1214 if (AslGbl_NsOutputFlag)
1216 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_NAMESPACE);
1219 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
1220 0, 0, 0, 0, NULL, NULL);
1224 /* Open the namespace file, text mode */
1226 FlOpenFile (ASL_FILE_NAMESPACE_OUTPUT, Filename, "w+t");
1228 AslCompilerSignon (ASL_FILE_NAMESPACE_OUTPUT);
1229 AslCompilerFileHeader (ASL_FILE_NAMESPACE_OUTPUT);
1232 /* Create a debug file for the converter */
1234 if (AcpiGbl_DebugAslConversion)
1236 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_CONVERT_DEBUG);
1239 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
1240 0, 0, 0, 0, NULL, NULL);
1244 /* Open the converter debug file, text mode */
1246 FlOpenFile (ASL_FILE_CONV_DEBUG_OUTPUT, Filename, "w+t");
1248 AslCompilerSignon (ASL_FILE_CONV_DEBUG_OUTPUT);
1249 AslCompilerFileHeader (ASL_FILE_CONV_DEBUG_OUTPUT);
1251 AcpiGbl_ConvDebugFile = AslGbl_Files[ASL_FILE_CONV_DEBUG_OUTPUT].Handle;
1258 #ifdef ACPI_OBSOLETE_FUNCTIONS
1259 /*******************************************************************************
1261 * FUNCTION: FlParseInputPathname
1263 * PARAMETERS: InputFilename - The user-specified ASL source file to be
1268 * DESCRIPTION: Split the input path into a directory and filename part
1269 * 1) Directory part used to open include files
1270 * 2) Filename part used to generate output filenames
1272 ******************************************************************************/
1275 FlParseInputPathname (
1276 char *InputFilename)
1286 /* Get the path to the input filename's directory */
1288 AslGbl_DirectoryPath = strdup (InputFilename);
1289 if (!AslGbl_DirectoryPath)
1291 return (AE_NO_MEMORY);
1294 Substring = strrchr (AslGbl_DirectoryPath, '\\');
1297 Substring = strrchr (AslGbl_DirectoryPath, '/');
1300 Substring = strrchr (AslGbl_DirectoryPath, ':');
1306 AslGbl_DirectoryPath[0] = 0;
1307 if (AslGbl_UseDefaultAmlFilename)
1309 AslGbl_OutputFilenamePrefix = strdup (InputFilename);
1314 if (AslGbl_UseDefaultAmlFilename)
1316 AslGbl_OutputFilenamePrefix = strdup (Substring + 1);
1321 UtConvertBackslashes (AslGbl_OutputFilenamePrefix);