aslfiles.c revision 217365
1 2/****************************************************************************** 3 * 4 * Module Name: aslfiles - file I/O suppoert 5 * 6 *****************************************************************************/ 7 8/* 9 * Copyright (C) 2000 - 2011, 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 53static FILE * 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 * FUNCTION: AslAbort 69 * 70 * PARAMETERS: None 71 * 72 * RETURN: None 73 * 74 * DESCRIPTION: Dump the error log and abort the compiler. Used for serious 75 * I/O errors 76 * 77 ******************************************************************************/ 78 79void 80AslAbort ( 81 void) 82{ 83 84 AePrintErrorLog (ASL_FILE_STDOUT); 85 if (Gbl_DebugFlag) 86 { 87 /* Print error summary to the debug file */ 88 89 AePrintErrorLog (ASL_FILE_STDERR); 90 } 91 92 exit (1); 93} 94 95 96/******************************************************************************* 97 * 98 * FUNCTION: FlFileError 99 * 100 * PARAMETERS: FileId - Index into file info array 101 * ErrorId - Index into error message array 102 * 103 * RETURN: None 104 * 105 * DESCRIPTION: Decode errno to an error message and add the entire error 106 * to the error log. 107 * 108 ******************************************************************************/ 109 110void 111FlFileError ( 112 UINT32 FileId, 113 UINT8 ErrorId) 114{ 115 116 sprintf (MsgBuffer, "\"%s\" (%s)", Gbl_Files[FileId].Filename, 117 strerror (errno)); 118 AslCommonError (ASL_ERROR, ErrorId, 0, 0, 0, 0, NULL, MsgBuffer); 119} 120 121 122/******************************************************************************* 123 * 124 * FUNCTION: FlOpenFile 125 * 126 * PARAMETERS: FileId - Index into file info array 127 * Filename - file pathname to open 128 * Mode - Open mode for fopen 129 * 130 * RETURN: None 131 * 132 * DESCRIPTION: Open a file. 133 * NOTE: Aborts compiler on any error. 134 * 135 ******************************************************************************/ 136 137void 138FlOpenFile ( 139 UINT32 FileId, 140 char *Filename, 141 char *Mode) 142{ 143 FILE *File; 144 145 146 File = fopen (Filename, Mode); 147 148 Gbl_Files[FileId].Filename = Filename; 149 Gbl_Files[FileId].Handle = File; 150 151 if (!File) 152 { 153 FlFileError (FileId, ASL_MSG_OPEN); 154 AslAbort (); 155 } 156} 157 158 159/******************************************************************************* 160 * 161 * FUNCTION: FlGetFileSize 162 * 163 * PARAMETERS: FileId - Index into file info array 164 * 165 * RETURN: File Size 166 * 167 * DESCRIPTION: Get current file size. Uses seek-to-EOF. File must be open. 168 * 169 ******************************************************************************/ 170 171UINT32 172FlGetFileSize ( 173 UINT32 FileId) 174{ 175 FILE *fp; 176 UINT32 FileSize; 177 178 179 fp = Gbl_Files[FileId].Handle; 180 181 fseek (fp, 0, SEEK_END); 182 FileSize = (UINT32) ftell (fp); 183 fseek (fp, 0, SEEK_SET); 184 185 return (FileSize); 186} 187 188 189/******************************************************************************* 190 * 191 * FUNCTION: FlReadFile 192 * 193 * PARAMETERS: FileId - Index into file info array 194 * Buffer - Where to place the data 195 * Length - Amount to read 196 * 197 * RETURN: Status. AE_ERROR indicates EOF. 198 * 199 * DESCRIPTION: Read data from an open file. 200 * NOTE: Aborts compiler on any error. 201 * 202 ******************************************************************************/ 203 204ACPI_STATUS 205FlReadFile ( 206 UINT32 FileId, 207 void *Buffer, 208 UINT32 Length) 209{ 210 UINT32 Actual; 211 212 213 /* Read and check for error */ 214 215 Actual = fread (Buffer, 1, Length, Gbl_Files[FileId].Handle); 216 if (Actual != Length) 217 { 218 if (feof (Gbl_Files[FileId].Handle)) 219 { 220 /* End-of-file, just return error */ 221 222 return (AE_ERROR); 223 } 224 225 FlFileError (FileId, ASL_MSG_READ); 226 AslAbort (); 227 } 228 229 return (AE_OK); 230} 231 232 233/******************************************************************************* 234 * 235 * FUNCTION: FlWriteFile 236 * 237 * PARAMETERS: FileId - Index into file info array 238 * Buffer - Data to write 239 * Length - Amount of data to write 240 * 241 * RETURN: None 242 * 243 * DESCRIPTION: Write data to an open file. 244 * NOTE: Aborts compiler on any error. 245 * 246 ******************************************************************************/ 247 248void 249FlWriteFile ( 250 UINT32 FileId, 251 void *Buffer, 252 UINT32 Length) 253{ 254 UINT32 Actual; 255 256 257 /* Write and check for error */ 258 259 Actual = fwrite ((char *) Buffer, 1, Length, Gbl_Files[FileId].Handle); 260 if (Actual != Length) 261 { 262 FlFileError (FileId, ASL_MSG_WRITE); 263 AslAbort (); 264 } 265} 266 267 268/******************************************************************************* 269 * 270 * FUNCTION: FlPrintFile 271 * 272 * PARAMETERS: FileId - Index into file info array 273 * Format - Printf format string 274 * ... - Printf arguments 275 * 276 * RETURN: None 277 * 278 * DESCRIPTION: Formatted write to an open file. 279 * NOTE: Aborts compiler on any error. 280 * 281 ******************************************************************************/ 282 283void 284FlPrintFile ( 285 UINT32 FileId, 286 char *Format, 287 ...) 288{ 289 INT32 Actual; 290 va_list Args; 291 292 293 va_start (Args, Format); 294 295 Actual = vfprintf (Gbl_Files[FileId].Handle, Format, Args); 296 va_end (Args); 297 298 if (Actual == -1) 299 { 300 FlFileError (FileId, ASL_MSG_WRITE); 301 AslAbort (); 302 } 303} 304 305 306/******************************************************************************* 307 * 308 * FUNCTION: FlSeekFile 309 * 310 * PARAMETERS: FileId - Index into file info array 311 * Offset - Absolute byte offset in file 312 * 313 * RETURN: None 314 * 315 * DESCRIPTION: Seek to absolute offset 316 * NOTE: Aborts compiler on any error. 317 * 318 ******************************************************************************/ 319 320void 321FlSeekFile ( 322 UINT32 FileId, 323 long Offset) 324{ 325 int Error; 326 327 328 Error = fseek (Gbl_Files[FileId].Handle, Offset, SEEK_SET); 329 if (Error) 330 { 331 FlFileError (FileId, ASL_MSG_SEEK); 332 AslAbort (); 333 } 334} 335 336 337/******************************************************************************* 338 * 339 * FUNCTION: FlCloseFile 340 * 341 * PARAMETERS: FileId - Index into file info array 342 * 343 * RETURN: None 344 * 345 * DESCRIPTION: Close an open file. Aborts compiler on error 346 * 347 ******************************************************************************/ 348 349void 350FlCloseFile ( 351 UINT32 FileId) 352{ 353 int Error; 354 355 356 if (!Gbl_Files[FileId].Handle) 357 { 358 return; 359 } 360 361 Error = fclose (Gbl_Files[FileId].Handle); 362 Gbl_Files[FileId].Handle = NULL; 363 364 if (Error) 365 { 366 FlFileError (FileId, ASL_MSG_CLOSE); 367 AslAbort (); 368 } 369 370 return; 371} 372 373 374/******************************************************************************* 375 * 376 * FUNCTION: FlSetLineNumber 377 * 378 * PARAMETERS: Op - Parse node for the LINE asl statement 379 * 380 * RETURN: None. 381 * 382 * DESCRIPTION: Set the current line number 383 * 384 ******************************************************************************/ 385 386void 387FlSetLineNumber ( 388 ACPI_PARSE_OBJECT *Op) 389{ 390 391 Gbl_CurrentLineNumber = (UINT32) Op->Asl.Value.Integer; 392 Gbl_LogicalLineNumber = (UINT32) Op->Asl.Value.Integer; 393} 394 395 396/******************************************************************************* 397 * 398 * FUNCTION: FlAddIncludeDirectory 399 * 400 * PARAMETERS: Dir - Directory pathname string 401 * 402 * RETURN: None 403 * 404 * DESCRIPTION: Add a directory the list of include prefix directories. 405 * 406 ******************************************************************************/ 407 408void 409FlAddIncludeDirectory ( 410 char *Dir) 411{ 412 ASL_INCLUDE_DIR *NewDir; 413 ASL_INCLUDE_DIR *NextDir; 414 ASL_INCLUDE_DIR *PrevDir = NULL; 415 UINT32 NeedsSeparator = 0; 416 size_t DirLength; 417 418 419 DirLength = strlen (Dir); 420 if (!DirLength) 421 { 422 return; 423 } 424 425 /* Make sure that the pathname ends with a path separator */ 426 427 if ((Dir[DirLength-1] != '/') && 428 (Dir[DirLength-1] != '\\')) 429 { 430 NeedsSeparator = 1; 431 } 432 433 NewDir = ACPI_ALLOCATE_ZEROED (sizeof (ASL_INCLUDE_DIR)); 434 NewDir->Dir = ACPI_ALLOCATE (DirLength + 1 + NeedsSeparator); 435 strcpy (NewDir->Dir, Dir); 436 if (NeedsSeparator) 437 { 438 strcat (NewDir->Dir, "/"); 439 } 440 441 /* 442 * Preserve command line ordering of -I options by adding new elements 443 * at the end of the list 444 */ 445 NextDir = Gbl_IncludeDirList; 446 while (NextDir) 447 { 448 PrevDir = NextDir; 449 NextDir = NextDir->Next; 450 } 451 452 if (PrevDir) 453 { 454 PrevDir->Next = NewDir; 455 } 456 else 457 { 458 Gbl_IncludeDirList = NewDir; 459 } 460} 461 462 463/******************************************************************************* 464 * 465 * FUNCTION: FlOpenIncludeWithPrefix 466 * 467 * PARAMETERS: PrefixDir - Prefix directory pathname. Can be a zero 468 * length string. 469 * Filename - The include filename from the source ASL. 470 * 471 * RETURN: Valid file descriptor if successful. Null otherwise. 472 * 473 * DESCRIPTION: Open an include file and push it on the input file stack. 474 * 475 ******************************************************************************/ 476 477static FILE * 478FlOpenIncludeWithPrefix ( 479 char *PrefixDir, 480 char *Filename) 481{ 482 FILE *IncludeFile; 483 char *Pathname; 484 485 486 /* Build the full pathname to the file */ 487 488 Pathname = ACPI_ALLOCATE (strlen (PrefixDir) + strlen (Filename) + 1); 489 490 strcpy (Pathname, PrefixDir); 491 strcat (Pathname, Filename); 492 493 DbgPrint (ASL_PARSE_OUTPUT, "\nAttempt to open include file: path %s\n\n", 494 Pathname); 495 496 /* Attempt to open the file, push if successful */ 497 498 IncludeFile = fopen (Pathname, "r"); 499 if (IncludeFile) 500 { 501 /* Push the include file on the open input file stack */ 502 503 AslPushInputFileStack (IncludeFile, Pathname); 504 return (IncludeFile); 505 } 506 507 ACPI_FREE (Pathname); 508 return (NULL); 509} 510 511 512/******************************************************************************* 513 * 514 * FUNCTION: FlOpenIncludeFile 515 * 516 * PARAMETERS: Op - Parse node for the INCLUDE ASL statement 517 * 518 * RETURN: None. 519 * 520 * DESCRIPTION: Open an include file and push it on the input file stack. 521 * 522 ******************************************************************************/ 523 524void 525FlOpenIncludeFile ( 526 ACPI_PARSE_OBJECT *Op) 527{ 528 FILE *IncludeFile; 529 ASL_INCLUDE_DIR *NextDir; 530 531 532 /* Op must be valid */ 533 534 if (!Op) 535 { 536 AslCommonError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, 537 Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, 538 Gbl_InputByteCount, Gbl_CurrentColumn, 539 Gbl_Files[ASL_FILE_INPUT].Filename, " - Null parse node"); 540 541 return; 542 } 543 544 /* 545 * Flush out the "include ()" statement on this line, start 546 * the actual include file on the next line 547 */ 548 ResetCurrentLineBuffer (); 549 FlPrintFile (ASL_FILE_SOURCE_OUTPUT, "\n"); 550 Gbl_CurrentLineOffset++; 551 552 553 /* Attempt to open the include file */ 554 555 /* If the file specifies an absolute path, just open it */ 556 557 if ((Op->Asl.Value.String[0] == '/') || 558 (Op->Asl.Value.String[0] == '\\') || 559 (Op->Asl.Value.String[1] == ':')) 560 { 561 IncludeFile = FlOpenIncludeWithPrefix ("", Op->Asl.Value.String); 562 if (!IncludeFile) 563 { 564 goto ErrorExit; 565 } 566 return; 567 } 568 569 /* 570 * The include filename is not an absolute path. 571 * 572 * First, search for the file within the "local" directory -- meaning 573 * the same directory that contains the source file. 574 * 575 * Construct the file pathname from the global directory name. 576 */ 577 IncludeFile = FlOpenIncludeWithPrefix (Gbl_DirectoryPath, Op->Asl.Value.String); 578 if (IncludeFile) 579 { 580 return; 581 } 582 583 /* 584 * Second, search for the file within the (possibly multiple) directories 585 * specified by the -I option on the command line. 586 */ 587 NextDir = Gbl_IncludeDirList; 588 while (NextDir) 589 { 590 IncludeFile = FlOpenIncludeWithPrefix (NextDir->Dir, Op->Asl.Value.String); 591 if (IncludeFile) 592 { 593 return; 594 } 595 596 NextDir = NextDir->Next; 597 } 598 599 /* We could not open the include file after trying very hard */ 600 601ErrorExit: 602 sprintf (MsgBuffer, "%s, %s", Op->Asl.Value.String, strerror (errno)); 603 AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, Op, MsgBuffer); 604} 605 606 607/******************************************************************************* 608 * 609 * FUNCTION: FlOpenInputFile 610 * 611 * PARAMETERS: InputFilename - The user-specified ASL source file to be 612 * compiled 613 * 614 * RETURN: Status 615 * 616 * DESCRIPTION: Open the specified input file, and save the directory path to 617 * the file so that include files can be opened in 618 * the same directory. 619 * 620 ******************************************************************************/ 621 622ACPI_STATUS 623FlOpenInputFile ( 624 char *InputFilename) 625{ 626 627 /* Open the input ASL file, text mode */ 628 629 FlOpenFile (ASL_FILE_INPUT, InputFilename, "r"); 630 AslCompilerin = Gbl_Files[ASL_FILE_INPUT].Handle; 631 632 return (AE_OK); 633} 634 635 636/******************************************************************************* 637 * 638 * FUNCTION: FlOpenAmlOutputFile 639 * 640 * PARAMETERS: FilenamePrefix - The user-specified ASL source file 641 * 642 * RETURN: Status 643 * 644 * DESCRIPTION: Create the output filename (*.AML) and open the file. The file 645 * is created in the same directory as the parent input file. 646 * 647 ******************************************************************************/ 648 649ACPI_STATUS 650FlOpenAmlOutputFile ( 651 char *FilenamePrefix) 652{ 653 char *Filename; 654 655 656 /* Output filename usually comes from the ASL itself */ 657 658 Filename = Gbl_Files[ASL_FILE_AML_OUTPUT].Filename; 659 if (!Filename) 660 { 661 /* Create the output AML filename */ 662 663 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_AML_CODE); 664 if (!Filename) 665 { 666 AslCommonError (ASL_ERROR, ASL_MSG_OUTPUT_FILENAME, 667 0, 0, 0, 0, NULL, NULL); 668 return (AE_ERROR); 669 } 670 } 671 672 /* Open the output AML file in binary mode */ 673 674 FlOpenFile (ASL_FILE_AML_OUTPUT, Filename, "w+b"); 675 return (AE_OK); 676} 677 678 679/******************************************************************************* 680 * 681 * FUNCTION: FlOpenMiscOutputFiles 682 * 683 * PARAMETERS: FilenamePrefix - The user-specified ASL source file 684 * 685 * RETURN: Status 686 * 687 * DESCRIPTION: Create and open the various output files needed, depending on 688 * the command line options 689 * 690 ******************************************************************************/ 691 692ACPI_STATUS 693FlOpenMiscOutputFiles ( 694 char *FilenamePrefix) 695{ 696 char *Filename; 697 698 699 /* Create/Open a hex output file if asked */ 700 701 if (Gbl_HexOutputFlag) 702 { 703 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_HEX_DUMP); 704 if (!Filename) 705 { 706 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 707 0, 0, 0, 0, NULL, NULL); 708 return (AE_ERROR); 709 } 710 711 /* Open the hex file, text mode */ 712 713 FlOpenFile (ASL_FILE_HEX_OUTPUT, Filename, "w+"); 714 715 AslCompilerSignon (ASL_FILE_HEX_OUTPUT); 716 AslCompilerFileHeader (ASL_FILE_HEX_OUTPUT); 717 } 718 719 /* Create/Open a debug output file if asked */ 720 721 if (Gbl_DebugFlag) 722 { 723 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_DEBUG); 724 if (!Filename) 725 { 726 AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME, 727 0, 0, 0, 0, NULL, NULL); 728 return (AE_ERROR); 729 } 730 731 /* Open the debug file as STDERR, text mode */ 732 733 /* TBD: hide this behind a FlReopenFile function */ 734 735 Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Filename = Filename; 736 Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle = 737 freopen (Filename, "w+t", stderr); 738 739 AslCompilerSignon (ASL_FILE_DEBUG_OUTPUT); 740 AslCompilerFileHeader (ASL_FILE_DEBUG_OUTPUT); 741 } 742 743 /* Create/Open a listing output file if asked */ 744 745 if (Gbl_ListingFlag) 746 { 747 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_LISTING); 748 if (!Filename) 749 { 750 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 751 0, 0, 0, 0, NULL, NULL); 752 return (AE_ERROR); 753 } 754 755 /* Open the listing file, text mode */ 756 757 FlOpenFile (ASL_FILE_LISTING_OUTPUT, Filename, "w+"); 758 759 AslCompilerSignon (ASL_FILE_LISTING_OUTPUT); 760 AslCompilerFileHeader (ASL_FILE_LISTING_OUTPUT); 761 } 762 763 if (Gbl_FileType == ASL_INPUT_TYPE_ASCII_DATA) 764 { 765 return (AE_OK); 766 } 767 768 /* Create/Open a combined source output file */ 769 770 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_SOURCE); 771 if (!Filename) 772 { 773 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 774 0, 0, 0, 0, NULL, NULL); 775 return (AE_ERROR); 776 } 777 778 /* 779 * Open the source output file, binary mode (so that LF does not get 780 * expanded to CR/LF on some systems, messing up our seek 781 * calculations.) 782 */ 783 FlOpenFile (ASL_FILE_SOURCE_OUTPUT, Filename, "w+b"); 784 785 /* Create/Open a assembly code source output file if asked */ 786 787 if (Gbl_AsmOutputFlag) 788 { 789 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_SOURCE); 790 if (!Filename) 791 { 792 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 793 0, 0, 0, 0, NULL, NULL); 794 return (AE_ERROR); 795 } 796 797 /* Open the assembly code source file, text mode */ 798 799 FlOpenFile (ASL_FILE_ASM_SOURCE_OUTPUT, Filename, "w+"); 800 801 AslCompilerSignon (ASL_FILE_ASM_SOURCE_OUTPUT); 802 AslCompilerFileHeader (ASL_FILE_ASM_SOURCE_OUTPUT); 803 } 804 805 /* Create/Open a C code source output file if asked */ 806 807 if (Gbl_C_OutputFlag) 808 { 809 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_SOURCE); 810 if (!Filename) 811 { 812 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 813 0, 0, 0, 0, NULL, NULL); 814 return (AE_ERROR); 815 } 816 817 /* Open the C code source file, text mode */ 818 819 FlOpenFile (ASL_FILE_C_SOURCE_OUTPUT, Filename, "w+"); 820 821 FlPrintFile (ASL_FILE_C_SOURCE_OUTPUT, "/*\n"); 822 AslCompilerSignon (ASL_FILE_C_SOURCE_OUTPUT); 823 AslCompilerFileHeader (ASL_FILE_C_SOURCE_OUTPUT); 824 } 825 826 /* Create/Open a assembly include output file if asked */ 827 828 if (Gbl_AsmIncludeOutputFlag) 829 { 830 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_INCLUDE); 831 if (!Filename) 832 { 833 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 834 0, 0, 0, 0, NULL, NULL); 835 return (AE_ERROR); 836 } 837 838 /* Open the assembly include file, text mode */ 839 840 FlOpenFile (ASL_FILE_ASM_INCLUDE_OUTPUT, Filename, "w+"); 841 842 AslCompilerSignon (ASL_FILE_ASM_INCLUDE_OUTPUT); 843 AslCompilerFileHeader (ASL_FILE_ASM_INCLUDE_OUTPUT); 844 } 845 846 /* Create/Open a C include output file if asked */ 847 848 if (Gbl_C_IncludeOutputFlag) 849 { 850 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_INCLUDE); 851 if (!Filename) 852 { 853 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 854 0, 0, 0, 0, NULL, NULL); 855 return (AE_ERROR); 856 } 857 858 /* Open the C include file, text mode */ 859 860 FlOpenFile (ASL_FILE_C_INCLUDE_OUTPUT, Filename, "w+"); 861 862 FlPrintFile (ASL_FILE_C_INCLUDE_OUTPUT, "/*\n"); 863 AslCompilerSignon (ASL_FILE_C_INCLUDE_OUTPUT); 864 AslCompilerFileHeader (ASL_FILE_C_INCLUDE_OUTPUT); 865 } 866 867 /* Create a namespace output file if asked */ 868 869 if (Gbl_NsOutputFlag) 870 { 871 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_NAMESPACE); 872 if (!Filename) 873 { 874 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 875 0, 0, 0, 0, NULL, NULL); 876 return (AE_ERROR); 877 } 878 879 /* Open the namespace file, text mode */ 880 881 FlOpenFile (ASL_FILE_NAMESPACE_OUTPUT, Filename, "w+"); 882 883 AslCompilerSignon (ASL_FILE_NAMESPACE_OUTPUT); 884 AslCompilerFileHeader (ASL_FILE_NAMESPACE_OUTPUT); 885 } 886 887 return (AE_OK); 888} 889 890 891#ifdef ACPI_OBSOLETE_FUNCTIONS 892/******************************************************************************* 893 * 894 * FUNCTION: FlParseInputPathname 895 * 896 * PARAMETERS: InputFilename - The user-specified ASL source file to be 897 * compiled 898 * 899 * RETURN: Status 900 * 901 * DESCRIPTION: Split the input path into a directory and filename part 902 * 1) Directory part used to open include files 903 * 2) Filename part used to generate output filenames 904 * 905 ******************************************************************************/ 906 907ACPI_STATUS 908FlParseInputPathname ( 909 char *InputFilename) 910{ 911 char *Substring; 912 913 914 if (!InputFilename) 915 { 916 return (AE_OK); 917 } 918 919 /* Get the path to the input filename's directory */ 920 921 Gbl_DirectoryPath = strdup (InputFilename); 922 if (!Gbl_DirectoryPath) 923 { 924 return (AE_NO_MEMORY); 925 } 926 927 Substring = strrchr (Gbl_DirectoryPath, '\\'); 928 if (!Substring) 929 { 930 Substring = strrchr (Gbl_DirectoryPath, '/'); 931 if (!Substring) 932 { 933 Substring = strrchr (Gbl_DirectoryPath, ':'); 934 } 935 } 936 937 if (!Substring) 938 { 939 Gbl_DirectoryPath[0] = 0; 940 if (Gbl_UseDefaultAmlFilename) 941 { 942 Gbl_OutputFilenamePrefix = strdup (InputFilename); 943 } 944 } 945 else 946 { 947 if (Gbl_UseDefaultAmlFilename) 948 { 949 Gbl_OutputFilenamePrefix = strdup (Substring + 1); 950 } 951 *(Substring+1) = 0; 952 } 953 954 return (AE_OK); 955} 956#endif 957 958 959