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