1118611Snjl 2118611Snjl/****************************************************************************** 3118611Snjl * 4118611Snjl * Module Name: aslfiles - file I/O suppoert 5118611Snjl * 6118611Snjl *****************************************************************************/ 7118611Snjl 8217365Sjkim/* 9217365Sjkim * Copyright (C) 2000 - 2011, Intel Corp. 10118611Snjl * All rights reserved. 11118611Snjl * 12217365Sjkim * Redistribution and use in source and binary forms, with or without 13217365Sjkim * modification, are permitted provided that the following conditions 14217365Sjkim * are met: 15217365Sjkim * 1. Redistributions of source code must retain the above copyright 16217365Sjkim * notice, this list of conditions, and the following disclaimer, 17217365Sjkim * without modification. 18217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 19217365Sjkim * substantially similar to the "NO WARRANTY" disclaimer below 20217365Sjkim * ("Disclaimer") and any redistribution must be conditioned upon 21217365Sjkim * including a substantially similar Disclaimer requirement for further 22217365Sjkim * binary redistribution. 23217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names 24217365Sjkim * of any contributors may be used to endorse or promote products derived 25217365Sjkim * from this software without specific prior written permission. 26118611Snjl * 27217365Sjkim * Alternatively, this software may be distributed under the terms of the 28217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free 29217365Sjkim * Software Foundation. 30118611Snjl * 31217365Sjkim * NO WARRANTY 32217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 33217365Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34217365Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 35217365Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 36217365Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 37217365Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 38217365Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 39217365Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 40217365Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 41217365Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 42217365Sjkim * POSSIBILITY OF SUCH DAMAGES. 43217365Sjkim */ 44118611Snjl 45151937Sjkim#include <contrib/dev/acpica/compiler/aslcompiler.h> 46193529Sjkim#include <contrib/dev/acpica/include/acapps.h> 47118611Snjl 48118611Snjl#define _COMPONENT ACPI_COMPILER 49118611Snjl ACPI_MODULE_NAME ("aslfiles") 50118611Snjl 51151937Sjkim/* Local prototypes */ 52118611Snjl 53212761Sjkimstatic FILE * 54197104SjkimFlOpenIncludeWithPrefix ( 55197104Sjkim char *PrefixDir, 56197104Sjkim char *Filename); 57151937Sjkim 58197104Sjkim 59151937Sjkim#ifdef ACPI_OBSOLETE_FUNCTIONS 60151937SjkimACPI_STATUS 61151937SjkimFlParseInputPathname ( 62151937Sjkim char *InputFilename); 63151937Sjkim#endif 64151937Sjkim 65151937Sjkim 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 80151937SjkimAslAbort ( 81151937Sjkim 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 92151937Sjkim 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 116151937Sjkim sprintf (MsgBuffer, "\"%s\" (%s)", Gbl_Files[FileId].Filename, 117151937Sjkim strerror (errno)); 118118611Snjl AslCommonError (ASL_ERROR, ErrorId, 0, 0, 0, 0, NULL, MsgBuffer); 119118611Snjl} 120118611Snjl 121118611Snjl 122118611Snjl/******************************************************************************* 123118611Snjl * 124118611Snjl * FUNCTION: FlOpenFile 125118611Snjl * 126118611Snjl * PARAMETERS: FileId - Index into file info array 127118611Snjl * Filename - file pathname to open 128118611Snjl * Mode - Open mode for fopen 129118611Snjl * 130151937Sjkim * RETURN: None 131118611Snjl * 132118611Snjl * DESCRIPTION: Open a file. 133118611Snjl * NOTE: Aborts compiler on any error. 134118611Snjl * 135118611Snjl ******************************************************************************/ 136118611Snjl 137209746Sjkimvoid 138118611SnjlFlOpenFile ( 139118611Snjl UINT32 FileId, 140118611Snjl char *Filename, 141118611Snjl char *Mode) 142118611Snjl{ 143118611Snjl 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 158118611Snjl 159118611Snjl/******************************************************************************* 160118611Snjl * 161207344Sjkim * FUNCTION: FlGetFileSize 162207344Sjkim * 163207344Sjkim * PARAMETERS: FileId - Index into file info array 164207344Sjkim * 165207344Sjkim * RETURN: File Size 166207344Sjkim * 167207344Sjkim * DESCRIPTION: Get current file size. Uses seek-to-EOF. File must be open. 168207344Sjkim * 169207344Sjkim ******************************************************************************/ 170207344Sjkim 171207344SjkimUINT32 172207344SjkimFlGetFileSize ( 173207344Sjkim UINT32 FileId) 174207344Sjkim{ 175207344Sjkim FILE *fp; 176207344Sjkim UINT32 FileSize; 177207344Sjkim 178207344Sjkim 179207344Sjkim fp = Gbl_Files[FileId].Handle; 180207344Sjkim 181207344Sjkim fseek (fp, 0, SEEK_END); 182207344Sjkim FileSize = (UINT32) ftell (fp); 183207344Sjkim fseek (fp, 0, SEEK_SET); 184207344Sjkim 185207344Sjkim return (FileSize); 186207344Sjkim} 187207344Sjkim 188207344Sjkim 189207344Sjkim/******************************************************************************* 190207344Sjkim * 191118611Snjl * FUNCTION: FlReadFile 192118611Snjl * 193118611Snjl * PARAMETERS: FileId - Index into file info array 194118611Snjl * Buffer - Where to place the data 195118611Snjl * Length - Amount to read 196118611Snjl * 197118611Snjl * RETURN: Status. AE_ERROR indicates EOF. 198118611Snjl * 199118611Snjl * DESCRIPTION: Read data from an open file. 200118611Snjl * NOTE: Aborts compiler on any error. 201118611Snjl * 202118611Snjl ******************************************************************************/ 203118611Snjl 204118611SnjlACPI_STATUS 205118611SnjlFlReadFile ( 206118611Snjl UINT32 FileId, 207118611Snjl void *Buffer, 208118611Snjl UINT32 Length) 209118611Snjl{ 210118611Snjl UINT32 Actual; 211118611Snjl 212118611Snjl 213118611Snjl /* Read and check for error */ 214118611Snjl 215118611Snjl Actual = fread (Buffer, 1, Length, Gbl_Files[FileId].Handle); 216118611Snjl if (Actual != Length) 217118611Snjl { 218118611Snjl if (feof (Gbl_Files[FileId].Handle)) 219118611Snjl { 220118611Snjl /* End-of-file, just return error */ 221118611Snjl 222118611Snjl return (AE_ERROR); 223118611Snjl } 224118611Snjl 225118611Snjl FlFileError (FileId, ASL_MSG_READ); 226118611Snjl AslAbort (); 227118611Snjl } 228118611Snjl 229118611Snjl return (AE_OK); 230118611Snjl} 231118611Snjl 232118611Snjl 233118611Snjl/******************************************************************************* 234118611Snjl * 235118611Snjl * FUNCTION: FlWriteFile 236118611Snjl * 237118611Snjl * PARAMETERS: FileId - Index into file info array 238118611Snjl * Buffer - Data to write 239118611Snjl * Length - Amount of data to write 240118611Snjl * 241151937Sjkim * RETURN: None 242118611Snjl * 243118611Snjl * DESCRIPTION: Write data to an open file. 244118611Snjl * NOTE: Aborts compiler on any error. 245118611Snjl * 246118611Snjl ******************************************************************************/ 247118611Snjl 248118611Snjlvoid 249118611SnjlFlWriteFile ( 250118611Snjl UINT32 FileId, 251118611Snjl void *Buffer, 252118611Snjl UINT32 Length) 253118611Snjl{ 254118611Snjl UINT32 Actual; 255118611Snjl 256118611Snjl 257118611Snjl /* Write and check for error */ 258118611Snjl 259118611Snjl Actual = fwrite ((char *) Buffer, 1, Length, Gbl_Files[FileId].Handle); 260118611Snjl if (Actual != Length) 261118611Snjl { 262118611Snjl FlFileError (FileId, ASL_MSG_WRITE); 263118611Snjl AslAbort (); 264118611Snjl } 265118611Snjl} 266118611Snjl 267118611Snjl 268118611Snjl/******************************************************************************* 269118611Snjl * 270118611Snjl * FUNCTION: FlPrintFile 271118611Snjl * 272118611Snjl * PARAMETERS: FileId - Index into file info array 273118611Snjl * Format - Printf format string 274118611Snjl * ... - Printf arguments 275118611Snjl * 276118611Snjl * RETURN: None 277118611Snjl * 278118611Snjl * DESCRIPTION: Formatted write to an open file. 279118611Snjl * NOTE: Aborts compiler on any error. 280118611Snjl * 281118611Snjl ******************************************************************************/ 282118611Snjl 283118611Snjlvoid 284118611SnjlFlPrintFile ( 285118611Snjl UINT32 FileId, 286118611Snjl char *Format, 287118611Snjl ...) 288118611Snjl{ 289118611Snjl INT32 Actual; 290118611Snjl va_list Args; 291118611Snjl 292118611Snjl 293118611Snjl va_start (Args, Format); 294118611Snjl 295118611Snjl Actual = vfprintf (Gbl_Files[FileId].Handle, Format, Args); 296193529Sjkim va_end (Args); 297193529Sjkim 298118611Snjl if (Actual == -1) 299118611Snjl { 300118611Snjl FlFileError (FileId, ASL_MSG_WRITE); 301118611Snjl AslAbort (); 302118611Snjl } 303118611Snjl} 304118611Snjl 305118611Snjl 306118611Snjl/******************************************************************************* 307118611Snjl * 308118611Snjl * FUNCTION: FlSeekFile 309118611Snjl * 310118611Snjl * PARAMETERS: FileId - Index into file info array 311118611Snjl * Offset - Absolute byte offset in file 312118611Snjl * 313151937Sjkim * RETURN: None 314118611Snjl * 315118611Snjl * DESCRIPTION: Seek to absolute offset 316118611Snjl * NOTE: Aborts compiler on any error. 317118611Snjl * 318118611Snjl ******************************************************************************/ 319118611Snjl 320118611Snjlvoid 321118611SnjlFlSeekFile ( 322118611Snjl UINT32 FileId, 323118611Snjl long Offset) 324118611Snjl{ 325118611Snjl int Error; 326118611Snjl 327118611Snjl 328118611Snjl Error = fseek (Gbl_Files[FileId].Handle, Offset, SEEK_SET); 329118611Snjl if (Error) 330118611Snjl { 331118611Snjl FlFileError (FileId, ASL_MSG_SEEK); 332118611Snjl AslAbort (); 333118611Snjl } 334118611Snjl} 335118611Snjl 336118611Snjl 337118611Snjl/******************************************************************************* 338118611Snjl * 339118611Snjl * FUNCTION: FlCloseFile 340118611Snjl * 341118611Snjl * PARAMETERS: FileId - Index into file info array 342118611Snjl * 343151937Sjkim * RETURN: None 344118611Snjl * 345118611Snjl * DESCRIPTION: Close an open file. Aborts compiler on error 346118611Snjl * 347118611Snjl ******************************************************************************/ 348118611Snjl 349118611Snjlvoid 350118611SnjlFlCloseFile ( 351118611Snjl UINT32 FileId) 352118611Snjl{ 353118611Snjl int Error; 354118611Snjl 355118611Snjl 356118611Snjl if (!Gbl_Files[FileId].Handle) 357118611Snjl { 358118611Snjl return; 359118611Snjl } 360118611Snjl 361118611Snjl Error = fclose (Gbl_Files[FileId].Handle); 362118611Snjl Gbl_Files[FileId].Handle = NULL; 363118611Snjl 364118611Snjl if (Error) 365118611Snjl { 366118611Snjl FlFileError (FileId, ASL_MSG_CLOSE); 367118611Snjl AslAbort (); 368118611Snjl } 369118611Snjl 370118611Snjl return; 371118611Snjl} 372118611Snjl 373118611Snjl 374118611Snjl/******************************************************************************* 375118611Snjl * 376118611Snjl * FUNCTION: FlSetLineNumber 377118611Snjl * 378118611Snjl * PARAMETERS: Op - Parse node for the LINE asl statement 379118611Snjl * 380118611Snjl * RETURN: None. 381118611Snjl * 382118611Snjl * DESCRIPTION: Set the current line number 383118611Snjl * 384118611Snjl ******************************************************************************/ 385118611Snjl 386118611Snjlvoid 387118611SnjlFlSetLineNumber ( 388118611Snjl ACPI_PARSE_OBJECT *Op) 389118611Snjl{ 390118611Snjl 391118611Snjl Gbl_CurrentLineNumber = (UINT32) Op->Asl.Value.Integer; 392118611Snjl Gbl_LogicalLineNumber = (UINT32) Op->Asl.Value.Integer; 393118611Snjl} 394118611Snjl 395118611Snjl 396118611Snjl/******************************************************************************* 397118611Snjl * 398197104Sjkim * FUNCTION: FlAddIncludeDirectory 399197104Sjkim * 400197104Sjkim * PARAMETERS: Dir - Directory pathname string 401197104Sjkim * 402197104Sjkim * RETURN: None 403197104Sjkim * 404197104Sjkim * DESCRIPTION: Add a directory the list of include prefix directories. 405197104Sjkim * 406197104Sjkim ******************************************************************************/ 407197104Sjkim 408197104Sjkimvoid 409197104SjkimFlAddIncludeDirectory ( 410197104Sjkim char *Dir) 411197104Sjkim{ 412197104Sjkim ASL_INCLUDE_DIR *NewDir; 413197104Sjkim ASL_INCLUDE_DIR *NextDir; 414197104Sjkim ASL_INCLUDE_DIR *PrevDir = NULL; 415197104Sjkim UINT32 NeedsSeparator = 0; 416197104Sjkim size_t DirLength; 417197104Sjkim 418197104Sjkim 419197104Sjkim DirLength = strlen (Dir); 420197104Sjkim if (!DirLength) 421197104Sjkim { 422197104Sjkim return; 423197104Sjkim } 424197104Sjkim 425197104Sjkim /* Make sure that the pathname ends with a path separator */ 426197104Sjkim 427197104Sjkim if ((Dir[DirLength-1] != '/') && 428197104Sjkim (Dir[DirLength-1] != '\\')) 429197104Sjkim { 430197104Sjkim NeedsSeparator = 1; 431197104Sjkim } 432197104Sjkim 433197104Sjkim NewDir = ACPI_ALLOCATE_ZEROED (sizeof (ASL_INCLUDE_DIR)); 434197104Sjkim NewDir->Dir = ACPI_ALLOCATE (DirLength + 1 + NeedsSeparator); 435197104Sjkim strcpy (NewDir->Dir, Dir); 436197104Sjkim if (NeedsSeparator) 437197104Sjkim { 438197104Sjkim strcat (NewDir->Dir, "/"); 439197104Sjkim } 440197104Sjkim 441197104Sjkim /* 442197104Sjkim * Preserve command line ordering of -I options by adding new elements 443197104Sjkim * at the end of the list 444197104Sjkim */ 445197104Sjkim NextDir = Gbl_IncludeDirList; 446197104Sjkim while (NextDir) 447197104Sjkim { 448197104Sjkim PrevDir = NextDir; 449197104Sjkim NextDir = NextDir->Next; 450197104Sjkim } 451197104Sjkim 452197104Sjkim if (PrevDir) 453197104Sjkim { 454197104Sjkim PrevDir->Next = NewDir; 455197104Sjkim } 456197104Sjkim else 457197104Sjkim { 458197104Sjkim Gbl_IncludeDirList = NewDir; 459197104Sjkim } 460197104Sjkim} 461197104Sjkim 462197104Sjkim 463197104Sjkim/******************************************************************************* 464197104Sjkim * 465197104Sjkim * FUNCTION: FlOpenIncludeWithPrefix 466197104Sjkim * 467197104Sjkim * PARAMETERS: PrefixDir - Prefix directory pathname. Can be a zero 468197104Sjkim * length string. 469197104Sjkim * Filename - The include filename from the source ASL. 470197104Sjkim * 471197104Sjkim * RETURN: Valid file descriptor if successful. Null otherwise. 472197104Sjkim * 473197104Sjkim * DESCRIPTION: Open an include file and push it on the input file stack. 474197104Sjkim * 475197104Sjkim ******************************************************************************/ 476197104Sjkim 477212761Sjkimstatic FILE * 478197104SjkimFlOpenIncludeWithPrefix ( 479197104Sjkim char *PrefixDir, 480197104Sjkim char *Filename) 481197104Sjkim{ 482197104Sjkim FILE *IncludeFile; 483197104Sjkim char *Pathname; 484197104Sjkim 485197104Sjkim 486197104Sjkim /* Build the full pathname to the file */ 487197104Sjkim 488197104Sjkim Pathname = ACPI_ALLOCATE (strlen (PrefixDir) + strlen (Filename) + 1); 489197104Sjkim 490197104Sjkim strcpy (Pathname, PrefixDir); 491197104Sjkim strcat (Pathname, Filename); 492197104Sjkim 493197104Sjkim DbgPrint (ASL_PARSE_OUTPUT, "\nAttempt to open include file: path %s\n\n", 494197104Sjkim Pathname); 495197104Sjkim 496197104Sjkim /* Attempt to open the file, push if successful */ 497197104Sjkim 498197104Sjkim IncludeFile = fopen (Pathname, "r"); 499197104Sjkim if (IncludeFile) 500197104Sjkim { 501197104Sjkim /* Push the include file on the open input file stack */ 502197104Sjkim 503197104Sjkim AslPushInputFileStack (IncludeFile, Pathname); 504197104Sjkim return (IncludeFile); 505197104Sjkim } 506197104Sjkim 507197104Sjkim ACPI_FREE (Pathname); 508197104Sjkim return (NULL); 509197104Sjkim} 510197104Sjkim 511197104Sjkim 512197104Sjkim/******************************************************************************* 513197104Sjkim * 514118611Snjl * FUNCTION: FlOpenIncludeFile 515118611Snjl * 516118611Snjl * PARAMETERS: Op - Parse node for the INCLUDE ASL statement 517118611Snjl * 518118611Snjl * RETURN: None. 519118611Snjl * 520118611Snjl * DESCRIPTION: Open an include file and push it on the input file stack. 521118611Snjl * 522118611Snjl ******************************************************************************/ 523118611Snjl 524118611Snjlvoid 525118611SnjlFlOpenIncludeFile ( 526118611Snjl ACPI_PARSE_OBJECT *Op) 527118611Snjl{ 528197104Sjkim FILE *IncludeFile; 529197104Sjkim ASL_INCLUDE_DIR *NextDir; 530118611Snjl 531118611Snjl 532118611Snjl /* Op must be valid */ 533118611Snjl 534118611Snjl if (!Op) 535118611Snjl { 536118611Snjl AslCommonError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, 537118611Snjl Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, 538118611Snjl Gbl_InputByteCount, Gbl_CurrentColumn, 539118611Snjl Gbl_Files[ASL_FILE_INPUT].Filename, " - Null parse node"); 540118611Snjl 541118611Snjl return; 542118611Snjl } 543118611Snjl 544118611Snjl /* 545118611Snjl * Flush out the "include ()" statement on this line, start 546118611Snjl * the actual include file on the next line 547118611Snjl */ 548118611Snjl ResetCurrentLineBuffer (); 549118611Snjl FlPrintFile (ASL_FILE_SOURCE_OUTPUT, "\n"); 550118611Snjl Gbl_CurrentLineOffset++; 551118611Snjl 552118611Snjl 553197104Sjkim /* Attempt to open the include file */ 554197104Sjkim 555197104Sjkim /* If the file specifies an absolute path, just open it */ 556197104Sjkim 557197104Sjkim if ((Op->Asl.Value.String[0] == '/') || 558197104Sjkim (Op->Asl.Value.String[0] == '\\') || 559197104Sjkim (Op->Asl.Value.String[1] == ':')) 560118611Snjl { 561197104Sjkim IncludeFile = FlOpenIncludeWithPrefix ("", Op->Asl.Value.String); 562197104Sjkim if (!IncludeFile) 563197104Sjkim { 564197104Sjkim goto ErrorExit; 565197104Sjkim } 566118611Snjl return; 567118611Snjl } 568118611Snjl 569197104Sjkim /* 570197104Sjkim * The include filename is not an absolute path. 571197104Sjkim * 572197104Sjkim * First, search for the file within the "local" directory -- meaning 573197104Sjkim * the same directory that contains the source file. 574197104Sjkim * 575197104Sjkim * Construct the file pathname from the global directory name. 576197104Sjkim */ 577197104Sjkim IncludeFile = FlOpenIncludeWithPrefix (Gbl_DirectoryPath, Op->Asl.Value.String); 578197104Sjkim if (IncludeFile) 579197104Sjkim { 580197104Sjkim return; 581197104Sjkim } 582118611Snjl 583197104Sjkim /* 584197104Sjkim * Second, search for the file within the (possibly multiple) directories 585197104Sjkim * specified by the -I option on the command line. 586197104Sjkim */ 587197104Sjkim NextDir = Gbl_IncludeDirList; 588197104Sjkim while (NextDir) 589197104Sjkim { 590197104Sjkim IncludeFile = FlOpenIncludeWithPrefix (NextDir->Dir, Op->Asl.Value.String); 591197104Sjkim if (IncludeFile) 592197104Sjkim { 593197104Sjkim return; 594197104Sjkim } 595197104Sjkim 596197104Sjkim NextDir = NextDir->Next; 597197104Sjkim } 598197104Sjkim 599197104Sjkim /* We could not open the include file after trying very hard */ 600197104Sjkim 601197104SjkimErrorExit: 602197104Sjkim sprintf (MsgBuffer, "%s, %s", Op->Asl.Value.String, strerror (errno)); 603197104Sjkim AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, Op, MsgBuffer); 604118611Snjl} 605118611Snjl 606118611Snjl 607118611Snjl/******************************************************************************* 608118611Snjl * 609118611Snjl * FUNCTION: FlOpenInputFile 610118611Snjl * 611118611Snjl * PARAMETERS: InputFilename - The user-specified ASL source file to be 612118611Snjl * compiled 613118611Snjl * 614118611Snjl * RETURN: Status 615118611Snjl * 616118611Snjl * DESCRIPTION: Open the specified input file, and save the directory path to 617118611Snjl * the file so that include files can be opened in 618118611Snjl * the same directory. 619118611Snjl * 620118611Snjl ******************************************************************************/ 621118611Snjl 622118611SnjlACPI_STATUS 623118611SnjlFlOpenInputFile ( 624118611Snjl char *InputFilename) 625118611Snjl{ 626118611Snjl 627118611Snjl /* Open the input ASL file, text mode */ 628118611Snjl 629118611Snjl FlOpenFile (ASL_FILE_INPUT, InputFilename, "r"); 630118611Snjl AslCompilerin = Gbl_Files[ASL_FILE_INPUT].Handle; 631118611Snjl 632118611Snjl return (AE_OK); 633118611Snjl} 634118611Snjl 635118611Snjl 636118611Snjl/******************************************************************************* 637118611Snjl * 638118611Snjl * FUNCTION: FlOpenAmlOutputFile 639118611Snjl * 640118611Snjl * PARAMETERS: FilenamePrefix - The user-specified ASL source file 641118611Snjl * 642118611Snjl * RETURN: Status 643118611Snjl * 644118611Snjl * DESCRIPTION: Create the output filename (*.AML) and open the file. The file 645118611Snjl * is created in the same directory as the parent input file. 646118611Snjl * 647118611Snjl ******************************************************************************/ 648118611Snjl 649118611SnjlACPI_STATUS 650118611SnjlFlOpenAmlOutputFile ( 651118611Snjl char *FilenamePrefix) 652118611Snjl{ 653118611Snjl char *Filename; 654118611Snjl 655118611Snjl 656118611Snjl /* Output filename usually comes from the ASL itself */ 657118611Snjl 658118611Snjl Filename = Gbl_Files[ASL_FILE_AML_OUTPUT].Filename; 659118611Snjl if (!Filename) 660118611Snjl { 661118611Snjl /* Create the output AML filename */ 662118611Snjl 663118611Snjl Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_AML_CODE); 664118611Snjl if (!Filename) 665118611Snjl { 666151937Sjkim AslCommonError (ASL_ERROR, ASL_MSG_OUTPUT_FILENAME, 667151937Sjkim 0, 0, 0, 0, NULL, NULL); 668118611Snjl return (AE_ERROR); 669118611Snjl } 670118611Snjl } 671118611Snjl 672118611Snjl /* Open the output AML file in binary mode */ 673118611Snjl 674118611Snjl FlOpenFile (ASL_FILE_AML_OUTPUT, Filename, "w+b"); 675118611Snjl return (AE_OK); 676118611Snjl} 677118611Snjl 678118611Snjl 679118611Snjl/******************************************************************************* 680118611Snjl * 681118611Snjl * FUNCTION: FlOpenMiscOutputFiles 682118611Snjl * 683118611Snjl * PARAMETERS: FilenamePrefix - The user-specified ASL source file 684118611Snjl * 685118611Snjl * RETURN: Status 686118611Snjl * 687118611Snjl * DESCRIPTION: Create and open the various output files needed, depending on 688118611Snjl * the command line options 689118611Snjl * 690118611Snjl ******************************************************************************/ 691118611Snjl 692118611SnjlACPI_STATUS 693118611SnjlFlOpenMiscOutputFiles ( 694118611Snjl char *FilenamePrefix) 695118611Snjl{ 696118611Snjl char *Filename; 697118611Snjl 698118611Snjl 699209746Sjkim /* Create/Open a hex output file if asked */ 700209746Sjkim 701209746Sjkim if (Gbl_HexOutputFlag) 702209746Sjkim { 703209746Sjkim Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_HEX_DUMP); 704209746Sjkim if (!Filename) 705209746Sjkim { 706209746Sjkim AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 707209746Sjkim 0, 0, 0, 0, NULL, NULL); 708209746Sjkim return (AE_ERROR); 709209746Sjkim } 710209746Sjkim 711209746Sjkim /* Open the hex file, text mode */ 712209746Sjkim 713209746Sjkim FlOpenFile (ASL_FILE_HEX_OUTPUT, Filename, "w+"); 714209746Sjkim 715209746Sjkim AslCompilerSignon (ASL_FILE_HEX_OUTPUT); 716209746Sjkim AslCompilerFileHeader (ASL_FILE_HEX_OUTPUT); 717209746Sjkim } 718209746Sjkim 719209746Sjkim /* Create/Open a debug output file if asked */ 720209746Sjkim 721209746Sjkim if (Gbl_DebugFlag) 722209746Sjkim { 723209746Sjkim Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_DEBUG); 724209746Sjkim if (!Filename) 725209746Sjkim { 726209746Sjkim AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME, 727209746Sjkim 0, 0, 0, 0, NULL, NULL); 728209746Sjkim return (AE_ERROR); 729209746Sjkim } 730209746Sjkim 731209746Sjkim /* Open the debug file as STDERR, text mode */ 732209746Sjkim 733209746Sjkim /* TBD: hide this behind a FlReopenFile function */ 734209746Sjkim 735209746Sjkim Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Filename = Filename; 736209746Sjkim Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle = 737209746Sjkim freopen (Filename, "w+t", stderr); 738209746Sjkim 739209746Sjkim AslCompilerSignon (ASL_FILE_DEBUG_OUTPUT); 740209746Sjkim AslCompilerFileHeader (ASL_FILE_DEBUG_OUTPUT); 741209746Sjkim } 742209746Sjkim 743217365Sjkim /* Create/Open a listing output file if asked */ 744217365Sjkim 745217365Sjkim if (Gbl_ListingFlag) 746217365Sjkim { 747217365Sjkim Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_LISTING); 748217365Sjkim if (!Filename) 749217365Sjkim { 750217365Sjkim AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 751217365Sjkim 0, 0, 0, 0, NULL, NULL); 752217365Sjkim return (AE_ERROR); 753217365Sjkim } 754217365Sjkim 755217365Sjkim /* Open the listing file, text mode */ 756217365Sjkim 757217365Sjkim FlOpenFile (ASL_FILE_LISTING_OUTPUT, Filename, "w+"); 758217365Sjkim 759217365Sjkim AslCompilerSignon (ASL_FILE_LISTING_OUTPUT); 760217365Sjkim AslCompilerFileHeader (ASL_FILE_LISTING_OUTPUT); 761217365Sjkim } 762217365Sjkim 763209746Sjkim if (Gbl_FileType == ASL_INPUT_TYPE_ASCII_DATA) 764209746Sjkim { 765209746Sjkim return (AE_OK); 766209746Sjkim } 767209746Sjkim 768118611Snjl /* Create/Open a combined source output file */ 769118611Snjl 770118611Snjl Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_SOURCE); 771118611Snjl if (!Filename) 772118611Snjl { 773151937Sjkim AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 774151937Sjkim 0, 0, 0, 0, NULL, NULL); 775118611Snjl return (AE_ERROR); 776118611Snjl } 777118611Snjl 778118611Snjl /* 779118611Snjl * Open the source output file, binary mode (so that LF does not get 780118611Snjl * expanded to CR/LF on some systems, messing up our seek 781118611Snjl * calculations.) 782118611Snjl */ 783118611Snjl FlOpenFile (ASL_FILE_SOURCE_OUTPUT, Filename, "w+b"); 784118611Snjl 785118611Snjl /* Create/Open a assembly code source output file if asked */ 786118611Snjl 787118611Snjl if (Gbl_AsmOutputFlag) 788118611Snjl { 789118611Snjl Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_SOURCE); 790118611Snjl if (!Filename) 791118611Snjl { 792151937Sjkim AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 793151937Sjkim 0, 0, 0, 0, NULL, NULL); 794118611Snjl return (AE_ERROR); 795118611Snjl } 796118611Snjl 797118611Snjl /* Open the assembly code source file, text mode */ 798118611Snjl 799118611Snjl FlOpenFile (ASL_FILE_ASM_SOURCE_OUTPUT, Filename, "w+"); 800118611Snjl 801118611Snjl AslCompilerSignon (ASL_FILE_ASM_SOURCE_OUTPUT); 802118611Snjl AslCompilerFileHeader (ASL_FILE_ASM_SOURCE_OUTPUT); 803118611Snjl } 804118611Snjl 805118611Snjl /* Create/Open a C code source output file if asked */ 806118611Snjl 807118611Snjl if (Gbl_C_OutputFlag) 808118611Snjl { 809118611Snjl Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_SOURCE); 810118611Snjl if (!Filename) 811118611Snjl { 812151937Sjkim AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 813151937Sjkim 0, 0, 0, 0, NULL, NULL); 814118611Snjl return (AE_ERROR); 815118611Snjl } 816118611Snjl 817118611Snjl /* Open the C code source file, text mode */ 818118611Snjl 819118611Snjl FlOpenFile (ASL_FILE_C_SOURCE_OUTPUT, Filename, "w+"); 820118611Snjl 821118611Snjl FlPrintFile (ASL_FILE_C_SOURCE_OUTPUT, "/*\n"); 822118611Snjl AslCompilerSignon (ASL_FILE_C_SOURCE_OUTPUT); 823118611Snjl AslCompilerFileHeader (ASL_FILE_C_SOURCE_OUTPUT); 824118611Snjl } 825118611Snjl 826118611Snjl /* Create/Open a assembly include output file if asked */ 827118611Snjl 828118611Snjl if (Gbl_AsmIncludeOutputFlag) 829118611Snjl { 830118611Snjl Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_INCLUDE); 831118611Snjl if (!Filename) 832118611Snjl { 833151937Sjkim AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 834151937Sjkim 0, 0, 0, 0, NULL, NULL); 835118611Snjl return (AE_ERROR); 836118611Snjl } 837118611Snjl 838118611Snjl /* Open the assembly include file, text mode */ 839118611Snjl 840118611Snjl FlOpenFile (ASL_FILE_ASM_INCLUDE_OUTPUT, Filename, "w+"); 841118611Snjl 842118611Snjl AslCompilerSignon (ASL_FILE_ASM_INCLUDE_OUTPUT); 843118611Snjl AslCompilerFileHeader (ASL_FILE_ASM_INCLUDE_OUTPUT); 844118611Snjl } 845118611Snjl 846118611Snjl /* Create/Open a C include output file if asked */ 847118611Snjl 848118611Snjl if (Gbl_C_IncludeOutputFlag) 849118611Snjl { 850118611Snjl Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_INCLUDE); 851118611Snjl if (!Filename) 852118611Snjl { 853151937Sjkim AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 854151937Sjkim 0, 0, 0, 0, NULL, NULL); 855118611Snjl return (AE_ERROR); 856118611Snjl } 857118611Snjl 858118611Snjl /* Open the C include file, text mode */ 859118611Snjl 860118611Snjl FlOpenFile (ASL_FILE_C_INCLUDE_OUTPUT, Filename, "w+"); 861118611Snjl 862118611Snjl FlPrintFile (ASL_FILE_C_INCLUDE_OUTPUT, "/*\n"); 863118611Snjl AslCompilerSignon (ASL_FILE_C_INCLUDE_OUTPUT); 864118611Snjl AslCompilerFileHeader (ASL_FILE_C_INCLUDE_OUTPUT); 865118611Snjl } 866118611Snjl 867118611Snjl /* Create a namespace output file if asked */ 868118611Snjl 869118611Snjl if (Gbl_NsOutputFlag) 870118611Snjl { 871118611Snjl Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_NAMESPACE); 872118611Snjl if (!Filename) 873118611Snjl { 874151937Sjkim AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 875151937Sjkim 0, 0, 0, 0, NULL, NULL); 876118611Snjl return (AE_ERROR); 877118611Snjl } 878118611Snjl 879118611Snjl /* Open the namespace file, text mode */ 880118611Snjl 881118611Snjl FlOpenFile (ASL_FILE_NAMESPACE_OUTPUT, Filename, "w+"); 882118611Snjl 883118611Snjl AslCompilerSignon (ASL_FILE_NAMESPACE_OUTPUT); 884118611Snjl AslCompilerFileHeader (ASL_FILE_NAMESPACE_OUTPUT); 885118611Snjl } 886118611Snjl 887118611Snjl return (AE_OK); 888118611Snjl} 889118611Snjl 890118611Snjl 891151937Sjkim#ifdef ACPI_OBSOLETE_FUNCTIONS 892151937Sjkim/******************************************************************************* 893151937Sjkim * 894151937Sjkim * FUNCTION: FlParseInputPathname 895151937Sjkim * 896151937Sjkim * PARAMETERS: InputFilename - The user-specified ASL source file to be 897151937Sjkim * compiled 898151937Sjkim * 899151937Sjkim * RETURN: Status 900151937Sjkim * 901151937Sjkim * DESCRIPTION: Split the input path into a directory and filename part 902151937Sjkim * 1) Directory part used to open include files 903151937Sjkim * 2) Filename part used to generate output filenames 904151937Sjkim * 905151937Sjkim ******************************************************************************/ 906151937Sjkim 907151937SjkimACPI_STATUS 908151937SjkimFlParseInputPathname ( 909151937Sjkim char *InputFilename) 910151937Sjkim{ 911151937Sjkim char *Substring; 912151937Sjkim 913151937Sjkim 914151937Sjkim if (!InputFilename) 915151937Sjkim { 916151937Sjkim return (AE_OK); 917151937Sjkim } 918151937Sjkim 919151937Sjkim /* Get the path to the input filename's directory */ 920151937Sjkim 921151937Sjkim Gbl_DirectoryPath = strdup (InputFilename); 922151937Sjkim if (!Gbl_DirectoryPath) 923151937Sjkim { 924151937Sjkim return (AE_NO_MEMORY); 925151937Sjkim } 926151937Sjkim 927151937Sjkim Substring = strrchr (Gbl_DirectoryPath, '\\'); 928151937Sjkim if (!Substring) 929151937Sjkim { 930151937Sjkim Substring = strrchr (Gbl_DirectoryPath, '/'); 931151937Sjkim if (!Substring) 932151937Sjkim { 933151937Sjkim Substring = strrchr (Gbl_DirectoryPath, ':'); 934151937Sjkim } 935151937Sjkim } 936151937Sjkim 937151937Sjkim if (!Substring) 938151937Sjkim { 939151937Sjkim Gbl_DirectoryPath[0] = 0; 940151937Sjkim if (Gbl_UseDefaultAmlFilename) 941151937Sjkim { 942151937Sjkim Gbl_OutputFilenamePrefix = strdup (InputFilename); 943151937Sjkim } 944151937Sjkim } 945151937Sjkim else 946151937Sjkim { 947151937Sjkim if (Gbl_UseDefaultAmlFilename) 948151937Sjkim { 949151937Sjkim Gbl_OutputFilenamePrefix = strdup (Substring + 1); 950151937Sjkim } 951151937Sjkim *(Substring+1) = 0; 952151937Sjkim } 953151937Sjkim 954151937Sjkim return (AE_OK); 955151937Sjkim} 956151937Sjkim#endif 957151937Sjkim 958151937Sjkim 959