-From 05b823a34a12884f87a62a041d9fbe8416fbf5e5 Mon Sep 17 00:00:00 2001
+From 83f3eca31b6ddf869cee4f165a0db09813c6a4e6 Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Julian=20R=C3=BCth?= <julian.rueth@fsfe.org>
 Date: Sun, 18 Sep 2022 16:17:47 +0300
 Subject: [PATCH] Use INCLUDE environment variable

does not perform any linking or compiling but only runs the
preprocessor.
---
 src/libclang/libclang_parser.cpp | 51 ++------------------------------
 1 file changed, 3 insertions(+), 48 deletions(-)

diff --git a/src/libclang/libclang_parser.cpp b/src/libclang/libclang_parser.cpp
index cdacc8a..9db2a98 100644
--- a/src/libclang/libclang_parser.cpp
+++ b/src/libclang/libclang_parser.cpp
@@ -260,54 +260,9 @@ bool is_valid_binary(const std::string& binary)
 
 void add_default_include_dirs(libclang_compile_config& config)
 {

-            else
-                path += c;
-        }
+    const char* include = std::getenv("INCLUDE");
+    if (include == nullptr)
+      return;
+
+    std::string paths = include;
+    while (true) {
+      std::string path = paths;
+
+      size_t end = paths.find(';');
+      if (end != std::string::npos)
+        path = path.substr(0, end);
+
+      if (!path.empty())
+        config.add_include_dir(path);
+
+      if (end == std::string::npos)
+        break;
 
-        config.add_include_dir(std::move(path));
+      paths = paths.substr(end + 1);
     }
 }
 } // namespace
-- 
2.37.3

