aslfiles.c revision 306536
1/******************************************************************************
2 *
3 * Module Name: aslfiles - File support functions
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2016, 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#include <contrib/dev/acpica/compiler/dtcompiler.h>
47
48#define _COMPONENT          ACPI_COMPILER
49        ACPI_MODULE_NAME    ("aslfiles")
50
51/* Local prototypes */
52
53static FILE *
54FlOpenIncludeWithPrefix (
55    char                    *PrefixDir,
56    ACPI_PARSE_OBJECT       *Op,
57    char                    *Filename);
58
59#ifdef ACPI_OBSOLETE_FUNCTIONS
60ACPI_STATUS
61FlParseInputPathname (
62    char                    *InputFilename);
63#endif
64
65
66/*******************************************************************************
67 *
68 * FUNCTION:    FlSetLineNumber
69 *
70 * PARAMETERS:  Op        - Parse node for the LINE asl statement
71 *
72 * RETURN:      None.
73 *
74 * DESCRIPTION: Set the current line number
75 *
76 ******************************************************************************/
77
78void
79FlSetLineNumber (
80    UINT32                  LineNumber)
81{
82
83    DbgPrint (ASL_PARSE_OUTPUT, "\n#line: New line number %u (old %u)\n",
84         LineNumber, Gbl_LogicalLineNumber);
85
86    Gbl_CurrentLineNumber = 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 (
265        strlen (CommonPath) + strlen (FilePathname) + 2);
266    if (LastElement && *CommonPath)
267    {
268        strcpy (Pathname, CommonPath);
269        strcat (Pathname, "/");
270    }
271    strcat (Pathname, FilePathname);
272
273    /* Convert all backslashes to normal slashes */
274
275ConvertBackslashes:
276    UtConvertBackslashes (Pathname);
277
278    DbgPrint (ASL_PARSE_OUTPUT, "Include: Merged Pathname - \"%s\"\n",
279         Pathname);
280    return (Pathname);
281}
282
283
284/*******************************************************************************
285 *
286 * FUNCTION:    FlOpenIncludeWithPrefix
287 *
288 * PARAMETERS:  PrefixDir       - Prefix directory pathname. Can be a zero
289 *                                length string.
290 *              Filename        - The include filename from the source ASL.
291 *
292 * RETURN:      Valid file descriptor if successful. Null otherwise.
293 *
294 * DESCRIPTION: Open an include file and push it on the input file stack.
295 *
296 ******************************************************************************/
297
298static FILE *
299FlOpenIncludeWithPrefix (
300    char                    *PrefixDir,
301    ACPI_PARSE_OBJECT       *Op,
302    char                    *Filename)
303{
304    FILE                    *IncludeFile;
305    char                    *Pathname;
306    UINT32                  OriginalLineNumber;
307
308
309    /* Build the full pathname to the file */
310
311    Pathname = FlMergePathnames (PrefixDir, Filename);
312
313    DbgPrint (ASL_PARSE_OUTPUT, "Include: Opening file - \"%s\"\n\n",
314        Pathname);
315
316    /* Attempt to open the file, push if successful */
317
318    IncludeFile = fopen (Pathname, "r");
319    if (!IncludeFile)
320    {
321        fprintf (stderr, "Could not open include file %s\n", Pathname);
322        ACPI_FREE (Pathname);
323        return (NULL);
324    }
325
326    /*
327     * Check the entire include file for any # preprocessor directives.
328     * This is because there may be some confusion between the #include
329     * preprocessor directive and the ASL Include statement. A file included
330     * by the ASL include cannot contain preprocessor directives because
331     * the preprocessor has already run by the time the ASL include is
332     * recognized (by the compiler, not the preprocessor.)
333     *
334     * Note: DtGetNextLine strips/ignores comments.
335     * Save current line number since DtGetNextLine modifies it.
336     */
337    Gbl_CurrentLineNumber--;
338    OriginalLineNumber = Gbl_CurrentLineNumber;
339
340    while (DtGetNextLine (IncludeFile, DT_ALLOW_MULTILINE_QUOTES) != ASL_EOF)
341    {
342        if (Gbl_CurrentLineBuffer[0] == '#')
343        {
344            AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE,
345                Op, "use #include instead");
346        }
347    }
348
349    Gbl_CurrentLineNumber = OriginalLineNumber;
350
351    /* Must seek back to the start of the file */
352
353    fseek (IncludeFile, 0, SEEK_SET);
354
355    /* Push the include file on the open input file stack */
356
357    AslPushInputFileStack (IncludeFile, Pathname);
358    return (IncludeFile);
359}
360
361
362/*******************************************************************************
363 *
364 * FUNCTION:    FlOpenIncludeFile
365 *
366 * PARAMETERS:  Op        - Parse node for the INCLUDE ASL statement
367 *
368 * RETURN:      None.
369 *
370 * DESCRIPTION: Open an include file and push it on the input file stack.
371 *
372 ******************************************************************************/
373
374void
375FlOpenIncludeFile (
376    ACPI_PARSE_OBJECT       *Op)
377{
378    FILE                    *IncludeFile;
379    ASL_INCLUDE_DIR         *NextDir;
380
381
382    /* Op must be valid */
383
384    if (!Op)
385    {
386        AslCommonError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN,
387            Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
388            Gbl_InputByteCount, Gbl_CurrentColumn,
389            Gbl_Files[ASL_FILE_INPUT].Filename, " - Null parse node");
390
391        return;
392    }
393
394    /*
395     * Flush out the "include ()" statement on this line, start
396     * the actual include file on the next line
397     */
398    AslResetCurrentLineBuffer ();
399    FlPrintFile (ASL_FILE_SOURCE_OUTPUT, "\n");
400    Gbl_CurrentLineOffset++;
401
402
403    /* Attempt to open the include file */
404
405    /* If the file specifies an absolute path, just open it */
406
407    if ((Op->Asl.Value.String[0] == '/')  ||
408        (Op->Asl.Value.String[0] == '\\') ||
409        (Op->Asl.Value.String[1] == ':'))
410    {
411        IncludeFile = FlOpenIncludeWithPrefix ("", Op, Op->Asl.Value.String);
412        if (!IncludeFile)
413        {
414            goto ErrorExit;
415        }
416        return;
417    }
418
419    /*
420     * The include filename is not an absolute path.
421     *
422     * First, search for the file within the "local" directory -- meaning
423     * the same directory that contains the source file.
424     *
425     * Construct the file pathname from the global directory name.
426     */
427    IncludeFile = FlOpenIncludeWithPrefix (
428        Gbl_DirectoryPath, Op, Op->Asl.Value.String);
429    if (IncludeFile)
430    {
431        return;
432    }
433
434    /*
435     * Second, search for the file within the (possibly multiple) directories
436     * specified by the -I option on the command line.
437     */
438    NextDir = Gbl_IncludeDirList;
439    while (NextDir)
440    {
441        IncludeFile = FlOpenIncludeWithPrefix (
442            NextDir->Dir, Op, Op->Asl.Value.String);
443        if (IncludeFile)
444        {
445            return;
446        }
447
448        NextDir = NextDir->Next;
449    }
450
451    /* We could not open the include file after trying very hard */
452
453ErrorExit:
454    sprintf (MsgBuffer, "%s, %s", Op->Asl.Value.String, strerror (errno));
455    AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, Op, MsgBuffer);
456}
457
458
459/*******************************************************************************
460 *
461 * FUNCTION:    FlOpenInputFile
462 *
463 * PARAMETERS:  InputFilename       - The user-specified ASL source file to be
464 *                                    compiled
465 *
466 * RETURN:      Status
467 *
468 * DESCRIPTION: Open the specified input file, and save the directory path to
469 *              the file so that include files can be opened in
470 *              the same directory.
471 *
472 ******************************************************************************/
473
474ACPI_STATUS
475FlOpenInputFile (
476    char                    *InputFilename)
477{
478
479    /* Open the input ASL file, text mode */
480
481    FlOpenFile (ASL_FILE_INPUT, InputFilename, "rt");
482    AslCompilerin = Gbl_Files[ASL_FILE_INPUT].Handle;
483
484    return (AE_OK);
485}
486
487
488/*******************************************************************************
489 *
490 * FUNCTION:    FlOpenAmlOutputFile
491 *
492 * PARAMETERS:  FilenamePrefix       - The user-specified ASL source file
493 *
494 * RETURN:      Status
495 *
496 * DESCRIPTION: Create the output filename (*.AML) and open the file. The file
497 *              is created in the same directory as the parent input file.
498 *
499 ******************************************************************************/
500
501ACPI_STATUS
502FlOpenAmlOutputFile (
503    char                    *FilenamePrefix)
504{
505    char                    *Filename;
506
507
508    /* Output filename usually comes from the ASL itself */
509
510    Filename = Gbl_Files[ASL_FILE_AML_OUTPUT].Filename;
511    if (!Filename)
512    {
513        /* Create the output AML filename */
514
515        Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_AML_CODE);
516        if (!Filename)
517        {
518            AslCommonError (ASL_ERROR, ASL_MSG_OUTPUT_FILENAME,
519                0, 0, 0, 0, NULL, NULL);
520            return (AE_ERROR);
521        }
522
523        Gbl_Files[ASL_FILE_AML_OUTPUT].Filename = Filename;
524    }
525
526    /* Open the output AML file in binary mode */
527
528    FlOpenFile (ASL_FILE_AML_OUTPUT, Filename, "w+b");
529    return (AE_OK);
530}
531
532
533/*******************************************************************************
534 *
535 * FUNCTION:    FlOpenMiscOutputFiles
536 *
537 * PARAMETERS:  FilenamePrefix       - The user-specified ASL source file
538 *
539 * RETURN:      Status
540 *
541 * DESCRIPTION: Create and open the various output files needed, depending on
542 *              the command line options
543 *
544 ******************************************************************************/
545
546ACPI_STATUS
547FlOpenMiscOutputFiles (
548    char                    *FilenamePrefix)
549{
550    char                    *Filename;
551
552
553     /* Create/Open a map file if requested */
554
555    if (Gbl_MapfileFlag)
556    {
557        Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_MAP);
558        if (!Filename)
559        {
560            AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
561                0, 0, 0, 0, NULL, NULL);
562            return (AE_ERROR);
563        }
564
565        /* Open the hex file, text mode (closed at compiler exit) */
566
567        FlOpenFile (ASL_FILE_MAP_OUTPUT, Filename, "w+t");
568
569        AslCompilerSignon (ASL_FILE_MAP_OUTPUT);
570        AslCompilerFileHeader (ASL_FILE_MAP_OUTPUT);
571    }
572
573    /* All done for disassembler */
574
575    if (Gbl_FileType == ASL_INPUT_TYPE_BINARY_ACPI_TABLE)
576    {
577        return (AE_OK);
578    }
579
580    /* Create/Open a hex output file if asked */
581
582    if (Gbl_HexOutputFlag)
583    {
584        Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_HEX_DUMP);
585        if (!Filename)
586        {
587            AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
588                0, 0, 0, 0, NULL, NULL);
589            return (AE_ERROR);
590        }
591
592        /* Open the hex file, text mode */
593
594        FlOpenFile (ASL_FILE_HEX_OUTPUT, Filename, "w+t");
595
596        AslCompilerSignon (ASL_FILE_HEX_OUTPUT);
597        AslCompilerFileHeader (ASL_FILE_HEX_OUTPUT);
598    }
599
600    /* Create/Open a debug output file if asked */
601
602    if (Gbl_DebugFlag)
603    {
604        Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_DEBUG);
605        if (!Filename)
606        {
607            AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME,
608                0, 0, 0, 0, NULL, NULL);
609            return (AE_ERROR);
610        }
611
612        /* Open the debug file as STDERR, text mode */
613
614        Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Filename = Filename;
615        Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle =
616            freopen (Filename, "w+t", stderr);
617
618        if (!Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle)
619        {
620            /*
621             * A problem with freopen is that on error, we no longer
622             * have stderr and cannot emit normal error messages.
623             * Emit error to stdout, close files, and exit.
624             */
625            fprintf (stdout,
626                "\nCould not open debug output file: %s\n\n", Filename);
627
628            CmCleanupAndExit ();
629            exit (1);
630        }
631
632        AslCompilerSignon (ASL_FILE_DEBUG_OUTPUT);
633        AslCompilerFileHeader (ASL_FILE_DEBUG_OUTPUT);
634    }
635
636    /* Create/Open a cross-reference output file if asked */
637
638    if (Gbl_CrossReferenceOutput)
639    {
640        Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_XREF);
641        if (!Filename)
642        {
643            AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME,
644                0, 0, 0, 0, NULL, NULL);
645            return (AE_ERROR);
646        }
647
648        FlOpenFile (ASL_FILE_XREF_OUTPUT, Filename, "w+t");
649
650        AslCompilerSignon (ASL_FILE_XREF_OUTPUT);
651        AslCompilerFileHeader (ASL_FILE_XREF_OUTPUT);
652    }
653
654    /* Create/Open a listing output file if asked */
655
656    if (Gbl_ListingFlag)
657    {
658        Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_LISTING);
659        if (!Filename)
660        {
661            AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
662                0, 0, 0, 0, NULL, NULL);
663            return (AE_ERROR);
664        }
665
666        /* Open the listing file, text mode */
667
668        FlOpenFile (ASL_FILE_LISTING_OUTPUT, Filename, "w+t");
669
670        AslCompilerSignon (ASL_FILE_LISTING_OUTPUT);
671        AslCompilerFileHeader (ASL_FILE_LISTING_OUTPUT);
672    }
673
674    /* Create the preprocessor output temp file if preprocessor enabled */
675
676    if (Gbl_PreprocessFlag)
677    {
678        Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_PREPROCESSOR);
679        if (!Filename)
680        {
681            AslCommonError (ASL_ERROR, ASL_MSG_PREPROCESSOR_FILENAME,
682                0, 0, 0, 0, NULL, NULL);
683            return (AE_ERROR);
684        }
685
686        FlOpenFile (ASL_FILE_PREPROCESSOR, Filename, "w+t");
687    }
688
689    /*
690     * Create the "user" preprocessor output file if -li flag set.
691     * Note, this file contains no embedded #line directives.
692     */
693    if (Gbl_PreprocessorOutputFlag)
694    {
695        Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_PREPROC_USER);
696        if (!Filename)
697        {
698            AslCommonError (ASL_ERROR, ASL_MSG_PREPROCESSOR_FILENAME,
699                0, 0, 0, 0, NULL, NULL);
700            return (AE_ERROR);
701        }
702
703        FlOpenFile (ASL_FILE_PREPROCESSOR_USER, Filename, "w+t");
704    }
705
706    /* All done for data table compiler */
707
708    if (Gbl_FileType == ASL_INPUT_TYPE_ASCII_DATA)
709    {
710        return (AE_OK);
711    }
712
713    /* Create/Open a combined source output file */
714
715    Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_SOURCE);
716    if (!Filename)
717    {
718        AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
719            0, 0, 0, 0, NULL, NULL);
720        return (AE_ERROR);
721    }
722
723    /*
724     * Open the source output file, binary mode (so that LF does not get
725     * expanded to CR/LF on some systems, messing up our seek
726     * calculations.)
727     */
728    FlOpenFile (ASL_FILE_SOURCE_OUTPUT, Filename, "w+b");
729
730/*
731// TBD: TEMP
732//    AslCompilerin = Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle;
733*/
734    /* Create/Open a assembly code source output file if asked */
735
736    if (Gbl_AsmOutputFlag)
737    {
738        Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_SOURCE);
739        if (!Filename)
740        {
741            AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
742                0, 0, 0, 0, NULL, NULL);
743            return (AE_ERROR);
744        }
745
746        /* Open the assembly code source file, text mode */
747
748        FlOpenFile (ASL_FILE_ASM_SOURCE_OUTPUT, Filename, "w+t");
749
750        AslCompilerSignon (ASL_FILE_ASM_SOURCE_OUTPUT);
751        AslCompilerFileHeader (ASL_FILE_ASM_SOURCE_OUTPUT);
752    }
753
754    /* Create/Open a C code source output file if asked */
755
756    if (Gbl_C_OutputFlag)
757    {
758        Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_SOURCE);
759        if (!Filename)
760        {
761            AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
762                0, 0, 0, 0, NULL, NULL);
763            return (AE_ERROR);
764        }
765
766        /* Open the C code source file, text mode */
767
768        FlOpenFile (ASL_FILE_C_SOURCE_OUTPUT, Filename, "w+t");
769
770        FlPrintFile (ASL_FILE_C_SOURCE_OUTPUT, "/*\n");
771        AslCompilerSignon (ASL_FILE_C_SOURCE_OUTPUT);
772        AslCompilerFileHeader (ASL_FILE_C_SOURCE_OUTPUT);
773    }
774
775    /* Create/Open a C code source output file for the offset table if asked */
776
777    if (Gbl_C_OffsetTableFlag)
778    {
779        Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_OFFSET);
780        if (!Filename)
781        {
782            AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
783                0, 0, 0, 0, NULL, NULL);
784            return (AE_ERROR);
785        }
786
787        /* Open the C code source file, text mode */
788
789        FlOpenFile (ASL_FILE_C_OFFSET_OUTPUT, Filename, "w+t");
790
791        FlPrintFile (ASL_FILE_C_OFFSET_OUTPUT, "/*\n");
792        AslCompilerSignon (ASL_FILE_C_OFFSET_OUTPUT);
793        AslCompilerFileHeader (ASL_FILE_C_OFFSET_OUTPUT);
794    }
795
796    /* Create/Open a assembly include output file if asked */
797
798    if (Gbl_AsmIncludeOutputFlag)
799    {
800        Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_INCLUDE);
801        if (!Filename)
802        {
803            AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
804                0, 0, 0, 0, NULL, NULL);
805            return (AE_ERROR);
806        }
807
808        /* Open the assembly include file, text mode */
809
810        FlOpenFile (ASL_FILE_ASM_INCLUDE_OUTPUT, Filename, "w+t");
811
812        AslCompilerSignon (ASL_FILE_ASM_INCLUDE_OUTPUT);
813        AslCompilerFileHeader (ASL_FILE_ASM_INCLUDE_OUTPUT);
814    }
815
816    /* Create/Open a C include output file if asked */
817
818    if (Gbl_C_IncludeOutputFlag)
819    {
820        Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_INCLUDE);
821        if (!Filename)
822        {
823            AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
824                0, 0, 0, 0, NULL, NULL);
825            return (AE_ERROR);
826        }
827
828        /* Open the C include file, text mode */
829
830        FlOpenFile (ASL_FILE_C_INCLUDE_OUTPUT, Filename, "w+t");
831
832        FlPrintFile (ASL_FILE_C_INCLUDE_OUTPUT, "/*\n");
833        AslCompilerSignon (ASL_FILE_C_INCLUDE_OUTPUT);
834        AslCompilerFileHeader (ASL_FILE_C_INCLUDE_OUTPUT);
835    }
836
837    /* Create a namespace output file if asked */
838
839    if (Gbl_NsOutputFlag)
840    {
841        Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_NAMESPACE);
842        if (!Filename)
843        {
844            AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
845                0, 0, 0, 0, NULL, NULL);
846            return (AE_ERROR);
847        }
848
849        /* Open the namespace file, text mode */
850
851        FlOpenFile (ASL_FILE_NAMESPACE_OUTPUT, Filename, "w+t");
852
853        AslCompilerSignon (ASL_FILE_NAMESPACE_OUTPUT);
854        AslCompilerFileHeader (ASL_FILE_NAMESPACE_OUTPUT);
855    }
856
857    return (AE_OK);
858}
859
860
861#ifdef ACPI_OBSOLETE_FUNCTIONS
862/*******************************************************************************
863 *
864 * FUNCTION:    FlParseInputPathname
865 *
866 * PARAMETERS:  InputFilename       - The user-specified ASL source file to be
867 *                                    compiled
868 *
869 * RETURN:      Status
870 *
871 * DESCRIPTION: Split the input path into a directory and filename part
872 *              1) Directory part used to open include files
873 *              2) Filename part used to generate output filenames
874 *
875 ******************************************************************************/
876
877ACPI_STATUS
878FlParseInputPathname (
879    char                    *InputFilename)
880{
881    char                    *Substring;
882
883
884    if (!InputFilename)
885    {
886        return (AE_OK);
887    }
888
889    /* Get the path to the input filename's directory */
890
891    Gbl_DirectoryPath = strdup (InputFilename);
892    if (!Gbl_DirectoryPath)
893    {
894        return (AE_NO_MEMORY);
895    }
896
897    Substring = strrchr (Gbl_DirectoryPath, '\\');
898    if (!Substring)
899    {
900        Substring = strrchr (Gbl_DirectoryPath, '/');
901        if (!Substring)
902        {
903            Substring = strrchr (Gbl_DirectoryPath, ':');
904        }
905    }
906
907    if (!Substring)
908    {
909        Gbl_DirectoryPath[0] = 0;
910        if (Gbl_UseDefaultAmlFilename)
911        {
912            Gbl_OutputFilenamePrefix = strdup (InputFilename);
913        }
914    }
915    else
916    {
917        if (Gbl_UseDefaultAmlFilename)
918        {
919            Gbl_OutputFilenamePrefix = strdup (Substring + 1);
920        }
921        *(Substring+1) = 0;
922    }
923
924    UtConvertBackslashes (Gbl_OutputFilenamePrefix);
925    return (AE_OK);
926}
927#endif
928