From 4649c4908e4270332abc1176c40e9222c1f3c59e Mon Sep 17 00:00:00 2001
From: Alexander Golubev <fatzer2@gmail.com>
Date: Thu, 19 Mar 2026 04:25:15 +0300
Subject: Fix build against libxml2-2.14+ and 2.15+

libxml2-2.14 moved[1] shell functions from the library to xpath
executable, so they are no longer available via library API. This
resulted in FTBFS of libxsldbg. This commit adopts previously imported
libxml files to provide those APIs.

Also fix build against libxml 2.15. Was failing due to remove of const
on _xmlDoc::encoding[2].

[1]: https://gitlab.gnome.org/GNOME/libxml2/-/commit/1341deac131af51bdd3b4dd124440c198d361cc9
[2]: https://gitlab.gnome.org/GNOME/libxml2/-/commit/7c91385040ffab197f92135f7240e4d86b8f0cbb

See-also: https://mirror.git.trinitydesktop.org/gitea/TDE/tdebase/pulls/671#issuecomment-76639
Signed-off-by: Alexander Golubev <fatzer2@gmail.com>
---
 src/kxsldbgpart/libxsldbg/CMakeLists.txt    |  1 +
 src/kxsldbgpart/libxsldbg/debugXML_compat.c | 26 +++++++++++++++++++++++---
 src/kxsldbgpart/libxsldbg/debugXML_compat.h | 19 ++++++++++++++++---
 src/kxsldbgpart/libxsldbg/debugXSL.cpp      |  2 --
 src/kxsldbgpart/libxsldbg/debugXSL.h        |  2 ++
 src/kxsldbgpart/libxsldbg/nodeview_cmds.cpp |  3 +--
 src/kxsldbgpart/libxsldbg/utils.h           |  1 -
 src/kxsldbgpart/libxsldbg/xsldbg.cpp        |  1 -
 8 files changed, 43 insertions(+), 12 deletions(-)

