From 10fe04edc5adf942c2bf9806eea5dd81edd2c9a5 Mon Sep 17 00:00:00 2001 From: Robert Pluim Date: Tue, 24 Oct 2017 19:01:28 +0200 Subject: [PATCH] Provide libxml-available-p * src/emacs.c (main): Call syms_of_xml unconditionally * src/lisp.h: Provide syms_of_xml prototype even when HAVE_LIBXML2 is not defined * src/xml.c (Flibxml_available_p): New function, cloned from Fgnutls_available_p (syms_of_xml): Provide Slibxml_available_p * doc/lispref/text.texi (Parsing HTML/XML): Document libxml-available-p --- doc/lispref/text.texi | 5 +++++ src/emacs.c | 2 -- src/lisp.h | 2 +- src/xml.c | 37 ++++++++++++++++++++++++++++++++----- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi index baa3c708e9..565d098069 100644 --- a/doc/lispref/text.texi +++ b/doc/lispref/text.texi @@ -4723,6 +4723,11 @@ Parsing HTML/XML @section Parsing HTML and XML @cindex parsing html +@defun libxml-available-p +This function returns non-@code{nil} if built-in libxml2 support is +available. +@end defun + When Emacs is compiled with libxml2 support, the following functions are available to parse HTML or XML text into Lisp object trees. diff --git a/src/emacs.c b/src/emacs.c index 0fe7d9113b..808abcd9aa 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -1542,9 +1542,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem #endif #endif /* HAVE_X_WINDOWS */ -#ifdef HAVE_LIBXML2 syms_of_xml (); -#endif #ifdef HAVE_LCMS2 syms_of_lcms2 (); diff --git a/src/lisp.h b/src/lisp.h index 266370333f..cc8d90cbf1 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4399,9 +4399,9 @@ extern void syms_of_xterm (void); extern char *x_get_keysym_name (int); #endif /* HAVE_WINDOW_SYSTEM */ -#ifdef HAVE_LIBXML2 /* Defined in xml.c. */ extern void syms_of_xml (void); +#ifdef HAVE_LIBXML2 extern void xml_cleanup_parser (void); #endif diff --git a/src/xml.c b/src/xml.c index d087a34a5e..7afaa63c42 100644 --- a/src/xml.c +++ b/src/xml.c @@ -18,15 +18,15 @@ along with GNU Emacs. If not, see . */ #include +#include "lisp.h" +#include "buffer.h" + #ifdef HAVE_LIBXML2 #include #include #include -#include "lisp.h" -#include "buffer.h" - #ifdef WINDOWSNT @@ -291,16 +291,43 @@ If DISCARD-COMMENTS is non-nil, all HTML comments are discarded. */) return parse_region (start, end, base_url, discard_comments, false); return Qnil; } +#endif /* HAVE_LIBXML2 */ + +DEFUN ("libxml-available-p", Flibxml_available_p, Slibxml_available_p, 0, 0, 0, + doc: /* Return t if libxml2 support is available in this instance of Emacs.*/) + (void) +{ +#ifdef HAVE_LIBXML2 +# ifdef WINDOWSNT + Lisp_Object found = Fassq (Qlibxml2, Vlibrary_cache); + if (CONSP (found)) + return XCDR (found); + else + { + Lisp_Object status; + status = init_libxml2_functions () ? Qt : Qnil; + Vlibrary_cache = Fcons (Fcons (Qlibxml2, status), Vlibrary_cache); + return status; + } +# else + return Qt; +# endif /* WINDOWSNT */ +#else + return Qnil; +#endif /* HAVE_LIBXML2 */ +} + /*********************************************************************** Initialization ***********************************************************************/ void syms_of_xml (void) { +#ifdef HAVE_LIBXML2 defsubr (&Slibxml_parse_html_region); defsubr (&Slibxml_parse_xml_region); +#endif + defsubr (&Slibxml_available_p); } - -#endif /* HAVE_LIBXML2 */ -- 2.15.0.rc1