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