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