Home | History | Annotate | Line # | Download | only in compiler
aslfiles.c revision 1.1.1.15
      1       1.1    jruoho /******************************************************************************
      2       1.1    jruoho  *
      3   1.1.1.3  christos  * Module Name: aslfiles - File support functions
      4       1.1    jruoho  *
      5       1.1    jruoho  *****************************************************************************/
      6       1.1    jruoho 
      7   1.1.1.2    jruoho /*
      8  1.1.1.14  christos  * Copyright (C) 2000 - 2019, Intel Corp.
      9       1.1    jruoho  * All rights reserved.
     10       1.1    jruoho  *
     11   1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
     12   1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
     13   1.1.1.2    jruoho  * are met:
     14   1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
     15   1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16   1.1.1.2    jruoho  *    without modification.
     17   1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18   1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19   1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20   1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
     21   1.1.1.2    jruoho  *    binary redistribution.
     22   1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23   1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
     24   1.1.1.2    jruoho  *    from this software without specific prior written permission.
     25   1.1.1.2    jruoho  *
     26   1.1.1.2    jruoho  * Alternatively, this software may be distributed under the terms of the
     27   1.1.1.2    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28   1.1.1.2    jruoho  * Software Foundation.
     29   1.1.1.2    jruoho  *
     30   1.1.1.2    jruoho  * NO WARRANTY
     31   1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32   1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33   1.1.1.2    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34   1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35   1.1.1.2    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36   1.1.1.2    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37   1.1.1.2    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38   1.1.1.2    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39   1.1.1.2    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40   1.1.1.2    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41   1.1.1.2    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42   1.1.1.2    jruoho  */
     43       1.1    jruoho 
     44       1.1    jruoho #include "aslcompiler.h"
     45       1.1    jruoho #include "acapps.h"
     46       1.1    jruoho 
     47       1.1    jruoho #define _COMPONENT          ACPI_COMPILER
     48       1.1    jruoho         ACPI_MODULE_NAME    ("aslfiles")
     49       1.1    jruoho 
     50       1.1    jruoho /* Local prototypes */
     51       1.1    jruoho 
     52   1.1.1.6  christos static FILE *
     53       1.1    jruoho FlOpenIncludeWithPrefix (
     54       1.1    jruoho     char                    *PrefixDir,
     55   1.1.1.6  christos     ACPI_PARSE_OBJECT       *Op,
     56       1.1    jruoho     char                    *Filename);
     57       1.1    jruoho 
     58  1.1.1.15  christos static BOOLEAN
     59  1.1.1.15  christos FlInputFileExists (
     60  1.1.1.15  christos     char                    *InputFilename);
     61  1.1.1.15  christos 
     62       1.1    jruoho #ifdef ACPI_OBSOLETE_FUNCTIONS
     63       1.1    jruoho ACPI_STATUS
     64       1.1    jruoho FlParseInputPathname (
     65       1.1    jruoho     char                    *InputFilename);
     66       1.1    jruoho #endif
     67       1.1    jruoho 
     68       1.1    jruoho 
     69       1.1    jruoho /*******************************************************************************
     70       1.1    jruoho  *
     71  1.1.1.14  christos  * FUNCTION:    FlInitOneFile
     72  1.1.1.14  christos  *
     73  1.1.1.14  christos  * PARAMETERS:  InputFilename       - The user-specified ASL source file to be
     74  1.1.1.14  christos  *                                    compiled
     75  1.1.1.14  christos  *
     76  1.1.1.14  christos  * RETURN:      Status
     77  1.1.1.14  christos  *
     78  1.1.1.14  christos  * DESCRIPTION: Initialize global file structure for one input file. This file
     79  1.1.1.14  christos  *              structure contains references to input, output, debugging, and
     80  1.1.1.14  christos  *              other miscellaneous files that are associated for a single
     81  1.1.1.14  christos  *              input ASL file.
     82  1.1.1.14  christos  *
     83  1.1.1.14  christos  ******************************************************************************/
     84  1.1.1.14  christos 
     85  1.1.1.14  christos ACPI_STATUS
     86  1.1.1.14  christos FlInitOneFile (
     87  1.1.1.14  christos     char                    *InputFilename)
     88  1.1.1.14  christos {
     89  1.1.1.14  christos     UINT32                  i;
     90  1.1.1.14  christos     ASL_GLOBAL_FILE_NODE    *NewFileNode;
     91  1.1.1.14  christos 
     92  1.1.1.14  christos 
     93  1.1.1.14  christos     if (FlInputFileExists (InputFilename))
     94  1.1.1.14  christos     {
     95  1.1.1.14  christos         AslError (ASL_ERROR, ASL_MSG_DUPLICATE_INPUT_FILE, NULL, InputFilename);
     96  1.1.1.14  christos         return (AE_ALREADY_EXISTS);
     97  1.1.1.14  christos     }
     98  1.1.1.14  christos 
     99  1.1.1.14  christos     NewFileNode = ACPI_CAST_PTR (ASL_GLOBAL_FILE_NODE,
    100  1.1.1.14  christos         UtLocalCacheCalloc (sizeof (ASL_GLOBAL_FILE_NODE)));
    101  1.1.1.14  christos 
    102  1.1.1.14  christos     if (!NewFileNode)
    103  1.1.1.14  christos     {
    104  1.1.1.14  christos         AslError (ASL_ERROR, ASL_MSG_MEMORY_ALLOCATION, NULL, NULL);
    105  1.1.1.14  christos         return (AE_NO_MEMORY);
    106  1.1.1.14  christos     }
    107  1.1.1.14  christos 
    108  1.1.1.14  christos     NewFileNode->ParserErrorDetected = FALSE;
    109  1.1.1.14  christos     NewFileNode->Next = AslGbl_FilesList;
    110  1.1.1.14  christos 
    111  1.1.1.14  christos     AslGbl_FilesList = NewFileNode;
    112  1.1.1.14  christos     AslGbl_Files = NewFileNode->Files;
    113  1.1.1.14  christos 
    114  1.1.1.14  christos     for (i = 0; i < ASL_NUM_FILES; i++)
    115  1.1.1.14  christos     {
    116  1.1.1.14  christos         AslGbl_Files[i].Handle = NULL;
    117  1.1.1.14  christos         AslGbl_Files[i].Filename = NULL;
    118  1.1.1.14  christos     }
    119  1.1.1.14  christos 
    120  1.1.1.14  christos     AslGbl_Files[ASL_FILE_STDOUT].Handle   = stdout;
    121  1.1.1.14  christos     AslGbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT";
    122  1.1.1.14  christos 
    123  1.1.1.14  christos     if (AslGbl_VerboseErrors)
    124  1.1.1.14  christos     {
    125  1.1.1.14  christos         AslGbl_Files[ASL_FILE_STDERR].Handle = stderr;
    126  1.1.1.14  christos     }
    127  1.1.1.14  christos     else
    128  1.1.1.14  christos     {
    129  1.1.1.14  christos         AslGbl_Files[ASL_FILE_STDERR].Handle = stdout;
    130  1.1.1.14  christos     }
    131  1.1.1.14  christos 
    132  1.1.1.14  christos     AslGbl_Files[ASL_FILE_STDERR].Filename = "STDERR";
    133  1.1.1.14  christos     return (AE_OK);
    134  1.1.1.14  christos }
    135  1.1.1.14  christos 
    136  1.1.1.14  christos 
    137  1.1.1.14  christos /*******************************************************************************
    138  1.1.1.14  christos  *
    139  1.1.1.14  christos  * FUNCTION:    FlInputFileExists
    140  1.1.1.14  christos  *
    141  1.1.1.14  christos  * PARAMETERS:  Filename       - File name to be searched
    142  1.1.1.14  christos  *
    143  1.1.1.14  christos  * RETURN:      Status
    144  1.1.1.14  christos  *
    145  1.1.1.14  christos  * DESCRIPTION: Returns true if the file name already exists.
    146  1.1.1.14  christos  *
    147  1.1.1.14  christos  ******************************************************************************/
    148  1.1.1.14  christos 
    149  1.1.1.15  christos static BOOLEAN
    150  1.1.1.14  christos FlInputFileExists (
    151  1.1.1.14  christos     char                    *Filename)
    152  1.1.1.14  christos {
    153  1.1.1.14  christos     ASL_GLOBAL_FILE_NODE    *Current = AslGbl_FilesList;
    154  1.1.1.14  christos 
    155  1.1.1.14  christos 
    156  1.1.1.14  christos     while (Current)
    157  1.1.1.14  christos     {
    158  1.1.1.14  christos         if (!strcmp (Filename, Current->Files[ASL_FILE_INPUT].Filename))
    159  1.1.1.14  christos         {
    160  1.1.1.14  christos             return (TRUE);
    161  1.1.1.14  christos         }
    162  1.1.1.14  christos 
    163  1.1.1.14  christos         Current = Current->Next;
    164  1.1.1.14  christos     }
    165  1.1.1.14  christos 
    166  1.1.1.14  christos     return (FALSE);
    167  1.1.1.14  christos }
    168  1.1.1.14  christos 
    169  1.1.1.14  christos 
    170  1.1.1.14  christos /*******************************************************************************
    171  1.1.1.14  christos  *
    172  1.1.1.14  christos  * FUNCTION:    FlSwitchFileSet
    173  1.1.1.14  christos  *
    174  1.1.1.14  christos  * PARAMETERS:  Op        - Parse node for the LINE asl statement
    175  1.1.1.14  christos  *
    176  1.1.1.14  christos  * RETURN:      None.
    177  1.1.1.14  christos  *
    178  1.1.1.14  christos  * DESCRIPTION: Set the current line number
    179  1.1.1.14  christos  *
    180  1.1.1.14  christos  ******************************************************************************/
    181  1.1.1.14  christos 
    182  1.1.1.14  christos ASL_FILE_SWITCH_STATUS
    183  1.1.1.14  christos FlSwitchFileSet (
    184  1.1.1.14  christos     char                    *InputFilename)
    185  1.1.1.14  christos {
    186  1.1.1.14  christos     ASL_GLOBAL_FILE_NODE    *Current = AslGbl_FilesList;
    187  1.1.1.14  christos     char                    *PrevFilename = Current->Files[ASL_FILE_INPUT].Filename;
    188  1.1.1.14  christos 
    189  1.1.1.14  christos 
    190  1.1.1.14  christos     while (Current)
    191  1.1.1.14  christos     {
    192  1.1.1.14  christos         if (!strcmp(Current->Files[ASL_FILE_INPUT].Filename, InputFilename))
    193  1.1.1.14  christos         {
    194  1.1.1.14  christos             AslGbl_Files = Current->Files;
    195  1.1.1.14  christos             AslGbl_TableSignature = Current->TableSignature;
    196  1.1.1.14  christos             AslGbl_TableId = Current->TableId;
    197  1.1.1.14  christos 
    198  1.1.1.14  christos             if (!strcmp (InputFilename, PrevFilename))
    199  1.1.1.14  christos             {
    200  1.1.1.14  christos                 return (SWITCH_TO_SAME_FILE);
    201  1.1.1.14  christos             }
    202  1.1.1.14  christos             else
    203  1.1.1.14  christos             {
    204  1.1.1.14  christos                 return (SWITCH_TO_DIFFERENT_FILE);
    205  1.1.1.14  christos             }
    206  1.1.1.14  christos         }
    207  1.1.1.14  christos 
    208  1.1.1.14  christos         Current = Current->Next;
    209  1.1.1.14  christos     }
    210  1.1.1.14  christos 
    211  1.1.1.14  christos     return (FILE_NOT_FOUND);
    212  1.1.1.14  christos }
    213  1.1.1.14  christos 
    214  1.1.1.14  christos 
    215  1.1.1.14  christos /*******************************************************************************
    216  1.1.1.14  christos  *
    217  1.1.1.14  christos  * FUNCTION:    FlGetFileHandle
    218  1.1.1.14  christos  *
    219  1.1.1.14  christos  * PARAMETERS:  OutFileId       - denotes file type of output handle
    220  1.1.1.14  christos  *              InFileId        - denotes file type of the input Filename
    221  1.1.1.14  christos  *              Filename
    222  1.1.1.14  christos  *
    223  1.1.1.14  christos  * RETURN:      File handle
    224  1.1.1.14  christos  *
    225  1.1.1.14  christos  * DESCRIPTION: Get the file handle for a particular filename/FileId. This
    226  1.1.1.14  christos  *              function also allows the caller to specify the file Id of the
    227  1.1.1.14  christos  *              desired type.
    228  1.1.1.14  christos  *
    229  1.1.1.14  christos  ******************************************************************************/
    230  1.1.1.14  christos 
    231  1.1.1.14  christos FILE *
    232  1.1.1.14  christos FlGetFileHandle (
    233  1.1.1.14  christos     UINT32                  OutFileId,
    234  1.1.1.14  christos     UINT32                  InFileId,
    235  1.1.1.14  christos     char                    *Filename)
    236  1.1.1.14  christos {
    237  1.1.1.14  christos     ASL_GLOBAL_FILE_NODE    *Current = AslGbl_FilesList;
    238  1.1.1.14  christos 
    239  1.1.1.14  christos 
    240  1.1.1.14  christos     if (!Filename)
    241  1.1.1.14  christos     {
    242  1.1.1.14  christos         return (NULL);
    243  1.1.1.14  christos     }
    244  1.1.1.14  christos 
    245  1.1.1.14  christos     while (Current)
    246  1.1.1.14  christos     {
    247  1.1.1.14  christos         if (!strcmp (Current->Files[InFileId].Filename, Filename))
    248  1.1.1.14  christos         {
    249  1.1.1.14  christos             return (Current->Files[OutFileId].Handle);
    250  1.1.1.14  christos         }
    251  1.1.1.14  christos 
    252  1.1.1.14  christos         Current = Current->Next;
    253  1.1.1.14  christos     }
    254  1.1.1.14  christos 
    255  1.1.1.14  christos     return (NULL);
    256  1.1.1.14  christos }
    257  1.1.1.14  christos 
    258  1.1.1.14  christos 
    259  1.1.1.14  christos /*******************************************************************************
    260  1.1.1.14  christos  *
    261  1.1.1.14  christos  * FUNCTION:    FlGetFileNode
    262  1.1.1.14  christos  *
    263  1.1.1.14  christos  * PARAMETERS:  FileId        - File type (ID) of the input Filename
    264  1.1.1.14  christos  *              Filename      - File to search for
    265  1.1.1.14  christos  *
    266  1.1.1.14  christos  * RETURN:      A global file node
    267  1.1.1.14  christos  *
    268  1.1.1.14  christos  * DESCRIPTION: Get the file node for a particular filename/FileId.
    269  1.1.1.14  christos  *
    270  1.1.1.14  christos  ******************************************************************************/
    271  1.1.1.14  christos 
    272  1.1.1.14  christos ASL_GLOBAL_FILE_NODE *
    273  1.1.1.14  christos FlGetFileNode (
    274  1.1.1.14  christos     UINT32                  FileId,
    275  1.1.1.14  christos     char                    *Filename)
    276  1.1.1.14  christos {
    277  1.1.1.14  christos     ASL_GLOBAL_FILE_NODE    *Current = AslGbl_FilesList;
    278  1.1.1.14  christos 
    279  1.1.1.14  christos 
    280  1.1.1.14  christos     if (!Filename)
    281  1.1.1.14  christos     {
    282  1.1.1.14  christos         return (NULL);
    283  1.1.1.14  christos     }
    284  1.1.1.14  christos 
    285  1.1.1.14  christos     while (Current)
    286  1.1.1.14  christos     {
    287  1.1.1.14  christos         if (!strcmp (Current->Files[FileId].Filename, Filename))
    288  1.1.1.14  christos         {
    289  1.1.1.14  christos             return (Current);
    290  1.1.1.14  christos         }
    291  1.1.1.14  christos 
    292  1.1.1.14  christos         Current = Current->Next;
    293  1.1.1.14  christos     }
    294  1.1.1.14  christos 
    295  1.1.1.14  christos     return (NULL);
    296  1.1.1.14  christos }
    297  1.1.1.14  christos 
    298  1.1.1.14  christos 
    299  1.1.1.14  christos /*******************************************************************************
    300  1.1.1.14  christos  *
    301  1.1.1.14  christos  * FUNCTION:    FlGetCurrentFileNode
    302  1.1.1.14  christos  *
    303  1.1.1.14  christos  * PARAMETERS:  None
    304  1.1.1.14  christos  *
    305  1.1.1.14  christos  * RETURN:      Global file node
    306  1.1.1.14  christos  *
    307  1.1.1.14  christos  * DESCRIPTION: Get the current input file node
    308  1.1.1.14  christos  *
    309  1.1.1.14  christos  ******************************************************************************/
    310  1.1.1.14  christos 
    311  1.1.1.14  christos ASL_GLOBAL_FILE_NODE *
    312  1.1.1.14  christos FlGetCurrentFileNode (
    313  1.1.1.14  christos     void)
    314  1.1.1.14  christos {
    315  1.1.1.14  christos     return (FlGetFileNode (
    316  1.1.1.14  christos         ASL_FILE_INPUT,AslGbl_Files[ASL_FILE_INPUT].Filename));
    317  1.1.1.14  christos }
    318  1.1.1.14  christos 
    319  1.1.1.14  christos 
    320  1.1.1.14  christos /*******************************************************************************
    321  1.1.1.14  christos  *
    322   1.1.1.3  christos  * FUNCTION:    FlSetLineNumber
    323       1.1    jruoho  *
    324   1.1.1.3  christos  * PARAMETERS:  Op        - Parse node for the LINE asl statement
    325       1.1    jruoho  *
    326   1.1.1.3  christos  * RETURN:      None.
    327       1.1    jruoho  *
    328   1.1.1.3  christos  * DESCRIPTION: Set the current line number
    329       1.1    jruoho  *
    330       1.1    jruoho  ******************************************************************************/
    331       1.1    jruoho 
    332       1.1    jruoho void
    333   1.1.1.3  christos FlSetLineNumber (
    334   1.1.1.3  christos     UINT32                  LineNumber)
    335       1.1    jruoho {
    336       1.1    jruoho 
    337   1.1.1.3  christos     DbgPrint (ASL_PARSE_OUTPUT, "\n#line: New line number %u (old %u)\n",
    338  1.1.1.13  christos          LineNumber, AslGbl_LogicalLineNumber);
    339       1.1    jruoho 
    340  1.1.1.13  christos     AslGbl_CurrentLineNumber = LineNumber;
    341       1.1    jruoho }
    342       1.1    jruoho 
    343       1.1    jruoho 
    344       1.1    jruoho /*******************************************************************************
    345       1.1    jruoho  *
    346   1.1.1.3  christos  * FUNCTION:    FlSetFilename
    347       1.1    jruoho  *
    348       1.1    jruoho  * PARAMETERS:  Op        - Parse node for the LINE asl statement
    349       1.1    jruoho  *
    350       1.1    jruoho  * RETURN:      None.
    351       1.1    jruoho  *
    352   1.1.1.3  christos  * DESCRIPTION: Set the current filename
    353       1.1    jruoho  *
    354       1.1    jruoho  ******************************************************************************/
    355       1.1    jruoho 
    356       1.1    jruoho void
    357   1.1.1.3  christos FlSetFilename (
    358   1.1.1.3  christos     char                    *Filename)
    359       1.1    jruoho {
    360       1.1    jruoho 
    361   1.1.1.3  christos     DbgPrint (ASL_PARSE_OUTPUT, "\n#line: New filename %s (old %s)\n",
    362  1.1.1.13  christos          Filename, AslGbl_Files[ASL_FILE_INPUT].Filename);
    363   1.1.1.3  christos 
    364   1.1.1.4  christos     /* No need to free any existing filename */
    365   1.1.1.4  christos 
    366  1.1.1.13  christos     AslGbl_Files[ASL_FILE_INPUT].Filename = Filename;
    367       1.1    jruoho }
    368       1.1    jruoho 
    369       1.1    jruoho 
    370       1.1    jruoho /*******************************************************************************
    371       1.1    jruoho  *
    372       1.1    jruoho  * FUNCTION:    FlAddIncludeDirectory
    373       1.1    jruoho  *
    374       1.1    jruoho  * PARAMETERS:  Dir             - Directory pathname string
    375       1.1    jruoho  *
    376       1.1    jruoho  * RETURN:      None
    377       1.1    jruoho  *
    378       1.1    jruoho  * DESCRIPTION: Add a directory the list of include prefix directories.
    379       1.1    jruoho  *
    380       1.1    jruoho  ******************************************************************************/
    381       1.1    jruoho 
    382       1.1    jruoho void
    383       1.1    jruoho FlAddIncludeDirectory (
    384       1.1    jruoho     char                    *Dir)
    385       1.1    jruoho {
    386       1.1    jruoho     ASL_INCLUDE_DIR         *NewDir;
    387       1.1    jruoho     ASL_INCLUDE_DIR         *NextDir;
    388       1.1    jruoho     ASL_INCLUDE_DIR         *PrevDir = NULL;
    389       1.1    jruoho     UINT32                  NeedsSeparator = 0;
    390       1.1    jruoho     size_t                  DirLength;
    391       1.1    jruoho 
    392       1.1    jruoho 
    393       1.1    jruoho     DirLength = strlen (Dir);
    394       1.1    jruoho     if (!DirLength)
    395       1.1    jruoho     {
    396       1.1    jruoho         return;
    397       1.1    jruoho     }
    398       1.1    jruoho 
    399       1.1    jruoho     /* Make sure that the pathname ends with a path separator */
    400       1.1    jruoho 
    401       1.1    jruoho     if ((Dir[DirLength-1] != '/') &&
    402       1.1    jruoho         (Dir[DirLength-1] != '\\'))
    403       1.1    jruoho     {
    404       1.1    jruoho         NeedsSeparator = 1;
    405       1.1    jruoho     }
    406       1.1    jruoho 
    407  1.1.1.13  christos     NewDir = ACPI_CAST_PTR (ASL_INCLUDE_DIR,
    408  1.1.1.13  christos         UtLocalCacheCalloc (sizeof (ASL_INCLUDE_DIR)));
    409  1.1.1.13  christos     NewDir->Dir = UtLocalCacheCalloc (DirLength + 1 + NeedsSeparator);
    410       1.1    jruoho     strcpy (NewDir->Dir, Dir);
    411       1.1    jruoho     if (NeedsSeparator)
    412       1.1    jruoho     {
    413       1.1    jruoho         strcat (NewDir->Dir, "/");
    414       1.1    jruoho     }
    415       1.1    jruoho 
    416       1.1    jruoho     /*
    417       1.1    jruoho      * Preserve command line ordering of -I options by adding new elements
    418       1.1    jruoho      * at the end of the list
    419       1.1    jruoho      */
    420  1.1.1.13  christos     NextDir = AslGbl_IncludeDirList;
    421       1.1    jruoho     while (NextDir)
    422       1.1    jruoho     {
    423       1.1    jruoho         PrevDir = NextDir;
    424       1.1    jruoho         NextDir = NextDir->Next;
    425       1.1    jruoho     }
    426       1.1    jruoho 
    427       1.1    jruoho     if (PrevDir)
    428       1.1    jruoho     {
    429       1.1    jruoho         PrevDir->Next = NewDir;
    430       1.1    jruoho     }
    431       1.1    jruoho     else
    432       1.1    jruoho     {
    433  1.1.1.13  christos         AslGbl_IncludeDirList = NewDir;
    434       1.1    jruoho     }
    435       1.1    jruoho }
    436       1.1    jruoho 
    437       1.1    jruoho 
    438       1.1    jruoho /*******************************************************************************
    439       1.1    jruoho  *
    440   1.1.1.3  christos  * FUNCTION:    FlMergePathnames
    441   1.1.1.3  christos  *
    442   1.1.1.3  christos  * PARAMETERS:  PrefixDir       - Prefix directory pathname. Can be NULL or
    443   1.1.1.3  christos  *                                a zero length string.
    444   1.1.1.3  christos  *              FilePathname    - The include filename from the source ASL.
    445   1.1.1.3  christos  *
    446   1.1.1.3  christos  * RETURN:      Merged pathname string
    447   1.1.1.3  christos  *
    448   1.1.1.3  christos  * DESCRIPTION: Merge two pathnames that (probably) have common elements, to
    449   1.1.1.3  christos  *              arrive at a minimal length string. Merge can occur if the
    450   1.1.1.3  christos  *              FilePathname is relative to the PrefixDir.
    451   1.1.1.3  christos  *
    452   1.1.1.3  christos  ******************************************************************************/
    453   1.1.1.3  christos 
    454   1.1.1.3  christos char *
    455   1.1.1.3  christos FlMergePathnames (
    456   1.1.1.3  christos     char                    *PrefixDir,
    457   1.1.1.3  christos     char                    *FilePathname)
    458   1.1.1.3  christos {
    459   1.1.1.3  christos     char                    *CommonPath;
    460   1.1.1.3  christos     char                    *Pathname;
    461   1.1.1.3  christos     char                    *LastElement;
    462   1.1.1.3  christos 
    463   1.1.1.3  christos 
    464   1.1.1.3  christos     DbgPrint (ASL_PARSE_OUTPUT, "Include: Prefix path - \"%s\"\n"
    465   1.1.1.3  christos         "Include: FilePathname - \"%s\"\n",
    466   1.1.1.3  christos          PrefixDir, FilePathname);
    467   1.1.1.3  christos 
    468   1.1.1.3  christos     /*
    469   1.1.1.3  christos      * If there is no prefix directory or if the file pathname is absolute,
    470   1.1.1.3  christos      * just return the original file pathname
    471   1.1.1.3  christos      */
    472   1.1.1.3  christos     if (!PrefixDir || (!*PrefixDir) ||
    473   1.1.1.3  christos         (*FilePathname == '/') ||
    474   1.1.1.3  christos          (FilePathname[1] == ':'))
    475   1.1.1.3  christos     {
    476  1.1.1.11  christos         Pathname = UtLocalCacheCalloc (strlen (FilePathname) + 1);
    477   1.1.1.3  christos         strcpy (Pathname, FilePathname);
    478   1.1.1.3  christos         goto ConvertBackslashes;
    479   1.1.1.3  christos     }
    480   1.1.1.3  christos 
    481   1.1.1.3  christos     /* Need a local copy of the prefix directory path */
    482   1.1.1.3  christos 
    483  1.1.1.11  christos     CommonPath = UtLocalCacheCalloc (strlen (PrefixDir) + 1);
    484   1.1.1.3  christos     strcpy (CommonPath, PrefixDir);
    485   1.1.1.3  christos 
    486   1.1.1.3  christos     /*
    487   1.1.1.3  christos      * Walk forward through the file path, and simultaneously backward
    488   1.1.1.3  christos      * through the prefix directory path until there are no more
    489   1.1.1.3  christos      * relative references at the start of the file path.
    490   1.1.1.3  christos      */
    491   1.1.1.3  christos     while (*FilePathname && (!strncmp (FilePathname, "../", 3)))
    492   1.1.1.3  christos     {
    493   1.1.1.3  christos         /* Remove last element of the prefix directory path */
    494   1.1.1.3  christos 
    495   1.1.1.3  christos         LastElement = strrchr (CommonPath, '/');
    496   1.1.1.3  christos         if (!LastElement)
    497   1.1.1.3  christos         {
    498   1.1.1.3  christos             goto ConcatenatePaths;
    499   1.1.1.3  christos         }
    500   1.1.1.3  christos 
    501   1.1.1.3  christos         *LastElement = 0;   /* Terminate CommonPath string */
    502   1.1.1.3  christos         FilePathname += 3;  /* Point to next path element */
    503   1.1.1.3  christos     }
    504   1.1.1.3  christos 
    505   1.1.1.3  christos     /*
    506   1.1.1.3  christos      * Remove the last element of the prefix directory path (it is the same as
    507   1.1.1.3  christos      * the first element of the file pathname), and build the final merged
    508   1.1.1.3  christos      * pathname.
    509   1.1.1.3  christos      */
    510   1.1.1.3  christos     LastElement = strrchr (CommonPath, '/');
    511   1.1.1.3  christos     if (LastElement)
    512   1.1.1.3  christos     {
    513   1.1.1.3  christos         *LastElement = 0;
    514   1.1.1.3  christos     }
    515   1.1.1.3  christos 
    516   1.1.1.3  christos     /* Build the final merged pathname */
    517   1.1.1.3  christos 
    518   1.1.1.3  christos ConcatenatePaths:
    519  1.1.1.11  christos     Pathname = UtLocalCacheCalloc (
    520   1.1.1.7  christos         strlen (CommonPath) + strlen (FilePathname) + 2);
    521   1.1.1.3  christos     if (LastElement && *CommonPath)
    522   1.1.1.3  christos     {
    523   1.1.1.3  christos         strcpy (Pathname, CommonPath);
    524   1.1.1.3  christos         strcat (Pathname, "/");
    525   1.1.1.3  christos     }
    526   1.1.1.3  christos     strcat (Pathname, FilePathname);
    527   1.1.1.3  christos 
    528   1.1.1.3  christos     /* Convert all backslashes to normal slashes */
    529   1.1.1.3  christos 
    530   1.1.1.3  christos ConvertBackslashes:
    531   1.1.1.3  christos     UtConvertBackslashes (Pathname);
    532   1.1.1.3  christos 
    533   1.1.1.3  christos     DbgPrint (ASL_PARSE_OUTPUT, "Include: Merged Pathname - \"%s\"\n",
    534   1.1.1.3  christos          Pathname);
    535   1.1.1.3  christos     return (Pathname);
    536   1.1.1.3  christos }
    537   1.1.1.3  christos 
    538   1.1.1.3  christos 
    539   1.1.1.3  christos /*******************************************************************************
    540   1.1.1.3  christos  *
    541       1.1    jruoho  * FUNCTION:    FlOpenIncludeWithPrefix
    542       1.1    jruoho  *
    543       1.1    jruoho  * PARAMETERS:  PrefixDir       - Prefix directory pathname. Can be a zero
    544       1.1    jruoho  *                                length string.
    545       1.1    jruoho  *              Filename        - The include filename from the source ASL.
    546       1.1    jruoho  *
    547       1.1    jruoho  * RETURN:      Valid file descriptor if successful. Null otherwise.
    548       1.1    jruoho  *
    549       1.1    jruoho  * DESCRIPTION: Open an include file and push it on the input file stack.
    550       1.1    jruoho  *
    551       1.1    jruoho  ******************************************************************************/
    552       1.1    jruoho 
    553   1.1.1.6  christos static FILE *
    554       1.1    jruoho FlOpenIncludeWithPrefix (
    555       1.1    jruoho     char                    *PrefixDir,
    556   1.1.1.6  christos     ACPI_PARSE_OBJECT       *Op,
    557       1.1    jruoho     char                    *Filename)
    558       1.1    jruoho {
    559       1.1    jruoho     FILE                    *IncludeFile;
    560       1.1    jruoho     char                    *Pathname;
    561   1.1.1.6  christos     UINT32                  OriginalLineNumber;
    562       1.1    jruoho 
    563       1.1    jruoho 
    564       1.1    jruoho     /* Build the full pathname to the file */
    565       1.1    jruoho 
    566   1.1.1.3  christos     Pathname = FlMergePathnames (PrefixDir, Filename);
    567       1.1    jruoho 
    568   1.1.1.3  christos     DbgPrint (ASL_PARSE_OUTPUT, "Include: Opening file - \"%s\"\n\n",
    569       1.1    jruoho         Pathname);
    570       1.1    jruoho 
    571       1.1    jruoho     /* Attempt to open the file, push if successful */
    572       1.1    jruoho 
    573       1.1    jruoho     IncludeFile = fopen (Pathname, "r");
    574   1.1.1.3  christos     if (!IncludeFile)
    575       1.1    jruoho     {
    576   1.1.1.3  christos         return (NULL);
    577       1.1    jruoho     }
    578       1.1    jruoho 
    579   1.1.1.6  christos     /*
    580   1.1.1.6  christos      * Check the entire include file for any # preprocessor directives.
    581   1.1.1.6  christos      * This is because there may be some confusion between the #include
    582   1.1.1.6  christos      * preprocessor directive and the ASL Include statement. A file included
    583   1.1.1.6  christos      * by the ASL include cannot contain preprocessor directives because
    584   1.1.1.6  christos      * the preprocessor has already run by the time the ASL include is
    585   1.1.1.6  christos      * recognized (by the compiler, not the preprocessor.)
    586   1.1.1.6  christos      *
    587   1.1.1.6  christos      * Note: DtGetNextLine strips/ignores comments.
    588   1.1.1.6  christos      * Save current line number since DtGetNextLine modifies it.
    589   1.1.1.6  christos      */
    590  1.1.1.13  christos     AslGbl_CurrentLineNumber--;
    591  1.1.1.13  christos     OriginalLineNumber = AslGbl_CurrentLineNumber;
    592   1.1.1.7  christos 
    593   1.1.1.6  christos     while (DtGetNextLine (IncludeFile, DT_ALLOW_MULTILINE_QUOTES) != ASL_EOF)
    594   1.1.1.6  christos     {
    595  1.1.1.13  christos         if (AslGbl_CurrentLineBuffer[0] == '#')
    596   1.1.1.6  christos         {
    597   1.1.1.6  christos             AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE,
    598   1.1.1.6  christos                 Op, "use #include instead");
    599   1.1.1.6  christos         }
    600   1.1.1.6  christos     }
    601   1.1.1.7  christos 
    602  1.1.1.13  christos     AslGbl_CurrentLineNumber = OriginalLineNumber;
    603   1.1.1.6  christos 
    604   1.1.1.6  christos     /* Must seek back to the start of the file */
    605   1.1.1.6  christos 
    606   1.1.1.6  christos     fseek (IncludeFile, 0, SEEK_SET);
    607   1.1.1.6  christos 
    608   1.1.1.3  christos     /* Push the include file on the open input file stack */
    609   1.1.1.3  christos 
    610   1.1.1.3  christos     AslPushInputFileStack (IncludeFile, Pathname);
    611   1.1.1.3  christos     return (IncludeFile);
    612       1.1    jruoho }
    613       1.1    jruoho 
    614       1.1    jruoho 
    615       1.1    jruoho /*******************************************************************************
    616       1.1    jruoho  *
    617       1.1    jruoho  * FUNCTION:    FlOpenIncludeFile
    618       1.1    jruoho  *
    619       1.1    jruoho  * PARAMETERS:  Op        - Parse node for the INCLUDE ASL statement
    620       1.1    jruoho  *
    621       1.1    jruoho  * RETURN:      None.
    622       1.1    jruoho  *
    623       1.1    jruoho  * DESCRIPTION: Open an include file and push it on the input file stack.
    624       1.1    jruoho  *
    625       1.1    jruoho  ******************************************************************************/
    626       1.1    jruoho 
    627       1.1    jruoho void
    628       1.1    jruoho FlOpenIncludeFile (
    629       1.1    jruoho     ACPI_PARSE_OBJECT       *Op)
    630       1.1    jruoho {
    631       1.1    jruoho     FILE                    *IncludeFile;
    632       1.1    jruoho     ASL_INCLUDE_DIR         *NextDir;
    633       1.1    jruoho 
    634       1.1    jruoho 
    635       1.1    jruoho     /* Op must be valid */
    636       1.1    jruoho 
    637       1.1    jruoho     if (!Op)
    638       1.1    jruoho     {
    639       1.1    jruoho         AslCommonError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN,
    640  1.1.1.13  christos             AslGbl_CurrentLineNumber, AslGbl_LogicalLineNumber,
    641  1.1.1.13  christos             AslGbl_InputByteCount, AslGbl_CurrentColumn,
    642  1.1.1.13  christos             AslGbl_Files[ASL_FILE_INPUT].Filename, " - Null parse node");
    643       1.1    jruoho 
    644       1.1    jruoho         return;
    645       1.1    jruoho     }
    646       1.1    jruoho 
    647       1.1    jruoho     /*
    648       1.1    jruoho      * Flush out the "include ()" statement on this line, start
    649       1.1    jruoho      * the actual include file on the next line
    650       1.1    jruoho      */
    651   1.1.1.3  christos     AslResetCurrentLineBuffer ();
    652       1.1    jruoho     FlPrintFile (ASL_FILE_SOURCE_OUTPUT, "\n");
    653  1.1.1.13  christos     AslGbl_CurrentLineOffset++;
    654       1.1    jruoho 
    655       1.1    jruoho 
    656       1.1    jruoho     /* Attempt to open the include file */
    657       1.1    jruoho 
    658       1.1    jruoho     /* If the file specifies an absolute path, just open it */
    659       1.1    jruoho 
    660       1.1    jruoho     if ((Op->Asl.Value.String[0] == '/')  ||
    661       1.1    jruoho         (Op->Asl.Value.String[0] == '\\') ||
    662       1.1    jruoho         (Op->Asl.Value.String[1] == ':'))
    663       1.1    jruoho     {
    664   1.1.1.6  christos         IncludeFile = FlOpenIncludeWithPrefix ("", Op, Op->Asl.Value.String);
    665       1.1    jruoho         if (!IncludeFile)
    666       1.1    jruoho         {
    667       1.1    jruoho             goto ErrorExit;
    668       1.1    jruoho         }
    669       1.1    jruoho         return;
    670       1.1    jruoho     }
    671       1.1    jruoho 
    672       1.1    jruoho     /*
    673       1.1    jruoho      * The include filename is not an absolute path.
    674       1.1    jruoho      *
    675       1.1    jruoho      * First, search for the file within the "local" directory -- meaning
    676       1.1    jruoho      * the same directory that contains the source file.
    677       1.1    jruoho      *
    678       1.1    jruoho      * Construct the file pathname from the global directory name.
    679       1.1    jruoho      */
    680   1.1.1.7  christos     IncludeFile = FlOpenIncludeWithPrefix (
    681  1.1.1.13  christos         AslGbl_DirectoryPath, Op, Op->Asl.Value.String);
    682       1.1    jruoho     if (IncludeFile)
    683       1.1    jruoho     {
    684       1.1    jruoho         return;
    685       1.1    jruoho     }
    686       1.1    jruoho 
    687       1.1    jruoho     /*
    688       1.1    jruoho      * Second, search for the file within the (possibly multiple) directories
    689       1.1    jruoho      * specified by the -I option on the command line.
    690       1.1    jruoho      */
    691  1.1.1.13  christos     NextDir = AslGbl_IncludeDirList;
    692       1.1    jruoho     while (NextDir)
    693       1.1    jruoho     {
    694   1.1.1.7  christos         IncludeFile = FlOpenIncludeWithPrefix (
    695   1.1.1.7  christos             NextDir->Dir, Op, Op->Asl.Value.String);
    696       1.1    jruoho         if (IncludeFile)
    697       1.1    jruoho         {
    698       1.1    jruoho             return;
    699       1.1    jruoho         }
    700       1.1    jruoho 
    701       1.1    jruoho         NextDir = NextDir->Next;
    702       1.1    jruoho     }
    703       1.1    jruoho 
    704       1.1    jruoho     /* We could not open the include file after trying very hard */
    705       1.1    jruoho 
    706       1.1    jruoho ErrorExit:
    707  1.1.1.13  christos     sprintf (AslGbl_MsgBuffer, "%s, %s", Op->Asl.Value.String, strerror (errno));
    708  1.1.1.13  christos     AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, Op, AslGbl_MsgBuffer);
    709       1.1    jruoho }
    710       1.1    jruoho 
    711       1.1    jruoho 
    712       1.1    jruoho /*******************************************************************************
    713       1.1    jruoho  *
    714       1.1    jruoho  * FUNCTION:    FlOpenInputFile
    715       1.1    jruoho  *
    716       1.1    jruoho  * PARAMETERS:  InputFilename       - The user-specified ASL source file to be
    717       1.1    jruoho  *                                    compiled
    718       1.1    jruoho  *
    719       1.1    jruoho  * RETURN:      Status
    720       1.1    jruoho  *
    721       1.1    jruoho  * DESCRIPTION: Open the specified input file, and save the directory path to
    722       1.1    jruoho  *              the file so that include files can be opened in
    723       1.1    jruoho  *              the same directory.
    724       1.1    jruoho  *
    725       1.1    jruoho  ******************************************************************************/
    726       1.1    jruoho 
    727       1.1    jruoho ACPI_STATUS
    728       1.1    jruoho FlOpenInputFile (
    729       1.1    jruoho     char                    *InputFilename)
    730       1.1    jruoho {
    731       1.1    jruoho 
    732       1.1    jruoho     /* Open the input ASL file, text mode */
    733       1.1    jruoho 
    734   1.1.1.3  christos     FlOpenFile (ASL_FILE_INPUT, InputFilename, "rt");
    735  1.1.1.13  christos     AslCompilerin = AslGbl_Files[ASL_FILE_INPUT].Handle;
    736       1.1    jruoho 
    737       1.1    jruoho     return (AE_OK);
    738       1.1    jruoho }
    739       1.1    jruoho 
    740       1.1    jruoho 
    741       1.1    jruoho /*******************************************************************************
    742       1.1    jruoho  *
    743       1.1    jruoho  * FUNCTION:    FlOpenAmlOutputFile
    744       1.1    jruoho  *
    745       1.1    jruoho  * PARAMETERS:  FilenamePrefix       - The user-specified ASL source file
    746       1.1    jruoho  *
    747       1.1    jruoho  * RETURN:      Status
    748       1.1    jruoho  *
    749   1.1.1.3  christos  * DESCRIPTION: Create the output filename (*.AML) and open the file. The file
    750       1.1    jruoho  *              is created in the same directory as the parent input file.
    751       1.1    jruoho  *
    752       1.1    jruoho  ******************************************************************************/
    753       1.1    jruoho 
    754       1.1    jruoho ACPI_STATUS
    755       1.1    jruoho FlOpenAmlOutputFile (
    756       1.1    jruoho     char                    *FilenamePrefix)
    757       1.1    jruoho {
    758       1.1    jruoho     char                    *Filename;
    759       1.1    jruoho 
    760       1.1    jruoho 
    761       1.1    jruoho     /* Output filename usually comes from the ASL itself */
    762       1.1    jruoho 
    763  1.1.1.13  christos     Filename = AslGbl_Files[ASL_FILE_AML_OUTPUT].Filename;
    764       1.1    jruoho     if (!Filename)
    765       1.1    jruoho     {
    766       1.1    jruoho         /* Create the output AML filename */
    767  1.1.1.12  christos         if (!AcpiGbl_CaptureComments)
    768  1.1.1.10  christos         {
    769  1.1.1.10  christos             Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_AML_CODE);
    770  1.1.1.10  christos         }
    771  1.1.1.10  christos         else
    772  1.1.1.10  christos         {
    773  1.1.1.10  christos             Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_CONVERT_AML);
    774  1.1.1.10  christos         }
    775       1.1    jruoho         if (!Filename)
    776       1.1    jruoho         {
    777       1.1    jruoho             AslCommonError (ASL_ERROR, ASL_MSG_OUTPUT_FILENAME,
    778       1.1    jruoho                 0, 0, 0, 0, NULL, NULL);
    779       1.1    jruoho             return (AE_ERROR);
    780       1.1    jruoho         }
    781   1.1.1.5  christos 
    782  1.1.1.13  christos         AslGbl_Files[ASL_FILE_AML_OUTPUT].Filename = Filename;
    783       1.1    jruoho     }
    784       1.1    jruoho 
    785       1.1    jruoho     /* Open the output AML file in binary mode */
    786       1.1    jruoho 
    787       1.1    jruoho     FlOpenFile (ASL_FILE_AML_OUTPUT, Filename, "w+b");
    788       1.1    jruoho     return (AE_OK);
    789       1.1    jruoho }
    790       1.1    jruoho 
    791       1.1    jruoho 
    792       1.1    jruoho /*******************************************************************************
    793       1.1    jruoho  *
    794       1.1    jruoho  * FUNCTION:    FlOpenMiscOutputFiles
    795       1.1    jruoho  *
    796       1.1    jruoho  * PARAMETERS:  FilenamePrefix       - The user-specified ASL source file
    797       1.1    jruoho  *
    798       1.1    jruoho  * RETURN:      Status
    799       1.1    jruoho  *
    800       1.1    jruoho  * DESCRIPTION: Create and open the various output files needed, depending on
    801       1.1    jruoho  *              the command line options
    802       1.1    jruoho  *
    803       1.1    jruoho  ******************************************************************************/
    804       1.1    jruoho 
    805       1.1    jruoho ACPI_STATUS
    806       1.1    jruoho FlOpenMiscOutputFiles (
    807       1.1    jruoho     char                    *FilenamePrefix)
    808       1.1    jruoho {
    809       1.1    jruoho     char                    *Filename;
    810       1.1    jruoho 
    811       1.1    jruoho 
    812   1.1.1.6  christos      /* Create/Open a map file if requested */
    813   1.1.1.6  christos 
    814  1.1.1.13  christos     if (AslGbl_MapfileFlag)
    815   1.1.1.6  christos     {
    816   1.1.1.6  christos         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_MAP);
    817   1.1.1.6  christos         if (!Filename)
    818   1.1.1.6  christos         {
    819   1.1.1.6  christos             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
    820   1.1.1.6  christos                 0, 0, 0, 0, NULL, NULL);
    821   1.1.1.6  christos             return (AE_ERROR);
    822   1.1.1.6  christos         }
    823   1.1.1.6  christos 
    824   1.1.1.6  christos         /* Open the hex file, text mode (closed at compiler exit) */
    825   1.1.1.6  christos 
    826   1.1.1.6  christos         FlOpenFile (ASL_FILE_MAP_OUTPUT, Filename, "w+t");
    827   1.1.1.6  christos 
    828   1.1.1.6  christos         AslCompilerSignon (ASL_FILE_MAP_OUTPUT);
    829   1.1.1.6  christos         AslCompilerFileHeader (ASL_FILE_MAP_OUTPUT);
    830   1.1.1.6  christos     }
    831   1.1.1.6  christos 
    832   1.1.1.3  christos     /* All done for disassembler */
    833   1.1.1.3  christos 
    834  1.1.1.13  christos     if (AslGbl_FileType == ASL_INPUT_TYPE_BINARY_ACPI_TABLE)
    835   1.1.1.3  christos     {
    836   1.1.1.3  christos         return (AE_OK);
    837   1.1.1.3  christos     }
    838   1.1.1.3  christos 
    839   1.1.1.2    jruoho     /* Create/Open a hex output file if asked */
    840       1.1    jruoho 
    841  1.1.1.13  christos     if (AslGbl_HexOutputFlag)
    842       1.1    jruoho     {
    843   1.1.1.2    jruoho         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_HEX_DUMP);
    844   1.1.1.2    jruoho         if (!Filename)
    845   1.1.1.2    jruoho         {
    846   1.1.1.2    jruoho             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
    847   1.1.1.2    jruoho                 0, 0, 0, 0, NULL, NULL);
    848   1.1.1.2    jruoho             return (AE_ERROR);
    849   1.1.1.2    jruoho         }
    850   1.1.1.2    jruoho 
    851   1.1.1.2    jruoho         /* Open the hex file, text mode */
    852   1.1.1.2    jruoho 
    853   1.1.1.3  christos         FlOpenFile (ASL_FILE_HEX_OUTPUT, Filename, "w+t");
    854   1.1.1.2    jruoho 
    855   1.1.1.2    jruoho         AslCompilerSignon (ASL_FILE_HEX_OUTPUT);
    856   1.1.1.2    jruoho         AslCompilerFileHeader (ASL_FILE_HEX_OUTPUT);
    857       1.1    jruoho     }
    858       1.1    jruoho 
    859   1.1.1.2    jruoho     /* Create/Open a debug output file if asked */
    860   1.1.1.2    jruoho 
    861  1.1.1.13  christos     if (AslGbl_DebugFlag)
    862   1.1.1.2    jruoho     {
    863   1.1.1.2    jruoho         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_DEBUG);
    864   1.1.1.2    jruoho         if (!Filename)
    865   1.1.1.2    jruoho         {
    866   1.1.1.2    jruoho             AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME,
    867   1.1.1.2    jruoho                 0, 0, 0, 0, NULL, NULL);
    868   1.1.1.2    jruoho             return (AE_ERROR);
    869   1.1.1.2    jruoho         }
    870   1.1.1.2    jruoho 
    871   1.1.1.2    jruoho         /* Open the debug file as STDERR, text mode */
    872   1.1.1.2    jruoho 
    873  1.1.1.13  christos         AslGbl_Files[ASL_FILE_DEBUG_OUTPUT].Filename = Filename;
    874  1.1.1.13  christos         AslGbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle =
    875   1.1.1.2    jruoho             freopen (Filename, "w+t", stderr);
    876   1.1.1.2    jruoho 
    877  1.1.1.13  christos         if (!AslGbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle)
    878   1.1.1.3  christos         {
    879   1.1.1.5  christos             /*
    880   1.1.1.6  christos              * A problem with freopen is that on error, we no longer
    881   1.1.1.6  christos              * have stderr and cannot emit normal error messages.
    882   1.1.1.6  christos              * Emit error to stdout, close files, and exit.
    883   1.1.1.5  christos              */
    884   1.1.1.6  christos             fprintf (stdout,
    885   1.1.1.6  christos                 "\nCould not open debug output file: %s\n\n", Filename);
    886   1.1.1.6  christos 
    887   1.1.1.6  christos             CmCleanupAndExit ();
    888   1.1.1.6  christos             exit (1);
    889   1.1.1.3  christos         }
    890   1.1.1.3  christos 
    891   1.1.1.2    jruoho         AslCompilerSignon (ASL_FILE_DEBUG_OUTPUT);
    892   1.1.1.2    jruoho         AslCompilerFileHeader (ASL_FILE_DEBUG_OUTPUT);
    893   1.1.1.2    jruoho     }
    894       1.1    jruoho 
    895   1.1.1.8  christos     /* Create/Open a cross-reference output file if asked */
    896   1.1.1.8  christos 
    897  1.1.1.13  christos     if (AslGbl_CrossReferenceOutput)
    898   1.1.1.8  christos     {
    899   1.1.1.8  christos         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_XREF);
    900   1.1.1.8  christos         if (!Filename)
    901   1.1.1.8  christos         {
    902   1.1.1.8  christos             AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME,
    903   1.1.1.8  christos                 0, 0, 0, 0, NULL, NULL);
    904   1.1.1.8  christos             return (AE_ERROR);
    905   1.1.1.8  christos         }
    906   1.1.1.8  christos 
    907   1.1.1.8  christos         FlOpenFile (ASL_FILE_XREF_OUTPUT, Filename, "w+t");
    908   1.1.1.8  christos 
    909   1.1.1.8  christos         AslCompilerSignon (ASL_FILE_XREF_OUTPUT);
    910   1.1.1.8  christos         AslCompilerFileHeader (ASL_FILE_XREF_OUTPUT);
    911   1.1.1.8  christos     }
    912   1.1.1.8  christos 
    913       1.1    jruoho     /* Create/Open a listing output file if asked */
    914       1.1    jruoho 
    915  1.1.1.13  christos     if (AslGbl_ListingFlag)
    916       1.1    jruoho     {
    917       1.1    jruoho         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_LISTING);
    918       1.1    jruoho         if (!Filename)
    919       1.1    jruoho         {
    920       1.1    jruoho             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
    921       1.1    jruoho                 0, 0, 0, 0, NULL, NULL);
    922       1.1    jruoho             return (AE_ERROR);
    923       1.1    jruoho         }
    924       1.1    jruoho 
    925       1.1    jruoho         /* Open the listing file, text mode */
    926       1.1    jruoho 
    927   1.1.1.3  christos         FlOpenFile (ASL_FILE_LISTING_OUTPUT, Filename, "w+t");
    928       1.1    jruoho 
    929       1.1    jruoho         AslCompilerSignon (ASL_FILE_LISTING_OUTPUT);
    930       1.1    jruoho         AslCompilerFileHeader (ASL_FILE_LISTING_OUTPUT);
    931       1.1    jruoho     }
    932       1.1    jruoho 
    933   1.1.1.6  christos     /* Create the preprocessor output temp file if preprocessor enabled */
    934   1.1.1.3  christos 
    935  1.1.1.13  christos     if (AslGbl_PreprocessFlag)
    936   1.1.1.3  christos     {
    937   1.1.1.3  christos         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_PREPROCESSOR);
    938   1.1.1.3  christos         if (!Filename)
    939   1.1.1.3  christos         {
    940   1.1.1.3  christos             AslCommonError (ASL_ERROR, ASL_MSG_PREPROCESSOR_FILENAME,
    941   1.1.1.3  christos                 0, 0, 0, 0, NULL, NULL);
    942   1.1.1.3  christos             return (AE_ERROR);
    943   1.1.1.3  christos         }
    944   1.1.1.3  christos 
    945   1.1.1.3  christos         FlOpenFile (ASL_FILE_PREPROCESSOR, Filename, "w+t");
    946   1.1.1.3  christos     }
    947   1.1.1.3  christos 
    948   1.1.1.6  christos     /*
    949   1.1.1.6  christos      * Create the "user" preprocessor output file if -li flag set.
    950   1.1.1.6  christos      * Note, this file contains no embedded #line directives.
    951   1.1.1.6  christos      */
    952  1.1.1.13  christos     if (AslGbl_PreprocessorOutputFlag)
    953   1.1.1.6  christos     {
    954   1.1.1.6  christos         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_PREPROC_USER);
    955   1.1.1.6  christos         if (!Filename)
    956   1.1.1.6  christos         {
    957   1.1.1.6  christos             AslCommonError (ASL_ERROR, ASL_MSG_PREPROCESSOR_FILENAME,
    958   1.1.1.6  christos                 0, 0, 0, 0, NULL, NULL);
    959   1.1.1.6  christos             return (AE_ERROR);
    960   1.1.1.6  christos         }
    961   1.1.1.6  christos 
    962   1.1.1.6  christos         FlOpenFile (ASL_FILE_PREPROCESSOR_USER, Filename, "w+t");
    963   1.1.1.6  christos     }
    964   1.1.1.6  christos 
    965   1.1.1.3  christos     /* All done for data table compiler */
    966   1.1.1.3  christos 
    967  1.1.1.13  christos     if (AslGbl_FileType == ASL_INPUT_TYPE_ASCII_DATA)
    968   1.1.1.2    jruoho     {
    969   1.1.1.2    jruoho         return (AE_OK);
    970   1.1.1.2    jruoho     }
    971   1.1.1.2    jruoho 
    972   1.1.1.2    jruoho     /* Create/Open a combined source output file */
    973   1.1.1.2    jruoho 
    974   1.1.1.2    jruoho     Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_SOURCE);
    975   1.1.1.2    jruoho     if (!Filename)
    976   1.1.1.2    jruoho     {
    977   1.1.1.2    jruoho         AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
    978   1.1.1.2    jruoho             0, 0, 0, 0, NULL, NULL);
    979   1.1.1.2    jruoho         return (AE_ERROR);
    980   1.1.1.2    jruoho     }
    981   1.1.1.2    jruoho 
    982   1.1.1.2    jruoho     /*
    983   1.1.1.2    jruoho      * Open the source output file, binary mode (so that LF does not get
    984   1.1.1.2    jruoho      * expanded to CR/LF on some systems, messing up our seek
    985   1.1.1.2    jruoho      * calculations.)
    986   1.1.1.2    jruoho      */
    987   1.1.1.2    jruoho     FlOpenFile (ASL_FILE_SOURCE_OUTPUT, Filename, "w+b");
    988   1.1.1.2    jruoho 
    989   1.1.1.3  christos /*
    990   1.1.1.3  christos // TBD: TEMP
    991  1.1.1.13  christos //    AslCompilerin = AslGbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle;
    992   1.1.1.3  christos */
    993       1.1    jruoho     /* Create/Open a assembly code source output file if asked */
    994       1.1    jruoho 
    995  1.1.1.13  christos     if (AslGbl_AsmOutputFlag)
    996       1.1    jruoho     {
    997       1.1    jruoho         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_SOURCE);
    998       1.1    jruoho         if (!Filename)
    999       1.1    jruoho         {
   1000       1.1    jruoho             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
   1001       1.1    jruoho                 0, 0, 0, 0, NULL, NULL);
   1002       1.1    jruoho             return (AE_ERROR);
   1003       1.1    jruoho         }
   1004       1.1    jruoho 
   1005       1.1    jruoho         /* Open the assembly code source file, text mode */
   1006       1.1    jruoho 
   1007   1.1.1.3  christos         FlOpenFile (ASL_FILE_ASM_SOURCE_OUTPUT, Filename, "w+t");
   1008       1.1    jruoho 
   1009       1.1    jruoho         AslCompilerSignon (ASL_FILE_ASM_SOURCE_OUTPUT);
   1010       1.1    jruoho         AslCompilerFileHeader (ASL_FILE_ASM_SOURCE_OUTPUT);
   1011       1.1    jruoho     }
   1012       1.1    jruoho 
   1013       1.1    jruoho     /* Create/Open a C code source output file if asked */
   1014       1.1    jruoho 
   1015  1.1.1.13  christos     if (AslGbl_C_OutputFlag)
   1016       1.1    jruoho     {
   1017       1.1    jruoho         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_SOURCE);
   1018       1.1    jruoho         if (!Filename)
   1019       1.1    jruoho         {
   1020       1.1    jruoho             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
   1021       1.1    jruoho                 0, 0, 0, 0, NULL, NULL);
   1022       1.1    jruoho             return (AE_ERROR);
   1023       1.1    jruoho         }
   1024       1.1    jruoho 
   1025       1.1    jruoho         /* Open the C code source file, text mode */
   1026       1.1    jruoho 
   1027   1.1.1.3  christos         FlOpenFile (ASL_FILE_C_SOURCE_OUTPUT, Filename, "w+t");
   1028       1.1    jruoho 
   1029       1.1    jruoho         FlPrintFile (ASL_FILE_C_SOURCE_OUTPUT, "/*\n");
   1030       1.1    jruoho         AslCompilerSignon (ASL_FILE_C_SOURCE_OUTPUT);
   1031       1.1    jruoho         AslCompilerFileHeader (ASL_FILE_C_SOURCE_OUTPUT);
   1032       1.1    jruoho     }
   1033       1.1    jruoho 
   1034   1.1.1.3  christos     /* Create/Open a C code source output file for the offset table if asked */
   1035   1.1.1.3  christos 
   1036  1.1.1.13  christos     if (AslGbl_C_OffsetTableFlag)
   1037   1.1.1.3  christos     {
   1038   1.1.1.3  christos         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_OFFSET);
   1039   1.1.1.3  christos         if (!Filename)
   1040   1.1.1.3  christos         {
   1041   1.1.1.3  christos             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
   1042   1.1.1.3  christos                 0, 0, 0, 0, NULL, NULL);
   1043   1.1.1.3  christos             return (AE_ERROR);
   1044   1.1.1.3  christos         }
   1045   1.1.1.3  christos 
   1046   1.1.1.3  christos         /* Open the C code source file, text mode */
   1047   1.1.1.3  christos 
   1048   1.1.1.3  christos         FlOpenFile (ASL_FILE_C_OFFSET_OUTPUT, Filename, "w+t");
   1049   1.1.1.3  christos 
   1050   1.1.1.3  christos         FlPrintFile (ASL_FILE_C_OFFSET_OUTPUT, "/*\n");
   1051   1.1.1.3  christos         AslCompilerSignon (ASL_FILE_C_OFFSET_OUTPUT);
   1052   1.1.1.3  christos         AslCompilerFileHeader (ASL_FILE_C_OFFSET_OUTPUT);
   1053   1.1.1.3  christos     }
   1054   1.1.1.3  christos 
   1055       1.1    jruoho     /* Create/Open a assembly include output file if asked */
   1056       1.1    jruoho 
   1057  1.1.1.13  christos     if (AslGbl_AsmIncludeOutputFlag)
   1058       1.1    jruoho     {
   1059       1.1    jruoho         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_INCLUDE);
   1060       1.1    jruoho         if (!Filename)
   1061       1.1    jruoho         {
   1062       1.1    jruoho             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
   1063       1.1    jruoho                 0, 0, 0, 0, NULL, NULL);
   1064       1.1    jruoho             return (AE_ERROR);
   1065       1.1    jruoho         }
   1066       1.1    jruoho 
   1067       1.1    jruoho         /* Open the assembly include file, text mode */
   1068       1.1    jruoho 
   1069   1.1.1.3  christos         FlOpenFile (ASL_FILE_ASM_INCLUDE_OUTPUT, Filename, "w+t");
   1070       1.1    jruoho 
   1071       1.1    jruoho         AslCompilerSignon (ASL_FILE_ASM_INCLUDE_OUTPUT);
   1072       1.1    jruoho         AslCompilerFileHeader (ASL_FILE_ASM_INCLUDE_OUTPUT);
   1073       1.1    jruoho     }
   1074       1.1    jruoho 
   1075       1.1    jruoho     /* Create/Open a C include output file if asked */
   1076       1.1    jruoho 
   1077  1.1.1.13  christos     if (AslGbl_C_IncludeOutputFlag)
   1078       1.1    jruoho     {
   1079       1.1    jruoho         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_INCLUDE);
   1080       1.1    jruoho         if (!Filename)
   1081       1.1    jruoho         {
   1082       1.1    jruoho             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
   1083       1.1    jruoho                 0, 0, 0, 0, NULL, NULL);
   1084       1.1    jruoho             return (AE_ERROR);
   1085       1.1    jruoho         }
   1086       1.1    jruoho 
   1087       1.1    jruoho         /* Open the C include file, text mode */
   1088       1.1    jruoho 
   1089   1.1.1.3  christos         FlOpenFile (ASL_FILE_C_INCLUDE_OUTPUT, Filename, "w+t");
   1090       1.1    jruoho 
   1091       1.1    jruoho         FlPrintFile (ASL_FILE_C_INCLUDE_OUTPUT, "/*\n");
   1092       1.1    jruoho         AslCompilerSignon (ASL_FILE_C_INCLUDE_OUTPUT);
   1093       1.1    jruoho         AslCompilerFileHeader (ASL_FILE_C_INCLUDE_OUTPUT);
   1094       1.1    jruoho     }
   1095       1.1    jruoho 
   1096       1.1    jruoho     /* Create a namespace output file if asked */
   1097       1.1    jruoho 
   1098  1.1.1.13  christos     if (AslGbl_NsOutputFlag)
   1099       1.1    jruoho     {
   1100       1.1    jruoho         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_NAMESPACE);
   1101       1.1    jruoho         if (!Filename)
   1102       1.1    jruoho         {
   1103       1.1    jruoho             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
   1104       1.1    jruoho                 0, 0, 0, 0, NULL, NULL);
   1105       1.1    jruoho             return (AE_ERROR);
   1106       1.1    jruoho         }
   1107       1.1    jruoho 
   1108       1.1    jruoho         /* Open the namespace file, text mode */
   1109       1.1    jruoho 
   1110   1.1.1.3  christos         FlOpenFile (ASL_FILE_NAMESPACE_OUTPUT, Filename, "w+t");
   1111       1.1    jruoho 
   1112       1.1    jruoho         AslCompilerSignon (ASL_FILE_NAMESPACE_OUTPUT);
   1113       1.1    jruoho         AslCompilerFileHeader (ASL_FILE_NAMESPACE_OUTPUT);
   1114       1.1    jruoho     }
   1115       1.1    jruoho 
   1116  1.1.1.10  christos     /* Create a debug file for the converter */
   1117  1.1.1.10  christos 
   1118  1.1.1.10  christos     if (AcpiGbl_DebugAslConversion)
   1119  1.1.1.10  christos     {
   1120  1.1.1.10  christos         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_CONVERT_DEBUG);
   1121  1.1.1.10  christos         if (!Filename)
   1122  1.1.1.10  christos         {
   1123  1.1.1.10  christos             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
   1124  1.1.1.10  christos                 0, 0, 0, 0, NULL, NULL);
   1125  1.1.1.10  christos             return (AE_ERROR);
   1126  1.1.1.10  christos         }
   1127  1.1.1.10  christos 
   1128  1.1.1.10  christos         /* Open the converter debug file, text mode */
   1129  1.1.1.10  christos 
   1130  1.1.1.10  christos         FlOpenFile (ASL_FILE_CONV_DEBUG_OUTPUT, Filename, "w+t");
   1131  1.1.1.10  christos 
   1132  1.1.1.10  christos         AslCompilerSignon (ASL_FILE_CONV_DEBUG_OUTPUT);
   1133  1.1.1.10  christos         AslCompilerFileHeader (ASL_FILE_CONV_DEBUG_OUTPUT);
   1134  1.1.1.10  christos 
   1135  1.1.1.13  christos         AcpiGbl_ConvDebugFile = AslGbl_Files[ASL_FILE_CONV_DEBUG_OUTPUT].Handle;
   1136  1.1.1.10  christos     }
   1137  1.1.1.10  christos 
   1138       1.1    jruoho     return (AE_OK);
   1139       1.1    jruoho }
   1140       1.1    jruoho 
   1141       1.1    jruoho 
   1142       1.1    jruoho #ifdef ACPI_OBSOLETE_FUNCTIONS
   1143       1.1    jruoho /*******************************************************************************
   1144       1.1    jruoho  *
   1145       1.1    jruoho  * FUNCTION:    FlParseInputPathname
   1146       1.1    jruoho  *
   1147       1.1    jruoho  * PARAMETERS:  InputFilename       - The user-specified ASL source file to be
   1148       1.1    jruoho  *                                    compiled
   1149       1.1    jruoho  *
   1150       1.1    jruoho  * RETURN:      Status
   1151       1.1    jruoho  *
   1152       1.1    jruoho  * DESCRIPTION: Split the input path into a directory and filename part
   1153       1.1    jruoho  *              1) Directory part used to open include files
   1154       1.1    jruoho  *              2) Filename part used to generate output filenames
   1155       1.1    jruoho  *
   1156       1.1    jruoho  ******************************************************************************/
   1157       1.1    jruoho 
   1158       1.1    jruoho ACPI_STATUS
   1159       1.1    jruoho FlParseInputPathname (
   1160       1.1    jruoho     char                    *InputFilename)
   1161       1.1    jruoho {
   1162       1.1    jruoho     char                    *Substring;
   1163       1.1    jruoho 
   1164       1.1    jruoho 
   1165       1.1    jruoho     if (!InputFilename)
   1166       1.1    jruoho     {
   1167       1.1    jruoho         return (AE_OK);
   1168       1.1    jruoho     }
   1169       1.1    jruoho 
   1170       1.1    jruoho     /* Get the path to the input filename's directory */
   1171       1.1    jruoho 
   1172  1.1.1.13  christos     AslGbl_DirectoryPath = strdup (InputFilename);
   1173  1.1.1.13  christos     if (!AslGbl_DirectoryPath)
   1174       1.1    jruoho     {
   1175       1.1    jruoho         return (AE_NO_MEMORY);
   1176       1.1    jruoho     }
   1177       1.1    jruoho 
   1178  1.1.1.13  christos     Substring = strrchr (AslGbl_DirectoryPath, '\\');
   1179       1.1    jruoho     if (!Substring)
   1180       1.1    jruoho     {
   1181  1.1.1.13  christos         Substring = strrchr (AslGbl_DirectoryPath, '/');
   1182       1.1    jruoho         if (!Substring)
   1183       1.1    jruoho         {
   1184  1.1.1.13  christos             Substring = strrchr (AslGbl_DirectoryPath, ':');
   1185       1.1    jruoho         }
   1186       1.1    jruoho     }
   1187       1.1    jruoho 
   1188       1.1    jruoho     if (!Substring)
   1189       1.1    jruoho     {
   1190  1.1.1.13  christos         AslGbl_DirectoryPath[0] = 0;
   1191  1.1.1.13  christos         if (AslGbl_UseDefaultAmlFilename)
   1192       1.1    jruoho         {
   1193  1.1.1.13  christos             AslGbl_OutputFilenamePrefix = strdup (InputFilename);
   1194       1.1    jruoho         }
   1195       1.1    jruoho     }
   1196       1.1    jruoho     else
   1197       1.1    jruoho     {
   1198  1.1.1.13  christos         if (AslGbl_UseDefaultAmlFilename)
   1199       1.1    jruoho         {
   1200  1.1.1.13  christos             AslGbl_OutputFilenamePrefix = strdup (Substring + 1);
   1201       1.1    jruoho         }
   1202       1.1    jruoho         *(Substring+1) = 0;
   1203       1.1    jruoho     }
   1204       1.1    jruoho 
   1205  1.1.1.13  christos     UtConvertBackslashes (AslGbl_OutputFilenamePrefix);
   1206       1.1    jruoho     return (AE_OK);
   1207       1.1    jruoho }
   1208       1.1    jruoho #endif
   1209