aslfiles.c revision 228110
1118611Snjl 2118611Snjl/****************************************************************************** 3118611Snjl * 4118611Snjl * Module Name: aslfiles - file I/O suppoert 5151937Sjkim * 6118611Snjl *****************************************************************************/ 7118611Snjl 8118611Snjl/* 9118611Snjl * Copyright (C) 2000 - 2011, Intel Corp. 10118611Snjl * All rights reserved. 11118611Snjl * 12118611Snjl * Redistribution and use in source and binary forms, with or without 13151937Sjkim * modification, are permitted provided that the following conditions 14118611Snjl * are met: 15118611Snjl * 1. Redistributions of source code must retain the above copyright 16118611Snjl * notice, this list of conditions, and the following disclaimer, 17118611Snjl * without modification. 18118611Snjl * 2. Redistributions in binary form must reproduce at minimum a disclaimer 19118611Snjl * substantially similar to the "NO WARRANTY" disclaimer below 20118611Snjl * ("Disclaimer") and any redistribution must be conditioned upon 21118611Snjl * including a substantially similar Disclaimer requirement for further 22118611Snjl * binary redistribution. 23118611Snjl * 3. Neither the names of the above-listed copyright holders nor the names 24118611Snjl * of any contributors may be used to endorse or promote products derived 25118611Snjl * from this software without specific prior written permission. 26118611Snjl * 27118611Snjl * Alternatively, this software may be distributed under the terms of the 28118611Snjl * GNU General Public License ("GPL") version 2 as published by the Free 29118611Snjl * Software Foundation. 30118611Snjl * 31118611Snjl * NO WARRANTY 32118611Snjl * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 33118611Snjl * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34118611Snjl * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 35118611Snjl * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 36118611Snjl * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 37118611Snjl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 38118611Snjl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 39118611Snjl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 40118611Snjl * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 41118611Snjl * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 42118611Snjl * POSSIBILITY OF SUCH DAMAGES. 43118611Snjl */ 44118611Snjl 45118611Snjl#include <contrib/dev/acpica/compiler/aslcompiler.h> 46118611Snjl#include <contrib/dev/acpica/include/acapps.h> 47118611Snjl 48118611Snjl#define _COMPONENT ACPI_COMPILER 49118611Snjl ACPI_MODULE_NAME ("aslfiles") 50118611Snjl 51118611Snjl/* Local prototypes */ 52118611Snjl 53118611Snjlstatic FILE * 54118611SnjlFlOpenIncludeWithPrefix ( 55118611Snjl char *PrefixDir, 56118611Snjl char *Filename); 57118611Snjl 58118611Snjl 59118611Snjl#ifdef ACPI_OBSOLETE_FUNCTIONS 60118611SnjlACPI_STATUS 61118611SnjlFlParseInputPathname ( 62118611Snjl char *InputFilename); 63118611Snjl#endif 64118611Snjl 65118611Snjl 66118611Snjl/******************************************************************************* 67118611Snjl * 68118611Snjl * FUNCTION: AslAbort 69118611Snjl * 70118611Snjl * PARAMETERS: None 71118611Snjl * 72118611Snjl * RETURN: None 73118611Snjl * 74118611Snjl * DESCRIPTION: Dump the error log and abort the compiler. Used for serious 75118611Snjl * I/O errors 76118611Snjl * 77118611Snjl ******************************************************************************/ 78118611Snjl 79118611Snjlvoid 80118611SnjlAslAbort ( 81118611Snjl void) 82118611Snjl{ 83118611Snjl 84118611Snjl AePrintErrorLog (ASL_FILE_STDOUT); 85118611Snjl if (Gbl_DebugFlag) 86118611Snjl { 87118611Snjl /* Print error summary to the debug file */ 88118611Snjl 89118611Snjl AePrintErrorLog (ASL_FILE_STDERR); 90118611Snjl } 91118611Snjl 92118611Snjl exit (1); 93118611Snjl} 94118611Snjl 95118611Snjl 96118611Snjl/******************************************************************************* 97118611Snjl * 98118611Snjl * FUNCTION: FlFileError 99118611Snjl * 100118611Snjl * PARAMETERS: FileId - Index into file info array 101118611Snjl * ErrorId - Index into error message array 102118611Snjl * 103118611Snjl * RETURN: None 104118611Snjl * 105118611Snjl * DESCRIPTION: Decode errno to an error message and add the entire error 106118611Snjl * to the error log. 107118611Snjl * 108118611Snjl ******************************************************************************/ 109118611Snjl 110118611Snjlvoid 111118611SnjlFlFileError ( 112118611Snjl UINT32 FileId, 113118611Snjl UINT8 ErrorId) 114118611Snjl{ 115118611Snjl 116118611Snjl sprintf (MsgBuffer, "\"%s\" (%s)", Gbl_Files[FileId].Filename, 117118611Snjl strerror (errno)); 118151937Sjkim AslCommonError (ASL_ERROR, ErrorId, 0, 0, 0, 0, NULL, MsgBuffer); 119151937Sjkim} 120118611Snjl 121118611Snjl 122118611Snjl/******************************************************************************* 123118611Snjl * 124151937Sjkim * FUNCTION: FlOpenFile 125118611Snjl * 126151937Sjkim * PARAMETERS: FileId - Index into file info array 127151937Sjkim * Filename - file pathname to open 128151937Sjkim * Mode - Open mode for fopen 129151937Sjkim * 130151937Sjkim * RETURN: None 131151937Sjkim * 132151937Sjkim * DESCRIPTION: Open a file. 133151937Sjkim * NOTE: Aborts compiler on any error. 134151937Sjkim * 135151937Sjkim ******************************************************************************/ 136151937Sjkim 137151937Sjkimvoid 138151937SjkimFlOpenFile ( 139151937Sjkim UINT32 FileId, 140151937Sjkim char *Filename, 141151937Sjkim char *Mode) 142151937Sjkim{ 143151937Sjkim FILE *File; 144118611Snjl 145118611Snjl 146118611Snjl File = fopen (Filename, Mode); 147118611Snjl 148118611Snjl Gbl_Files[FileId].Filename = Filename; 149118611Snjl Gbl_Files[FileId].Handle = File; 150118611Snjl 151118611Snjl if (!File) 152118611Snjl { 153118611Snjl FlFileError (FileId, ASL_MSG_OPEN); 154118611Snjl AslAbort (); 155118611Snjl } 156118611Snjl} 157118611Snjl 158151937Sjkim 159151937Sjkim/******************************************************************************* 160118611Snjl * 161118611Snjl * FUNCTION: FlGetFileSize 162118611Snjl * 163118611Snjl * PARAMETERS: FileId - Index into file info array 164118611Snjl * 165118611Snjl * RETURN: File Size 166118611Snjl * 167118611Snjl * DESCRIPTION: Get current file size. Uses seek-to-EOF. File must be open. 168118611Snjl * 169118611Snjl ******************************************************************************/ 170151937Sjkim 171118611SnjlUINT32 172118611SnjlFlGetFileSize ( 173118611Snjl UINT32 FileId) 174118611Snjl{ 175118611Snjl FILE *fp; 176118611Snjl UINT32 FileSize; 177118611Snjl long Offset; 178118611Snjl 179118611Snjl 180118611Snjl fp = Gbl_Files[FileId].Handle; 181118611Snjl Offset = ftell (fp); 182118611Snjl 183118611Snjl fseek (fp, 0, SEEK_END); 184118611Snjl FileSize = (UINT32) ftell (fp); 185118611Snjl 186118611Snjl /* Restore file pointer */ 187118611Snjl 188151937Sjkim fseek (fp, Offset, SEEK_SET); 189118611Snjl return (FileSize); 190118611Snjl} 191118611Snjl 192118611Snjl 193118611Snjl/******************************************************************************* 194118611Snjl * 195118611Snjl * FUNCTION: FlReadFile 196118611Snjl * 197118611Snjl * PARAMETERS: FileId - Index into file info array 198118611Snjl * Buffer - Where to place the data 199118611Snjl * Length - Amount to read 200118611Snjl * 201118611Snjl * RETURN: Status. AE_ERROR indicates EOF. 202118611Snjl * 203118611Snjl * DESCRIPTION: Read data from an open file. 204118611Snjl * NOTE: Aborts compiler on any error. 205118611Snjl * 206118611Snjl ******************************************************************************/ 207118611Snjl 208118611SnjlACPI_STATUS 209118611SnjlFlReadFile ( 210118611Snjl UINT32 FileId, 211118611Snjl void *Buffer, 212118611Snjl UINT32 Length) 213118611Snjl{ 214118611Snjl UINT32 Actual; 215118611Snjl 216118611Snjl 217118611Snjl /* Read and check for error */ 218118611Snjl 219118611Snjl Actual = fread (Buffer, 1, Length, Gbl_Files[FileId].Handle); 220118611Snjl if (Actual != Length) 221118611Snjl { 222151937Sjkim if (feof (Gbl_Files[FileId].Handle)) 223151937Sjkim { 224118611Snjl /* End-of-file, just return error */ 225118611Snjl 226118611Snjl return (AE_ERROR); 227118611Snjl } 228118611Snjl 229118611Snjl FlFileError (FileId, ASL_MSG_READ); 230118611Snjl AslAbort (); 231118611Snjl } 232118611Snjl 233118611Snjl return (AE_OK); 234118611Snjl} 235118611Snjl 236151937Sjkim 237118611Snjl/******************************************************************************* 238118611Snjl * 239118611Snjl * FUNCTION: FlWriteFile 240118611Snjl * 241118611Snjl * PARAMETERS: FileId - Index into file info array 242118611Snjl * Buffer - Data to write 243151937Sjkim * Length - Amount of data to write 244118611Snjl * 245118611Snjl * RETURN: None 246118611Snjl * 247118611Snjl * DESCRIPTION: Write data to an open file. 248118611Snjl * NOTE: Aborts compiler on any error. 249118611Snjl * 250118611Snjl ******************************************************************************/ 251118611Snjl 252118611Snjlvoid 253118611SnjlFlWriteFile ( 254118611Snjl UINT32 FileId, 255118611Snjl void *Buffer, 256118611Snjl UINT32 Length) 257118611Snjl{ 258118611Snjl UINT32 Actual; 259118611Snjl 260118611Snjl 261118611Snjl /* Write and check for error */ 262118611Snjl 263118611Snjl Actual = fwrite ((char *) Buffer, 1, Length, Gbl_Files[FileId].Handle); 264118611Snjl if (Actual != Length) 265118611Snjl { 266118611Snjl FlFileError (FileId, ASL_MSG_WRITE); 267118611Snjl AslAbort (); 268118611Snjl } 269118611Snjl} 270118611Snjl 271118611Snjl 272118611Snjl/******************************************************************************* 273118611Snjl * 274118611Snjl * FUNCTION: FlPrintFile 275118611Snjl * 276118611Snjl * PARAMETERS: FileId - Index into file info array 277118611Snjl * Format - Printf format string 278118611Snjl * ... - Printf arguments 279118611Snjl * 280118611Snjl * RETURN: None 281118611Snjl * 282118611Snjl * DESCRIPTION: Formatted write to an open file. 283118611Snjl * NOTE: Aborts compiler on any error. 284118611Snjl * 285118611Snjl ******************************************************************************/ 286118611Snjl 287118611Snjlvoid 288118611SnjlFlPrintFile ( 289118611Snjl UINT32 FileId, 290118611Snjl char *Format, 291118611Snjl ...) 292118611Snjl{ 293118611Snjl INT32 Actual; 294118611Snjl va_list Args; 295118611Snjl 296118611Snjl 297118611Snjl va_start (Args, Format); 298118611Snjl 299118611Snjl Actual = vfprintf (Gbl_Files[FileId].Handle, Format, Args); 300118611Snjl va_end (Args); 301118611Snjl 302118611Snjl if (Actual == -1) 303118611Snjl { 304118611Snjl FlFileError (FileId, ASL_MSG_WRITE); 305118611Snjl AslAbort (); 306118611Snjl } 307118611Snjl} 308118611Snjl 309118611Snjl 310118611Snjl/******************************************************************************* 311118611Snjl * 312118611Snjl * FUNCTION: FlSeekFile 313118611Snjl * 314118611Snjl * PARAMETERS: FileId - Index into file info array 315118611Snjl * Offset - Absolute byte offset in file 316118611Snjl * 317151937Sjkim * RETURN: None 318118611Snjl * 319118611Snjl * DESCRIPTION: Seek to absolute offset 320118611Snjl * NOTE: Aborts compiler on any error. 321118611Snjl * 322118611Snjl ******************************************************************************/ 323118611Snjl 324118611Snjlvoid 325118611SnjlFlSeekFile ( 326118611Snjl UINT32 FileId, 327118611Snjl long Offset) 328118611Snjl{ 329118611Snjl int Error; 330118611Snjl 331118611Snjl 332118611Snjl Error = fseek (Gbl_Files[FileId].Handle, Offset, SEEK_SET); 333118611Snjl if (Error) 334118611Snjl { 335118611Snjl FlFileError (FileId, ASL_MSG_SEEK); 336118611Snjl AslAbort (); 337118611Snjl } 338118611Snjl} 339118611Snjl 340118611Snjl 341118611Snjl/******************************************************************************* 342118611Snjl * 343118611Snjl * FUNCTION: FlCloseFile 344118611Snjl * 345118611Snjl * PARAMETERS: FileId - Index into file info array 346118611Snjl * 347118611Snjl * RETURN: None 348118611Snjl * 349118611Snjl * DESCRIPTION: Close an open file. Aborts compiler on error 350118611Snjl * 351118611Snjl ******************************************************************************/ 352118611Snjl 353118611Snjlvoid 354118611SnjlFlCloseFile ( 355118611Snjl UINT32 FileId) 356118611Snjl{ 357118611Snjl int Error; 358118611Snjl 359118611Snjl 360118611Snjl if (!Gbl_Files[FileId].Handle) 361118611Snjl { 362118611Snjl return; 363118611Snjl } 364118611Snjl 365118611Snjl Error = fclose (Gbl_Files[FileId].Handle); 366118611Snjl Gbl_Files[FileId].Handle = NULL; 367118611Snjl 368118611Snjl if (Error) 369118611Snjl { 370118611Snjl FlFileError (FileId, ASL_MSG_CLOSE); 371118611Snjl AslAbort (); 372118611Snjl } 373118611Snjl 374118611Snjl return; 375118611Snjl} 376118611Snjl 377118611Snjl 378118611Snjl/******************************************************************************* 379118611Snjl * 380118611Snjl * FUNCTION: FlSetLineNumber 381118611Snjl * 382118611Snjl * PARAMETERS: Op - Parse node for the LINE asl statement 383118611Snjl * 384118611Snjl * RETURN: None. 385118611Snjl * 386118611Snjl * DESCRIPTION: Set the current line number 387151937Sjkim * 388118611Snjl ******************************************************************************/ 389118611Snjl 390118611Snjlvoid 391118611SnjlFlSetLineNumber ( 392118611Snjl ACPI_PARSE_OBJECT *Op) 393118611Snjl{ 394118611Snjl 395118611Snjl Gbl_CurrentLineNumber = (UINT32) Op->Asl.Value.Integer; 396118611Snjl Gbl_LogicalLineNumber = (UINT32) Op->Asl.Value.Integer; 397118611Snjl} 398118611Snjl 399118611Snjl 400118611Snjl/******************************************************************************* 401118611Snjl * 402118611Snjl * FUNCTION: FlAddIncludeDirectory 403118611Snjl * 404118611Snjl * PARAMETERS: Dir - Directory pathname string 405118611Snjl * 406118611Snjl * RETURN: None 407118611Snjl * 408118611Snjl * DESCRIPTION: Add a directory the list of include prefix directories. 409118611Snjl * 410118611Snjl ******************************************************************************/ 411118611Snjl 412118611Snjlvoid 413118611SnjlFlAddIncludeDirectory ( 414118611Snjl char *Dir) 415118611Snjl{ 416118611Snjl ASL_INCLUDE_DIR *NewDir; 417151937Sjkim ASL_INCLUDE_DIR *NextDir; 418118611Snjl ASL_INCLUDE_DIR *PrevDir = NULL; 419118611Snjl UINT32 NeedsSeparator = 0; 420118611Snjl size_t DirLength; 421118611Snjl 422118611Snjl 423118611Snjl DirLength = strlen (Dir); 424118611Snjl if (!DirLength) 425118611Snjl { 426118611Snjl return; 427118611Snjl } 428118611Snjl 429118611Snjl /* Make sure that the pathname ends with a path separator */ 430118611Snjl 431118611Snjl if ((Dir[DirLength-1] != '/') && 432118611Snjl (Dir[DirLength-1] != '\\')) 433118611Snjl { 434118611Snjl NeedsSeparator = 1; 435118611Snjl } 436118611Snjl 437118611Snjl NewDir = ACPI_ALLOCATE_ZEROED (sizeof (ASL_INCLUDE_DIR)); 438118611Snjl NewDir->Dir = ACPI_ALLOCATE (DirLength + 1 + NeedsSeparator); 439118611Snjl strcpy (NewDir->Dir, Dir); 440118611Snjl if (NeedsSeparator) 441118611Snjl { 442118611Snjl strcat (NewDir->Dir, "/"); 443118611Snjl } 444118611Snjl 445118611Snjl /* 446118611Snjl * Preserve command line ordering of -I options by adding new elements 447118611Snjl * at the end of the list 448118611Snjl */ 449118611Snjl NextDir = Gbl_IncludeDirList; 450118611Snjl while (NextDir) 451118611Snjl { 452118611Snjl PrevDir = NextDir; 453118611Snjl NextDir = NextDir->Next; 454118611Snjl } 455118611Snjl 456118611Snjl if (PrevDir) 457118611Snjl { 458118611Snjl PrevDir->Next = NewDir; 459118611Snjl } 460118611Snjl else 461118611Snjl { 462118611Snjl Gbl_IncludeDirList = NewDir; 463118611Snjl } 464118611Snjl} 465118611Snjl 466118611Snjl 467118611Snjl/******************************************************************************* 468118611Snjl * 469118611Snjl * FUNCTION: FlOpenIncludeWithPrefix 470118611Snjl * 471118611Snjl * PARAMETERS: PrefixDir - Prefix directory pathname. Can be a zero 472118611Snjl * length string. 473118611Snjl * Filename - The include filename from the source ASL. 474118611Snjl * 475118611Snjl * RETURN: Valid file descriptor if successful. Null otherwise. 476118611Snjl * 477118611Snjl * DESCRIPTION: Open an include file and push it on the input file stack. 478118611Snjl * 479118611Snjl ******************************************************************************/ 480118611Snjl 481118611Snjlstatic FILE * 482118611SnjlFlOpenIncludeWithPrefix ( 483118611Snjl char *PrefixDir, 484118611Snjl char *Filename) 485118611Snjl{ 486118611Snjl FILE *IncludeFile; 487118611Snjl char *Pathname; 488118611Snjl 489118611Snjl 490118611Snjl /* Build the full pathname to the file */ 491118611Snjl 492118611Snjl Pathname = ACPI_ALLOCATE (strlen (PrefixDir) + strlen (Filename) + 1); 493118611Snjl 494118611Snjl strcpy (Pathname, PrefixDir); 495118611Snjl strcat (Pathname, Filename); 496118611Snjl 497118611Snjl DbgPrint (ASL_PARSE_OUTPUT, "\nAttempt to open include file: path %s\n\n", 498118611Snjl Pathname); 499118611Snjl 500118611Snjl /* Attempt to open the file, push if successful */ 501118611Snjl 502118611Snjl IncludeFile = fopen (Pathname, "r"); 503118611Snjl if (IncludeFile) 504118611Snjl { 505118611Snjl /* Push the include file on the open input file stack */ 506118611Snjl 507118611Snjl AslPushInputFileStack (IncludeFile, Pathname); 508118611Snjl return (IncludeFile); 509118611Snjl } 510118611Snjl 511151937Sjkim ACPI_FREE (Pathname); 512151937Sjkim return (NULL); 513118611Snjl} 514118611Snjl 515118611Snjl 516118611Snjl/******************************************************************************* 517118611Snjl * 518118611Snjl * FUNCTION: FlOpenIncludeFile 519118611Snjl * 520118611Snjl * PARAMETERS: Op - Parse node for the INCLUDE ASL statement 521118611Snjl * 522118611Snjl * RETURN: None. 523118611Snjl * 524118611Snjl * DESCRIPTION: Open an include file and push it on the input file stack. 525118611Snjl * 526118611Snjl ******************************************************************************/ 527118611Snjl 528118611Snjlvoid 529118611SnjlFlOpenIncludeFile ( 530118611Snjl ACPI_PARSE_OBJECT *Op) 531118611Snjl{ 532118611Snjl FILE *IncludeFile; 533118611Snjl ASL_INCLUDE_DIR *NextDir; 534118611Snjl 535118611Snjl 536118611Snjl /* Op must be valid */ 537118611Snjl 538118611Snjl if (!Op) 539118611Snjl { 540118611Snjl AslCommonError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, 541118611Snjl Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, 542118611Snjl Gbl_InputByteCount, Gbl_CurrentColumn, 543118611Snjl Gbl_Files[ASL_FILE_INPUT].Filename, " - Null parse node"); 544118611Snjl 545118611Snjl return; 546118611Snjl } 547118611Snjl 548118611Snjl /* 549118611Snjl * Flush out the "include ()" statement on this line, start 550118611Snjl * the actual include file on the next line 551118611Snjl */ 552118611Snjl ResetCurrentLineBuffer (); 553118611Snjl FlPrintFile (ASL_FILE_SOURCE_OUTPUT, "\n"); 554118611Snjl Gbl_CurrentLineOffset++; 555118611Snjl 556118611Snjl 557118611Snjl /* Attempt to open the include file */ 558118611Snjl 559118611Snjl /* If the file specifies an absolute path, just open it */ 560118611Snjl 561118611Snjl if ((Op->Asl.Value.String[0] == '/') || 562118611Snjl (Op->Asl.Value.String[0] == '\\') || 563118611Snjl (Op->Asl.Value.String[1] == ':')) 564118611Snjl { 565118611Snjl IncludeFile = FlOpenIncludeWithPrefix ("", Op->Asl.Value.String); 566118611Snjl if (!IncludeFile) 567118611Snjl { 568118611Snjl goto ErrorExit; 569118611Snjl } 570118611Snjl return; 571118611Snjl } 572118611Snjl 573118611Snjl /* 574118611Snjl * The include filename is not an absolute path. 575118611Snjl * 576118611Snjl * First, search for the file within the "local" directory -- meaning 577118611Snjl * the same directory that contains the source file. 578118611Snjl * 579118611Snjl * Construct the file pathname from the global directory name. 580118611Snjl */ 581118611Snjl IncludeFile = FlOpenIncludeWithPrefix (Gbl_DirectoryPath, Op->Asl.Value.String); 582118611Snjl if (IncludeFile) 583118611Snjl { 584118611Snjl return; 585118611Snjl } 586151937Sjkim 587151937Sjkim /* 588118611Snjl * Second, search for the file within the (possibly multiple) directories 589118611Snjl * specified by the -I option on the command line. 590118611Snjl */ 591118611Snjl NextDir = Gbl_IncludeDirList; 592118611Snjl while (NextDir) 593118611Snjl { 594118611Snjl IncludeFile = FlOpenIncludeWithPrefix (NextDir->Dir, Op->Asl.Value.String); 595118611Snjl if (IncludeFile) 596118611Snjl { 597118611Snjl return; 598118611Snjl } 599118611Snjl 600118611Snjl NextDir = NextDir->Next; 601118611Snjl } 602118611Snjl 603118611Snjl /* We could not open the include file after trying very hard */ 604118611Snjl 605118611SnjlErrorExit: 606118611Snjl sprintf (MsgBuffer, "%s, %s", Op->Asl.Value.String, strerror (errno)); 607118611Snjl AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, Op, MsgBuffer); 608118611Snjl} 609118611Snjl 610118611Snjl 611118611Snjl/******************************************************************************* 612118611Snjl * 613118611Snjl * FUNCTION: FlOpenInputFile 614118611Snjl * 615118611Snjl * PARAMETERS: InputFilename - The user-specified ASL source file to be 616118611Snjl * compiled 617118611Snjl * 618118611Snjl * RETURN: Status 619118611Snjl * 620118611Snjl * DESCRIPTION: Open the specified input file, and save the directory path to 621118611Snjl * the file so that include files can be opened in 622118611Snjl * the same directory. 623118611Snjl * 624151937Sjkim ******************************************************************************/ 625151937Sjkim 626118611SnjlACPI_STATUS 627118611SnjlFlOpenInputFile ( 628118611Snjl char *InputFilename) 629118611Snjl{ 630118611Snjl 631118611Snjl /* Open the input ASL file, text mode */ 632118611Snjl 633118611Snjl FlOpenFile (ASL_FILE_INPUT, InputFilename, "r"); 634118611Snjl AslCompilerin = Gbl_Files[ASL_FILE_INPUT].Handle; 635118611Snjl 636118611Snjl return (AE_OK); 637118611Snjl} 638118611Snjl 639118611Snjl 640118611Snjl/******************************************************************************* 641118611Snjl * 642118611Snjl * FUNCTION: FlOpenAmlOutputFile 643151937Sjkim * 644151937Sjkim * PARAMETERS: FilenamePrefix - The user-specified ASL source file 645118611Snjl * 646118611Snjl * RETURN: Status 647118611Snjl * 648118611Snjl * DESCRIPTION: Create the output filename (*.AML) and open the file. The file 649118611Snjl * is created in the same directory as the parent input file. 650118611Snjl * 651118611Snjl ******************************************************************************/ 652118611Snjl 653118611SnjlACPI_STATUS 654118611SnjlFlOpenAmlOutputFile ( 655118611Snjl char *FilenamePrefix) 656118611Snjl{ 657118611Snjl char *Filename; 658118611Snjl 659118611Snjl 660118611Snjl /* Output filename usually comes from the ASL itself */ 661118611Snjl 662118611Snjl Filename = Gbl_Files[ASL_FILE_AML_OUTPUT].Filename; 663151937Sjkim if (!Filename) 664151937Sjkim { 665118611Snjl /* Create the output AML filename */ 666118611Snjl 667118611Snjl Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_AML_CODE); 668118611Snjl if (!Filename) 669118611Snjl { 670118611Snjl AslCommonError (ASL_ERROR, ASL_MSG_OUTPUT_FILENAME, 671118611Snjl 0, 0, 0, 0, NULL, NULL); 672118611Snjl return (AE_ERROR); 673118611Snjl } 674118611Snjl } 675118611Snjl 676118611Snjl /* Open the output AML file in binary mode */ 677118611Snjl 678118611Snjl FlOpenFile (ASL_FILE_AML_OUTPUT, Filename, "w+b"); 679118611Snjl return (AE_OK); 680118611Snjl} 681118611Snjl 682118611Snjl 683151937Sjkim/******************************************************************************* 684151937Sjkim * 685118611Snjl * FUNCTION: FlOpenMiscOutputFiles 686118611Snjl * 687118611Snjl * PARAMETERS: FilenamePrefix - The user-specified ASL source file 688118611Snjl * 689118611Snjl * RETURN: Status 690118611Snjl * 691118611Snjl * DESCRIPTION: Create and open the various output files needed, depending on 692118611Snjl * the command line options 693118611Snjl * 694118611Snjl ******************************************************************************/ 695118611Snjl 696118611SnjlACPI_STATUS 697118611SnjlFlOpenMiscOutputFiles ( 698118611Snjl char *FilenamePrefix) 699118611Snjl{ 700118611Snjl char *Filename; 701118611Snjl 702118611Snjl 703118611Snjl /* Create/Open a hex output file if asked */ 704151937Sjkim 705151937Sjkim if (Gbl_HexOutputFlag) 706118611Snjl { 707118611Snjl Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_HEX_DUMP); 708118611Snjl if (!Filename) 709118611Snjl { 710118611Snjl AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 711118611Snjl 0, 0, 0, 0, NULL, NULL); 712118611Snjl return (AE_ERROR); 713118611Snjl } 714118611Snjl 715118611Snjl /* Open the hex file, text mode */ 716118611Snjl 717118611Snjl FlOpenFile (ASL_FILE_HEX_OUTPUT, Filename, "w+"); 718118611Snjl 719118611Snjl AslCompilerSignon (ASL_FILE_HEX_OUTPUT); 720118611Snjl AslCompilerFileHeader (ASL_FILE_HEX_OUTPUT); 721118611Snjl } 722118611Snjl 723118611Snjl /* Create/Open a debug output file if asked */ 724151937Sjkim 725151937Sjkim if (Gbl_DebugFlag) 726118611Snjl { 727118611Snjl Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_DEBUG); 728118611Snjl if (!Filename) 729118611Snjl { 730118611Snjl AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME, 731118611Snjl 0, 0, 0, 0, NULL, NULL); 732118611Snjl return (AE_ERROR); 733118611Snjl } 734118611Snjl 735118611Snjl /* Open the debug file as STDERR, text mode */ 736118611Snjl 737118611Snjl /* TBD: hide this behind a FlReopenFile function */ 738118611Snjl 739118611Snjl Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Filename = Filename; 740118611Snjl Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle = 741118611Snjl freopen (Filename, "w+t", stderr); 742118611Snjl 743118611Snjl AslCompilerSignon (ASL_FILE_DEBUG_OUTPUT); 744118611Snjl AslCompilerFileHeader (ASL_FILE_DEBUG_OUTPUT); 745151937Sjkim } 746151937Sjkim 747118611Snjl /* Create/Open a listing output file if asked */ 748118611Snjl 749118611Snjl if (Gbl_ListingFlag) 750118611Snjl { 751118611Snjl Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_LISTING); 752118611Snjl if (!Filename) 753118611Snjl { 754118611Snjl AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 755118611Snjl 0, 0, 0, 0, NULL, NULL); 756118611Snjl return (AE_ERROR); 757118611Snjl } 758118611Snjl 759118611Snjl /* Open the listing file, text mode */ 760118611Snjl 761118611Snjl FlOpenFile (ASL_FILE_LISTING_OUTPUT, Filename, "w+"); 762118611Snjl 763118611Snjl AslCompilerSignon (ASL_FILE_LISTING_OUTPUT); 764118611Snjl AslCompilerFileHeader (ASL_FILE_LISTING_OUTPUT); 765151937Sjkim } 766151937Sjkim 767118611Snjl if (Gbl_FileType == ASL_INPUT_TYPE_ASCII_DATA) 768118611Snjl { 769118611Snjl return (AE_OK); 770118611Snjl } 771118611Snjl 772118611Snjl /* Create/Open a combined source output file */ 773118611Snjl 774118611Snjl Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_SOURCE); 775118611Snjl if (!Filename) 776118611Snjl { 777118611Snjl AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 778118611Snjl 0, 0, 0, 0, NULL, NULL); 779118611Snjl return (AE_ERROR); 780118611Snjl } 781118611Snjl 782118611Snjl /* 783118611Snjl * Open the source output file, binary mode (so that LF does not get 784118611Snjl * expanded to CR/LF on some systems, messing up our seek 785151937Sjkim * calculations.) 786151937Sjkim */ 787118611Snjl FlOpenFile (ASL_FILE_SOURCE_OUTPUT, Filename, "w+b"); 788118611Snjl 789118611Snjl /* Create/Open a assembly code source output file if asked */ 790118611Snjl 791118611Snjl if (Gbl_AsmOutputFlag) 792118611Snjl { 793118611Snjl Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_SOURCE); 794118611Snjl if (!Filename) 795151937Sjkim { 796151937Sjkim AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 797118611Snjl 0, 0, 0, 0, NULL, NULL); 798118611Snjl return (AE_ERROR); 799118611Snjl } 800118611Snjl 801118611Snjl /* Open the assembly code source file, text mode */ 802118611Snjl 803118611Snjl FlOpenFile (ASL_FILE_ASM_SOURCE_OUTPUT, Filename, "w+"); 804118611Snjl 805118611Snjl AslCompilerSignon (ASL_FILE_ASM_SOURCE_OUTPUT); 806151937Sjkim AslCompilerFileHeader (ASL_FILE_ASM_SOURCE_OUTPUT); 807151937Sjkim } 808151937Sjkim 809151937Sjkim /* Create/Open a C code source output file if asked */ 810151937Sjkim 811151937Sjkim if (Gbl_C_OutputFlag) 812151937Sjkim { 813151937Sjkim Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_SOURCE); 814151937Sjkim if (!Filename) 815151937Sjkim { 816151937Sjkim AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 817151937Sjkim 0, 0, 0, 0, NULL, NULL); 818151937Sjkim return (AE_ERROR); 819151937Sjkim } 820151937Sjkim 821151937Sjkim /* Open the C code source file, text mode */ 822151937Sjkim 823151937Sjkim FlOpenFile (ASL_FILE_C_SOURCE_OUTPUT, Filename, "w+"); 824151937Sjkim 825151937Sjkim FlPrintFile (ASL_FILE_C_SOURCE_OUTPUT, "/*\n"); 826151937Sjkim AslCompilerSignon (ASL_FILE_C_SOURCE_OUTPUT); 827151937Sjkim AslCompilerFileHeader (ASL_FILE_C_SOURCE_OUTPUT); 828151937Sjkim } 829151937Sjkim 830151937Sjkim /* Create/Open a assembly include output file if asked */ 831151937Sjkim 832151937Sjkim if (Gbl_AsmIncludeOutputFlag) 833151937Sjkim { 834151937Sjkim Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_INCLUDE); 835151937Sjkim if (!Filename) 836151937Sjkim { 837151937Sjkim AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 838151937Sjkim 0, 0, 0, 0, NULL, NULL); 839151937Sjkim return (AE_ERROR); 840151937Sjkim } 841151937Sjkim 842151937Sjkim /* Open the assembly include file, text mode */ 843151937Sjkim 844151937Sjkim FlOpenFile (ASL_FILE_ASM_INCLUDE_OUTPUT, Filename, "w+"); 845151937Sjkim 846151937Sjkim AslCompilerSignon (ASL_FILE_ASM_INCLUDE_OUTPUT); 847151937Sjkim AslCompilerFileHeader (ASL_FILE_ASM_INCLUDE_OUTPUT); 848151937Sjkim } 849151937Sjkim 850151937Sjkim /* Create/Open a C include output file if asked */ 851151937Sjkim 852151937Sjkim if (Gbl_C_IncludeOutputFlag) 853151937Sjkim { 854151937Sjkim Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_INCLUDE); 855151937Sjkim if (!Filename) 856151937Sjkim { 857151937Sjkim AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 858151937Sjkim 0, 0, 0, 0, NULL, NULL); 859151937Sjkim return (AE_ERROR); 860151937Sjkim } 861151937Sjkim 862151937Sjkim /* Open the C include file, text mode */ 863151937Sjkim 864151937Sjkim FlOpenFile (ASL_FILE_C_INCLUDE_OUTPUT, Filename, "w+"); 865151937Sjkim 866151937Sjkim FlPrintFile (ASL_FILE_C_INCLUDE_OUTPUT, "/*\n"); 867151937Sjkim AslCompilerSignon (ASL_FILE_C_INCLUDE_OUTPUT); 868151937Sjkim AslCompilerFileHeader (ASL_FILE_C_INCLUDE_OUTPUT); 869151937Sjkim } 870151937Sjkim 871151937Sjkim /* Create a namespace output file if asked */ 872151937Sjkim 873151937Sjkim if (Gbl_NsOutputFlag) 874 { 875 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_NAMESPACE); 876 if (!Filename) 877 { 878 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 879 0, 0, 0, 0, NULL, NULL); 880 return (AE_ERROR); 881 } 882 883 /* Open the namespace file, text mode */ 884 885 FlOpenFile (ASL_FILE_NAMESPACE_OUTPUT, Filename, "w+"); 886 887 AslCompilerSignon (ASL_FILE_NAMESPACE_OUTPUT); 888 AslCompilerFileHeader (ASL_FILE_NAMESPACE_OUTPUT); 889 } 890 891 return (AE_OK); 892} 893 894 895#ifdef ACPI_OBSOLETE_FUNCTIONS 896/******************************************************************************* 897 * 898 * FUNCTION: FlParseInputPathname 899 * 900 * PARAMETERS: InputFilename - The user-specified ASL source file to be 901 * compiled 902 * 903 * RETURN: Status 904 * 905 * DESCRIPTION: Split the input path into a directory and filename part 906 * 1) Directory part used to open include files 907 * 2) Filename part used to generate output filenames 908 * 909 ******************************************************************************/ 910 911ACPI_STATUS 912FlParseInputPathname ( 913 char *InputFilename) 914{ 915 char *Substring; 916 917 918 if (!InputFilename) 919 { 920 return (AE_OK); 921 } 922 923 /* Get the path to the input filename's directory */ 924 925 Gbl_DirectoryPath = strdup (InputFilename); 926 if (!Gbl_DirectoryPath) 927 { 928 return (AE_NO_MEMORY); 929 } 930 931 Substring = strrchr (Gbl_DirectoryPath, '\\'); 932 if (!Substring) 933 { 934 Substring = strrchr (Gbl_DirectoryPath, '/'); 935 if (!Substring) 936 { 937 Substring = strrchr (Gbl_DirectoryPath, ':'); 938 } 939 } 940 941 if (!Substring) 942 { 943 Gbl_DirectoryPath[0] = 0; 944 if (Gbl_UseDefaultAmlFilename) 945 { 946 Gbl_OutputFilenamePrefix = strdup (InputFilename); 947 } 948 } 949 else 950 { 951 if (Gbl_UseDefaultAmlFilename) 952 { 953 Gbl_OutputFilenamePrefix = strdup (Substring + 1); 954 } 955 *(Substring+1) = 0; 956 } 957 958 return (AE_OK); 959} 960#endif 961 962 963