1 /****************************************************************************** 2 * 3 * Module Name: aslfiles - File support functions 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2015, Intel Corp. 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions, and the following disclaimer, 16 * without modification. 17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18 * substantially similar to the "NO WARRANTY" disclaimer below 19 * ("Disclaimer") and any redistribution must be conditioned upon 20 * including a substantially similar Disclaimer requirement for further 21 * binary redistribution. 22 * 3. Neither the names of the above-listed copyright holders nor the names 23 * of any contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * Alternatively, this software may be distributed under the terms of the 27 * GNU General Public License ("GPL") version 2 as published by the Free 28 * Software Foundation. 29 * 30 * NO WARRANTY 31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41 * POSSIBILITY OF SUCH DAMAGES. 42 */ 43 44 #ifdef __DragonFly__ 45 #include <unistd.h> 46 #endif 47 48 #include "aslcompiler.h" 49 #include "acapps.h" 50 51 #define _COMPONENT ACPI_COMPILER 52 ACPI_MODULE_NAME ("aslfiles") 53 54 /* Local prototypes */ 55 56 FILE * 57 FlOpenIncludeWithPrefix ( 58 char *PrefixDir, 59 char *Filename); 60 61 62 #ifdef ACPI_OBSOLETE_FUNCTIONS 63 ACPI_STATUS 64 FlParseInputPathname ( 65 char *InputFilename); 66 #endif 67 68 69 /******************************************************************************* 70 * 71 * FUNCTION: FlSetLineNumber 72 * 73 * PARAMETERS: Op - Parse node for the LINE asl statement 74 * 75 * RETURN: None. 76 * 77 * DESCRIPTION: Set the current line number 78 * 79 ******************************************************************************/ 80 81 void 82 FlSetLineNumber ( 83 UINT32 LineNumber) 84 { 85 86 DbgPrint (ASL_PARSE_OUTPUT, "\n#line: New line number %u (old %u)\n", 87 LineNumber, Gbl_LogicalLineNumber); 88 89 Gbl_CurrentLineNumber = LineNumber; 90 Gbl_LogicalLineNumber = LineNumber; 91 } 92 93 94 /******************************************************************************* 95 * 96 * FUNCTION: FlSetFilename 97 * 98 * PARAMETERS: Op - Parse node for the LINE asl statement 99 * 100 * RETURN: None. 101 * 102 * DESCRIPTION: Set the current filename 103 * 104 ******************************************************************************/ 105 106 void 107 FlSetFilename ( 108 char *Filename) 109 { 110 111 DbgPrint (ASL_PARSE_OUTPUT, "\n#line: New filename %s (old %s)\n", 112 Filename, Gbl_Files[ASL_FILE_INPUT].Filename); 113 114 /* No need to free any existing filename */ 115 116 Gbl_Files[ASL_FILE_INPUT].Filename = Filename; 117 } 118 119 120 /******************************************************************************* 121 * 122 * FUNCTION: FlAddIncludeDirectory 123 * 124 * PARAMETERS: Dir - Directory pathname string 125 * 126 * RETURN: None 127 * 128 * DESCRIPTION: Add a directory the list of include prefix directories. 129 * 130 ******************************************************************************/ 131 132 void 133 FlAddIncludeDirectory ( 134 char *Dir) 135 { 136 ASL_INCLUDE_DIR *NewDir; 137 ASL_INCLUDE_DIR *NextDir; 138 ASL_INCLUDE_DIR *PrevDir = NULL; 139 UINT32 NeedsSeparator = 0; 140 size_t DirLength; 141 142 143 DirLength = strlen (Dir); 144 if (!DirLength) 145 { 146 return; 147 } 148 149 /* Make sure that the pathname ends with a path separator */ 150 151 if ((Dir[DirLength-1] != '/') && 152 (Dir[DirLength-1] != '\\')) 153 { 154 NeedsSeparator = 1; 155 } 156 157 NewDir = ACPI_ALLOCATE_ZEROED (sizeof (ASL_INCLUDE_DIR)); 158 NewDir->Dir = ACPI_ALLOCATE (DirLength + 1 + NeedsSeparator); 159 strcpy (NewDir->Dir, Dir); 160 if (NeedsSeparator) 161 { 162 strcat (NewDir->Dir, "/"); 163 } 164 165 /* 166 * Preserve command line ordering of -I options by adding new elements 167 * at the end of the list 168 */ 169 NextDir = Gbl_IncludeDirList; 170 while (NextDir) 171 { 172 PrevDir = NextDir; 173 NextDir = NextDir->Next; 174 } 175 176 if (PrevDir) 177 { 178 PrevDir->Next = NewDir; 179 } 180 else 181 { 182 Gbl_IncludeDirList = NewDir; 183 } 184 } 185 186 187 /******************************************************************************* 188 * 189 * FUNCTION: FlMergePathnames 190 * 191 * PARAMETERS: PrefixDir - Prefix directory pathname. Can be NULL or 192 * a zero length string. 193 * FilePathname - The include filename from the source ASL. 194 * 195 * RETURN: Merged pathname string 196 * 197 * DESCRIPTION: Merge two pathnames that (probably) have common elements, to 198 * arrive at a minimal length string. Merge can occur if the 199 * FilePathname is relative to the PrefixDir. 200 * 201 ******************************************************************************/ 202 203 char * 204 FlMergePathnames ( 205 char *PrefixDir, 206 char *FilePathname) 207 { 208 char *CommonPath; 209 char *Pathname; 210 char *LastElement; 211 212 213 DbgPrint (ASL_PARSE_OUTPUT, "Include: Prefix path - \"%s\"\n" 214 "Include: FilePathname - \"%s\"\n", 215 PrefixDir, FilePathname); 216 217 /* 218 * If there is no prefix directory or if the file pathname is absolute, 219 * just return the original file pathname 220 */ 221 if (!PrefixDir || (!*PrefixDir) || 222 (*FilePathname == '/') || 223 (FilePathname[1] == ':')) 224 { 225 Pathname = UtStringCacheCalloc (strlen (FilePathname) + 1); 226 strcpy (Pathname, FilePathname); 227 goto ConvertBackslashes; 228 } 229 230 /* Need a local copy of the prefix directory path */ 231 232 CommonPath = UtStringCacheCalloc (strlen (PrefixDir) + 1); 233 strcpy (CommonPath, PrefixDir); 234 235 /* 236 * Walk forward through the file path, and simultaneously backward 237 * through the prefix directory path until there are no more 238 * relative references at the start of the file path. 239 */ 240 while (*FilePathname && (!strncmp (FilePathname, "../", 3))) 241 { 242 /* Remove last element of the prefix directory path */ 243 244 LastElement = strrchr (CommonPath, '/'); 245 if (!LastElement) 246 { 247 goto ConcatenatePaths; 248 } 249 250 *LastElement = 0; /* Terminate CommonPath string */ 251 FilePathname += 3; /* Point to next path element */ 252 } 253 254 /* 255 * Remove the last element of the prefix directory path (it is the same as 256 * the first element of the file pathname), and build the final merged 257 * pathname. 258 */ 259 LastElement = strrchr (CommonPath, '/'); 260 if (LastElement) 261 { 262 *LastElement = 0; 263 } 264 265 /* Build the final merged pathname */ 266 267 ConcatenatePaths: 268 Pathname = UtStringCacheCalloc (strlen (CommonPath) + strlen (FilePathname) + 2); 269 if (LastElement && *CommonPath) 270 { 271 strcpy (Pathname, CommonPath); 272 strcat (Pathname, "/"); 273 } 274 strcat (Pathname, FilePathname); 275 276 /* Convert all backslashes to normal slashes */ 277 278 ConvertBackslashes: 279 UtConvertBackslashes (Pathname); 280 281 DbgPrint (ASL_PARSE_OUTPUT, "Include: Merged Pathname - \"%s\"\n", 282 Pathname); 283 return (Pathname); 284 } 285 286 287 /******************************************************************************* 288 * 289 * FUNCTION: FlOpenIncludeWithPrefix 290 * 291 * PARAMETERS: PrefixDir - Prefix directory pathname. Can be a zero 292 * length string. 293 * Filename - The include filename from the source ASL. 294 * 295 * RETURN: Valid file descriptor if successful. Null otherwise. 296 * 297 * DESCRIPTION: Open an include file and push it on the input file stack. 298 * 299 ******************************************************************************/ 300 301 FILE * 302 FlOpenIncludeWithPrefix ( 303 char *PrefixDir, 304 char *Filename) 305 { 306 FILE *IncludeFile; 307 char *Pathname; 308 309 310 /* Build the full pathname to the file */ 311 312 Pathname = FlMergePathnames (PrefixDir, Filename); 313 314 DbgPrint (ASL_PARSE_OUTPUT, "Include: Opening file - \"%s\"\n\n", 315 Pathname); 316 317 /* Attempt to open the file, push if successful */ 318 319 IncludeFile = fopen (Pathname, "r"); 320 if (!IncludeFile) 321 { 322 fprintf (stderr, "Could not open include file %s\n", Pathname); 323 ACPI_FREE (Pathname); 324 return (NULL); 325 } 326 327 /* Push the include file on the open input file stack */ 328 329 AslPushInputFileStack (IncludeFile, Pathname); 330 return (IncludeFile); 331 } 332 333 334 /******************************************************************************* 335 * 336 * FUNCTION: FlOpenIncludeFile 337 * 338 * PARAMETERS: Op - Parse node for the INCLUDE ASL statement 339 * 340 * RETURN: None. 341 * 342 * DESCRIPTION: Open an include file and push it on the input file stack. 343 * 344 ******************************************************************************/ 345 346 void 347 FlOpenIncludeFile ( 348 ACPI_PARSE_OBJECT *Op) 349 { 350 FILE *IncludeFile; 351 ASL_INCLUDE_DIR *NextDir; 352 353 354 /* Op must be valid */ 355 356 if (!Op) 357 { 358 AslCommonError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, 359 Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, 360 Gbl_InputByteCount, Gbl_CurrentColumn, 361 Gbl_Files[ASL_FILE_INPUT].Filename, " - Null parse node"); 362 363 return; 364 } 365 366 /* 367 * Flush out the "include ()" statement on this line, start 368 * the actual include file on the next line 369 */ 370 AslResetCurrentLineBuffer (); 371 FlPrintFile (ASL_FILE_SOURCE_OUTPUT, "\n"); 372 Gbl_CurrentLineOffset++; 373 374 375 /* Attempt to open the include file */ 376 377 /* If the file specifies an absolute path, just open it */ 378 379 if ((Op->Asl.Value.String[0] == '/') || 380 (Op->Asl.Value.String[0] == '\\') || 381 (Op->Asl.Value.String[1] == ':')) 382 { 383 IncludeFile = FlOpenIncludeWithPrefix ("", Op->Asl.Value.String); 384 if (!IncludeFile) 385 { 386 goto ErrorExit; 387 } 388 return; 389 } 390 391 /* 392 * The include filename is not an absolute path. 393 * 394 * First, search for the file within the "local" directory -- meaning 395 * the same directory that contains the source file. 396 * 397 * Construct the file pathname from the global directory name. 398 */ 399 IncludeFile = FlOpenIncludeWithPrefix (Gbl_DirectoryPath, Op->Asl.Value.String); 400 if (IncludeFile) 401 { 402 return; 403 } 404 405 /* 406 * Second, search for the file within the (possibly multiple) directories 407 * specified by the -I option on the command line. 408 */ 409 NextDir = Gbl_IncludeDirList; 410 while (NextDir) 411 { 412 IncludeFile = FlOpenIncludeWithPrefix (NextDir->Dir, Op->Asl.Value.String); 413 if (IncludeFile) 414 { 415 return; 416 } 417 418 NextDir = NextDir->Next; 419 } 420 421 /* We could not open the include file after trying very hard */ 422 423 ErrorExit: 424 sprintf (MsgBuffer, "%s, %s", Op->Asl.Value.String, strerror (errno)); 425 AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, Op, MsgBuffer); 426 } 427 428 429 /******************************************************************************* 430 * 431 * FUNCTION: FlOpenInputFile 432 * 433 * PARAMETERS: InputFilename - The user-specified ASL source file to be 434 * compiled 435 * 436 * RETURN: Status 437 * 438 * DESCRIPTION: Open the specified input file, and save the directory path to 439 * the file so that include files can be opened in 440 * the same directory. 441 * 442 ******************************************************************************/ 443 444 ACPI_STATUS 445 FlOpenInputFile ( 446 char *InputFilename) 447 { 448 449 /* Open the input ASL file, text mode */ 450 451 FlOpenFile (ASL_FILE_INPUT, InputFilename, "rt"); 452 AslCompilerin = Gbl_Files[ASL_FILE_INPUT].Handle; 453 454 return (AE_OK); 455 } 456 457 458 /******************************************************************************* 459 * 460 * FUNCTION: FlOpenAmlOutputFile 461 * 462 * PARAMETERS: FilenamePrefix - The user-specified ASL source file 463 * 464 * RETURN: Status 465 * 466 * DESCRIPTION: Create the output filename (*.AML) and open the file. The file 467 * is created in the same directory as the parent input file. 468 * 469 ******************************************************************************/ 470 471 ACPI_STATUS 472 FlOpenAmlOutputFile ( 473 char *FilenamePrefix) 474 { 475 char *Filename; 476 477 478 /* Output filename usually comes from the ASL itself */ 479 480 Filename = Gbl_Files[ASL_FILE_AML_OUTPUT].Filename; 481 if (!Filename) 482 { 483 /* Create the output AML filename */ 484 485 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_AML_CODE); 486 if (!Filename) 487 { 488 AslCommonError (ASL_ERROR, ASL_MSG_OUTPUT_FILENAME, 489 0, 0, 0, 0, NULL, NULL); 490 return (AE_ERROR); 491 } 492 493 Gbl_Files[ASL_FILE_AML_OUTPUT].Filename = Filename; 494 } 495 496 /* Open the output AML file in binary mode */ 497 498 FlOpenFile (ASL_FILE_AML_OUTPUT, Filename, "w+b"); 499 return (AE_OK); 500 } 501 502 503 /******************************************************************************* 504 * 505 * FUNCTION: FlOpenMiscOutputFiles 506 * 507 * PARAMETERS: FilenamePrefix - The user-specified ASL source file 508 * 509 * RETURN: Status 510 * 511 * DESCRIPTION: Create and open the various output files needed, depending on 512 * the command line options 513 * 514 ******************************************************************************/ 515 516 ACPI_STATUS 517 FlOpenMiscOutputFiles ( 518 char *FilenamePrefix) 519 { 520 char *Filename; 521 522 523 /* All done for disassembler */ 524 525 if (Gbl_FileType == ASL_INPUT_TYPE_ACPI_TABLE) 526 { 527 return (AE_OK); 528 } 529 530 /* Create/Open a hex output file if asked */ 531 532 if (Gbl_HexOutputFlag) 533 { 534 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_HEX_DUMP); 535 if (!Filename) 536 { 537 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 538 0, 0, 0, 0, NULL, NULL); 539 return (AE_ERROR); 540 } 541 542 /* Open the hex file, text mode */ 543 544 FlOpenFile (ASL_FILE_HEX_OUTPUT, Filename, "w+t"); 545 546 AslCompilerSignon (ASL_FILE_HEX_OUTPUT); 547 AslCompilerFileHeader (ASL_FILE_HEX_OUTPUT); 548 } 549 550 /* Create/Open a debug output file if asked */ 551 552 if (Gbl_DebugFlag) 553 { 554 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_DEBUG); 555 if (!Filename) 556 { 557 AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME, 558 0, 0, 0, 0, NULL, NULL); 559 return (AE_ERROR); 560 } 561 562 /* Open the debug file as STDERR, text mode */ 563 564 /* TBD: hide this behind a FlReopenFile function */ 565 566 Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Filename = Filename; 567 Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle = 568 freopen (Filename, "w+t", stderr); 569 570 if (!Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle) 571 { 572 #ifdef __DragonFly__ 573 int temp_fd; 574 #endif 575 576 /* 577 * A problem with freopen is that on error, 578 * we no longer have stderr. 579 */ 580 Gbl_DebugFlag = FALSE; 581 #ifdef __DragonFly__ 582 stderr = NULL; 583 temp_fd = dup(STDERR_FILENO); 584 if (temp_fd >= 0) { 585 stderr = fdopen(temp_fd, "w"); 586 if (stderr != NULL) 587 setvbuf(stderr, NULL, _IONBF, 0); 588 else 589 close(temp_fd); 590 } 591 if (stderr == NULL) { 592 /* This is wrong, but better than nothing */ 593 stderr = stdout; 594 } 595 #else 596 /* WTF */ 597 memcpy (stderr, stdout, sizeof (FILE)); 598 #endif 599 FlFileError (ASL_FILE_DEBUG_OUTPUT, ASL_MSG_DEBUG_FILENAME); 600 AslAbort (); 601 } 602 603 AslCompilerSignon (ASL_FILE_DEBUG_OUTPUT); 604 AslCompilerFileHeader (ASL_FILE_DEBUG_OUTPUT); 605 } 606 607 /* Create/Open a listing output file if asked */ 608 609 if (Gbl_ListingFlag) 610 { 611 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_LISTING); 612 if (!Filename) 613 { 614 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 615 0, 0, 0, 0, NULL, NULL); 616 return (AE_ERROR); 617 } 618 619 /* Open the listing file, text mode */ 620 621 FlOpenFile (ASL_FILE_LISTING_OUTPUT, Filename, "w+t"); 622 623 AslCompilerSignon (ASL_FILE_LISTING_OUTPUT); 624 AslCompilerFileHeader (ASL_FILE_LISTING_OUTPUT); 625 } 626 627 /* Create the preprocessor output file if preprocessor enabled */ 628 629 if (Gbl_PreprocessFlag) 630 { 631 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_PREPROCESSOR); 632 if (!Filename) 633 { 634 AslCommonError (ASL_ERROR, ASL_MSG_PREPROCESSOR_FILENAME, 635 0, 0, 0, 0, NULL, NULL); 636 return (AE_ERROR); 637 } 638 639 FlOpenFile (ASL_FILE_PREPROCESSOR, Filename, "w+t"); 640 } 641 642 /* All done for data table compiler */ 643 644 if (Gbl_FileType == ASL_INPUT_TYPE_ASCII_DATA) 645 { 646 return (AE_OK); 647 } 648 649 /* Create/Open a combined source output file */ 650 651 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_SOURCE); 652 if (!Filename) 653 { 654 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 655 0, 0, 0, 0, NULL, NULL); 656 return (AE_ERROR); 657 } 658 659 /* 660 * Open the source output file, binary mode (so that LF does not get 661 * expanded to CR/LF on some systems, messing up our seek 662 * calculations.) 663 */ 664 FlOpenFile (ASL_FILE_SOURCE_OUTPUT, Filename, "w+b"); 665 666 /* 667 // TBD: TEMP 668 // AslCompilerin = Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle; 669 */ 670 /* Create/Open a assembly code source output file if asked */ 671 672 if (Gbl_AsmOutputFlag) 673 { 674 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_SOURCE); 675 if (!Filename) 676 { 677 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 678 0, 0, 0, 0, NULL, NULL); 679 return (AE_ERROR); 680 } 681 682 /* Open the assembly code source file, text mode */ 683 684 FlOpenFile (ASL_FILE_ASM_SOURCE_OUTPUT, Filename, "w+t"); 685 686 AslCompilerSignon (ASL_FILE_ASM_SOURCE_OUTPUT); 687 AslCompilerFileHeader (ASL_FILE_ASM_SOURCE_OUTPUT); 688 } 689 690 /* Create/Open a C code source output file if asked */ 691 692 if (Gbl_C_OutputFlag) 693 { 694 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_SOURCE); 695 if (!Filename) 696 { 697 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 698 0, 0, 0, 0, NULL, NULL); 699 return (AE_ERROR); 700 } 701 702 /* Open the C code source file, text mode */ 703 704 FlOpenFile (ASL_FILE_C_SOURCE_OUTPUT, Filename, "w+t"); 705 706 FlPrintFile (ASL_FILE_C_SOURCE_OUTPUT, "/*\n"); 707 AslCompilerSignon (ASL_FILE_C_SOURCE_OUTPUT); 708 AslCompilerFileHeader (ASL_FILE_C_SOURCE_OUTPUT); 709 } 710 711 /* Create/Open a C code source output file for the offset table if asked */ 712 713 if (Gbl_C_OffsetTableFlag) 714 { 715 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_OFFSET); 716 if (!Filename) 717 { 718 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 719 0, 0, 0, 0, NULL, NULL); 720 return (AE_ERROR); 721 } 722 723 /* Open the C code source file, text mode */ 724 725 FlOpenFile (ASL_FILE_C_OFFSET_OUTPUT, Filename, "w+t"); 726 727 FlPrintFile (ASL_FILE_C_OFFSET_OUTPUT, "/*\n"); 728 AslCompilerSignon (ASL_FILE_C_OFFSET_OUTPUT); 729 AslCompilerFileHeader (ASL_FILE_C_OFFSET_OUTPUT); 730 } 731 732 /* Create/Open a assembly include output file if asked */ 733 734 if (Gbl_AsmIncludeOutputFlag) 735 { 736 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_INCLUDE); 737 if (!Filename) 738 { 739 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 740 0, 0, 0, 0, NULL, NULL); 741 return (AE_ERROR); 742 } 743 744 /* Open the assembly include file, text mode */ 745 746 FlOpenFile (ASL_FILE_ASM_INCLUDE_OUTPUT, Filename, "w+t"); 747 748 AslCompilerSignon (ASL_FILE_ASM_INCLUDE_OUTPUT); 749 AslCompilerFileHeader (ASL_FILE_ASM_INCLUDE_OUTPUT); 750 } 751 752 /* Create/Open a C include output file if asked */ 753 754 if (Gbl_C_IncludeOutputFlag) 755 { 756 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_INCLUDE); 757 if (!Filename) 758 { 759 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 760 0, 0, 0, 0, NULL, NULL); 761 return (AE_ERROR); 762 } 763 764 /* Open the C include file, text mode */ 765 766 FlOpenFile (ASL_FILE_C_INCLUDE_OUTPUT, Filename, "w+t"); 767 768 FlPrintFile (ASL_FILE_C_INCLUDE_OUTPUT, "/*\n"); 769 AslCompilerSignon (ASL_FILE_C_INCLUDE_OUTPUT); 770 AslCompilerFileHeader (ASL_FILE_C_INCLUDE_OUTPUT); 771 } 772 773 /* Create a namespace output file if asked */ 774 775 if (Gbl_NsOutputFlag) 776 { 777 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_NAMESPACE); 778 if (!Filename) 779 { 780 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 781 0, 0, 0, 0, NULL, NULL); 782 return (AE_ERROR); 783 } 784 785 /* Open the namespace file, text mode */ 786 787 FlOpenFile (ASL_FILE_NAMESPACE_OUTPUT, Filename, "w+t"); 788 789 AslCompilerSignon (ASL_FILE_NAMESPACE_OUTPUT); 790 AslCompilerFileHeader (ASL_FILE_NAMESPACE_OUTPUT); 791 } 792 793 /* Create/Open a map file if requested */ 794 795 if (Gbl_MapfileFlag) 796 { 797 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_MAP); 798 if (!Filename) 799 { 800 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 801 0, 0, 0, 0, NULL, NULL); 802 return (AE_ERROR); 803 } 804 805 /* Open the hex file, text mode (closed at compiler exit) */ 806 807 FlOpenFile (ASL_FILE_MAP_OUTPUT, Filename, "w+t"); 808 809 AslCompilerSignon (ASL_FILE_MAP_OUTPUT); 810 AslCompilerFileHeader (ASL_FILE_MAP_OUTPUT); 811 } 812 813 return (AE_OK); 814 } 815 816 817 #ifdef ACPI_OBSOLETE_FUNCTIONS 818 /******************************************************************************* 819 * 820 * FUNCTION: FlParseInputPathname 821 * 822 * PARAMETERS: InputFilename - The user-specified ASL source file to be 823 * compiled 824 * 825 * RETURN: Status 826 * 827 * DESCRIPTION: Split the input path into a directory and filename part 828 * 1) Directory part used to open include files 829 * 2) Filename part used to generate output filenames 830 * 831 ******************************************************************************/ 832 833 ACPI_STATUS 834 FlParseInputPathname ( 835 char *InputFilename) 836 { 837 char *Substring; 838 839 840 if (!InputFilename) 841 { 842 return (AE_OK); 843 } 844 845 /* Get the path to the input filename's directory */ 846 847 Gbl_DirectoryPath = strdup (InputFilename); 848 if (!Gbl_DirectoryPath) 849 { 850 return (AE_NO_MEMORY); 851 } 852 853 Substring = strrchr (Gbl_DirectoryPath, '\\'); 854 if (!Substring) 855 { 856 Substring = strrchr (Gbl_DirectoryPath, '/'); 857 if (!Substring) 858 { 859 Substring = strrchr (Gbl_DirectoryPath, ':'); 860 } 861 } 862 863 if (!Substring) 864 { 865 Gbl_DirectoryPath[0] = 0; 866 if (Gbl_UseDefaultAmlFilename) 867 { 868 Gbl_OutputFilenamePrefix = strdup (InputFilename); 869 } 870 } 871 else 872 { 873 if (Gbl_UseDefaultAmlFilename) 874 { 875 Gbl_OutputFilenamePrefix = strdup (Substring + 1); 876 } 877 *(Substring+1) = 0; 878 } 879 880 UtConvertBackslashes (Gbl_OutputFilenamePrefix); 881 return (AE_OK); 882 } 883 #endif 884