aslfiles.c revision 1.6 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 "aslcompiler.h"
45 #include "acapps.h"
46 #include "dtcompiler.h"
47
48 #define _COMPONENT ACPI_COMPILER
49 ACPI_MODULE_NAME ("aslfiles")
50
51 /* Local prototypes */
52
53 static FILE *
54 FlOpenIncludeWithPrefix (
55 char *PrefixDir,
56 ACPI_PARSE_OBJECT *Op,
57 char *Filename);
58
59 #ifdef ACPI_OBSOLETE_FUNCTIONS
60 ACPI_STATUS
61 FlParseInputPathname (
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
78 void
79 FlSetLineNumber (
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
102 void
103 FlSetFilename (
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
128 void
129 FlAddIncludeDirectory (
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
199 char *
200 FlMergePathnames (
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
263 ConcatenatePaths:
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
275 ConvertBackslashes:
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
298 static FILE *
299 FlOpenIncludeWithPrefix (
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
374 void
375 FlOpenIncludeFile (
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
453 ErrorExit:
454 snprintf (MsgBuffer, sizeof(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
474 ACPI_STATUS
475 FlOpenInputFile (
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
501 ACPI_STATUS
502 FlOpenAmlOutputFile (
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
546 ACPI_STATUS
547 FlOpenMiscOutputFiles (
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 listing output file if asked */
637
638 if (Gbl_ListingFlag)
639 {
640 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_LISTING);
641 if (!Filename)
642 {
643 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
644 0, 0, 0, 0, NULL, NULL);
645 return (AE_ERROR);
646 }
647
648 /* Open the listing file, text mode */
649
650 FlOpenFile (ASL_FILE_LISTING_OUTPUT, Filename, "w+t");
651
652 AslCompilerSignon (ASL_FILE_LISTING_OUTPUT);
653 AslCompilerFileHeader (ASL_FILE_LISTING_OUTPUT);
654 }
655
656 /* Create the preprocessor output temp file if preprocessor enabled */
657
658 if (Gbl_PreprocessFlag)
659 {
660 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_PREPROCESSOR);
661 if (!Filename)
662 {
663 AslCommonError (ASL_ERROR, ASL_MSG_PREPROCESSOR_FILENAME,
664 0, 0, 0, 0, NULL, NULL);
665 return (AE_ERROR);
666 }
667
668 FlOpenFile (ASL_FILE_PREPROCESSOR, Filename, "w+t");
669 }
670
671 /*
672 * Create the "user" preprocessor output file if -li flag set.
673 * Note, this file contains no embedded #line directives.
674 */
675 if (Gbl_PreprocessorOutputFlag)
676 {
677 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_PREPROC_USER);
678 if (!Filename)
679 {
680 AslCommonError (ASL_ERROR, ASL_MSG_PREPROCESSOR_FILENAME,
681 0, 0, 0, 0, NULL, NULL);
682 return (AE_ERROR);
683 }
684
685 FlOpenFile (ASL_FILE_PREPROCESSOR_USER, Filename, "w+t");
686 }
687
688 /* All done for data table compiler */
689
690 if (Gbl_FileType == ASL_INPUT_TYPE_ASCII_DATA)
691 {
692 return (AE_OK);
693 }
694
695 /* Create/Open a combined source output file */
696
697 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_SOURCE);
698 if (!Filename)
699 {
700 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
701 0, 0, 0, 0, NULL, NULL);
702 return (AE_ERROR);
703 }
704
705 /*
706 * Open the source output file, binary mode (so that LF does not get
707 * expanded to CR/LF on some systems, messing up our seek
708 * calculations.)
709 */
710 FlOpenFile (ASL_FILE_SOURCE_OUTPUT, Filename, "w+b");
711
712 /*
713 // TBD: TEMP
714 // AslCompilerin = Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle;
715 */
716 /* Create/Open a assembly code source output file if asked */
717
718 if (Gbl_AsmOutputFlag)
719 {
720 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_SOURCE);
721 if (!Filename)
722 {
723 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
724 0, 0, 0, 0, NULL, NULL);
725 return (AE_ERROR);
726 }
727
728 /* Open the assembly code source file, text mode */
729
730 FlOpenFile (ASL_FILE_ASM_SOURCE_OUTPUT, Filename, "w+t");
731
732 AslCompilerSignon (ASL_FILE_ASM_SOURCE_OUTPUT);
733 AslCompilerFileHeader (ASL_FILE_ASM_SOURCE_OUTPUT);
734 }
735
736 /* Create/Open a C code source output file if asked */
737
738 if (Gbl_C_OutputFlag)
739 {
740 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_SOURCE);
741 if (!Filename)
742 {
743 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
744 0, 0, 0, 0, NULL, NULL);
745 return (AE_ERROR);
746 }
747
748 /* Open the C code source file, text mode */
749
750 FlOpenFile (ASL_FILE_C_SOURCE_OUTPUT, Filename, "w+t");
751
752 FlPrintFile (ASL_FILE_C_SOURCE_OUTPUT, "/*\n");
753 AslCompilerSignon (ASL_FILE_C_SOURCE_OUTPUT);
754 AslCompilerFileHeader (ASL_FILE_C_SOURCE_OUTPUT);
755 }
756
757 /* Create/Open a C code source output file for the offset table if asked */
758
759 if (Gbl_C_OffsetTableFlag)
760 {
761 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_OFFSET);
762 if (!Filename)
763 {
764 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
765 0, 0, 0, 0, NULL, NULL);
766 return (AE_ERROR);
767 }
768
769 /* Open the C code source file, text mode */
770
771 FlOpenFile (ASL_FILE_C_OFFSET_OUTPUT, Filename, "w+t");
772
773 FlPrintFile (ASL_FILE_C_OFFSET_OUTPUT, "/*\n");
774 AslCompilerSignon (ASL_FILE_C_OFFSET_OUTPUT);
775 AslCompilerFileHeader (ASL_FILE_C_OFFSET_OUTPUT);
776 }
777
778 /* Create/Open a assembly include output file if asked */
779
780 if (Gbl_AsmIncludeOutputFlag)
781 {
782 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_INCLUDE);
783 if (!Filename)
784 {
785 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
786 0, 0, 0, 0, NULL, NULL);
787 return (AE_ERROR);
788 }
789
790 /* Open the assembly include file, text mode */
791
792 FlOpenFile (ASL_FILE_ASM_INCLUDE_OUTPUT, Filename, "w+t");
793
794 AslCompilerSignon (ASL_FILE_ASM_INCLUDE_OUTPUT);
795 AslCompilerFileHeader (ASL_FILE_ASM_INCLUDE_OUTPUT);
796 }
797
798 /* Create/Open a C include output file if asked */
799
800 if (Gbl_C_IncludeOutputFlag)
801 {
802 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_INCLUDE);
803 if (!Filename)
804 {
805 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
806 0, 0, 0, 0, NULL, NULL);
807 return (AE_ERROR);
808 }
809
810 /* Open the C include file, text mode */
811
812 FlOpenFile (ASL_FILE_C_INCLUDE_OUTPUT, Filename, "w+t");
813
814 FlPrintFile (ASL_FILE_C_INCLUDE_OUTPUT, "/*\n");
815 AslCompilerSignon (ASL_FILE_C_INCLUDE_OUTPUT);
816 AslCompilerFileHeader (ASL_FILE_C_INCLUDE_OUTPUT);
817 }
818
819 /* Create a namespace output file if asked */
820
821 if (Gbl_NsOutputFlag)
822 {
823 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_NAMESPACE);
824 if (!Filename)
825 {
826 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
827 0, 0, 0, 0, NULL, NULL);
828 return (AE_ERROR);
829 }
830
831 /* Open the namespace file, text mode */
832
833 FlOpenFile (ASL_FILE_NAMESPACE_OUTPUT, Filename, "w+t");
834
835 AslCompilerSignon (ASL_FILE_NAMESPACE_OUTPUT);
836 AslCompilerFileHeader (ASL_FILE_NAMESPACE_OUTPUT);
837 }
838
839 return (AE_OK);
840 }
841
842
843 #ifdef ACPI_OBSOLETE_FUNCTIONS
844 /*******************************************************************************
845 *
846 * FUNCTION: FlParseInputPathname
847 *
848 * PARAMETERS: InputFilename - The user-specified ASL source file to be
849 * compiled
850 *
851 * RETURN: Status
852 *
853 * DESCRIPTION: Split the input path into a directory and filename part
854 * 1) Directory part used to open include files
855 * 2) Filename part used to generate output filenames
856 *
857 ******************************************************************************/
858
859 ACPI_STATUS
860 FlParseInputPathname (
861 char *InputFilename)
862 {
863 char *Substring;
864
865
866 if (!InputFilename)
867 {
868 return (AE_OK);
869 }
870
871 /* Get the path to the input filename's directory */
872
873 Gbl_DirectoryPath = strdup (InputFilename);
874 if (!Gbl_DirectoryPath)
875 {
876 return (AE_NO_MEMORY);
877 }
878
879 Substring = strrchr (Gbl_DirectoryPath, '\\');
880 if (!Substring)
881 {
882 Substring = strrchr (Gbl_DirectoryPath, '/');
883 if (!Substring)
884 {
885 Substring = strrchr (Gbl_DirectoryPath, ':');
886 }
887 }
888
889 if (!Substring)
890 {
891 Gbl_DirectoryPath[0] = 0;
892 if (Gbl_UseDefaultAmlFilename)
893 {
894 Gbl_OutputFilenamePrefix = strdup (InputFilename);
895 }
896 }
897 else
898 {
899 if (Gbl_UseDefaultAmlFilename)
900 {
901 Gbl_OutputFilenamePrefix = strdup (Substring + 1);
902 }
903 *(Substring+1) = 0;
904 }
905
906 UtConvertBackslashes (Gbl_OutputFilenamePrefix);
907 return (AE_OK);
908 }
909 #endif
910