Home | History | Annotate | Line # | Download | only in compiler
aslfiles.c revision 1.1
      1 
      2 /******************************************************************************
      3  *
      4  * Module Name: aslfiles - file I/O suppoert
      5  *
      6  *****************************************************************************/
      7 
      8 /******************************************************************************
      9  *
     10  * 1. Copyright Notice
     11  *
     12  * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
     13  * All rights reserved.
     14  *
     15  * 2. License
     16  *
     17  * 2.1. This is your license from Intel Corp. under its intellectual property
     18  * rights.  You may have additional license terms from the party that provided
     19  * you this software, covering your right to use that party's intellectual
     20  * property rights.
     21  *
     22  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
     23  * copy of the source code appearing in this file ("Covered Code") an
     24  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
     25  * base code distributed originally by Intel ("Original Intel Code") to copy,
     26  * make derivatives, distribute, use and display any portion of the Covered
     27  * Code in any form, with the right to sublicense such rights; and
     28  *
     29  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
     30  * license (with the right to sublicense), under only those claims of Intel
     31  * patents that are infringed by the Original Intel Code, to make, use, sell,
     32  * offer to sell, and import the Covered Code and derivative works thereof
     33  * solely to the minimum extent necessary to exercise the above copyright
     34  * license, and in no event shall the patent license extend to any additions
     35  * to or modifications of the Original Intel Code.  No other license or right
     36  * is granted directly or by implication, estoppel or otherwise;
     37  *
     38  * The above copyright and patent license is granted only if the following
     39  * conditions are met:
     40  *
     41  * 3. Conditions
     42  *
     43  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
     44  * Redistribution of source code of any substantial portion of the Covered
     45  * Code or modification with rights to further distribute source must include
     46  * the above Copyright Notice, the above License, this list of Conditions,
     47  * and the following Disclaimer and Export Compliance provision.  In addition,
     48  * Licensee must cause all Covered Code to which Licensee contributes to
     49  * contain a file documenting the changes Licensee made to create that Covered
     50  * Code and the date of any change.  Licensee must include in that file the
     51  * documentation of any changes made by any predecessor Licensee.  Licensee
     52  * must include a prominent statement that the modification is derived,
     53  * directly or indirectly, from Original Intel Code.
     54  *
     55  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
     56  * Redistribution of source code of any substantial portion of the Covered
     57  * Code or modification without rights to further distribute source must
     58  * include the following Disclaimer and Export Compliance provision in the
     59  * documentation and/or other materials provided with distribution.  In
     60  * addition, Licensee may not authorize further sublicense of source of any
     61  * portion of the Covered Code, and must include terms to the effect that the
     62  * license from Licensee to its licensee is limited to the intellectual
     63  * property embodied in the software Licensee provides to its licensee, and
     64  * not to intellectual property embodied in modifications its licensee may
     65  * make.
     66  *
     67  * 3.3. Redistribution of Executable. Redistribution in executable form of any
     68  * substantial portion of the Covered Code or modification must reproduce the
     69  * above Copyright Notice, and the following Disclaimer and Export Compliance
     70  * provision in the documentation and/or other materials provided with the
     71  * distribution.
     72  *
     73  * 3.4. Intel retains all right, title, and interest in and to the Original
     74  * Intel Code.
     75  *
     76  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
     77  * Intel shall be used in advertising or otherwise to promote the sale, use or
     78  * other dealings in products derived from or relating to the Covered Code
     79  * without prior written authorization from Intel.
     80  *
     81  * 4. Disclaimer and Export Compliance
     82  *
     83  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
     84  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
     85  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
     86  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
     87  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
     88  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
     89  * PARTICULAR PURPOSE.
     90  *
     91  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
     92  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
     93  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
     94  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
     95  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
     96  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
     97  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
     98  * LIMITED REMEDY.
     99  *
    100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
    101  * software or system incorporating such software without first obtaining any
    102  * required license or other approval from the U. S. Department of Commerce or
    103  * any other agency or department of the United States Government.  In the
    104  * event Licensee exports any such software from the United States or
    105  * re-exports any such software from a foreign destination, Licensee shall
    106  * ensure that the distribution and export/re-export of the software is in
    107  * compliance with all laws, regulations, orders, or other restrictions of the
    108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
    109  * any of its subsidiaries will export/re-export any technical data, process,
    110  * software, or service, directly or indirectly, to any country for which the
    111  * United States government or any agency thereof requires an export license,
    112  * other governmental approval, or letter of assurance, without first obtaining
    113  * such license, approval or letter.
    114  *
    115  *****************************************************************************/
    116 
    117 #include "aslcompiler.h"
    118 #include "acapps.h"
    119 
    120 #define _COMPONENT          ACPI_COMPILER
    121         ACPI_MODULE_NAME    ("aslfiles")
    122 
    123 /* Local prototypes */
    124 
    125 FILE *
    126 FlOpenIncludeWithPrefix (
    127     char                    *PrefixDir,
    128     char                    *Filename);
    129 
    130 
    131 #ifdef ACPI_OBSOLETE_FUNCTIONS
    132 ACPI_STATUS
    133 FlParseInputPathname (
    134     char                    *InputFilename);
    135 #endif
    136 
    137 
    138 /*******************************************************************************
    139  *
    140  * FUNCTION:    AslAbort
    141  *
    142  * PARAMETERS:  None
    143  *
    144  * RETURN:      None
    145  *
    146  * DESCRIPTION: Dump the error log and abort the compiler.  Used for serious
    147  *              I/O errors
    148  *
    149  ******************************************************************************/
    150 
    151 void
    152 AslAbort (
    153     void)
    154 {
    155 
    156     AePrintErrorLog (ASL_FILE_STDOUT);
    157     if (Gbl_DebugFlag)
    158     {
    159         /* Print error summary to the debug file */
    160 
    161         AePrintErrorLog (ASL_FILE_STDERR);
    162     }
    163 
    164     exit (1);
    165 }
    166 
    167 
    168 /*******************************************************************************
    169  *
    170  * FUNCTION:    FlFileError
    171  *
    172  * PARAMETERS:  FileId              - Index into file info array
    173  *              ErrorId             - Index into error message array
    174  *
    175  * RETURN:      None
    176  *
    177  * DESCRIPTION: Decode errno to an error message and add the entire error
    178  *              to the error log.
    179  *
    180  ******************************************************************************/
    181 
    182 void
    183 FlFileError (
    184     UINT32                  FileId,
    185     UINT8                   ErrorId)
    186 {
    187 
    188     sprintf (MsgBuffer, "\"%s\" (%s)", Gbl_Files[FileId].Filename,
    189         strerror (errno));
    190     AslCommonError (ASL_ERROR, ErrorId, 0, 0, 0, 0, NULL, MsgBuffer);
    191 }
    192 
    193 
    194 /*******************************************************************************
    195  *
    196  * FUNCTION:    FlOpenFile
    197  *
    198  * PARAMETERS:  FileId              - Index into file info array
    199  *              Filename            - file pathname to open
    200  *              Mode                - Open mode for fopen
    201  *
    202  * RETURN:      None
    203  *
    204  * DESCRIPTION: Open a file.
    205  *              NOTE: Aborts compiler on any error.
    206  *
    207  ******************************************************************************/
    208 
    209 void
    210 FlOpenFile (
    211     UINT32                  FileId,
    212     char                    *Filename,
    213     char                    *Mode)
    214 {
    215     FILE                    *File;
    216 
    217 
    218     File = fopen (Filename, Mode);
    219 
    220     Gbl_Files[FileId].Filename = Filename;
    221     Gbl_Files[FileId].Handle   = File;
    222 
    223     if (!File)
    224     {
    225         FlFileError (FileId, ASL_MSG_OPEN);
    226         AslAbort ();
    227     }
    228 }
    229 
    230 
    231 /*******************************************************************************
    232  *
    233  * FUNCTION:    FlGetFileSize
    234  *
    235  * PARAMETERS:  FileId              - Index into file info array
    236  *
    237  * RETURN:      File Size
    238  *
    239  * DESCRIPTION: Get current file size. Uses seek-to-EOF. File must be open.
    240  *
    241  ******************************************************************************/
    242 
    243 UINT32
    244 FlGetFileSize (
    245     UINT32                  FileId)
    246 {
    247     FILE                    *fp;
    248     UINT32                  FileSize;
    249 
    250 
    251     fp = Gbl_Files[FileId].Handle;
    252 
    253     fseek (fp, 0, SEEK_END);
    254     FileSize = (UINT32) ftell (fp);
    255     fseek (fp, 0, SEEK_SET);
    256 
    257     return (FileSize);
    258 }
    259 
    260 
    261 /*******************************************************************************
    262  *
    263  * FUNCTION:    FlReadFile
    264  *
    265  * PARAMETERS:  FileId              - Index into file info array
    266  *              Buffer              - Where to place the data
    267  *              Length              - Amount to read
    268  *
    269  * RETURN:      Status.  AE_ERROR indicates EOF.
    270  *
    271  * DESCRIPTION: Read data from an open file.
    272  *              NOTE: Aborts compiler on any error.
    273  *
    274  ******************************************************************************/
    275 
    276 ACPI_STATUS
    277 FlReadFile (
    278     UINT32                  FileId,
    279     void                    *Buffer,
    280     UINT32                  Length)
    281 {
    282     UINT32                  Actual;
    283 
    284 
    285     /* Read and check for error */
    286 
    287     Actual = fread (Buffer, 1, Length, Gbl_Files[FileId].Handle);
    288     if (Actual != Length)
    289     {
    290         if (feof (Gbl_Files[FileId].Handle))
    291         {
    292             /* End-of-file, just return error */
    293 
    294             return (AE_ERROR);
    295         }
    296 
    297         FlFileError (FileId, ASL_MSG_READ);
    298         AslAbort ();
    299     }
    300 
    301     return (AE_OK);
    302 }
    303 
    304 
    305 /*******************************************************************************
    306  *
    307  * FUNCTION:    FlWriteFile
    308  *
    309  * PARAMETERS:  FileId              - Index into file info array
    310  *              Buffer              - Data to write
    311  *              Length              - Amount of data to write
    312  *
    313  * RETURN:      None
    314  *
    315  * DESCRIPTION: Write data to an open file.
    316  *              NOTE: Aborts compiler on any error.
    317  *
    318  ******************************************************************************/
    319 
    320 void
    321 FlWriteFile (
    322     UINT32                  FileId,
    323     void                    *Buffer,
    324     UINT32                  Length)
    325 {
    326     UINT32                  Actual;
    327 
    328 
    329     /* Write and check for error */
    330 
    331     Actual = fwrite ((char *) Buffer, 1, Length, Gbl_Files[FileId].Handle);
    332     if (Actual != Length)
    333     {
    334         FlFileError (FileId, ASL_MSG_WRITE);
    335         AslAbort ();
    336     }
    337 }
    338 
    339 
    340 /*******************************************************************************
    341  *
    342  * FUNCTION:    FlPrintFile
    343  *
    344  * PARAMETERS:  FileId              - Index into file info array
    345  *              Format              - Printf format string
    346  *              ...                 - Printf arguments
    347  *
    348  * RETURN:      None
    349  *
    350  * DESCRIPTION: Formatted write to an open file.
    351  *              NOTE: Aborts compiler on any error.
    352  *
    353  ******************************************************************************/
    354 
    355 void
    356 FlPrintFile (
    357     UINT32                  FileId,
    358     char                    *Format,
    359     ...)
    360 {
    361     INT32                   Actual;
    362     va_list                 Args;
    363 
    364 
    365     va_start (Args, Format);
    366 
    367     Actual = vfprintf (Gbl_Files[FileId].Handle, Format, Args);
    368     va_end (Args);
    369 
    370     if (Actual == -1)
    371     {
    372         FlFileError (FileId, ASL_MSG_WRITE);
    373         AslAbort ();
    374     }
    375 }
    376 
    377 
    378 /*******************************************************************************
    379  *
    380  * FUNCTION:    FlSeekFile
    381  *
    382  * PARAMETERS:  FileId              - Index into file info array
    383  *              Offset              - Absolute byte offset in file
    384  *
    385  * RETURN:      None
    386  *
    387  * DESCRIPTION: Seek to absolute offset
    388  *              NOTE: Aborts compiler on any error.
    389  *
    390  ******************************************************************************/
    391 
    392 void
    393 FlSeekFile (
    394     UINT32                  FileId,
    395     long                    Offset)
    396 {
    397     int                     Error;
    398 
    399 
    400     Error = fseek (Gbl_Files[FileId].Handle, Offset, SEEK_SET);
    401     if (Error)
    402     {
    403         FlFileError (FileId, ASL_MSG_SEEK);
    404         AslAbort ();
    405     }
    406 }
    407 
    408 
    409 /*******************************************************************************
    410  *
    411  * FUNCTION:    FlCloseFile
    412  *
    413  * PARAMETERS:  FileId              - Index into file info array
    414  *
    415  * RETURN:      None
    416  *
    417  * DESCRIPTION: Close an open file.  Aborts compiler on error
    418  *
    419  ******************************************************************************/
    420 
    421 void
    422 FlCloseFile (
    423     UINT32                  FileId)
    424 {
    425     int                     Error;
    426 
    427 
    428     if (!Gbl_Files[FileId].Handle)
    429     {
    430         return;
    431     }
    432 
    433     Error = fclose (Gbl_Files[FileId].Handle);
    434     Gbl_Files[FileId].Handle = NULL;
    435 
    436     if (Error)
    437     {
    438         FlFileError (FileId, ASL_MSG_CLOSE);
    439         AslAbort ();
    440     }
    441 
    442     return;
    443 }
    444 
    445 
    446 /*******************************************************************************
    447  *
    448  * FUNCTION:    FlSetLineNumber
    449  *
    450  * PARAMETERS:  Op        - Parse node for the LINE asl statement
    451  *
    452  * RETURN:      None.
    453  *
    454  * DESCRIPTION: Set the current line number
    455  *
    456  ******************************************************************************/
    457 
    458 void
    459 FlSetLineNumber (
    460     ACPI_PARSE_OBJECT       *Op)
    461 {
    462 
    463     Gbl_CurrentLineNumber = (UINT32) Op->Asl.Value.Integer;
    464     Gbl_LogicalLineNumber = (UINT32) Op->Asl.Value.Integer;
    465 }
    466 
    467 
    468 /*******************************************************************************
    469  *
    470  * FUNCTION:    FlAddIncludeDirectory
    471  *
    472  * PARAMETERS:  Dir             - Directory pathname string
    473  *
    474  * RETURN:      None
    475  *
    476  * DESCRIPTION: Add a directory the list of include prefix directories.
    477  *
    478  ******************************************************************************/
    479 
    480 void
    481 FlAddIncludeDirectory (
    482     char                    *Dir)
    483 {
    484     ASL_INCLUDE_DIR         *NewDir;
    485     ASL_INCLUDE_DIR         *NextDir;
    486     ASL_INCLUDE_DIR         *PrevDir = NULL;
    487     UINT32                  NeedsSeparator = 0;
    488     size_t                  DirLength;
    489 
    490 
    491     DirLength = strlen (Dir);
    492     if (!DirLength)
    493     {
    494         return;
    495     }
    496 
    497     /* Make sure that the pathname ends with a path separator */
    498 
    499     if ((Dir[DirLength-1] != '/') &&
    500         (Dir[DirLength-1] != '\\'))
    501     {
    502         NeedsSeparator = 1;
    503     }
    504 
    505     NewDir = ACPI_ALLOCATE_ZEROED (sizeof (ASL_INCLUDE_DIR));
    506     NewDir->Dir = ACPI_ALLOCATE (DirLength + 1 + NeedsSeparator);
    507     strcpy (NewDir->Dir, Dir);
    508     if (NeedsSeparator)
    509     {
    510         strcat (NewDir->Dir, "/");
    511     }
    512 
    513     /*
    514      * Preserve command line ordering of -I options by adding new elements
    515      * at the end of the list
    516      */
    517     NextDir = Gbl_IncludeDirList;
    518     while (NextDir)
    519     {
    520         PrevDir = NextDir;
    521         NextDir = NextDir->Next;
    522     }
    523 
    524     if (PrevDir)
    525     {
    526         PrevDir->Next = NewDir;
    527     }
    528     else
    529     {
    530         Gbl_IncludeDirList = NewDir;
    531     }
    532 }
    533 
    534 
    535 /*******************************************************************************
    536  *
    537  * FUNCTION:    FlOpenIncludeWithPrefix
    538  *
    539  * PARAMETERS:  PrefixDir       - Prefix directory pathname. Can be a zero
    540  *                                length string.
    541  *              Filename        - The include filename from the source ASL.
    542  *
    543  * RETURN:      Valid file descriptor if successful. Null otherwise.
    544  *
    545  * DESCRIPTION: Open an include file and push it on the input file stack.
    546  *
    547  ******************************************************************************/
    548 
    549 FILE *
    550 FlOpenIncludeWithPrefix (
    551     char                    *PrefixDir,
    552     char                    *Filename)
    553 {
    554     FILE                    *IncludeFile;
    555     char                    *Pathname;
    556 
    557 
    558     /* Build the full pathname to the file */
    559 
    560     Pathname = ACPI_ALLOCATE (strlen (PrefixDir) + strlen (Filename) + 1);
    561 
    562     strcpy (Pathname, PrefixDir);
    563     strcat (Pathname, Filename);
    564 
    565     DbgPrint (ASL_PARSE_OUTPUT, "\nAttempt to open include file: path %s\n\n",
    566         Pathname);
    567 
    568     /* Attempt to open the file, push if successful */
    569 
    570     IncludeFile = fopen (Pathname, "r");
    571     if (IncludeFile)
    572     {
    573         /* Push the include file on the open input file stack */
    574 
    575         AslPushInputFileStack (IncludeFile, Pathname);
    576         return (IncludeFile);
    577     }
    578 
    579     ACPI_FREE (Pathname);
    580     return (NULL);
    581 }
    582 
    583 
    584 /*******************************************************************************
    585  *
    586  * FUNCTION:    FlOpenIncludeFile
    587  *
    588  * PARAMETERS:  Op        - Parse node for the INCLUDE ASL statement
    589  *
    590  * RETURN:      None.
    591  *
    592  * DESCRIPTION: Open an include file and push it on the input file stack.
    593  *
    594  ******************************************************************************/
    595 
    596 void
    597 FlOpenIncludeFile (
    598     ACPI_PARSE_OBJECT       *Op)
    599 {
    600     FILE                    *IncludeFile;
    601     ASL_INCLUDE_DIR         *NextDir;
    602 
    603 
    604     /* Op must be valid */
    605 
    606     if (!Op)
    607     {
    608         AslCommonError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN,
    609             Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
    610             Gbl_InputByteCount, Gbl_CurrentColumn,
    611             Gbl_Files[ASL_FILE_INPUT].Filename, " - Null parse node");
    612 
    613         return;
    614     }
    615 
    616     /*
    617      * Flush out the "include ()" statement on this line, start
    618      * the actual include file on the next line
    619      */
    620     ResetCurrentLineBuffer ();
    621     FlPrintFile (ASL_FILE_SOURCE_OUTPUT, "\n");
    622     Gbl_CurrentLineOffset++;
    623 
    624 
    625     /* Attempt to open the include file */
    626 
    627     /* If the file specifies an absolute path, just open it */
    628 
    629     if ((Op->Asl.Value.String[0] == '/')  ||
    630         (Op->Asl.Value.String[0] == '\\') ||
    631         (Op->Asl.Value.String[1] == ':'))
    632     {
    633         IncludeFile = FlOpenIncludeWithPrefix ("", Op->Asl.Value.String);
    634         if (!IncludeFile)
    635         {
    636             goto ErrorExit;
    637         }
    638         return;
    639     }
    640 
    641     /*
    642      * The include filename is not an absolute path.
    643      *
    644      * First, search for the file within the "local" directory -- meaning
    645      * the same directory that contains the source file.
    646      *
    647      * Construct the file pathname from the global directory name.
    648      */
    649     IncludeFile = FlOpenIncludeWithPrefix (Gbl_DirectoryPath, Op->Asl.Value.String);
    650     if (IncludeFile)
    651     {
    652         return;
    653     }
    654 
    655     /*
    656      * Second, search for the file within the (possibly multiple) directories
    657      * specified by the -I option on the command line.
    658      */
    659     NextDir = Gbl_IncludeDirList;
    660     while (NextDir)
    661     {
    662         IncludeFile = FlOpenIncludeWithPrefix (NextDir->Dir, Op->Asl.Value.String);
    663         if (IncludeFile)
    664         {
    665             return;
    666         }
    667 
    668         NextDir = NextDir->Next;
    669     }
    670 
    671     /* We could not open the include file after trying very hard */
    672 
    673 ErrorExit:
    674     sprintf (MsgBuffer, "%s, %s", Op->Asl.Value.String, strerror (errno));
    675     AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, Op, MsgBuffer);
    676 }
    677 
    678 
    679 /*******************************************************************************
    680  *
    681  * FUNCTION:    FlOpenInputFile
    682  *
    683  * PARAMETERS:  InputFilename       - The user-specified ASL source file to be
    684  *                                    compiled
    685  *
    686  * RETURN:      Status
    687  *
    688  * DESCRIPTION: Open the specified input file, and save the directory path to
    689  *              the file so that include files can be opened in
    690  *              the same directory.
    691  *
    692  ******************************************************************************/
    693 
    694 ACPI_STATUS
    695 FlOpenInputFile (
    696     char                    *InputFilename)
    697 {
    698 
    699     /* Open the input ASL file, text mode */
    700 
    701     FlOpenFile (ASL_FILE_INPUT, InputFilename, "r");
    702     AslCompilerin = Gbl_Files[ASL_FILE_INPUT].Handle;
    703 
    704     return (AE_OK);
    705 }
    706 
    707 
    708 /*******************************************************************************
    709  *
    710  * FUNCTION:    FlOpenAmlOutputFile
    711  *
    712  * PARAMETERS:  FilenamePrefix       - The user-specified ASL source file
    713  *
    714  * RETURN:      Status
    715  *
    716  * DESCRIPTION: Create the output filename (*.AML) and open the file.  The file
    717  *              is created in the same directory as the parent input file.
    718  *
    719  ******************************************************************************/
    720 
    721 ACPI_STATUS
    722 FlOpenAmlOutputFile (
    723     char                    *FilenamePrefix)
    724 {
    725     char                    *Filename;
    726 
    727 
    728     /* Output filename usually comes from the ASL itself */
    729 
    730     Filename = Gbl_Files[ASL_FILE_AML_OUTPUT].Filename;
    731     if (!Filename)
    732     {
    733         /* Create the output AML filename */
    734 
    735         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_AML_CODE);
    736         if (!Filename)
    737         {
    738             AslCommonError (ASL_ERROR, ASL_MSG_OUTPUT_FILENAME,
    739                 0, 0, 0, 0, NULL, NULL);
    740             return (AE_ERROR);
    741         }
    742     }
    743 
    744     /* Open the output AML file in binary mode */
    745 
    746     FlOpenFile (ASL_FILE_AML_OUTPUT, Filename, "w+b");
    747     return (AE_OK);
    748 }
    749 
    750 
    751 /*******************************************************************************
    752  *
    753  * FUNCTION:    FlOpenMiscOutputFiles
    754  *
    755  * PARAMETERS:  FilenamePrefix       - The user-specified ASL source file
    756  *
    757  * RETURN:      Status
    758  *
    759  * DESCRIPTION: Create and open the various output files needed, depending on
    760  *              the command line options
    761  *
    762  ******************************************************************************/
    763 
    764 ACPI_STATUS
    765 FlOpenMiscOutputFiles (
    766     char                    *FilenamePrefix)
    767 {
    768     char                    *Filename;
    769 
    770 
    771     /* Create/Open a combined source output file */
    772 
    773     Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_SOURCE);
    774     if (!Filename)
    775     {
    776         AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
    777             0, 0, 0, 0, NULL, NULL);
    778         return (AE_ERROR);
    779     }
    780 
    781     /*
    782      * Open the source output file, binary mode (so that LF does not get
    783      * expanded to CR/LF on some systems, messing up our seek
    784      * calculations.)
    785      */
    786     FlOpenFile (ASL_FILE_SOURCE_OUTPUT, Filename, "w+b");
    787 
    788     /* Create/Open a listing output file if asked */
    789 
    790     if (Gbl_ListingFlag)
    791     {
    792         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_LISTING);
    793         if (!Filename)
    794         {
    795             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
    796                 0, 0, 0, 0, NULL, NULL);
    797             return (AE_ERROR);
    798         }
    799 
    800         /* Open the listing file, text mode */
    801 
    802         FlOpenFile (ASL_FILE_LISTING_OUTPUT, Filename, "w+");
    803 
    804         AslCompilerSignon (ASL_FILE_LISTING_OUTPUT);
    805         AslCompilerFileHeader (ASL_FILE_LISTING_OUTPUT);
    806     }
    807 
    808     /* Create/Open a assembly code source output file if asked */
    809 
    810     if (Gbl_AsmOutputFlag)
    811     {
    812         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_SOURCE);
    813         if (!Filename)
    814         {
    815             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
    816                 0, 0, 0, 0, NULL, NULL);
    817             return (AE_ERROR);
    818         }
    819 
    820         /* Open the assembly code source file, text mode */
    821 
    822         FlOpenFile (ASL_FILE_ASM_SOURCE_OUTPUT, Filename, "w+");
    823 
    824         AslCompilerSignon (ASL_FILE_ASM_SOURCE_OUTPUT);
    825         AslCompilerFileHeader (ASL_FILE_ASM_SOURCE_OUTPUT);
    826     }
    827 
    828     /* Create/Open a C code source output file if asked */
    829 
    830     if (Gbl_C_OutputFlag)
    831     {
    832         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_SOURCE);
    833         if (!Filename)
    834         {
    835             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
    836                 0, 0, 0, 0, NULL, NULL);
    837             return (AE_ERROR);
    838         }
    839 
    840         /* Open the C code source file, text mode */
    841 
    842         FlOpenFile (ASL_FILE_C_SOURCE_OUTPUT, Filename, "w+");
    843 
    844         FlPrintFile (ASL_FILE_C_SOURCE_OUTPUT, "/*\n");
    845         AslCompilerSignon (ASL_FILE_C_SOURCE_OUTPUT);
    846         AslCompilerFileHeader (ASL_FILE_C_SOURCE_OUTPUT);
    847     }
    848 
    849     /* Create/Open a assembly include output file if asked */
    850 
    851     if (Gbl_AsmIncludeOutputFlag)
    852     {
    853         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_INCLUDE);
    854         if (!Filename)
    855         {
    856             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
    857                 0, 0, 0, 0, NULL, NULL);
    858             return (AE_ERROR);
    859         }
    860 
    861         /* Open the assembly include file, text mode */
    862 
    863         FlOpenFile (ASL_FILE_ASM_INCLUDE_OUTPUT, Filename, "w+");
    864 
    865         AslCompilerSignon (ASL_FILE_ASM_INCLUDE_OUTPUT);
    866         AslCompilerFileHeader (ASL_FILE_ASM_INCLUDE_OUTPUT);
    867     }
    868 
    869     /* Create/Open a C include output file if asked */
    870 
    871     if (Gbl_C_IncludeOutputFlag)
    872     {
    873         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_INCLUDE);
    874         if (!Filename)
    875         {
    876             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
    877                 0, 0, 0, 0, NULL, NULL);
    878             return (AE_ERROR);
    879         }
    880 
    881         /* Open the C include file, text mode */
    882 
    883         FlOpenFile (ASL_FILE_C_INCLUDE_OUTPUT, Filename, "w+");
    884 
    885         FlPrintFile (ASL_FILE_C_INCLUDE_OUTPUT, "/*\n");
    886         AslCompilerSignon (ASL_FILE_C_INCLUDE_OUTPUT);
    887         AslCompilerFileHeader (ASL_FILE_C_INCLUDE_OUTPUT);
    888     }
    889 
    890     /* Create/Open a hex output file if asked */
    891 
    892     if (Gbl_HexOutputFlag)
    893     {
    894         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_HEX_DUMP);
    895         if (!Filename)
    896         {
    897             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
    898                 0, 0, 0, 0, NULL, NULL);
    899             return (AE_ERROR);
    900         }
    901 
    902         /* Open the hex file, text mode */
    903 
    904         FlOpenFile (ASL_FILE_HEX_OUTPUT, Filename, "w+");
    905 
    906         AslCompilerSignon (ASL_FILE_HEX_OUTPUT);
    907         AslCompilerFileHeader (ASL_FILE_HEX_OUTPUT);
    908     }
    909 
    910     /* Create a namespace output file if asked */
    911 
    912     if (Gbl_NsOutputFlag)
    913     {
    914         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_NAMESPACE);
    915         if (!Filename)
    916         {
    917             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
    918                 0, 0, 0, 0, NULL, NULL);
    919             return (AE_ERROR);
    920         }
    921 
    922         /* Open the namespace file, text mode */
    923 
    924         FlOpenFile (ASL_FILE_NAMESPACE_OUTPUT, Filename, "w+");
    925 
    926         AslCompilerSignon (ASL_FILE_NAMESPACE_OUTPUT);
    927         AslCompilerFileHeader (ASL_FILE_NAMESPACE_OUTPUT);
    928     }
    929 
    930     /* Create/Open a debug output file if asked */
    931 
    932     if (Gbl_DebugFlag)
    933     {
    934         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_DEBUG);
    935         if (!Filename)
    936         {
    937             AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME,
    938                 0, 0, 0, 0, NULL, NULL);
    939             return (AE_ERROR);
    940         }
    941 
    942         /* Open the debug file as STDERR, text mode */
    943 
    944         /* TBD: hide this behind a FlReopenFile function */
    945 
    946         Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Filename = Filename;
    947         Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle =
    948             freopen (Filename, "w+t", stderr);
    949 
    950         AslCompilerSignon (ASL_FILE_DEBUG_OUTPUT);
    951         AslCompilerFileHeader (ASL_FILE_DEBUG_OUTPUT);
    952     }
    953 
    954     return (AE_OK);
    955 }
    956 
    957 
    958 #ifdef ACPI_OBSOLETE_FUNCTIONS
    959 /*******************************************************************************
    960  *
    961  * FUNCTION:    FlParseInputPathname
    962  *
    963  * PARAMETERS:  InputFilename       - The user-specified ASL source file to be
    964  *                                    compiled
    965  *
    966  * RETURN:      Status
    967  *
    968  * DESCRIPTION: Split the input path into a directory and filename part
    969  *              1) Directory part used to open include files
    970  *              2) Filename part used to generate output filenames
    971  *
    972  ******************************************************************************/
    973 
    974 ACPI_STATUS
    975 FlParseInputPathname (
    976     char                    *InputFilename)
    977 {
    978     char                    *Substring;
    979 
    980 
    981     if (!InputFilename)
    982     {
    983         return (AE_OK);
    984     }
    985 
    986     /* Get the path to the input filename's directory */
    987 
    988     Gbl_DirectoryPath = strdup (InputFilename);
    989     if (!Gbl_DirectoryPath)
    990     {
    991         return (AE_NO_MEMORY);
    992     }
    993 
    994     Substring = strrchr (Gbl_DirectoryPath, '\\');
    995     if (!Substring)
    996     {
    997         Substring = strrchr (Gbl_DirectoryPath, '/');
    998         if (!Substring)
    999         {
   1000             Substring = strrchr (Gbl_DirectoryPath, ':');
   1001         }
   1002     }
   1003 
   1004     if (!Substring)
   1005     {
   1006         Gbl_DirectoryPath[0] = 0;
   1007         if (Gbl_UseDefaultAmlFilename)
   1008         {
   1009             Gbl_OutputFilenamePrefix = strdup (InputFilename);
   1010         }
   1011     }
   1012     else
   1013     {
   1014         if (Gbl_UseDefaultAmlFilename)
   1015         {
   1016             Gbl_OutputFilenamePrefix = strdup (Substring + 1);
   1017         }
   1018         *(Substring+1) = 0;
   1019     }
   1020 
   1021     return (AE_OK);
   1022 }
   1023 #endif
   1024 
   1025 
   1026