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