]> CyberLeo.Net >> Repos - FreeBSD/releng/8.0.git/blob - sys/contrib/dev/acpica/compiler/aslfiles.c
Adjust to reflect 8.0-RELEASE.
[FreeBSD/releng/8.0.git] / sys / contrib / dev / acpica / compiler / aslfiles.c
1
2 /******************************************************************************
3  *
4  * Module Name: aslfiles - file I/O suppoert
5  *
6  *****************************************************************************/
7
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
13  * All rights reserved.
14  *
15  * 2. License
16  *
17  * 2.1. This is your license from Intel Corp. under its intellectual property
18  * rights.  You may have additional license terms from the party that provided
19  * you this software, covering your right to use that party's intellectual
20  * property rights.
21  *
22  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23  * copy of the source code appearing in this file ("Covered Code") an
24  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25  * base code distributed originally by Intel ("Original Intel Code") to copy,
26  * make derivatives, distribute, use and display any portion of the Covered
27  * Code in any form, with the right to sublicense such rights; and
28  *
29  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30  * license (with the right to sublicense), under only those claims of Intel
31  * patents that are infringed by the Original Intel Code, to make, use, sell,
32  * offer to sell, and import the Covered Code and derivative works thereof
33  * solely to the minimum extent necessary to exercise the above copyright
34  * license, and in no event shall the patent license extend to any additions
35  * to or modifications of the Original Intel Code.  No other license or right
36  * is granted directly or by implication, estoppel or otherwise;
37  *
38  * The above copyright and patent license is granted only if the following
39  * conditions are met:
40  *
41  * 3. Conditions
42  *
43  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44  * Redistribution of source code of any substantial portion of the Covered
45  * Code or modification with rights to further distribute source must include
46  * the above Copyright Notice, the above License, this list of Conditions,
47  * and the following Disclaimer and Export Compliance provision.  In addition,
48  * Licensee must cause all Covered Code to which Licensee contributes to
49  * contain a file documenting the changes Licensee made to create that Covered
50  * Code and the date of any change.  Licensee must include in that file the
51  * documentation of any changes made by any predecessor Licensee.  Licensee
52  * must include a prominent statement that the modification is derived,
53  * directly or indirectly, from Original Intel Code.
54  *
55  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56  * Redistribution of source code of any substantial portion of the Covered
57  * Code or modification without rights to further distribute source must
58  * include the following Disclaimer and Export Compliance provision in the
59  * documentation and/or other materials provided with distribution.  In
60  * addition, Licensee may not authorize further sublicense of source of any
61  * portion of the Covered Code, and must include terms to the effect that the
62  * license from Licensee to its licensee is limited to the intellectual
63  * property embodied in the software Licensee provides to its licensee, and
64  * not to intellectual property embodied in modifications its licensee may
65  * make.
66  *
67  * 3.3. Redistribution of Executable. Redistribution in executable form of any
68  * substantial portion of the Covered Code or modification must reproduce the
69  * above Copyright Notice, and the following Disclaimer and Export Compliance
70  * provision in the documentation and/or other materials provided with the
71  * distribution.
72  *
73  * 3.4. Intel retains all right, title, and interest in and to the Original
74  * Intel Code.
75  *
76  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77  * Intel shall be used in advertising or otherwise to promote the sale, use or
78  * other dealings in products derived from or relating to the Covered Code
79  * without prior written authorization from Intel.
80  *
81  * 4. Disclaimer and Export Compliance
82  *
83  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89  * PARTICULAR PURPOSE.
90  *
91  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98  * LIMITED REMEDY.
99  *
100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
101  * software or system incorporating such software without first obtaining any
102  * required license or other approval from the U. S. Department of Commerce or
103  * any other agency or department of the United States Government.  In the
104  * event Licensee exports any such software from the United States or
105  * re-exports any such software from a foreign destination, Licensee shall
106  * ensure that the distribution and export/re-export of the software is in
107  * compliance with all laws, regulations, orders, or other restrictions of the
108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109  * any of its subsidiaries will export/re-export any technical data, process,
110  * software, or service, directly or indirectly, to any country for which the
111  * United States government or any agency thereof requires an export license,
112  * other governmental approval, or letter of assurance, without first obtaining
113  * such license, approval or letter.
114  *
115  *****************************************************************************/
116
117 #include <contrib/dev/acpica/compiler/aslcompiler.h>
118 #include <contrib/dev/acpica/include/acapps.h>
119
120 #define _COMPONENT          ACPI_COMPILER
121         ACPI_MODULE_NAME    ("aslfiles")
122
123 /* Local prototypes */
124
125 static void
126 FlOpenFile (
127     UINT32                  FileId,
128     char                    *Filename,
129     char                    *Mode);
130
131 static FILE *
132 FlOpenLocalFile (
133     char                    *LocalName,
134     char                    *Mode);
135
136 #ifdef ACPI_OBSOLETE_FUNCTIONS
137 ACPI_STATUS
138 FlParseInputPathname (
139     char                    *InputFilename);
140 #endif
141
142
143 /*******************************************************************************
144  *
145  * FUNCTION:    AslAbort
146  *
147  * PARAMETERS:  None
148  *
149  * RETURN:      None
150  *
151  * DESCRIPTION: Dump the error log and abort the compiler.  Used for serious
152  *              I/O errors
153  *
154  ******************************************************************************/
155
156 void
157 AslAbort (
158     void)
159 {
160
161     AePrintErrorLog (ASL_FILE_STDOUT);
162     if (Gbl_DebugFlag)
163     {
164         /* Print error summary to the debug file */
165
166         AePrintErrorLog (ASL_FILE_STDERR);
167     }
168
169     exit (1);
170 }
171
172
173 /*******************************************************************************
174  *
175  * FUNCTION:    FlOpenLocalFile
176  *
177  * PARAMETERS:  LocalName           - Single filename (not a pathname)
178  *              Mode                - Open mode for fopen
179  *
180  * RETURN:      File descriptor
181  *
182  * DESCRIPTION: Build a complete pathname for the input filename and open
183  *              the file.
184  *
185  ******************************************************************************/
186
187 static FILE *
188 FlOpenLocalFile (
189     char                    *LocalName,
190     char                    *Mode)
191 {
192
193     StringBuffer[0] = 0;
194
195     /* Check for an absolute pathname */
196
197     if ((LocalName[0] != '/') &&        /* Forward slash */
198         (LocalName[0] != '\\') &&       /* backslash (Win) */
199         (LocalName[1] != ':'))          /* Device name (Win) */
200     {
201         /* The include file path is relative, prepend the directory path */
202
203         strcat (StringBuffer, Gbl_DirectoryPath);
204     }
205     strcat (StringBuffer, LocalName);
206
207     DbgPrint (ASL_PARSE_OUTPUT, "FlOpenLocalFile: %s\n", StringBuffer);
208     return (fopen (StringBuffer, (const char *) Mode));
209 }
210
211
212 /*******************************************************************************
213  *
214  * FUNCTION:    FlFileError
215  *
216  * PARAMETERS:  FileId              - Index into file info array
217  *              ErrorId             - Index into error message array
218  *
219  * RETURN:      None
220  *
221  * DESCRIPTION: Decode errno to an error message and add the entire error
222  *              to the error log.
223  *
224  ******************************************************************************/
225
226 void
227 FlFileError (
228     UINT32                  FileId,
229     UINT8                   ErrorId)
230 {
231
232     sprintf (MsgBuffer, "\"%s\" (%s)", Gbl_Files[FileId].Filename,
233         strerror (errno));
234     AslCommonError (ASL_ERROR, ErrorId, 0, 0, 0, 0, NULL, MsgBuffer);
235 }
236
237
238 /*******************************************************************************
239  *
240  * FUNCTION:    FlOpenFile
241  *
242  * PARAMETERS:  FileId              - Index into file info array
243  *              Filename            - file pathname to open
244  *              Mode                - Open mode for fopen
245  *
246  * RETURN:      None
247  *
248  * DESCRIPTION: Open a file.
249  *              NOTE: Aborts compiler on any error.
250  *
251  ******************************************************************************/
252
253 static void
254 FlOpenFile (
255     UINT32                  FileId,
256     char                    *Filename,
257     char                    *Mode)
258 {
259     FILE                    *File;
260
261
262     File = fopen (Filename, Mode);
263
264     Gbl_Files[FileId].Filename = Filename;
265     Gbl_Files[FileId].Handle   = File;
266
267     if (!File)
268     {
269         FlFileError (FileId, ASL_MSG_OPEN);
270         AslAbort ();
271     }
272 }
273
274
275 /*******************************************************************************
276  *
277  * FUNCTION:    FlReadFile
278  *
279  * PARAMETERS:  FileId              - Index into file info array
280  *              Buffer              - Where to place the data
281  *              Length              - Amount to read
282  *
283  * RETURN:      Status.  AE_ERROR indicates EOF.
284  *
285  * DESCRIPTION: Read data from an open file.
286  *              NOTE: Aborts compiler on any error.
287  *
288  ******************************************************************************/
289
290 ACPI_STATUS
291 FlReadFile (
292     UINT32                  FileId,
293     void                    *Buffer,
294     UINT32                  Length)
295 {
296     UINT32                  Actual;
297
298
299     /* Read and check for error */
300
301     Actual = fread (Buffer, 1, Length, Gbl_Files[FileId].Handle);
302     if (Actual != Length)
303     {
304         if (feof (Gbl_Files[FileId].Handle))
305         {
306             /* End-of-file, just return error */
307
308             return (AE_ERROR);
309         }
310
311         FlFileError (FileId, ASL_MSG_READ);
312         AslAbort ();
313     }
314
315     return (AE_OK);
316 }
317
318
319 /*******************************************************************************
320  *
321  * FUNCTION:    FlWriteFile
322  *
323  * PARAMETERS:  FileId              - Index into file info array
324  *              Buffer              - Data to write
325  *              Length              - Amount of data to write
326  *
327  * RETURN:      None
328  *
329  * DESCRIPTION: Write data to an open file.
330  *              NOTE: Aborts compiler on any error.
331  *
332  ******************************************************************************/
333
334 void
335 FlWriteFile (
336     UINT32                  FileId,
337     void                    *Buffer,
338     UINT32                  Length)
339 {
340     UINT32                  Actual;
341
342
343     /* Write and check for error */
344
345     Actual = fwrite ((char *) Buffer, 1, Length, Gbl_Files[FileId].Handle);
346     if (Actual != Length)
347     {
348         FlFileError (FileId, ASL_MSG_WRITE);
349         AslAbort ();
350     }
351 }
352
353
354 /*******************************************************************************
355  *
356  * FUNCTION:    FlPrintFile
357  *
358  * PARAMETERS:  FileId              - Index into file info array
359  *              Format              - Printf format string
360  *              ...                 - Printf arguments
361  *
362  * RETURN:      None
363  *
364  * DESCRIPTION: Formatted write to an open file.
365  *              NOTE: Aborts compiler on any error.
366  *
367  ******************************************************************************/
368
369 void
370 FlPrintFile (
371     UINT32                  FileId,
372     char                    *Format,
373     ...)
374 {
375     INT32                   Actual;
376     va_list                 Args;
377
378
379     va_start (Args, Format);
380
381     Actual = vfprintf (Gbl_Files[FileId].Handle, Format, Args);
382     va_end (Args);
383
384     if (Actual == -1)
385     {
386         FlFileError (FileId, ASL_MSG_WRITE);
387         AslAbort ();
388     }
389 }
390
391
392 /*******************************************************************************
393  *
394  * FUNCTION:    FlSeekFile
395  *
396  * PARAMETERS:  FileId              - Index into file info array
397  *              Offset              - Absolute byte offset in file
398  *
399  * RETURN:      None
400  *
401  * DESCRIPTION: Seek to absolute offset
402  *              NOTE: Aborts compiler on any error.
403  *
404  ******************************************************************************/
405
406 void
407 FlSeekFile (
408     UINT32                  FileId,
409     long                    Offset)
410 {
411     int                     Error;
412
413
414     Error = fseek (Gbl_Files[FileId].Handle, Offset, SEEK_SET);
415     if (Error)
416     {
417         FlFileError (FileId, ASL_MSG_SEEK);
418         AslAbort ();
419     }
420 }
421
422
423 /*******************************************************************************
424  *
425  * FUNCTION:    FlCloseFile
426  *
427  * PARAMETERS:  FileId              - Index into file info array
428  *
429  * RETURN:      None
430  *
431  * DESCRIPTION: Close an open file.  Aborts compiler on error
432  *
433  ******************************************************************************/
434
435 void
436 FlCloseFile (
437     UINT32                  FileId)
438 {
439     int                     Error;
440
441
442     if (!Gbl_Files[FileId].Handle)
443     {
444         return;
445     }
446
447     Error = fclose (Gbl_Files[FileId].Handle);
448     Gbl_Files[FileId].Handle = NULL;
449
450     if (Error)
451     {
452         FlFileError (FileId, ASL_MSG_CLOSE);
453         AslAbort ();
454     }
455
456     return;
457 }
458
459
460 /*******************************************************************************
461  *
462  * FUNCTION:    FlSetLineNumber
463  *
464  * PARAMETERS:  Op        - Parse node for the LINE asl statement
465  *
466  * RETURN:      None.
467  *
468  * DESCRIPTION: Set the current line number
469  *
470  ******************************************************************************/
471
472 void
473 FlSetLineNumber (
474     ACPI_PARSE_OBJECT       *Op)
475 {
476
477     Gbl_CurrentLineNumber = (UINT32) Op->Asl.Value.Integer;
478     Gbl_LogicalLineNumber = (UINT32) Op->Asl.Value.Integer;
479 }
480
481
482 /*******************************************************************************
483  *
484  * FUNCTION:    FlOpenIncludeFile
485  *
486  * PARAMETERS:  Op        - Parse node for the INCLUDE ASL statement
487  *
488  * RETURN:      None.
489  *
490  * DESCRIPTION: Open an include file and push it on the input file stack.
491  *
492  ******************************************************************************/
493
494 void
495 FlOpenIncludeFile (
496     ACPI_PARSE_OBJECT       *Op)
497 {
498     FILE                    *IncFile;
499
500
501     /* Op must be valid */
502
503     if (!Op)
504     {
505         AslCommonError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN,
506             Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
507             Gbl_InputByteCount, Gbl_CurrentColumn,
508             Gbl_Files[ASL_FILE_INPUT].Filename, " - Null parse node");
509
510         return;
511     }
512
513     /*
514      * Flush out the "include ()" statement on this line, start
515      * the actual include file on the next line
516      */
517     ResetCurrentLineBuffer ();
518     FlPrintFile (ASL_FILE_SOURCE_OUTPUT, "\n");
519     Gbl_CurrentLineOffset++;
520
521     /* Prepend the directory pathname and open the include file */
522
523     DbgPrint (ASL_PARSE_OUTPUT, "\nOpen include file: path %s\n\n",
524         Op->Asl.Value.String);
525     IncFile = FlOpenLocalFile (Op->Asl.Value.String, "r");
526     if (!IncFile)
527     {
528         sprintf (MsgBuffer, "%s (%s)", Op->Asl.Value.String, strerror (errno));
529         AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, Op, MsgBuffer);
530         return;
531     }
532
533     /* Push the include file on the open input file stack */
534
535     AslPushInputFileStack (IncFile, Op->Asl.Value.String);
536 }
537
538
539 /*******************************************************************************
540  *
541  * FUNCTION:    FlOpenInputFile
542  *
543  * PARAMETERS:  InputFilename       - The user-specified ASL source file to be
544  *                                    compiled
545  *
546  * RETURN:      Status
547  *
548  * DESCRIPTION: Open the specified input file, and save the directory path to
549  *              the file so that include files can be opened in
550  *              the same directory.
551  *
552  ******************************************************************************/
553
554 ACPI_STATUS
555 FlOpenInputFile (
556     char                    *InputFilename)
557 {
558
559     /* Open the input ASL file, text mode */
560
561     FlOpenFile (ASL_FILE_INPUT, InputFilename, "r");
562     AslCompilerin = Gbl_Files[ASL_FILE_INPUT].Handle;
563
564     return (AE_OK);
565 }
566
567
568 /*******************************************************************************
569  *
570  * FUNCTION:    FlOpenAmlOutputFile
571  *
572  * PARAMETERS:  FilenamePrefix       - The user-specified ASL source file
573  *
574  * RETURN:      Status
575  *
576  * DESCRIPTION: Create the output filename (*.AML) and open the file.  The file
577  *              is created in the same directory as the parent input file.
578  *
579  ******************************************************************************/
580
581 ACPI_STATUS
582 FlOpenAmlOutputFile (
583     char                    *FilenamePrefix)
584 {
585     char                    *Filename;
586
587
588     /* Output filename usually comes from the ASL itself */
589
590     Filename = Gbl_Files[ASL_FILE_AML_OUTPUT].Filename;
591     if (!Filename)
592     {
593         /* Create the output AML filename */
594
595         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_AML_CODE);
596         if (!Filename)
597         {
598             AslCommonError (ASL_ERROR, ASL_MSG_OUTPUT_FILENAME,
599                 0, 0, 0, 0, NULL, NULL);
600             return (AE_ERROR);
601         }
602     }
603
604     /* Open the output AML file in binary mode */
605
606     FlOpenFile (ASL_FILE_AML_OUTPUT, Filename, "w+b");
607     return (AE_OK);
608 }
609
610
611 /*******************************************************************************
612  *
613  * FUNCTION:    FlOpenMiscOutputFiles
614  *
615  * PARAMETERS:  FilenamePrefix       - The user-specified ASL source file
616  *
617  * RETURN:      Status
618  *
619  * DESCRIPTION: Create and open the various output files needed, depending on
620  *              the command line options
621  *
622  ******************************************************************************/
623
624 ACPI_STATUS
625 FlOpenMiscOutputFiles (
626     char                    *FilenamePrefix)
627 {
628     char                    *Filename;
629
630
631     /* Create/Open a combined source output file */
632
633     Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_SOURCE);
634     if (!Filename)
635     {
636         AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
637             0, 0, 0, 0, NULL, NULL);
638         return (AE_ERROR);
639     }
640
641     /*
642      * Open the source output file, binary mode (so that LF does not get
643      * expanded to CR/LF on some systems, messing up our seek
644      * calculations.)
645      */
646     FlOpenFile (ASL_FILE_SOURCE_OUTPUT, Filename, "w+b");
647
648     /* Create/Open a listing output file if asked */
649
650     if (Gbl_ListingFlag)
651     {
652         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_LISTING);
653         if (!Filename)
654         {
655             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
656                 0, 0, 0, 0, NULL, NULL);
657             return (AE_ERROR);
658         }
659
660         /* Open the listing file, text mode */
661
662         FlOpenFile (ASL_FILE_LISTING_OUTPUT, Filename, "w+");
663
664         AslCompilerSignon (ASL_FILE_LISTING_OUTPUT);
665         AslCompilerFileHeader (ASL_FILE_LISTING_OUTPUT);
666     }
667
668     /* Create/Open a assembly code source output file if asked */
669
670     if (Gbl_AsmOutputFlag)
671     {
672         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_SOURCE);
673         if (!Filename)
674         {
675             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
676                 0, 0, 0, 0, NULL, NULL);
677             return (AE_ERROR);
678         }
679
680         /* Open the assembly code source file, text mode */
681
682         FlOpenFile (ASL_FILE_ASM_SOURCE_OUTPUT, Filename, "w+");
683
684         AslCompilerSignon (ASL_FILE_ASM_SOURCE_OUTPUT);
685         AslCompilerFileHeader (ASL_FILE_ASM_SOURCE_OUTPUT);
686     }
687
688     /* Create/Open a C code source output file if asked */
689
690     if (Gbl_C_OutputFlag)
691     {
692         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_SOURCE);
693         if (!Filename)
694         {
695             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
696                 0, 0, 0, 0, NULL, NULL);
697             return (AE_ERROR);
698         }
699
700         /* Open the C code source file, text mode */
701
702         FlOpenFile (ASL_FILE_C_SOURCE_OUTPUT, Filename, "w+");
703
704         FlPrintFile (ASL_FILE_C_SOURCE_OUTPUT, "/*\n");
705         AslCompilerSignon (ASL_FILE_C_SOURCE_OUTPUT);
706         AslCompilerFileHeader (ASL_FILE_C_SOURCE_OUTPUT);
707     }
708
709     /* Create/Open a assembly include output file if asked */
710
711     if (Gbl_AsmIncludeOutputFlag)
712     {
713         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_INCLUDE);
714         if (!Filename)
715         {
716             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
717                 0, 0, 0, 0, NULL, NULL);
718             return (AE_ERROR);
719         }
720
721         /* Open the assembly include file, text mode */
722
723         FlOpenFile (ASL_FILE_ASM_INCLUDE_OUTPUT, Filename, "w+");
724
725         AslCompilerSignon (ASL_FILE_ASM_INCLUDE_OUTPUT);
726         AslCompilerFileHeader (ASL_FILE_ASM_INCLUDE_OUTPUT);
727     }
728
729     /* Create/Open a C include output file if asked */
730
731     if (Gbl_C_IncludeOutputFlag)
732     {
733         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_INCLUDE);
734         if (!Filename)
735         {
736             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
737                 0, 0, 0, 0, NULL, NULL);
738             return (AE_ERROR);
739         }
740
741         /* Open the C include file, text mode */
742
743         FlOpenFile (ASL_FILE_C_INCLUDE_OUTPUT, Filename, "w+");
744
745         FlPrintFile (ASL_FILE_C_INCLUDE_OUTPUT, "/*\n");
746         AslCompilerSignon (ASL_FILE_C_INCLUDE_OUTPUT);
747         AslCompilerFileHeader (ASL_FILE_C_INCLUDE_OUTPUT);
748     }
749
750     /* Create/Open a hex output file if asked */
751
752     if (Gbl_HexOutputFlag)
753     {
754         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_HEX_DUMP);
755         if (!Filename)
756         {
757             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
758                 0, 0, 0, 0, NULL, NULL);
759             return (AE_ERROR);
760         }
761
762         /* Open the hex file, text mode */
763
764         FlOpenFile (ASL_FILE_HEX_OUTPUT, Filename, "w+");
765
766         AslCompilerSignon (ASL_FILE_HEX_OUTPUT);
767         AslCompilerFileHeader (ASL_FILE_HEX_OUTPUT);
768     }
769
770     /* Create a namespace output file if asked */
771
772     if (Gbl_NsOutputFlag)
773     {
774         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_NAMESPACE);
775         if (!Filename)
776         {
777             AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
778                 0, 0, 0, 0, NULL, NULL);
779             return (AE_ERROR);
780         }
781
782         /* Open the namespace file, text mode */
783
784         FlOpenFile (ASL_FILE_NAMESPACE_OUTPUT, Filename, "w+");
785
786         AslCompilerSignon (ASL_FILE_NAMESPACE_OUTPUT);
787         AslCompilerFileHeader (ASL_FILE_NAMESPACE_OUTPUT);
788     }
789
790     /* Create/Open a debug output file if asked */
791
792     if (Gbl_DebugFlag)
793     {
794         Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_DEBUG);
795         if (!Filename)
796         {
797             AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME,
798                 0, 0, 0, 0, NULL, NULL);
799             return (AE_ERROR);
800         }
801
802         /* Open the debug file as STDERR, text mode */
803
804         /* TBD: hide this behind a FlReopenFile function */
805
806         Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Filename = Filename;
807         Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle =
808             freopen (Filename, "w+t", stderr);
809
810         AslCompilerSignon (ASL_FILE_DEBUG_OUTPUT);
811         AslCompilerFileHeader (ASL_FILE_DEBUG_OUTPUT);
812     }
813
814     return (AE_OK);
815 }
816
817
818 #ifdef ACPI_OBSOLETE_FUNCTIONS
819 /*******************************************************************************
820  *
821  * FUNCTION:    FlParseInputPathname
822  *
823  * PARAMETERS:  InputFilename       - The user-specified ASL source file to be
824  *                                    compiled
825  *
826  * RETURN:      Status
827  *
828  * DESCRIPTION: Split the input path into a directory and filename part
829  *              1) Directory part used to open include files
830  *              2) Filename part used to generate output filenames
831  *
832  ******************************************************************************/
833
834 ACPI_STATUS
835 FlParseInputPathname (
836     char                    *InputFilename)
837 {
838     char                    *Substring;
839
840
841     if (!InputFilename)
842     {
843         return (AE_OK);
844     }
845
846     /* Get the path to the input filename's directory */
847
848     Gbl_DirectoryPath = strdup (InputFilename);
849     if (!Gbl_DirectoryPath)
850     {
851         return (AE_NO_MEMORY);
852     }
853
854     Substring = strrchr (Gbl_DirectoryPath, '\\');
855     if (!Substring)
856     {
857         Substring = strrchr (Gbl_DirectoryPath, '/');
858         if (!Substring)
859         {
860             Substring = strrchr (Gbl_DirectoryPath, ':');
861         }
862     }
863
864     if (!Substring)
865     {
866         Gbl_DirectoryPath[0] = 0;
867         if (Gbl_UseDefaultAmlFilename)
868         {
869             Gbl_OutputFilenamePrefix = strdup (InputFilename);
870         }
871     }
872     else
873     {
874         if (Gbl_UseDefaultAmlFilename)
875         {
876             Gbl_OutputFilenamePrefix = strdup (Substring + 1);
877         }
878         *(Substring+1) = 0;
879     }
880
881     return (AE_OK);
882 }
883 #endif
884
885