aslfiles.c revision 167802
126159Sse 226159Sse/****************************************************************************** 326159Sse * 426159Sse * Module Name: aslfiles - file I/O suppoert 526159Sse * $Revision: 1.54 $ 626159Sse * 726159Sse *****************************************************************************/ 826159Sse 926159Sse/****************************************************************************** 1026159Sse * 1126159Sse * 1. Copyright Notice 1226159Sse * 1326159Sse * Some or all of this work - Copyright (c) 1999 - 2007, Intel Corp. 1426159Sse * All rights reserved. 1526159Sse * 1626159Sse * 2. License 1726159Sse * 1826159Sse * 2.1. This is your license from Intel Corp. under its intellectual property 1926159Sse * rights. You may have additional license terms from the party that provided 2026159Sse * you this software, covering your right to use that party's intellectual 2126159Sse * property rights. 2226159Sse * 2326159Sse * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 2426159Sse * copy of the source code appearing in this file ("Covered Code") an 2526159Sse * irrevocable, perpetual, worldwide license under Intel's copyrights in the 2650477Speter * base code distributed originally by Intel ("Original Intel Code") to copy, 2726159Sse * make derivatives, distribute, use and display any portion of the Covered 2826159Sse * Code in any form, with the right to sublicense such rights; and 296104Sse * 3047307Speter * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 316734Sbde * license (with the right to sublicense), under only those claims of Intel 3247307Speter * patents that are infringed by the Original Intel Code, to make, use, sell, 3347307Speter * offer to sell, and import the Covered Code and derivative works thereof 346734Sbde * solely to the minimum extent necessary to exercise the above copyright 356104Sse * license, and in no event shall the patent license extend to any additions 3648832Smsmith * to or modifications of the Original Intel Code. No other license or right 3726159Sse * is granted directly or by implication, estoppel or otherwise; 386104Sse * 3926159Sse * The above copyright and patent license is granted only if the following 4026159Sse * conditions are met: 4126159Sse * 4226159Sse * 3. Conditions 4326159Sse * 4426159Sse * 3.1. Redistribution of Source with Rights to Further Distribute Source. 4526159Sse * Redistribution of source code of any substantial portion of the Covered 4626159Sse * Code or modification with rights to further distribute source must include 476104Sse * the above Copyright Notice, the above License, this list of Conditions, 4826159Sse * and the following Disclaimer and Export Compliance provision. In addition, 4926159Sse * Licensee must cause all Covered Code to which Licensee contributes to 5010887Sse * contain a file documenting the changes Licensee made to create that Covered 5126159Sse * Code and the date of any change. Licensee must include in that file the 5226159Sse * documentation of any changes made by any predecessor Licensee. Licensee 5326159Sse * must include a prominent statement that the modification is derived, 5410887Sse * directly or indirectly, from Original Intel Code. 5526159Sse * 5626159Sse * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 5726159Sse * Redistribution of source code of any substantial portion of the Covered 5826159Sse * Code or modification without rights to further distribute source must 5926159Sse * include the following Disclaimer and Export Compliance provision in the 6026159Sse * documentation and/or other materials provided with distribution. In 6126159Sse * addition, Licensee may not authorize further sublicense of source of any 6226159Sse * portion of the Covered Code, and must include terms to the effect that the 6326159Sse * license from Licensee to its licensee is limited to the intellectual 6426174Sse * property embodied in the software Licensee provides to its licensee, and 6526174Sse * not to intellectual property embodied in modifications its licensee may 6626174Sse * make. 6726174Sse * 6826159Sse * 3.3. Redistribution of Executable. Redistribution in executable form of any 6926159Sse * substantial portion of the Covered Code or modification must reproduce the 7026159Sse * above Copyright Notice, and the following Disclaimer and Export Compliance 7126159Sse * provision in the documentation and/or other materials provided with the 7226159Sse * distribution. 7326159Sse * 7426159Sse * 3.4. Intel retains all right, title, and interest in and to the Original 7526159Sse * Intel Code. 7626159Sse * 7726159Sse * 3.5. Neither the name Intel nor any other trademark owned or controlled by 786104Sse * Intel shall be used in advertising or otherwise to promote the sale, use or 7926159Sse * other dealings in products derived from or relating to the Covered Code 806104Sse * without prior written authorization from Intel. 816104Sse * 8226159Sse * 4. Disclaimer and Export Compliance 8326159Sse * 8426159Sse * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 8526159Sse * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 8626159Sse * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 8726159Sse * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 8826159Sse * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 8926159Sse * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 9026159Sse * PARTICULAR PURPOSE. 9126159Sse * 9226159Sse * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 9326159Sse * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 946104Sse * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 9526159Sse * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 966104Sse * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 9726159Sse * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 9826159Sse * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 9926159Sse * LIMITED REMEDY. 10026159Sse * 10126159Sse * 4.3. Licensee shall not export, either directly or indirectly, any of this 1027234Sse * software or system incorporating such software without first obtaining any 10326159Sse * required license or other approval from the U. S. Department of Commerce or 1047234Sse * any other agency or department of the United States Government. In the 10526159Sse * event Licensee exports any such software from the United States or 10626159Sse * re-exports any such software from a foreign destination, Licensee shall 10726159Sse * ensure that the distribution and export/re-export of the software is in 10826159Sse * compliance with all laws, regulations, orders, or other restrictions of the 10926159Sse * U.S. Export Administration Regulations. Licensee agrees that neither it nor 11026159Sse * any of its subsidiaries will export/re-export any technical data, process, 11126159Sse * software, or service, directly or indirectly, to any country for which the 11226159Sse * United States government or any agency thereof requires an export license, 11326159Sse * other governmental approval, or letter of assurance, without first obtaining 11426159Sse * such license, approval or letter. 11526159Sse * 11626159Sse *****************************************************************************/ 11726159Sse 11826159Sse#include <contrib/dev/acpica/compiler/aslcompiler.h> 11926159Sse#include <contrib/dev/acpica/acapps.h> 12026159Sse 1217234Sse#define _COMPONENT ACPI_COMPILER 12226159Sse ACPI_MODULE_NAME ("aslfiles") 1236104Sse 12426159Sse/* Local prototypes */ 12526159Sse 12626159Ssestatic void 12726159SseFlOpenFile ( 1286104Sse UINT32 FileId, 12926159Sse char *Filename, 13026159Sse char *Mode); 13126159Sse 13226159Ssestatic FILE * 13326159SseFlOpenLocalFile ( 13426159Sse char *LocalName, 13526159Sse char *Mode); 13626159Sse 13726159Sse#ifdef ACPI_OBSOLETE_FUNCTIONS 13826159SseACPI_STATUS 13926159SseFlParseInputPathname ( 14026159Sse char *InputFilename); 14126159Sse#endif 14226159Sse 14326159Sse 14426159Sse/******************************************************************************* 1456104Sse * 14626159Sse * FUNCTION: AslAbort 1476104Sse * 14810887Sse * PARAMETERS: None 14926159Sse * 15010887Sse * RETURN: None 15110887Sse * 15210735Sse * DESCRIPTION: Dump the error log and abort the compiler. Used for serious 15326159Sse * I/O errors 15426159Sse * 15510960Sse ******************************************************************************/ 15626159Sse 15726159Ssevoid 15811378SseAslAbort ( 15926159Sse void) 16026159Sse{ 16126159Sse 16226159Sse AePrintErrorLog (ASL_FILE_STDOUT); 16323415Sse if (Gbl_DebugFlag) 16423415Sse { 16526159Sse /* Print error summary to the debug file */ 16623415Sse 16726159Sse AePrintErrorLog (ASL_FILE_STDERR); 16831893Sse } 16923415Sse 17023415Sse exit (1); 17126159Sse} 17223415Sse 17326159Sse 17426159Sse/******************************************************************************* 17523415Sse * 17623415Sse * FUNCTION: FlOpenLocalFile 17726159Sse * 17826159Sse * PARAMETERS: LocalName - Single filename (not a pathname) 17926159Sse * Mode - Open mode for fopen 18026159Sse * 18126159Sse * RETURN: File descriptor 18210887Sse * 18311378Sse * DESCRIPTION: Build a complete pathname for the input filename and open 18426159Sse * the file. 18526159Sse * 18626159Sse ******************************************************************************/ 18726159Sse 18810887Ssestatic FILE * 18910887SseFlOpenLocalFile ( 19047307Speter char *LocalName, 19126159Sse char *Mode) 1926104Sse{ 19311524Sse 19411524Sse strcpy (StringBuffer, Gbl_DirectoryPath); 1956104Sse strcat (StringBuffer, LocalName); 19626159Sse 19710960Sse DbgPrint (ASL_PARSE_OUTPUT, "FlOpenLocalFile: %s\n", StringBuffer); 19810960Sse return (fopen (StringBuffer, (const char *) Mode)); 19926159Sse} 20026159Sse 20110960Sse 20210960Sse/******************************************************************************* 20311544Sse * 20410960Sse * FUNCTION: FlFileError 20526159Sse * 20626159Sse * PARAMETERS: FileId - Index into file info array 20710960Sse * ErrorId - Index into error message array 20826159Sse * 20926159Sse * RETURN: None 21026159Sse * 21126159Sse * DESCRIPTION: Decode errno to an error message and add the entire error 21210960Sse * to the error log. 21311524Sse * 21426159Sse ******************************************************************************/ 21526159Sse 2166104Ssevoid 21711524SseFlFileError ( 21826159Sse UINT32 FileId, 21926159Sse UINT8 ErrorId) 22026159Sse{ 22110960Sse 22226159Sse sprintf (MsgBuffer, "\"%s\" (%s)", Gbl_Files[FileId].Filename, 22311524Sse strerror (errno)); 22426159Sse AslCommonError (ASL_ERROR, ErrorId, 0, 0, 0, 0, NULL, MsgBuffer); 2256104Sse} 22611524Sse 22726159Sse 22826159Sse/******************************************************************************* 2299360Sse * 23011524Sse * FUNCTION: FlOpenFile 23126159Sse * 23226159Sse * PARAMETERS: FileId - Index into file info array 23326159Sse * Filename - file pathname to open 23411524Sse * Mode - Open mode for fopen 23510807Sse * 23626159Sse * RETURN: None 23710887Sse * 23811524Sse * DESCRIPTION: Open a file. 23926159Sse * NOTE: Aborts compiler on any error. 24026159Sse * 24111524Sse ******************************************************************************/ 24210887Sse 24311524Ssestatic void 24410887SseFlOpenFile ( 24526159Sse UINT32 FileId, 24626159Sse char *Filename, 24726159Sse char *Mode) 24826159Sse{ 24911524Sse FILE *File; 25026159Sse 25111524Sse 25211524Sse File = fopen (Filename, Mode); 25326159Sse 25426159Sse Gbl_Files[FileId].Filename = Filename; 25511524Sse Gbl_Files[FileId].Handle = File; 25611524Sse 25726159Sse if (!File) 25826159Sse { 25911524Sse FlFileError (FileId, ASL_MSG_OPEN); 26026159Sse AslAbort (); 26126159Sse } 26211524Sse} 26311524Sse 26411524Sse 26526159Sse/******************************************************************************* 26626159Sse * 26726159Sse * FUNCTION: FlReadFile 2686104Sse * 26947307Speter * PARAMETERS: FileId - Index into file info array 27047307Speter * Buffer - Where to place the data 27147307Speter * Length - Amount to read 27248832Smsmith * 27348832Smsmith * RETURN: Status. AE_ERROR indicates EOF. 27448832Smsmith * 27548832Smsmith * DESCRIPTION: Read data from an open file. 27648832Smsmith * NOTE: Aborts compiler on any error. 27749580Swpaul * 27848832Smsmith ******************************************************************************/ 27948832Smsmith 28048832SmsmithACPI_STATUS 28148832SmsmithFlReadFile ( 28248832Smsmith UINT32 FileId, 28348832Smsmith void *Buffer, 28448832Smsmith UINT32 Length) 28548832Smsmith{ 28648832Smsmith UINT32 Actual; 28748832Smsmith 28848832Smsmith 28948832Smsmith /* Read and check for error */ 29048832Smsmith 29148832Smsmith Actual = fread (Buffer, 1, Length, Gbl_Files[FileId].Handle); 29248832Smsmith if (Actual != Length) 29348832Smsmith { 29448832Smsmith if (feof (Gbl_Files[FileId].Handle)) 29548832Smsmith { 29648832Smsmith /* End-of-file, just return error */ 29748832Smsmith 29848832Smsmith return (AE_ERROR); 29948832Smsmith } 30048832Smsmith 30148832Smsmith FlFileError (FileId, ASL_MSG_READ); 30248832Smsmith AslAbort (); 30348832Smsmith } 30448832Smsmith 30548832Smsmith return (AE_OK); 30648832Smsmith} 30748832Smsmith 30848832Smsmith 30948832Smsmith/******************************************************************************* 31048832Smsmith * 31148832Smsmith * FUNCTION: FlWriteFile 31248832Smsmith * 31348832Smsmith * PARAMETERS: FileId - Index into file info array 31448832Smsmith * Buffer - Data to write 31548832Smsmith * Length - Amount of data to write 31648832Smsmith * 31748832Smsmith * RETURN: None 31848832Smsmith * 31948832Smsmith * DESCRIPTION: Write data to an open file. 32048832Smsmith * NOTE: Aborts compiler on any error. 32148832Smsmith * 32248832Smsmith ******************************************************************************/ 32348832Smsmith 32448832Smsmithvoid 32548832SmsmithFlWriteFile ( 32648832Smsmith UINT32 FileId, 32748832Smsmith void *Buffer, 32848832Smsmith UINT32 Length) 32948832Smsmith{ 33048832Smsmith UINT32 Actual; 33148832Smsmith 33248832Smsmith 33348832Smsmith /* Write and check for error */ 33448832Smsmith 33548832Smsmith Actual = fwrite ((char *) Buffer, 1, Length, Gbl_Files[FileId].Handle); 33648832Smsmith if (Actual != Length) 33748832Smsmith { 33848832Smsmith FlFileError (FileId, ASL_MSG_WRITE); 33948832Smsmith AslAbort (); 34048832Smsmith } 34148832Smsmith} 34248832Smsmith 34348832Smsmith 34448832Smsmith/******************************************************************************* 34548832Smsmith * 34648832Smsmith * FUNCTION: FlPrintFile 34748832Smsmith * 34852480Salc * PARAMETERS: FileId - Index into file info array 34952480Salc * Format - Printf format string 35052480Salc * ... - Printf arguments 35152480Salc * 35252480Salc * RETURN: None 35348832Smsmith * 35448832Smsmith * DESCRIPTION: Formatted write to an open file. 35548832Smsmith * NOTE: Aborts compiler on any error. 35648832Smsmith * 35748832Smsmith ******************************************************************************/ 35848832Smsmith 35948832Smsmithvoid 36048832SmsmithFlPrintFile ( 36148832Smsmith UINT32 FileId, 36248832Smsmith char *Format, 36348832Smsmith ...) 36448832Smsmith{ 36548832Smsmith INT32 Actual; 36648832Smsmith va_list Args; 36748832Smsmith 36848832Smsmith 36949404Speter va_start (Args, Format); 37048832Smsmith 37148832Smsmith Actual = vfprintf (Gbl_Files[FileId].Handle, Format, Args); 37248832Smsmith if (Actual == -1) 37348832Smsmith { 37448832Smsmith FlFileError (FileId, ASL_MSG_WRITE); 37548832Smsmith AslAbort (); 37648832Smsmith } 37748832Smsmith} 37848832Smsmith 37948832Smsmith 38048832Smsmith/******************************************************************************* 38148832Smsmith * 38248832Smsmith * FUNCTION: FlSeekFile 38348832Smsmith * 38448832Smsmith * PARAMETERS: FileId - Index into file info array 38548832Smsmith * Offset - Absolute byte offset in file 38648832Smsmith * 38748832Smsmith * RETURN: None 38848832Smsmith * 38948832Smsmith * DESCRIPTION: Seek to absolute offset 39048832Smsmith * NOTE: Aborts compiler on any error. 39148832Smsmith * 39248832Smsmith ******************************************************************************/ 39348832Smsmith 39449601Spetervoid 39548832SmsmithFlSeekFile ( 39648832Smsmith UINT32 FileId, 39748832Smsmith long Offset) 39848832Smsmith{ 39948832Smsmith int Error; 40049601Speter 40149601Speter 40249580Swpaul Error = fseek (Gbl_Files[FileId].Handle, Offset, SEEK_SET); 40349580Swpaul if (Error) 40449580Swpaul { 40549601Speter FlFileError (FileId, ASL_MSG_SEEK); 40649580Swpaul AslAbort (); 40749601Speter } 40849601Speter} 40949580Swpaul 41048832Smsmith 41148832Smsmith/******************************************************************************* 41248832Smsmith * 41348832Smsmith * FUNCTION: FlCloseFile 41448832Smsmith * 41548832Smsmith * PARAMETERS: FileId - Index into file info array 41648832Smsmith * 41748832Smsmith * RETURN: None 41848832Smsmith * 41948832Smsmith * DESCRIPTION: Close an open file. Aborts compiler on error 42048832Smsmith * 42148832Smsmith ******************************************************************************/ 42248832Smsmith 42348832Smsmithvoid 42449404SpeterFlCloseFile ( 42549404Speter UINT32 FileId) 42648832Smsmith{ 42748832Smsmith int Error; 42848832Smsmith 42948832Smsmith 43048832Smsmith if (!Gbl_Files[FileId].Handle) 43148832Smsmith { 43248832Smsmith return; 43348832Smsmith } 43448832Smsmith 43548832Smsmith Error = fclose (Gbl_Files[FileId].Handle); 43648832Smsmith Gbl_Files[FileId].Handle = NULL; 43748832Smsmith 43848832Smsmith if (Error) 43948832Smsmith { 44048832Smsmith FlFileError (FileId, ASL_MSG_CLOSE); 44148832Smsmith AslAbort (); 44248832Smsmith } 44348832Smsmith 44448832Smsmith return; 44548832Smsmith} 44648832Smsmith 44748832Smsmith 44848832Smsmith/******************************************************************************* 44948832Smsmith * 45048832Smsmith * FUNCTION: FlSetLineNumber 45150182Speter * 45250182Speter * PARAMETERS: Op - Parse node for the LINE asl statement 45350182Speter * 45450182Speter * RETURN: None. 45550182Speter * 45648832Smsmith * DESCRIPTION: Set the current line number 45748832Smsmith * 45848832Smsmith ******************************************************************************/ 45948832Smsmith 46048832Smsmithvoid 46148832SmsmithFlSetLineNumber ( 46248832Smsmith ACPI_PARSE_OBJECT *Op) 46347307Speter{ 46447307Speter 46547307Speter Gbl_CurrentLineNumber = (UINT32) Op->Asl.Value.Integer; 46647307Speter Gbl_LogicalLineNumber = (UINT32) Op->Asl.Value.Integer; 46748832Smsmith} 46847307Speter 46947307Speter 47047307Speter/******************************************************************************* 47147307Speter * 47247307Speter * FUNCTION: FlOpenIncludeFile 47347307Speter * 47447307Speter * PARAMETERS: Op - Parse node for the INCLUDE ASL statement 47548832Smsmith * 47647307Speter * RETURN: None. 47747307Speter * 47847307Speter * DESCRIPTION: Open an include file and push it on the input file stack. 47947307Speter * 48047307Speter ******************************************************************************/ 48147307Speter 48247307Spetervoid 48347307SpeterFlOpenIncludeFile ( 48447307Speter ACPI_PARSE_OBJECT *Op) 48547307Speter{ 48647307Speter FILE *IncFile; 48747307Speter 48847307Speter 48947307Speter /* Op must be valid */ 49047307Speter 49147307Speter if (!Op) 49247307Speter { 49347307Speter AslCommonError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, 49447307Speter Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, 49547307Speter Gbl_InputByteCount, Gbl_CurrentColumn, 49647307Speter Gbl_Files[ASL_FILE_INPUT].Filename, " - Null parse node"); 49747307Speter 49847307Speter return; 49947307Speter } 50047307Speter 501 /* 502 * Flush out the "include ()" statement on this line, start 503 * the actual include file on the next line 504 */ 505 ResetCurrentLineBuffer (); 506 FlPrintFile (ASL_FILE_SOURCE_OUTPUT, "\n"); 507 Gbl_CurrentLineOffset++; 508 509 /* Prepend the directory pathname and open the include file */ 510 511 DbgPrint (ASL_PARSE_OUTPUT, "\nOpen include file: path %s\n\n", 512 Op->Asl.Value.String); 513 IncFile = FlOpenLocalFile (Op->Asl.Value.String, "r"); 514 if (!IncFile) 515 { 516 sprintf (MsgBuffer, "%s (%s)", Op->Asl.Value.String, strerror (errno)); 517 AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, Op, MsgBuffer); 518 return; 519 } 520 521 /* Push the include file on the open input file stack */ 522 523 AslPushInputFileStack (IncFile, Op->Asl.Value.String); 524} 525 526 527/******************************************************************************* 528 * 529 * FUNCTION: FlOpenInputFile 530 * 531 * PARAMETERS: InputFilename - The user-specified ASL source file to be 532 * compiled 533 * 534 * RETURN: Status 535 * 536 * DESCRIPTION: Open the specified input file, and save the directory path to 537 * the file so that include files can be opened in 538 * the same directory. 539 * 540 ******************************************************************************/ 541 542ACPI_STATUS 543FlOpenInputFile ( 544 char *InputFilename) 545{ 546 547 /* Open the input ASL file, text mode */ 548 549 FlOpenFile (ASL_FILE_INPUT, InputFilename, "r"); 550 AslCompilerin = Gbl_Files[ASL_FILE_INPUT].Handle; 551 552 return (AE_OK); 553} 554 555 556/******************************************************************************* 557 * 558 * FUNCTION: FlOpenAmlOutputFile 559 * 560 * PARAMETERS: FilenamePrefix - The user-specified ASL source file 561 * 562 * RETURN: Status 563 * 564 * DESCRIPTION: Create the output filename (*.AML) and open the file. The file 565 * is created in the same directory as the parent input file. 566 * 567 ******************************************************************************/ 568 569ACPI_STATUS 570FlOpenAmlOutputFile ( 571 char *FilenamePrefix) 572{ 573 char *Filename; 574 575 576 /* Output filename usually comes from the ASL itself */ 577 578 Filename = Gbl_Files[ASL_FILE_AML_OUTPUT].Filename; 579 if (!Filename) 580 { 581 /* Create the output AML filename */ 582 583 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_AML_CODE); 584 if (!Filename) 585 { 586 AslCommonError (ASL_ERROR, ASL_MSG_OUTPUT_FILENAME, 587 0, 0, 0, 0, NULL, NULL); 588 return (AE_ERROR); 589 } 590 } 591 592 /* Open the output AML file in binary mode */ 593 594 FlOpenFile (ASL_FILE_AML_OUTPUT, Filename, "w+b"); 595 return (AE_OK); 596} 597 598 599/******************************************************************************* 600 * 601 * FUNCTION: FlOpenMiscOutputFiles 602 * 603 * PARAMETERS: FilenamePrefix - The user-specified ASL source file 604 * 605 * RETURN: Status 606 * 607 * DESCRIPTION: Create and open the various output files needed, depending on 608 * the command line options 609 * 610 ******************************************************************************/ 611 612ACPI_STATUS 613FlOpenMiscOutputFiles ( 614 char *FilenamePrefix) 615{ 616 char *Filename; 617 618 619 /* Create/Open a combined source output file */ 620 621 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_SOURCE); 622 if (!Filename) 623 { 624 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 625 0, 0, 0, 0, NULL, NULL); 626 return (AE_ERROR); 627 } 628 629 /* 630 * Open the source output file, binary mode (so that LF does not get 631 * expanded to CR/LF on some systems, messing up our seek 632 * calculations.) 633 */ 634 FlOpenFile (ASL_FILE_SOURCE_OUTPUT, Filename, "w+b"); 635 636 /* Create/Open a listing output file if asked */ 637 638 if (Gbl_ListingFlag) 639 { 640 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_LISTING); 641 if (!Filename) 642 { 643 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 644 0, 0, 0, 0, NULL, NULL); 645 return (AE_ERROR); 646 } 647 648 /* Open the listing file, text mode */ 649 650 FlOpenFile (ASL_FILE_LISTING_OUTPUT, Filename, "w+"); 651 652 AslCompilerSignon (ASL_FILE_LISTING_OUTPUT); 653 AslCompilerFileHeader (ASL_FILE_LISTING_OUTPUT); 654 } 655 656 /* Create/Open a assembly code source output file if asked */ 657 658 if (Gbl_AsmOutputFlag) 659 { 660 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_SOURCE); 661 if (!Filename) 662 { 663 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 664 0, 0, 0, 0, NULL, NULL); 665 return (AE_ERROR); 666 } 667 668 /* Open the assembly code source file, text mode */ 669 670 FlOpenFile (ASL_FILE_ASM_SOURCE_OUTPUT, Filename, "w+"); 671 672 AslCompilerSignon (ASL_FILE_ASM_SOURCE_OUTPUT); 673 AslCompilerFileHeader (ASL_FILE_ASM_SOURCE_OUTPUT); 674 } 675 676 /* Create/Open a C code source output file if asked */ 677 678 if (Gbl_C_OutputFlag) 679 { 680 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_SOURCE); 681 if (!Filename) 682 { 683 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 684 0, 0, 0, 0, NULL, NULL); 685 return (AE_ERROR); 686 } 687 688 /* Open the C code source file, text mode */ 689 690 FlOpenFile (ASL_FILE_C_SOURCE_OUTPUT, Filename, "w+"); 691 692 FlPrintFile (ASL_FILE_C_SOURCE_OUTPUT, "/*\n"); 693 AslCompilerSignon (ASL_FILE_C_SOURCE_OUTPUT); 694 AslCompilerFileHeader (ASL_FILE_C_SOURCE_OUTPUT); 695 } 696 697 /* Create/Open a assembly include output file if asked */ 698 699 if (Gbl_AsmIncludeOutputFlag) 700 { 701 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_INCLUDE); 702 if (!Filename) 703 { 704 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 705 0, 0, 0, 0, NULL, NULL); 706 return (AE_ERROR); 707 } 708 709 /* Open the assembly include file, text mode */ 710 711 FlOpenFile (ASL_FILE_ASM_INCLUDE_OUTPUT, Filename, "w+"); 712 713 AslCompilerSignon (ASL_FILE_ASM_INCLUDE_OUTPUT); 714 AslCompilerFileHeader (ASL_FILE_ASM_INCLUDE_OUTPUT); 715 } 716 717 /* Create/Open a C include output file if asked */ 718 719 if (Gbl_C_IncludeOutputFlag) 720 { 721 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_INCLUDE); 722 if (!Filename) 723 { 724 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 725 0, 0, 0, 0, NULL, NULL); 726 return (AE_ERROR); 727 } 728 729 /* Open the C include file, text mode */ 730 731 FlOpenFile (ASL_FILE_C_INCLUDE_OUTPUT, Filename, "w+"); 732 733 FlPrintFile (ASL_FILE_C_INCLUDE_OUTPUT, "/*\n"); 734 AslCompilerSignon (ASL_FILE_C_INCLUDE_OUTPUT); 735 AslCompilerFileHeader (ASL_FILE_C_INCLUDE_OUTPUT); 736 } 737 738 /* Create/Open a hex output file if asked */ 739 740 if (Gbl_HexOutputFlag) 741 { 742 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_HEX_DUMP); 743 if (!Filename) 744 { 745 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 746 0, 0, 0, 0, NULL, NULL); 747 return (AE_ERROR); 748 } 749 750 /* Open the hex file, text mode */ 751 752 FlOpenFile (ASL_FILE_HEX_OUTPUT, Filename, "w+"); 753 754 AslCompilerSignon (ASL_FILE_HEX_OUTPUT); 755 AslCompilerFileHeader (ASL_FILE_HEX_OUTPUT); 756 } 757 758 /* Create a namespace output file if asked */ 759 760 if (Gbl_NsOutputFlag) 761 { 762 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_NAMESPACE); 763 if (!Filename) 764 { 765 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 766 0, 0, 0, 0, NULL, NULL); 767 return (AE_ERROR); 768 } 769 770 /* Open the namespace file, text mode */ 771 772 FlOpenFile (ASL_FILE_NAMESPACE_OUTPUT, Filename, "w+"); 773 774 AslCompilerSignon (ASL_FILE_NAMESPACE_OUTPUT); 775 AslCompilerFileHeader (ASL_FILE_NAMESPACE_OUTPUT); 776 } 777 778 /* Create/Open a debug output file if asked */ 779 780 if (Gbl_DebugFlag) 781 { 782 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_DEBUG); 783 if (!Filename) 784 { 785 AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME, 786 0, 0, 0, 0, NULL, NULL); 787 return (AE_ERROR); 788 } 789 790 /* Open the debug file as STDERR, text mode */ 791 792 /* TBD: hide this behind a FlReopenFile function */ 793 794 Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Filename = Filename; 795 Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle = 796 freopen (Filename, "w+t", stderr); 797 798 AslCompilerSignon (ASL_FILE_DEBUG_OUTPUT); 799 AslCompilerFileHeader (ASL_FILE_DEBUG_OUTPUT); 800 } 801 802 return (AE_OK); 803} 804 805 806#ifdef ACPI_OBSOLETE_FUNCTIONS 807/******************************************************************************* 808 * 809 * FUNCTION: FlParseInputPathname 810 * 811 * PARAMETERS: InputFilename - The user-specified ASL source file to be 812 * compiled 813 * 814 * RETURN: Status 815 * 816 * DESCRIPTION: Split the input path into a directory and filename part 817 * 1) Directory part used to open include files 818 * 2) Filename part used to generate output filenames 819 * 820 ******************************************************************************/ 821 822ACPI_STATUS 823FlParseInputPathname ( 824 char *InputFilename) 825{ 826 char *Substring; 827 828 829 if (!InputFilename) 830 { 831 return (AE_OK); 832 } 833 834 /* Get the path to the input filename's directory */ 835 836 Gbl_DirectoryPath = strdup (InputFilename); 837 if (!Gbl_DirectoryPath) 838 { 839 return (AE_NO_MEMORY); 840 } 841 842 Substring = strrchr (Gbl_DirectoryPath, '\\'); 843 if (!Substring) 844 { 845 Substring = strrchr (Gbl_DirectoryPath, '/'); 846 if (!Substring) 847 { 848 Substring = strrchr (Gbl_DirectoryPath, ':'); 849 } 850 } 851 852 if (!Substring) 853 { 854 Gbl_DirectoryPath[0] = 0; 855 if (Gbl_UseDefaultAmlFilename) 856 { 857 Gbl_OutputFilenamePrefix = strdup (InputFilename); 858 } 859 } 860 else 861 { 862 if (Gbl_UseDefaultAmlFilename) 863 { 864 Gbl_OutputFilenamePrefix = strdup (Substring + 1); 865 } 866 *(Substring+1) = 0; 867 } 868 869 return (AE_OK); 870} 871#endif 872 873 874