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