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