static FILE * FlOpenIncludeWithPrefix ( char *PrefixDir, ACPI_PARSE_OBJECT *Op, char *Filename) { FILE *IncludeFile; char *Pathname; UINT32 OriginalLineNumber; /* Build the full pathname to the file */ Pathname = FlMergePathnames (PrefixDir, Filename); DbgPrint (ASL_PARSE_OUTPUT, "Include: Opening file - \"%s\"\n\n", Pathname); /* Attempt to open the file, push if successful */ IncludeFile = fopen (Pathname, "r"); if (!IncludeFile) { return (NULL); } /* * Check the entire include file for any # preprocessor directives. * This is because there may be some confusion between the #include * preprocessor directive and the ASL Include statement. A file included * by the ASL include cannot contain preprocessor directives because * the preprocessor has already run by the time the ASL include is * recognized (by the compiler, not the preprocessor.) * * Note: DtGetNextLine strips/ignores comments. * Save current line number since DtGetNextLine modifies it. */ AslGbl_CurrentLineNumber--; OriginalLineNumber = AslGbl_CurrentLineNumber; while (DtGetNextLine (IncludeFile, DT_ALLOW_MULTILINE_QUOTES) != ASL_EOF) { if (AslGbl_CurrentLineBuffer[0] == '#') { AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE, Op, "use #include instead"); } } AslGbl_CurrentLineNumber = OriginalLineNumber; /* Must seek back to the start of the file */ fseek (IncludeFile, 0, SEEK_SET); /* Push the include file on the open input file stack */ AslPushInputFileStack (IncludeFile, Pathname); return (IncludeFile); }
DT_FIELD * DtScanFile ( FILE *Handle) { ACPI_STATUS Status; UINT32 Offset; DT_FIELD *Next; ACPI_FUNCTION_NAME (DtScanFile); /* Get the file size */ Gbl_InputByteCount = DtGetFileSize (Handle); Gbl_CurrentLineNumber = 0; Gbl_CurrentLineOffset = 0; Gbl_NextLineOffset = 0; /* Scan line-by-line */ while ((Offset = DtGetNextLine (Handle)) != ASL_EOF) { ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Line %2.2u/%4.4X - %s", Gbl_CurrentLineNumber, Offset, Gbl_CurrentLineBuffer)); Status = DtParseLine (Gbl_CurrentLineBuffer, Gbl_CurrentLineNumber, Offset); if (Status == AE_NOT_FOUND) { break; } } /* Dump the parse tree if debug enabled */ if (Gbl_DebugFlag) { Next = Gbl_FieldList; DbgPrint (ASL_DEBUG_OUTPUT, "Tree: %32s %32s %8s %8s %8s %8s %8s %8s\n\n", "Name", "Value", "Line", "ByteOff", "NameCol", "Column", "TableOff", "Flags"); while (Next) { DbgPrint (ASL_DEBUG_OUTPUT, "Field: %32.32s %32.32s %.8X %.8X %.8X %.8X %.8X %.8X\n", Next->Name, Next->Value, Next->Line, Next->ByteOffset, Next->NameColumn, Next->Column, Next->TableOffset, Next->Flags); Next = Next->Next; } } return (Gbl_FieldList); }
DT_FIELD * DtScanFile ( FILE *Handle) { ACPI_STATUS Status; UINT32 Offset; ACPI_FUNCTION_NAME (DtScanFile); /* Get the file size */ Gbl_InputByteCount = DtGetFileSize (Handle); Gbl_CurrentLineNumber = 0; Gbl_CurrentLineOffset = 0; Gbl_NextLineOffset = 0; /* Scan line-by-line */ while ((Offset = DtGetNextLine (Handle))) { ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Line %2.2u/%4.4X - %s", Gbl_CurrentLineNumber, Offset, Gbl_CurrentLineBuffer)); Status = DtParseLine (Gbl_CurrentLineBuffer, Gbl_CurrentLineNumber, Offset); if (Status == AE_NOT_FOUND) { break; } } return (Gbl_FieldList); }
DT_FIELD * DtScanFile ( FILE *Handle) { ACPI_STATUS Status; UINT32 Offset; ACPI_FUNCTION_NAME (DtScanFile); /* Get the file size */ Gbl_InputByteCount = CmGetFileSize (Handle); if (Gbl_InputByteCount == ACPI_UINT32_MAX) { AslAbort (); } Gbl_CurrentLineNumber = 0; Gbl_CurrentLineOffset = 0; Gbl_NextLineOffset = 0; /* Scan line-by-line */ while ((Offset = DtGetNextLine (Handle, 0)) != ASL_EOF) { ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Line %2.2u/%4.4X - %s", Gbl_CurrentLineNumber, Offset, Gbl_CurrentLineBuffer)); Status = DtParseLine (Gbl_CurrentLineBuffer, Gbl_CurrentLineNumber, Offset); if (Status == AE_NOT_FOUND) { break; } } /* Dump the parse tree if debug enabled */ DtDumpFieldList (Gbl_FieldList); return (Gbl_FieldList); }
static void PrPreprocessInputFile ( void) { UINT32 Offset; char *Token; char *ReplaceString; PR_DEFINE_INFO *DefineInfo; ACPI_SIZE TokenOffset; BOOLEAN IgnoringThisCodeBlock = FALSE; char *Next; int OffsetAdjust; /* Scan line-by-line. Comments and blank lines are skipped by this function */ while ((Offset = DtGetNextLine (Gbl_Files[ASL_FILE_INPUT].Handle)) != ASL_EOF) { /* Need a copy of the input line for strok() */ strcpy (Gbl_MainTokenBuffer, Gbl_CurrentLineBuffer); Token = PrGetNextToken (Gbl_MainTokenBuffer, PR_TOKEN_SEPARATORS, &Next); OffsetAdjust = 0; /* All preprocessor directives must begin with '#' */ if (Token && (*Token == '#')) { if (strlen (Token) == 1) { Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, &Next); } else { Token++; /* Skip leading # */ } /* Execute the directive, do not write line to output file */ PrDoDirective (Token, &Next, &IgnoringThisCodeBlock); continue; } /* * If we are currently within the part of an IF/ELSE block that is * FALSE, ignore the line and do not write it to the output file. * This continues until an #else or #endif is encountered. */ if (IgnoringThisCodeBlock == TRUE) { continue; } /* Match and replace all #defined names within this source line */ while (Token) { DefineInfo = PrMatchDefine (Token); if (DefineInfo) { if (DefineInfo->Body) { /* This is a macro */ DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID "Matched Macro: %s->%s\n", Gbl_CurrentLineNumber, DefineInfo->Identifier, DefineInfo->Replacement); PrDoMacroInvocation (Gbl_MainTokenBuffer, Token, DefineInfo, &Next); } else { ReplaceString = DefineInfo->Replacement; /* Replace the name in the original line buffer */ TokenOffset = Token - Gbl_MainTokenBuffer + OffsetAdjust; PrReplaceData ( &Gbl_CurrentLineBuffer[TokenOffset], strlen (Token), ReplaceString, strlen (ReplaceString)); /* Adjust for length difference between old and new name length */ OffsetAdjust += strlen (ReplaceString) - strlen (Token); DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID "Matched #define: %s->%s\n", Gbl_CurrentLineNumber, Token, *ReplaceString ? ReplaceString : "(NULL STRING)"); } } Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, &Next); } #if 0 /* Line prefix */ FlPrintFile (ASL_FILE_PREPROCESSOR, "/* %14s %.5u i:%.5u */ ", Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_CurrentLineNumber, Gbl_PreprocessorLineNumber); #endif /* * Emit a #line directive if necessary, to keep the line numbers in * the (.i) file synchronized with the original source code file, so * that the correct line number appears in any error messages * generated by the actual compiler. */ if (Gbl_CurrentLineNumber > (Gbl_PreviousLineNumber + 1)) { FlPrintFile (ASL_FILE_PREPROCESSOR, "#line %u\n", Gbl_CurrentLineNumber); } Gbl_PreviousLineNumber = Gbl_CurrentLineNumber; Gbl_PreprocessorLineNumber++; /* * Now we can write the possibly modified source line to the * preprocessor (.i) file */ FlWriteFile (ASL_FILE_PREPROCESSOR, Gbl_CurrentLineBuffer, strlen (Gbl_CurrentLineBuffer)); } }