diff --git a/src/common/rendering/stb_include.cpp b/src/common/rendering/stb_include.cpp index 71e625d4b..8e5f7a595 100644 --- a/src/common/rendering/stb_include.cpp +++ b/src/common/rendering/stb_include.cpp @@ -138,7 +138,7 @@ static int64_t stb_include_find_includes(const char *text, TArray find_end_quote(include_filename); if (*include_filename == '"') - { + { // ignore unterminated quotes FString filename; filename.AppendCStrPart(s, include_filename - s); s = include_filename; @@ -163,27 +163,31 @@ static int64_t stb_include_find_includes(const char *text, TArray return inc_count; } -FString stb_include_string(FString str, FString &error) +FString stb_include_string(FString str, FString filename, TArray &filenames, FString &error) { error = ""; TArray inc_list; int64_t num = stb_include_find_includes(str.GetChars(), inc_list); FString text = ""; size_t last = 0; + + filenames.Push(filename); + size_t curIndex = filenames.Size(); + + text.AppendFormat("#line 1 %d // %s\n", curIndex, filename.GetChars()); + for (int64_t i = 0; i < num; ++i) { text.AppendCStrPart(str.GetChars() + last, inc_list[i].offset - last); - text.AppendFormat("#line 1 %d\n", i + 1); - - FString inc = stb_include_file(inc_list[i].filename.GetChars(), error); + FString inc = stb_include_file(inc_list[i].filename.GetChars(), filenames, error); if (!error.IsEmpty()) { return ""; } text += inc; - text.AppendFormat("#line %d 0\n", inc_list[i].next_line_after); + text.AppendFormat("#line %d %d // %s\n", inc_list[i].next_line_after, curIndex, filename.GetChars()); // no newlines, because we kept the #include newlines, which will get appended next last = inc_list[i].end; } @@ -191,7 +195,7 @@ FString stb_include_string(FString str, FString &error) return text; } -FString stb_include_file(FString filename, FString &error) +FString stb_include_file(FString filename, TArray &filenames, FString &error) { FString text; if (!stb_include_load_file(filename, text)) @@ -201,5 +205,5 @@ FString stb_include_file(FString filename, FString &error) error += "'"; return ""; } - return stb_include_string(text, error); + return stb_include_string(text, filename, filenames, error); } diff --git a/src/common/rendering/stb_include.h b/src/common/rendering/stb_include.h index 357e4137f..5bed93def 100644 --- a/src/common/rendering/stb_include.h +++ b/src/common/rendering/stb_include.h @@ -39,11 +39,10 @@ #include "zstring.h" -// Do include-processing on the string 'str'. To free the return value, pass it to free() -FString stb_include_string(FString str, FString &error); +// Do include-processing on the string 'str'. +FString stb_include_string(FString str, FString filename, TArray &filenames, FString &error); -// Load the file 'filename' and do include-processing on the string therein. note that -// 'filename' is opened directly; 'path_to_includes' is not used. To free the return value, pass it to free() -FString stb_include_file(FString filename, FString &error); +// Load the file 'filename' and do include-processing on the string therein. +FString stb_include_file(FString filename, TArray &filenames, FString &error); #endif