static void DoInclude (void) /* Open an include file. */ { char RTerm; InputType IT; StrBuf Filename = STATIC_STRBUF_INITIALIZER; /* Preprocess the remainder of the line */ PreprocessLine (); /* Skip blanks */ SkipWhitespace (0); /* Get the next char and check for a valid file name terminator. Setup * the include directory spec (SYS/USR) by looking at the terminator. */ switch (CurC) { case '\"': RTerm = '\"'; IT = IT_USRINC; break; case '<': RTerm = '>'; IT = IT_SYSINC; break; default: PPError ("`\"' or `<' expected"); goto Done; } NextChar (); /* Get a copy of the filename */ while (CurC != '\0' && CurC != RTerm) { SB_AppendChar (&Filename, CurC); NextChar (); } SB_Terminate (&Filename); /* Check if we got a terminator */ if (CurC == RTerm) { /* Open the include file */ OpenIncludeFile (SB_GetConstBuf (&Filename), IT); } else if (CurC == '\0') { /* No terminator found */ PPError ("#include expects \"FILENAME\" or <FILENAME>"); } Done: /* Free the allocated filename data */ SB_Done (&Filename); /* Clear the remaining line so the next input will come from the new * file (if open) */ ClearLine (); }
STDMETHODIMP D3DIncludeManager::Open(THIS_ D3D_INCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID* ppData, UINT* pBytes) { GT_UNREFERENCED_PARAMETER(pParentData); bool isDone = false; if (pFileName != nullptr) { std::string includeFileFullPath; switch (IncludeType) { case D3D_INCLUDE_LOCAL: { // First, try the shader's directory. includeFileFullPath = m_shaderDir; // Is it a relative path to the shader's directory. bool isRelative = IsBeginsWith(pFileName, "\\"); if (!isRelative) { AdjustIncludePath(includeFileFullPath); } includeFileFullPath += pFileName; isDone = OpenIncludeFile(includeFileFullPath, (char*&) * ppData, *pBytes); if (!isDone) { // Search in the user-defined directories. for (const std::string& includeDir : m_includeSearchDirs) { includeFileFullPath = includeDir; if (!isRelative) { AdjustIncludePath(includeFileFullPath); } includeFileFullPath += pFileName; isDone = OpenIncludeFile(includeFileFullPath, (char*&) * ppData, *pBytes); if (isDone) { break; } } } break; } case D3D_INCLUDE_SYSTEM: { // First, try the shader's directory. includeFileFullPath = m_shaderDir; AdjustIncludePath(includeFileFullPath); includeFileFullPath += pFileName; isDone = OpenIncludeFile(includeFileFullPath, (char*&) * ppData, *pBytes); if (!isDone) { // Go through the directories which the user specified. for (const std::string& includeDir : m_includeSearchDirs) { includeFileFullPath = includeDir; AdjustIncludePath(includeFileFullPath); includeFileFullPath += pFileName; isDone = OpenIncludeFile(includeFileFullPath, (char*&) * ppData, *pBytes); if (isDone) { break; } } } break; } default: GT_ASSERT_EX(false, L"Unknown D3D include type."); break; } } // Must return S_OK according to the documentation. return (isDone ? S_OK : E_FAIL); }