Home | History | Annotate | Line # | Download | only in compiler
aslfiles.c revision 1.5
      1  1.1    jruoho /******************************************************************************
      2  1.1    jruoho  *
      3  1.2  christos  * Module Name: aslfiles - File support functions
      4  1.1    jruoho  *
      5  1.1    jruoho  *****************************************************************************/
      6  1.1    jruoho 
      7  1.2  christos /*
      8  1.4  christos  * Copyright (C) 2000 - 2015, Intel Corp.
      9  1.1    jruoho  * All rights reserved.
     10  1.1    jruoho  *
     11  1.2  christos  * Redistribution and use in source and binary forms, with or without
     12  1.2  christos  * modification, are permitted provided that the following conditions
     13  1.2  christos  * are met:
     14  1.2  christos  * 1. Redistributions of source code must retain the above copyright
     15  1.2  christos  *    notice, this list of conditions, and the following disclaimer,
     16  1.2  christos  *    without modification.
     17  1.2  christos  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  1.2  christos  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  1.2  christos  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  1.2  christos  *    including a substantially similar Disclaimer requirement for further
     21  1.2  christos  *    binary redistribution.
     22  1.2  christos  * 3. Neither the names of the above-listed copyright holders nor the names
     23  1.2  christos  *    of any contributors may be used to endorse or promote products derived
     24  1.2  christos  *    from this software without specific prior written permission.
     25  1.2  christos  *
     26  1.2  christos  * Alternatively, this software may be distributed under the terms of the
     27  1.2  christos  * GNU General Public License ("GPL") version 2 as published by the Free
     28  1.2  christos  * Software Foundation.
     29  1.2  christos  *
     30  1.2  christos  * NO WARRANTY
     31  1.2  christos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  1.2  christos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.2  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  1.2  christos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  1.2  christos  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  1.2  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  1.2  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  1.2  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  1.2  christos  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  1.2  christos  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  1.2  christos  * POSSIBILITY OF SUCH DAMAGES.
     42  1.2  christos  */
     43  1.1    jruoho 
     44  1.1    jruoho #include "aslcompiler.h"
     45  1.1    jruoho #include "acapps.h"
     46  1.5  christos #include "dtcompiler.h"
     47  1.1    jruoho 
     48  1.1    jruoho #define _COMPONENT          ACPI_COMPILER
     49  1.1    jruoho         ACPI_MODULE_NAME    ("aslfiles")
     50  1.1    jruoho 
     51  1.1    jruoho /* Local prototypes */
     52  1.1    jruoho 
     53  1.5  christos static FILE *
     54  1.1    jruoho FlOpenIncludeWithPrefix (
     55  1.1    jruoho     char                    *PrefixDir,
     56  1.5  christos     ACPI_PARSE_OBJECT       *Op,
     57  1.1    jruoho     char                    *Filename);
     58  1.1    jruoho 
     59  1.1    jruoho 
     60  1.1    jruoho #ifdef ACPI_OBSOLETE_FUNCTIONS
     61  1.1    jruoho ACPI_STATUS
     62  1.1    jruoho FlParseInputPathname (
     63  1.1    jruoho     char                    *InputFilename);
     64  1.1    jruoho #endif
     65  1.1    jruoho 
     66  1.1    jruoho 
     67  1.1    jruoho /*******************************************************************************
     68  1.1    jruoho  *
     69  1.2  christos  * FUNCTION:    FlSetLineNumber
     70  1.1    jruoho  *
     71  1.2  christos  * PARAMETERS:  Op        - Parse node for the LINE asl statement
     72  1.1    jruoho  *
     73  1.2  christos  * RETURN:      None.
     74  1.1    jruoho  *
     75  1.2  christos  * DESCRIPTION: Set the current line number
     76  1.1    jruoho  *
     77  1.1    jruoho  ******************************************************************************/
     78  1.1    jruoho 
     79  1.1    jruoho void
     80  1.2  christos FlSetLineNumber (
     81  1.2  christos     UINT32                  LineNumber)
     82  1.1    jruoho {
     83  1.1    jruoho 
     84  1.2  christos     DbgPrint (ASL_PARSE_OUTPUT, "\n#line: New line number %u (old %u)\n",
     85  1.2  christos          LineNumber, Gbl_LogicalLineNumber);
     86  1.1    jruoho 
     87  1.2  christos     Gbl_CurrentLineNumber = LineNumber;
     88  1.1    jruoho }
     89  1.1    jruoho 
     90  1.1    jruoho 
     91  1.1    jruoho /*******************************************************************************
     92  1.1    jruoho  *
     93  1.2  christos  * FUNCTION:    FlSetFilename
     94  1.1    jruoho  *
     95  1.1    jruoho  * PARAMETERS:  Op        - Parse node for the LINE asl statement
     96  1.1    jruoho  *
     97  1.1    jruoho  * RETURN:      None.
     98  1.1    jruoho  *
     99  1.2  christos  * DESCRIPTION: Set the current filename
    100  1.1    jruoho  *
    101  1.1    jruoho  ******************************************************************************/
    102  1.1    jruoho 
    103  1.1    jruoho void
    104  1.2  christos FlSetFilename (
    105  1.2  christos     char                    *Filename)
    106  1.1    jruoho {
    107  1.1    jruoho 
    108  1.2  christos     DbgPrint (ASL_PARSE_OUTPUT, "\n#line: New filename %s (old %s)\n",
    109  1.2  christos          Filename, Gbl_Files[ASL_FILE_INPUT].Filename);
    110  1.2  christos 
    111  1.3  christos     /* No need to free any existing filename */
    112  1.3  christos 
    113  1.2  christos     Gbl_Files[ASL_FILE_INPUT].Filename = Filename;
    114  1.1    jruoho }
    115  1.1    jruoho 
    116  1.1    jruoho 
    117  1.1    jruoho /*******************************************************************************
    118  1.1    jruoho  *
    119  1.1    jruoho  * FUNCTION:    FlAddIncludeDirectory
    120  1.1    jruoho  *
    121  1.1    jruoho  * PARAMETERS:  Dir             - Directory pathname string
    122  1.1    jruoho  *
    123  1.1    jruoho  * RETURN:      None
    124  1.1    jruoho  *
    125  1.1    jruoho  * DESCRIPTION: Add a directory the list of include prefix directories.
    126  1.1    jruoho  *
    127  1.1    jruoho  ******************************************************************************/
    128  1.1    jruoho 
    129  1.1    jruoho void
    130  1.1    jruoho FlAddIncludeDirectory (
    131  1.1    jruoho     char                    *Dir)
    132  1.1    jruoho {
    133  1.1    jruoho     ASL_INCLUDE_DIR         *NewDir;
    134  1.1    jruoho     ASL_INCLUDE_DIR         *NextDir;
    135  1.1    jruoho     ASL_INCLUDE_DIR         *PrevDir = NULL;
    136  1.1    jruoho     UINT32                  NeedsSeparator = 0;
    137  1.1    jruoho     size_t                  DirLength;
    138  1.1    jruoho 
    139  1.1    jruoho 
    140  1.1    jruoho     DirLength = strlen (Dir);
    141  1.1    jruoho     if (!DirLength)
    142  1.1    jruoho     {
    143  1.1    jruoho         return;
    144  1.1    jruoho     }
    145  1.1    jruoho 
    146  1.1    jruoho     /* Make sure that the pathname ends with a path separator */
    147  1.1    jruoho 
    148  1.1    jruoho     if ((Dir[DirLength-1] != '/') &&
    149  1.1    jruoho         (Dir[DirLength-1] != '\\'))
    150  1.1    jruoho     {
    151  1.1    jruoho         NeedsSeparator = 1;
    152  1.1    jruoho     }
    153  1.1    jruoho 
    154  1.1    jruoho     NewDir = ACPI_ALLOCATE_ZEROED (sizeof (ASL_INCLUDE_DIR));
    155  1.1    jruoho     NewDir->Dir = ACPI_ALLOCATE (DirLength + 1 + NeedsSeparator);
    156  1.1    jruoho     strcpy (NewDir->Dir, Dir);
    157  1.1    jruoho     if (NeedsSeparator)
    158  1.1    jruoho     {
    159  1.1    jruoho         strcat (NewDir->Dir, "/");
    160  1.1    jruoho     }
    161  1.1    jruoho 
    162  1.1    jruoho     /*
    163  1.1    jruoho      * Preserve command line ordering of -I options by adding new elements
    164  1.1    jruoho      * at the end of the list
    165  1.1    jruoho      */
    166  1.1    jruoho     NextDir = Gbl_IncludeDirList;
    167  1.1    jruoho     while (NextDir)
    168  1.1    jruoho     {
    169  1.1    jruoho         PrevDir = NextDir;
    170  1.1    jruoho         NextDir = NextDir->Next;
    171  1.1    jruoho     }
    172  1.1    jruoho 
    173  1.1    jruoho     if (PrevDir)
    174  1.1    jruoho     {
    175  1.1    jruoho         PrevDir->Next = NewDir;
    176  1.1    jruoho     }
    177  1.1    jruoho     else
    178  1.1    jruoho     {
    179  1.1    jruoho         Gbl_IncludeDirList = NewDir;
    180  1.1    jruoho     }
    181  1.1    jruoho }
    182  1.1    jruoho 
    183  1.1    jruoho 
    184  1.1    jruoho /*******************************************************************************
    185  1.1    jruoho  *
    186  1.2  christos  * FUNCTION:    FlMergePathnames
    187  1.2  christos  *
    188  1.2  christos  * PARAMETERS:  PrefixDir       - Prefix directory pathname. Can be NULL or
    189  1.2  christos  *                                a zero length string.
    190  1.2  christos  *              FilePathname    - The include filename from the source ASL.
    191  1.2  christos  *
    192  1.2  christos  * RETURN:      Merged pathname string
    193  1.2  christos  *
    194  1.2  christos  * DESCRIPTION: Merge two pathnames that (probably) have common elements, to
    195  1.2  christos  *              arrive at a minimal length string. Merge can occur if the
    196  1.2  christos  *              FilePathname is relative to the PrefixDir.
    197  1.2  christos  *
    198  1.2  christos  ******************************************************************************/
    199  1.2  christos 
    200  1.2  christos char *
    201  1.2  christos FlMergePathnames (
    202  1.2  christos     char                    *PrefixDir,
    203  1.2  christos     char                    *FilePathname)
    204  1.2  christos {
    205  1.2  christos     char                    *CommonPath;
    206  1.2  christos     char                    *Pathname;
    207  1.2  christos     char                    *LastElement;
    208  1.2  christos 
    209  1.2  christos 
    210  1.2  christos     DbgPrint (ASL_PARSE_OUTPUT, "Include: Prefix path - \"%s\"\n"
    211  1.2  christos         "Include: FilePathname - \"%s\"\n",
    212  1.2  christos          PrefixDir, FilePathname);
    213  1.2  christos 
    214  1.2  christos     /*
    215  1.2  christos      * If there is no prefix directory or if the file pathname is absolute,
    216  1.2  christos      * just return the original file pathname
    217  1.2  christos      */
    218  1.2  christos     if (!PrefixDir || (!*PrefixDir) ||
    219  1.2  christos         (*FilePathname == '/') ||
    220  1.2  christos          (FilePathname[1] == ':'))
    221  1.2  christos     {
    222  1.3  christos         Pathname = UtStringCacheCalloc (strlen (FilePathname) + 1);
    223  1.2  christos         strcpy (Pathname, FilePathname);
    224  1.2  christos         goto ConvertBackslashes;
    225  1.2  christos     }
    226  1.2  christos 
    227  1.2  christos     /* Need a local copy of the prefix directory path */
    228  1.2  christos 
    229  1.3  christos     CommonPath = UtStringCacheCalloc (strlen (PrefixDir) + 1);
    230  1.2  christos     strcpy (CommonPath, PrefixDir);
    231  1.2  christos 
    232  1.2  christos     /*
    233  1.2  christos      * Walk forward through the file path, and simultaneously backward
    234  1.2  christos      * through the prefix directory path until there are no more
    235  1.2  christos      * relative references at the start of the file path.
    236  1.2  christos      */
    237  1.2  christos     while (*FilePathname && (!strncmp (FilePathname, "../", 3)))
    238  1.2  christos     {
    239  1.2  christos         /* Remove last element of the prefix directory path */
    240  1.2  christos 
    241  1.2  christos         LastElement = strrchr (CommonPath, '/');
    242  1.2  christos         if (!LastElement)
    243  1.2  christos         {
    244  1.2  christos             goto ConcatenatePaths;
    245  1.2  christos         }
    246  1.2  christos 
    247  1.2  christos         *LastElement = 0;   /* Terminate CommonPath string */
    248  1.2  christos         FilePathname += 3;  /* Point to next path element */
    249  1.2  christos     }
    250  1.2  christos 
    251  1.2  christos     /*
    252  1.2  christos      * Remove the last element of the prefix directory path (it is the same as
    253  1.2  christos      * the first element of the file pathname), and build the final merged
    254  1.2  christos      * pathname.
    255  1.2  christos      */
    256  1.2  christos     LastElement = strrchr (CommonPath, '/');
    257  1.2  christos     if (LastElement)
    258  1.2  christos     {
    259  1.2  christos         *LastElement = 0;
    260  1.2  christos     }
    261  1.2  christos 
    262  1.2  christos     /* Build the final merged pathname */
    263  1.2  christos 
    264  1.2  christos ConcatenatePaths:
    265  1.3  christos     Pathname = UtStringCacheCalloc (strlen (CommonPath) + strlen (FilePathname) + 2);
    266  1.2  christos     if (LastElement && *CommonPath)
    267  1.2  christos     {
    268  1.2  christos         strcpy (Pathname, CommonPath);
    269  1.2  christos         strcat (Pathname, "/");
    270  1.2  christos     }
    271  1.2  christos     strcat (Pathname, FilePathname);
    272  1.2  christos 
    273  1.2  christos     /* Convert all backslashes to normal slashes */
    274  1.2  christos 
    275  1.2  christos ConvertBackslashes:
    276  1.2  christos     UtConvertBackslashes (Pathname);
    277  1.2  christos 
    278  1.2  christos     DbgPrint (ASL_PARSE_OUTPUT, "Include: Merged Pathname - \"%s\"\n",
    279  1.2  christos          Pathname);
    280  1.2  christos     return (Pathname);
    281  1.2  christos }
    282  1.2  christos 
    283  1.2  christos 
    284  1.2  christos /*******************************************************************************
    285  1.2  christos  *
    286  1.1    jruoho  * FUNCTION:    FlOpenIncludeWithPrefix
    287  1.1    jruoho  *
    288  1.1    jruoho  * PARAMETERS:  PrefixDir       - Prefix directory pathname. Can be a zero
    289  1.1    jruoho  *                                length string.
    290  1.1    jruoho  *              Filename        - The include filename from the source ASL.
    291  1.1    jruoho  *
    292  1.1    jruoho  * RETURN:      Valid file descriptor if successful. Null otherwise.
    293  1.1    jruoho  *
    294  1.1    jruoho  * DESCRIPTION: Open an include file and push it on the input file stack.
    295  1.1    jruoho  *
    296  1.1    jruoho  ******************************************************************************/
    297  1.1    jruoho 
    298  1.5  christos static FILE *
    299  1.1    jruoho FlOpenIncludeWithPrefix (
    300  1.1    jruoho     char                    *PrefixDir,
    301  1.5  christos     ACPI_PARSE_OBJECT       *Op,
    302  1.1    jruoho     char                    *Filename)
    303  1.1    jruoho {
    304  1.1    jruoho     FILE                    *IncludeFile;
    305  1.1    jruoho     char                    *Pathname;
    306  1.5  christos     UINT32                  OriginalLineNumber;
    307  1.1    jruoho 
    308  1.1    jruoho 
    309  1.1    jruoho     /* Build the full pathname to the file */
    310  1.1    jruoho 
    311  1.2  christos     Pathname = FlMergePathnames (PrefixDir, Filename);
    312  1.1    jruoho 
    313  1.2  christos     DbgPrint (ASL_PARSE_OUTPUT, "Include: Opening file - \"%s\"\n\n",
    314  1.1    jruoho         Pathname);
    315  1.1    jruoho 
    316  1.1    jruoho     /* Attempt to open the file, push if successful */
    317  1.1    jruoho 
    318  1.1    jruoho     IncludeFile = fopen (Pathname, "r");
    319  1.2  christos     if (!IncludeFile)
    320  1.1    jruoho     {
    321  1.2  christos         fprintf (stderr, "Could not open include file %s\n", Pathname);
    322  1.2  christos         ACPI_FREE (Pathname);
    323  1.2  christos         return (NULL);
    324  1.2  christos     }
    325  1.1    jruoho 
    326  1.5  christos     /*
    327  1.5  christos      * Check the entire include file for any # preprocessor directives.
    328  1.5  christos      * This is because there may be some confusion between the #include
    329  1.5  christos      * preprocessor directive and the ASL Include statement. A file included
    330  1.5  christos      * by the ASL include cannot contain preprocessor directives because
    331  1.5  christos      * the preprocessor has already run by the time the ASL include is
    332  1.5  christos      * recognized (by the compiler, not the preprocessor.)
    333  1.5  christos      *
    334  1.5  christos      * Note: DtGetNextLine strips/ignores comments.
    335  1.5  christos      * Save current line number since DtGetNextLine modifies it.
    336  1.5  christos      */
    337  1.5  christos     Gbl_CurrentLineNumber--;
    338  1.5  christos     OriginalLineNumber = Gbl_CurrentLineNumber;
    339  1.5  christos     while (DtGetNextLine (IncludeFile, DT_ALLOW_MULTILINE_QUOTES) != ASL_EOF)
    340  1.5  christos     {
    341  1.5  christos         if (Gbl_CurrentLineBuffer[0] == '#')
    342  1.5  christos         {
    343  1.5  christos             AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE,
    344  1.5  christos                 Op, "use #include instead");
    345  1.5  christos         }
    346  1.5  christos     }
    347  1.5  christos     Gbl_CurrentLineNumber = OriginalLineNumber;
    348  1.5  christos 
    349  1.5  christos     /* Must seek back to the start of the file */
    350  1.5  christos 
    351  1.5  christos     fseek (IncludeFile, 0, SEEK_SET);
    352  1.5  christos 
    353  1.2  christos     /* Push the include file on the open input file stack */
    354  1.1    jruoho 
    355  1.2  christos     AslPushInputFileStack (IncludeFile, Pathname);
    356  1.2  christos     return (IncludeFile);
    357  1.1    jruoho }
    358  1.1    jruoho 
    359  1.1    jruoho 
    360  1.1    jruoho /*******************************************************************************
    361  1.1    jruoho  *
    362  1.1    jruoho  * FUNCTION:    FlOpenIncludeFile
    363  1.1    jruoho  *
    364  1.1    jruoho  * PARAMETERS:  Op        - Parse node for the INCLUDE ASL statement
    365  1.1    jruoho  *
    366  1.1    jruoho  * RETURN:      None.
    367  1.1    jruoho  *
    368  1.1    jruoho  * DESCRIPTION: Open an include file and push it on the input file stack.
    369  1.1    jruoho  *
    370  1.1    jruoho  ******************************************************************************/
    371  1.1    jruoho 
    372  1.1    jruoho void
    373  1.1    jruoho FlOpenIncludeFile (
    374  1.1    jruoho     ACPI_PARSE_OBJECT       *Op)
    375  1.1    jruoho {
    376  1.1    jruoho     FILE                    *IncludeFile;
    377  1.1    jruoho     ASL_INCLUDE_DIR         *NextDir;
    378  1.1    jruoho 
    379  1.1    jruoho 
    380  1.1    jruoho     /* Op must be valid */
    381  1.1    jruoho 
    382  1.1    jruoho     if (!Op)
    383  1.1    jruoho     {
    384  1.1    jruoho         AslCommonError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN,
    385  1.1    jruoho             Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
    386  1.1    jruoho             Gbl_InputByteCount, Gbl_CurrentColumn,
    387  1.1    jruoho             Gbl_Files[ASL_FILE_INPUT].Filename, " - Null parse node");
    388  1.1    jruoho 
    389  1.1    jruoho         return;
    390  1.1    jruoho     }
    391  1.1    jruoho 
    392  1.1    jruoho     /*
    393  1.1    jruoho      * Flush out the "include ()" statement on this line, start
    394  1.1    jruoho      * the actual include file on the next line
    395  1.1    jruoho      */
    396  1.2  christos     AslResetCurrentLineBuffer ();
    397  1.1    jruoho     FlPrintFile (ASL_FILE_SOURCE_OUTPUT, "\n");
    398  1.1    jruoho     Gbl_CurrentLineOffset++;
    399  1.1    jruoho 
    400  1.1    jruoho 
    401  1.1    jruoho     /* Attempt to open the include file */
    402  1.1    jruoho 
    403  1.1    jruoho     /* If the file specifies an absolute path, just open it */
    404  1.1    jruoho 
    405  1.1    jruoho     if ((Op->Asl.Value.String[0] == '/')  ||
    406  1.1    jruoho         (Op->Asl.Value.String[0] == '\\') ||
    407  1.1    jruoho         (Op->Asl.Value.String[1] == ':'))
    408  1.1    jruoho     {
    409  1.5  christos         IncludeFile = FlOpenIncludeWithPrefix ("", Op, Op->Asl.Value.String);
    410  1.1    jruoho         if (!IncludeFile)
    411  1.1    jruoho         {
    412  1.1    jruoho             goto ErrorExit;
    413  1.1    jruoho         }
    414  1.1    jruoho         return;
    415  1.1    jruoho     }
    416  1.1    jruoho 
    417  1.1    jruoho     /*
    418  1.1    jruoho      * The include filename is not an absolute path.
    419  1.1    jruoho      *
    420  1.1    jruoho      * First, search for the file within the "local" directory -- meaning
    421  1.1    jruoho      * the same directory that contains the source file.
    422  1.1    jruoho      *
    423  1.1    jruoho      * Construct the file pathname from the global directory name.
    424  1.1    jruoho      */
    425  1.5  christos     IncludeFile = FlOpenIncludeWithPrefix (Gbl_DirectoryPath, Op, Op->Asl.Value.String);
    426  1.1    jruoho     if (IncludeFile)
    427  1.1    jruoho     {
    428  1.1    jruoho         return;
    429  1.1    jruoho     }
    430  1.1    jruoho 
    431  1.1    jruoho     /*
    432  1.1    jruoho      * Second, search for the file within the (possibly multiple) directories
    433  1.1    jruoho      * specified by the -I option on the command line.
    434  1.1    jruoho      */
    435  1.1    jruoho     NextDir = Gbl_IncludeDirList;
    436  1.1    jruoho     while (NextDir)
    437  1.1    jruoho     {
    438  1.5  christos         IncludeFile = FlOpenIncludeWithPrefix (NextDir->Dir, Op, Op->Asl.Value.String);
    439  1.1    jruoho         if (IncludeFile)
    440  1.1    jruoho         {
    441  1.1    jruoho             return;
    442  1.1    jruoho         }
    443  1.1    jruoho 
    444  1.1    jruoho         NextDir = NextDir->Next;
    445  1.1    jruoho     }
    446  1.1    jruoho 
    447  1.1    jruoho     /* We could not open the include file after trying very hard */
    448  1.1    jruoho 
    449  1.1    jruoho ErrorExit:
    450  1.2  christos     snprintf (MsgBuffer, sizeof(MsgBuffer), "%s, %s", Op->Asl.Value.String, strerror (errno));
    451  1.1    jruoho     AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, Op, MsgBuffer);
    452  1.1    jruoho }
    453  1.1    jruoho 
    454  1.1    jruoho 
    455  1.1    jruoho /*******************************************************************************
    456  1.1    jruoho  *
    457  1.1    jruoho  * FUNCTION:    FlOpenInputFile
    458  1.1    jruoho  *
    459  1.1    jruoho  * PARAMETERS:  InputFilename       - The user-specified ASL source file to be
    460  1.1    jruoho  *                                    compiled
    461  1.1    jruoho  *
    462  1.1    jruoho  * RETURN:      Status
    463  1.1    jruoho  *
    464  1.1    jruoho  * DESCRIPTION: Open the specified input file, and save the directory path to
    465  1.1    jruoho  *              the file so that include files can be opened in
    466  1.1    jruoho  *              the same directory.
    467  1.1    jruoho  *
    468  1.1    jruoho  ******************************************************************************/
    469  1.1    jruoho 
    470  1.1    jruoho ACPI_STATUS
    471  1.1    jruoho FlOpenInputFile (
    472  1.1    jruoho     char                    *InputFilename)
    473  1.1    jruoho {
    474  1.1    jruoho 
    475  1.1    jruoho     /* Open the input ASL file, text mode */
    476  1.1    jruoho 
    477  1.2  christos     FlOpenFile (ASL_FILE_INPUT, InputFilename, "rt");
    478  1.1    jruoho     AslCompilerin = Gbl_Files[ASL_FILE_INPUT].Handle;
    479  1.1    jruoho 
    480  1.1    jruoho     return (AE_OK);
    481  1.1    jruoho }
    482  1.1    jruoho 
    483  1.1    jruoho 
    484  1.1    jruoho /*******************************************************************************
    485  1.1    jruoho  *
    486  1.1    jruoho  * FUNCTION:    FlOpenAmlOutputFile
    487  1.1    jruoho  *
    488  1.1    jruoho  * PARAMETERS:  FilenamePrefix       - The user-specified ASL source file
    489  1.1    jruoho  *
    490  1.1    jruoho  * RETURN:      Status
    491  1.1    jruoho  *
    492  1.2  christos  * DESCRIPTION: Create the output filename (*.AML) and open the file. The file
    493  1.1    jruoho  *              is created in the same directory as the parent input file.
    494  1.1    jruoho  *
    495  1.1    jruoho  ******************************************************************************/
    496  1.1    jruoho 
    497  1.1    jruoho ACPI_STATUS
    498  1.1    jruoho FlOpenAmlOutputFile (
    499  1.1    jruoho     char                    *FilenamePrefix)
    500  1.1    jruoho {
    501  1.1    jruoho     char                    *Filename;
    502  1.1    jruoho 
    503  1.1    jruoho 
    504  1.1    jruoho     /* Output filename usually comes from the ASL itself */
    505  1.1    jruoho 
    506  1.1    jruoho     Filename = Gbl_Files[ASL_FILE_AML_OUTPUT].Filename;
    507  1.1    jruoho     if (!Filename)
    508  1.1    jruoho     {
    509  1.1    jruoho         /* Create the output AML filename */
    510  1.1    jruoho 
    511  1.1    jruoho         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_AML_CODE);
    512  1.1    jruoho         if (!Filename)
    513  1.1    jruoho         {
    514  1.1    jruoho             AslCommonError (ASL_ERROR, ASL_MSG_OUTPUT_FILENAME,
    515  1.1    jruoho                 0, 0, 0, 0, NULL, NULL);
    516  1.1    jruoho             return (AE_ERROR);
    517  1.1    jruoho         }
    518  1.4  christos 
    519  1.4  christos         Gbl_Files[ASL_FILE_AML_OUTPUT].Filename = Filename;
    520  1.1    jruoho     }
    521  1.1    jruoho 
    522  1.1    jruoho     /* Open the output AML file in binary mode */
    523  1.1    jruoho 
    524  1.1    jruoho     FlOpenFile (ASL_FILE_AML_OUTPUT, Filename, "w+b");
    525  1.1    jruoho     return (AE_OK);
    526  1.1    jruoho }
    527  1.1    jruoho 
    528  1.1    jruoho 
    529  1.1    jruoho /*******************************************************************************
    530  1.1    jruoho  *
    531  1.1    jruoho  * FUNCTION:    FlOpenMiscOutputFiles
    532  1.1    jruoho  *
    533  1.1    jruoho  * PARAMETERS:  FilenamePrefix       - The user-specified ASL source file
    534  1.1    jruoho  *
    535  1.1    jruoho  * RETURN:      Status
    536  1.1    jruoho  *
    537  1.1    jruoho  * DESCRIPTION: Create and open the various output files needed, depending on
    538  1.1    jruoho  *              the command line options
    539  1.1    jruoho  *
    540  1.1    jruoho  ******************************************************************************/
    541  1.1    jruoho 
    542  1.1    jruoho ACPI_STATUS
    543  1.1    jruoho FlOpenMiscOutputFiles (
    544  1.1    jruoho     char                    *FilenamePrefix)
    545  1.1    jruoho {
    546  1.1    jruoho     char                    *Filename;
    547  1.1    jruoho 
    548  1.1    jruoho 
    549  1.5  christos      /* Create/Open a map file if requested */
    550  1.5  christos 
    551  1.5  christos     if (Gbl_MapfileFlag)
    552  1.5  christos     {
    553  1.5  christos         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_MAP);
    554  1.5  christos         if (!Filename)
    555  1.5  christos         {
    556  1.5  christos             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
    557  1.5  christos                 0, 0, 0, 0, NULL, NULL);
    558  1.5  christos             return (AE_ERROR);
    559  1.5  christos         }
    560  1.5  christos 
    561  1.5  christos         /* Open the hex file, text mode (closed at compiler exit) */
    562  1.5  christos 
    563  1.5  christos         FlOpenFile (ASL_FILE_MAP_OUTPUT, Filename, "w+t");
    564  1.5  christos 
    565  1.5  christos         AslCompilerSignon (ASL_FILE_MAP_OUTPUT);
    566  1.5  christos         AslCompilerFileHeader (ASL_FILE_MAP_OUTPUT);
    567  1.5  christos     }
    568  1.5  christos 
    569  1.2  christos     /* All done for disassembler */
    570  1.2  christos 
    571  1.2  christos     if (Gbl_FileType == ASL_INPUT_TYPE_ACPI_TABLE)
    572  1.2  christos     {
    573  1.2  christos         return (AE_OK);
    574  1.2  christos     }
    575  1.2  christos 
    576  1.2  christos     /* Create/Open a hex output file if asked */
    577  1.1    jruoho 
    578  1.2  christos     if (Gbl_HexOutputFlag)
    579  1.1    jruoho     {
    580  1.2  christos         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_HEX_DUMP);
    581  1.2  christos         if (!Filename)
    582  1.2  christos         {
    583  1.2  christos             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
    584  1.2  christos                 0, 0, 0, 0, NULL, NULL);
    585  1.2  christos             return (AE_ERROR);
    586  1.2  christos         }
    587  1.2  christos 
    588  1.2  christos         /* Open the hex file, text mode */
    589  1.2  christos 
    590  1.2  christos         FlOpenFile (ASL_FILE_HEX_OUTPUT, Filename, "w+t");
    591  1.2  christos 
    592  1.2  christos         AslCompilerSignon (ASL_FILE_HEX_OUTPUT);
    593  1.2  christos         AslCompilerFileHeader (ASL_FILE_HEX_OUTPUT);
    594  1.1    jruoho     }
    595  1.1    jruoho 
    596  1.2  christos     /* Create/Open a debug output file if asked */
    597  1.2  christos 
    598  1.2  christos     if (Gbl_DebugFlag)
    599  1.2  christos     {
    600  1.2  christos         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_DEBUG);
    601  1.2  christos         if (!Filename)
    602  1.2  christos         {
    603  1.2  christos             AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME,
    604  1.2  christos                 0, 0, 0, 0, NULL, NULL);
    605  1.2  christos             return (AE_ERROR);
    606  1.2  christos         }
    607  1.2  christos 
    608  1.2  christos         /* Open the debug file as STDERR, text mode */
    609  1.2  christos 
    610  1.2  christos         Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Filename = Filename;
    611  1.2  christos         Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle =
    612  1.2  christos             freopen (Filename, "w+t", stderr);
    613  1.2  christos 
    614  1.2  christos         if (!Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle)
    615  1.2  christos         {
    616  1.4  christos             /*
    617  1.5  christos              * A problem with freopen is that on error, we no longer
    618  1.5  christos              * have stderr and cannot emit normal error messages.
    619  1.5  christos              * Emit error to stdout, close files, and exit.
    620  1.4  christos              */
    621  1.5  christos             fprintf (stdout,
    622  1.5  christos                 "\nCould not open debug output file: %s\n\n", Filename);
    623  1.5  christos 
    624  1.5  christos             CmCleanupAndExit ();
    625  1.5  christos             exit (1);
    626  1.2  christos         }
    627  1.2  christos 
    628  1.2  christos         AslCompilerSignon (ASL_FILE_DEBUG_OUTPUT);
    629  1.2  christos         AslCompilerFileHeader (ASL_FILE_DEBUG_OUTPUT);
    630  1.2  christos     }
    631  1.1    jruoho 
    632  1.1    jruoho     /* Create/Open a listing output file if asked */
    633  1.1    jruoho 
    634  1.1    jruoho     if (Gbl_ListingFlag)
    635  1.1    jruoho     {
    636  1.1    jruoho         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_LISTING);
    637  1.1    jruoho         if (!Filename)
    638  1.1    jruoho         {
    639  1.1    jruoho             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
    640  1.1    jruoho                 0, 0, 0, 0, NULL, NULL);
    641  1.1    jruoho             return (AE_ERROR);
    642  1.1    jruoho         }
    643  1.1    jruoho 
    644  1.1    jruoho         /* Open the listing file, text mode */
    645  1.1    jruoho 
    646  1.2  christos         FlOpenFile (ASL_FILE_LISTING_OUTPUT, Filename, "w+t");
    647  1.1    jruoho 
    648  1.1    jruoho         AslCompilerSignon (ASL_FILE_LISTING_OUTPUT);
    649  1.1    jruoho         AslCompilerFileHeader (ASL_FILE_LISTING_OUTPUT);
    650  1.1    jruoho     }
    651  1.1    jruoho 
    652  1.5  christos     /* Create the preprocessor output temp file if preprocessor enabled */
    653  1.2  christos 
    654  1.2  christos     if (Gbl_PreprocessFlag)
    655  1.2  christos     {
    656  1.2  christos         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_PREPROCESSOR);
    657  1.2  christos         if (!Filename)
    658  1.2  christos         {
    659  1.2  christos             AslCommonError (ASL_ERROR, ASL_MSG_PREPROCESSOR_FILENAME,
    660  1.2  christos                 0, 0, 0, 0, NULL, NULL);
    661  1.2  christos             return (AE_ERROR);
    662  1.2  christos         }
    663  1.2  christos 
    664  1.2  christos         FlOpenFile (ASL_FILE_PREPROCESSOR, Filename, "w+t");
    665  1.2  christos     }
    666  1.2  christos 
    667  1.5  christos     /*
    668  1.5  christos      * Create the "user" preprocessor output file if -li flag set.
    669  1.5  christos      * Note, this file contains no embedded #line directives.
    670  1.5  christos      */
    671  1.5  christos     if (Gbl_PreprocessorOutputFlag)
    672  1.5  christos     {
    673  1.5  christos         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_PREPROC_USER);
    674  1.5  christos         if (!Filename)
    675  1.5  christos         {
    676  1.5  christos             AslCommonError (ASL_ERROR, ASL_MSG_PREPROCESSOR_FILENAME,
    677  1.5  christos                 0, 0, 0, 0, NULL, NULL);
    678  1.5  christos             return (AE_ERROR);
    679  1.5  christos         }
    680  1.5  christos 
    681  1.5  christos         FlOpenFile (ASL_FILE_PREPROCESSOR_USER, Filename, "w+t");
    682  1.5  christos     }
    683  1.5  christos 
    684  1.2  christos     /* All done for data table compiler */
    685  1.2  christos 
    686  1.2  christos     if (Gbl_FileType == ASL_INPUT_TYPE_ASCII_DATA)
    687  1.2  christos     {
    688  1.2  christos         return (AE_OK);
    689  1.2  christos     }
    690  1.2  christos 
    691  1.2  christos     /* Create/Open a combined source output file */
    692  1.2  christos 
    693  1.2  christos     Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_SOURCE);
    694  1.2  christos     if (!Filename)
    695  1.2  christos     {
    696  1.2  christos         AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
    697  1.2  christos             0, 0, 0, 0, NULL, NULL);
    698  1.2  christos         return (AE_ERROR);
    699  1.2  christos     }
    700  1.2  christos 
    701  1.2  christos     /*
    702  1.2  christos      * Open the source output file, binary mode (so that LF does not get
    703  1.2  christos      * expanded to CR/LF on some systems, messing up our seek
    704  1.2  christos      * calculations.)
    705  1.2  christos      */
    706  1.2  christos     FlOpenFile (ASL_FILE_SOURCE_OUTPUT, Filename, "w+b");
    707  1.2  christos 
    708  1.2  christos /*
    709  1.2  christos // TBD: TEMP
    710  1.2  christos //    AslCompilerin = Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle;
    711  1.2  christos */
    712  1.1    jruoho     /* Create/Open a assembly code source output file if asked */
    713  1.1    jruoho 
    714  1.1    jruoho     if (Gbl_AsmOutputFlag)
    715  1.1    jruoho     {
    716  1.1    jruoho         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_SOURCE);
    717  1.1    jruoho         if (!Filename)
    718  1.1    jruoho         {
    719  1.1    jruoho             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
    720  1.1    jruoho                 0, 0, 0, 0, NULL, NULL);
    721  1.1    jruoho             return (AE_ERROR);
    722  1.1    jruoho         }
    723  1.1    jruoho 
    724  1.1    jruoho         /* Open the assembly code source file, text mode */
    725  1.1    jruoho 
    726  1.2  christos         FlOpenFile (ASL_FILE_ASM_SOURCE_OUTPUT, Filename, "w+t");
    727  1.1    jruoho 
    728  1.1    jruoho         AslCompilerSignon (ASL_FILE_ASM_SOURCE_OUTPUT);
    729  1.1    jruoho         AslCompilerFileHeader (ASL_FILE_ASM_SOURCE_OUTPUT);
    730  1.1    jruoho     }
    731  1.1    jruoho 
    732  1.1    jruoho     /* Create/Open a C code source output file if asked */
    733  1.1    jruoho 
    734  1.1    jruoho     if (Gbl_C_OutputFlag)
    735  1.1    jruoho     {
    736  1.1    jruoho         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_SOURCE);
    737  1.1    jruoho         if (!Filename)
    738  1.1    jruoho         {
    739  1.1    jruoho             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
    740  1.1    jruoho                 0, 0, 0, 0, NULL, NULL);
    741  1.1    jruoho             return (AE_ERROR);
    742  1.1    jruoho         }
    743  1.1    jruoho 
    744  1.1    jruoho         /* Open the C code source file, text mode */
    745  1.1    jruoho 
    746  1.2  christos         FlOpenFile (ASL_FILE_C_SOURCE_OUTPUT, Filename, "w+t");
    747  1.1    jruoho 
    748  1.1    jruoho         FlPrintFile (ASL_FILE_C_SOURCE_OUTPUT, "/*\n");
    749  1.1    jruoho         AslCompilerSignon (ASL_FILE_C_SOURCE_OUTPUT);
    750  1.1    jruoho         AslCompilerFileHeader (ASL_FILE_C_SOURCE_OUTPUT);
    751  1.1    jruoho     }
    752  1.1    jruoho 
    753  1.2  christos     /* Create/Open a C code source output file for the offset table if asked */
    754  1.2  christos 
    755  1.2  christos     if (Gbl_C_OffsetTableFlag)
    756  1.2  christos     {
    757  1.2  christos         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_OFFSET);
    758  1.2  christos         if (!Filename)
    759  1.2  christos         {
    760  1.2  christos             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
    761  1.2  christos                 0, 0, 0, 0, NULL, NULL);
    762  1.2  christos             return (AE_ERROR);
    763  1.2  christos         }
    764  1.2  christos 
    765  1.2  christos         /* Open the C code source file, text mode */
    766  1.2  christos 
    767  1.2  christos         FlOpenFile (ASL_FILE_C_OFFSET_OUTPUT, Filename, "w+t");
    768  1.2  christos 
    769  1.2  christos         FlPrintFile (ASL_FILE_C_OFFSET_OUTPUT, "/*\n");
    770  1.2  christos         AslCompilerSignon (ASL_FILE_C_OFFSET_OUTPUT);
    771  1.2  christos         AslCompilerFileHeader (ASL_FILE_C_OFFSET_OUTPUT);
    772  1.2  christos     }
    773  1.2  christos 
    774  1.1    jruoho     /* Create/Open a assembly include output file if asked */
    775  1.1    jruoho 
    776  1.1    jruoho     if (Gbl_AsmIncludeOutputFlag)
    777  1.1    jruoho     {
    778  1.1    jruoho         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_INCLUDE);
    779  1.1    jruoho         if (!Filename)
    780  1.1    jruoho         {
    781  1.1    jruoho             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
    782  1.1    jruoho                 0, 0, 0, 0, NULL, NULL);
    783  1.1    jruoho             return (AE_ERROR);
    784  1.1    jruoho         }
    785  1.1    jruoho 
    786  1.1    jruoho         /* Open the assembly include file, text mode */
    787  1.1    jruoho 
    788  1.2  christos         FlOpenFile (ASL_FILE_ASM_INCLUDE_OUTPUT, Filename, "w+t");
    789  1.1    jruoho 
    790  1.1    jruoho         AslCompilerSignon (ASL_FILE_ASM_INCLUDE_OUTPUT);
    791  1.1    jruoho         AslCompilerFileHeader (ASL_FILE_ASM_INCLUDE_OUTPUT);
    792  1.1    jruoho     }
    793  1.1    jruoho 
    794  1.1    jruoho     /* Create/Open a C include output file if asked */
    795  1.1    jruoho 
    796  1.1    jruoho     if (Gbl_C_IncludeOutputFlag)
    797  1.1    jruoho     {
    798  1.1    jruoho         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_INCLUDE);
    799  1.1    jruoho         if (!Filename)
    800  1.1    jruoho         {
    801  1.1    jruoho             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
    802  1.1    jruoho                 0, 0, 0, 0, NULL, NULL);
    803  1.1    jruoho             return (AE_ERROR);
    804  1.1    jruoho         }
    805  1.1    jruoho 
    806  1.1    jruoho         /* Open the C include file, text mode */
    807  1.1    jruoho 
    808  1.2  christos         FlOpenFile (ASL_FILE_C_INCLUDE_OUTPUT, Filename, "w+t");
    809  1.1    jruoho 
    810  1.1    jruoho         FlPrintFile (ASL_FILE_C_INCLUDE_OUTPUT, "/*\n");
    811  1.1    jruoho         AslCompilerSignon (ASL_FILE_C_INCLUDE_OUTPUT);
    812  1.1    jruoho         AslCompilerFileHeader (ASL_FILE_C_INCLUDE_OUTPUT);
    813  1.1    jruoho     }
    814  1.1    jruoho 
    815  1.1    jruoho     /* Create a namespace output file if asked */
    816  1.1    jruoho 
    817  1.1    jruoho     if (Gbl_NsOutputFlag)
    818  1.1    jruoho     {
    819  1.1    jruoho         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_NAMESPACE);
    820  1.1    jruoho         if (!Filename)
    821  1.1    jruoho         {
    822  1.1    jruoho             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
    823  1.1    jruoho                 0, 0, 0, 0, NULL, NULL);
    824  1.1    jruoho             return (AE_ERROR);
    825  1.1    jruoho         }
    826  1.1    jruoho 
    827  1.1    jruoho         /* Open the namespace file, text mode */
    828  1.1    jruoho 
    829  1.2  christos         FlOpenFile (ASL_FILE_NAMESPACE_OUTPUT, Filename, "w+t");
    830  1.1    jruoho 
    831  1.1    jruoho         AslCompilerSignon (ASL_FILE_NAMESPACE_OUTPUT);
    832  1.1    jruoho         AslCompilerFileHeader (ASL_FILE_NAMESPACE_OUTPUT);
    833  1.1    jruoho     }
    834  1.1    jruoho 
    835  1.1    jruoho     return (AE_OK);
    836  1.1    jruoho }
    837  1.1    jruoho 
    838  1.1    jruoho 
    839  1.1    jruoho #ifdef ACPI_OBSOLETE_FUNCTIONS
    840  1.1    jruoho /*******************************************************************************
    841  1.1    jruoho  *
    842  1.1    jruoho  * FUNCTION:    FlParseInputPathname
    843  1.1    jruoho  *
    844  1.1    jruoho  * PARAMETERS:  InputFilename       - The user-specified ASL source file to be
    845  1.1    jruoho  *                                    compiled
    846  1.1    jruoho  *
    847  1.1    jruoho  * RETURN:      Status
    848  1.1    jruoho  *
    849  1.1    jruoho  * DESCRIPTION: Split the input path into a directory and filename part
    850  1.1    jruoho  *              1) Directory part used to open include files
    851  1.1    jruoho  *              2) Filename part used to generate output filenames
    852  1.1    jruoho  *
    853  1.1    jruoho  ******************************************************************************/
    854  1.1    jruoho 
    855  1.1    jruoho ACPI_STATUS
    856  1.1    jruoho FlParseInputPathname (
    857  1.1    jruoho     char                    *InputFilename)
    858  1.1    jruoho {
    859  1.1    jruoho     char                    *Substring;
    860  1.1    jruoho 
    861  1.1    jruoho 
    862  1.1    jruoho     if (!InputFilename)
    863  1.1    jruoho     {
    864  1.1    jruoho         return (AE_OK);
    865  1.1    jruoho     }
    866  1.1    jruoho 
    867  1.1    jruoho     /* Get the path to the input filename's directory */
    868  1.1    jruoho 
    869  1.1    jruoho     Gbl_DirectoryPath = strdup (InputFilename);
    870  1.1    jruoho     if (!Gbl_DirectoryPath)
    871  1.1    jruoho     {
    872  1.1    jruoho         return (AE_NO_MEMORY);
    873  1.1    jruoho     }
    874  1.1    jruoho 
    875  1.1    jruoho     Substring = strrchr (Gbl_DirectoryPath, '\\');
    876  1.1    jruoho     if (!Substring)
    877  1.1    jruoho     {
    878  1.1    jruoho         Substring = strrchr (Gbl_DirectoryPath, '/');
    879  1.1    jruoho         if (!Substring)
    880  1.1    jruoho         {
    881  1.1    jruoho             Substring = strrchr (Gbl_DirectoryPath, ':');
    882  1.1    jruoho         }
    883  1.1    jruoho     }
    884  1.1    jruoho 
    885  1.1    jruoho     if (!Substring)
    886  1.1    jruoho     {
    887  1.1    jruoho         Gbl_DirectoryPath[0] = 0;
    888  1.1    jruoho         if (Gbl_UseDefaultAmlFilename)
    889  1.1    jruoho         {
    890  1.1    jruoho             Gbl_OutputFilenamePrefix = strdup (InputFilename);
    891  1.1    jruoho         }
    892  1.1    jruoho     }
    893  1.1    jruoho     else
    894  1.1    jruoho     {
    895  1.1    jruoho         if (Gbl_UseDefaultAmlFilename)
    896  1.1    jruoho         {
    897  1.1    jruoho             Gbl_OutputFilenamePrefix = strdup (Substring + 1);
    898  1.1    jruoho         }
    899  1.1    jruoho         *(Substring+1) = 0;
    900  1.1    jruoho     }
    901  1.1    jruoho 
    902  1.2  christos     UtConvertBackslashes (Gbl_OutputFilenamePrefix);
    903  1.1    jruoho     return (AE_OK);
    904  1.1    jruoho }
    905  1.1    jruoho #endif
    906