diff --git a/src/kxsldbgpart/libxsldbg/CMakeLists.txt b/src/kxsldbgpart/libxsldbg/CMakeLists.txt
index 79160bc..9790a04 100644
--- a/src/kxsldbgpart/libxsldbg/CMakeLists.txt
+++ b/src/kxsldbgpart/libxsldbg/CMakeLists.txt
@@ -50,6 +50,7 @@ tde_add_library( xsldbg STATIC_PIC AUTOMOC
         breakpoint.cpp
         arraylist.cpp
         debugXSL.cpp
+        debugXML_compat.c
   LINK
      ${LIBXSLT_LIBRARIES}
      ${LIBEXSLT_LIBRARIES}
diff --git a/src/kxsldbgpart/libxsldbg/debugXML_compat.c b/src/kxsldbgpart/libxsldbg/debugXML_compat.c
index 2718a00..f55fe6e 100644
--- a/src/kxsldbgpart/libxsldbg/debugXML_compat.c
+++ b/src/kxsldbgpart/libxsldbg/debugXML_compat.c
@@ -40,8 +40,15 @@
  *    THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
-#define IN_LIBXML
-#include "libxml.h"
+#include <libxml/xmlversion.h>
+
+#if (LIBXML_VERSION >= 21400)
+
+/*
+ * This file provides compatibility wigh Shell libxml function which were
+ * removed from newer libxml.
+ */
+
 #ifdef LIBXML_DEBUG_ENABLED
 
 #include <string.h>
@@ -61,10 +68,21 @@
 #include <libxml/relaxng.h>
 #endif
 
-#include "private/error.h"
+#include "debugXML_compat.h"
 
 #define DUMP_TEXT_TYPE 1
 
+/*
+ * Attributes
+ */
+#ifndef ATTRIBUTE_UNUSED
+  #if __GNUC__ * 100 + __GNUC_MINOR__ >= 207 || defined(__clang__)
+    #define ATTRIBUTE_UNUSED __attribute__((unused))
+  #else
+    #define ATTRIBUTE_UNUSED
+  #endif
+#endif
+
 typedef struct _xmlDebugCtxt xmlDebugCtxt;
 typedef xmlDebugCtxt *xmlDebugCtxtPtr;
 struct _xmlDebugCtxt {
@@ -3447,3 +3465,5 @@ xmlShell(xmlDocPtr doc, const char *filename, xmlShellReadlineFunc input,
 #endif /* LIBXML_XPATH_ENABLED */
 
 #endif /* LIBXML_DEBUG_ENABLED */
+
+#endif /* LIBXML_VERSION >= 21400 */
diff --git a/src/kxsldbgpart/libxsldbg/debugXML_compat.h b/src/kxsldbgpart/libxsldbg/debugXML_compat.h
index b8a3b41..4ab35b5 100644
--- a/src/kxsldbgpart/libxsldbg/debugXML_compat.h
+++ b/src/kxsldbgpart/libxsldbg/debugXML_compat.h
@@ -40,8 +40,16 @@
  *    THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
-#ifndef __DEBUG_XML__
-#define __DEBUG_XML__
+#ifndef DEBUGXML_COMPAT_H_4CMW0PFD
+#define DEBUGXML_COMPAT_H_4CMW0PFD
+
+#if (LIBXML_VERSION >= 21400)
+
+/*
+ * This file provides compatibility wigh Shell libxml function which were
+ * removed from newer libxml.
+ */
+
 #include <stdio.h>
 #include <libxml/xmlversion.h>
 #include <libxml/tree.h>
@@ -246,4 +254,9 @@ XMLPUBFUN void
 #endif
 
 #endif /* LIBXML_DEBUG_ENABLED */
-#endif /* __DEBUG_XML__ */
+
+#else /* LIBXML_VERSION >= 21400 */
+#include<libxml/debugXML.h>
+#endif /* LIBXML_VERSION >= 21400 */
+
+#endif /* end of include guard: DEBUGXML_COMPAT_H_4CMW0PFD */
diff --git a/src/kxsldbgpart/libxsldbg/debugXSL.cpp b/src/kxsldbgpart/libxsldbg/debugXSL.cpp
index df63cdb..481793d 100644
--- a/src/kxsldbgpart/libxsldbg/debugXSL.cpp
+++ b/src/kxsldbgpart/libxsldbg/debugXSL.cpp
@@ -299,11 +299,9 @@ enum ShortcutsEnum {
 #include <libxml/tree.h>
 #include <libxml/parser.h>
 #include <libxml/valid.h>
-#include <libxml/debugXML.h>
 #include <libxml/HTMLtree.h>
 #include <libxml/HTMLparser.h>
 
-
 /* -----------------------------------------
    Private function declarations for debugXSL.c
  -------------------------------------------*/
diff --git a/src/kxsldbgpart/libxsldbg/debugXSL.h b/src/kxsldbgpart/libxsldbg/debugXSL.h
index 479448a..d70b05a 100644
--- a/src/kxsldbgpart/libxsldbg/debugXSL.h
+++ b/src/kxsldbgpart/libxsldbg/debugXSL.h
@@ -49,6 +49,8 @@
 #include "breakpoint.h"
 #endif
 
+#include "debugXML_compat.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/src/kxsldbgpart/libxsldbg/nodeview_cmds.cpp b/src/kxsldbgpart/libxsldbg/nodeview_cmds.cpp
index 5fcbef0..9a51cd6 100644
--- a/src/kxsldbgpart/libxsldbg/nodeview_cmds.cpp
+++ b/src/kxsldbgpart/libxsldbg/nodeview_cmds.cpp
@@ -169,8 +169,7 @@ xslDbgCatToFile(xmlNodePtr node, FILE * file)
         /* turn off encoding for the moment and just dump UTF-8 
          * which will be converted by xsldbgGeneralErrorFunc */
         xmlDocPtr doc = (xmlDocPtr) node;
-        const xmlChar *encoding = doc->encoding;
-
+        auto encoding = doc->encoding;
         if (encoding) {
             xsldbgGenericErrorFunc(i18n("Information: Temporarily setting document's encoding to UTF-8. Previously was %1.\n").arg(xsldbgText(encoding)));
         }
diff --git a/src/kxsldbgpart/libxsldbg/utils.h b/src/kxsldbgpart/libxsldbg/utils.h
index ada7b69..ec1fe34 100644
--- a/src/kxsldbgpart/libxsldbg/utils.h
+++ b/src/kxsldbgpart/libxsldbg/utils.h
@@ -31,7 +31,6 @@
 #include <stdio.h>
 #include <string.h>
 #include <libxml/tree.h>
-#include <libxml/debugXML.h>
 #include <libxslt/xsltInternals.h>
 #include <libxslt/xsltutils.h>
 #include <libxml/xpath.h>
diff --git a/src/kxsldbgpart/libxsldbg/xsldbg.cpp b/src/kxsldbgpart/libxsldbg/xsldbg.cpp
index 8b1e706..df133fd 100644
--- a/src/kxsldbgpart/libxsldbg/xsldbg.cpp
+++ b/src/kxsldbgpart/libxsldbg/xsldbg.cpp
@@ -118,7 +118,6 @@
 #include <time.h>
 #endif
 
-
 #endif /* WIN32 */
 
 #ifndef HAVE_STAT
-- 
cgit v1.2.3

