From 9328fa261e16f27c868d7b0e847efedc3baa8642 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Sat, 12 Jun 2021 17:37:11 +0200 Subject: [PATCH] [libdom] libdom also retired --- Makefile.config.in | 3 - configure.ac | 32 --- meson.build | 7 - meson_options.txt | 1 - src/document/Makefile | 1 - src/document/libdom/Makefile | 8 - src/document/libdom/meson.build | 2 - src/document/libdom/renderer.c | 398 -------------------------------- src/document/libdom/renderer.h | 19 -- src/document/meson.build | 3 - src/document/renderer.c | 9 - 11 files changed, 483 deletions(-) delete mode 100644 src/document/libdom/Makefile delete mode 100644 src/document/libdom/meson.build delete mode 100644 src/document/libdom/renderer.c delete mode 100644 src/document/libdom/renderer.h diff --git a/Makefile.config.in b/Makefile.config.in index 0b3bbce5..1c27a63a 100644 --- a/Makefile.config.in +++ b/Makefile.config.in @@ -71,8 +71,6 @@ INTLOBJS = @INTLOBJS@ INTL_LIBTOOL_SUFFIX_PREFIX = @INTL_LIBTOOL_SUFFIX_PREFIX@ DBLATEX = @DBLATEX@ LIBDIR = @LIBDIR@ -LIBDOM_CFLAGS = @LIBDOM_CFLAGS@ -LIBDOM_LIBS = @LIBDOM_LIBS@ LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ LOCALEDIR = @LOCALEDIR@ LUA_CFLAGS = @LUA_CFLAGS@ @@ -141,7 +139,6 @@ CONFIG_INTERLINK = @CONFIG_INTERLINK@ CONFIG_IPV6 = @CONFIG_IPV6@ CONFIG_DBLATEX = @CONFIG_DBLATEX@ CONFIG_LEDS = @CONFIG_LEDS@ -CONFIG_LIBDOM = @CONFIG_LIBDOM@ CONFIG_LZMA = @CONFIG_LZMA@ CONFIG_MAILCAP = @CONFIG_MAILCAP@ CONFIG_MANUAL = @CONFIG_MANUAL@ diff --git a/configure.ac b/configure.ac index f819e137..57cf7bfe 100644 --- a/configure.ac +++ b/configure.ac @@ -1639,38 +1639,6 @@ AC_SUBST(TRE_CFLAGS) AC_SUBST(TRE_LIBS) EL_LOG_CONFIG([CONFIG_TRE], [[Regexp searching]], [[$tre_log]]) -# =================================================================== -# libdom -# =================================================================== - -LIBDOM_CFLAGS= -LIBDOM_LIBS= -CONFIG_LIBDOM=no -enable_libdom=no - -AC_ARG_WITH(libdom, [ --with-libdom enable libdom], - [ if test "x$withval" != xno; then enable_libdom=yes; fi ]) - -if test "$enable_libdom" = no; then - AC_MSG_CHECKING([[for libdom]]) - AC_MSG_RESULT([[disabled]]) -else - AC_MSG_CHECKING([[for libdom in pkg-config]]) - if $PKG_CONFIG $pkg_config_static libdom; then - LIBDOM_CFLAGS=`$PKG_CONFIG $pkg_config_static --cflags libdom` - LIBDOM_LIBS=`$PKG_CONFIG $pkg_config_static --libs libdom` - LIBS="$LIBDOM_LIBS $LIBS" - CONFIG_LIBDOM=yes - AC_DEFINE([CONFIG_LIBDOM], [1], [Define as 1 to use the libdom library.]) - AC_MSG_RESULT([[yes]]) - else - enable_libdom=no - fi -fi -AC_SUBST(LIBDOM_CFLAGS) -AC_SUBST(LIBDOM_LIBS) -EL_LOG_CONFIG([CONFIG_LIBDOM], [[libdom]], [[$enable_libdom]]) - # =================================================================== # Further LDFLAGS tweaks diff --git a/meson.build b/meson.build index a7e60a7f..ee939f0b 100644 --- a/meson.build +++ b/meson.build @@ -86,7 +86,6 @@ conf_data.set('CONFIG_OPENSSL', get_option('openssl')) conf_data.set('CONFIG_LIBEV', get_option('libev')) conf_data.set('CONFIG_LIBEVENT', get_option('libevent')) conf_data.set('CONFIG_X', get_option('x')) -conf_data.set('CONFIG_LIBDOM', get_option('libdom')) conf_data.set('CONFIG_XML', get_option('xml')) #CONFIG_BOOKMARKS=true @@ -114,7 +113,6 @@ conf_data.set('CONFIG_SCRIPTING', true) #CONFIG_LEDS', true) #CONFIG_EXMODE', false) #CONFIG_CSS', true) -#CONFIG_LIBDOM', false) #CONFIG_BROTLI', true) #CONFIG_BZIP2', true) #CONFIG_GZIP', true) @@ -291,11 +289,6 @@ if conf_data.get('CONFIG_GPM') deps += libgpmdeps endif -if conf_data.get('CONFIG_LIBDOM') - domdeps = dependency('libdom') - deps += domdeps -endif - if conf_data.get('CONFIG_XML') xml2deps = dependency('libxml2') deps += xml2deps diff --git a/meson_options.txt b/meson_options.txt index 535876ef..162c5ce1 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -60,5 +60,4 @@ option('openssl', type: 'boolean', value: true, description: 'OpenSSL support') option('libev', type: 'boolean', value: false, description: 'compile with libev (libevent compatibility mode)') option('libevent', type: 'boolean', value: false, description: 'compile with libevent. Note that libev has precedence') option('x', type: 'boolean', value: false, description: 'use the X Window System') -option('libdom', type: 'boolean', value: false, description: 'libdom') option('xml', type: 'boolean', value: false, description: 'libxml++') diff --git a/src/document/Makefile b/src/document/Makefile index 59541e0d..8ea77ed2 100644 --- a/src/document/Makefile +++ b/src/document/Makefile @@ -3,7 +3,6 @@ include $(top_builddir)/Makefile.config SUBDIRS-$(CONFIG_CSS) += css SUBDIRS-$(CONFIG_DOM) += dom -SUBDIRS-$(CONFIG_LIBDOM) += libdom SUBDIRS = html plain diff --git a/src/document/libdom/Makefile b/src/document/libdom/Makefile deleted file mode 100644 index 1c454942..00000000 --- a/src/document/libdom/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -top_builddir=../../.. -include $(top_builddir)/Makefile.config - -INCLUDES += $(LIBDOM_CFLAGS) - -OBJS = renderer.o - -include $(top_srcdir)/Makefile.lib diff --git a/src/document/libdom/meson.build b/src/document/libdom/meson.build deleted file mode 100644 index c9768007..00000000 --- a/src/document/libdom/meson.build +++ /dev/null @@ -1,2 +0,0 @@ -#INCLUDES += $(LIBDOM_CFLAGS) -srcs += files('renderer.c') diff --git a/src/document/libdom/renderer.c b/src/document/libdom/renderer.c deleted file mode 100644 index 5090b7d3..00000000 --- a/src/document/libdom/renderer.c +++ /dev/null @@ -1,398 +0,0 @@ -/* Plain text document renderer */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#include "elinks.h" - -#include "bookmarks/bookmarks.h" -#include "cache/cache.h" -#include "config/options.h" -#include "document/docdata.h" -#include "document/document.h" -#include "document/format.h" -#include "document/options.h" -#include "document/libdom/renderer.h" -#include "document/plain/renderer.h" -#include "document/renderer.h" -#include "globhist/globhist.h" -#include "intl/charsets.h" -#include "protocol/protocol.h" -#include "protocol/uri.h" -#include "terminal/color.h" -#include "terminal/draw.h" -#include "util/color.h" -#include "util/error.h" -#include "util/memory.h" -#include "util/string.h" - -#include -#include - -struct source_renderer { - struct string tmp_buffer; - struct string *source; - char *enc; -}; - -/** - * Generate a LibDOM document DOM from an HTML file - * - * \param file The file path - * \return pointer to DOM document, or NULL on error - */ -static dom_document * -create_doc_dom_from_buffer(struct source_renderer *renderer) -{ - dom_hubbub_parser *parser = NULL; - dom_hubbub_error error; - dom_hubbub_parser_params params; - dom_document *doc; - - params.enc = renderer->enc; - params.fix_enc = true; - params.enable_script = false; - params.msg = NULL; - params.script = NULL; - params.ctx = NULL; - params.daf = NULL; - - /* Create Hubbub parser */ - error = dom_hubbub_parser_create(¶ms, &parser, &doc); - if (error != DOM_HUBBUB_OK) { - DBG("Can't create Hubbub Parser\n"); - return NULL; - } - - /* Parse data */ - error = dom_hubbub_parser_parse_chunk(parser, renderer->source->source, renderer->source->length); - if (error != DOM_HUBBUB_OK) { - dom_hubbub_parser_destroy(parser); - DBG("Parsing errors occur %d\n", error & ~DOM_HUBBUB_HUBBUB_ERR); - return NULL; - } - - /* Done parsing file */ - error = dom_hubbub_parser_completed(parser); - if (error != DOM_HUBBUB_OK) { - dom_hubbub_parser_destroy(parser); - DBG("Parsing error when construct DOM\n"); - return NULL; - } - - /* Finished with parser */ - dom_hubbub_parser_destroy(parser); - - return doc; -} - -/** - * Dump attribute/value for an element node - * - * \param node The attribute node to dump details for - * \return true on success, or false on error - */ -static bool -dump_node_element_attribute(struct source_renderer *renderer, dom_node *node) -{ - dom_exception exc; - dom_string *attr = NULL; - dom_string *attr_value = NULL; - - exc = dom_attr_get_name((struct dom_attr *)node, &attr); - - if (exc != DOM_NO_ERR) { - DBG("Exception raised for dom_string_create\n"); - return false; - } - - /* Get attribute's value */ - exc = dom_attr_get_value((struct dom_attr *)node, &attr_value); - if (exc != DOM_NO_ERR) { - DBG("Exception raised for element_get_attribute\n"); - dom_string_unref(attr); - return false; - } else if (attr_value == NULL) { - /* Element lacks required attribute */ - dom_string_unref(attr); - return true; - } - - add_to_string(&renderer->tmp_buffer, " \033[0;33m"); - add_bytes_to_string(&renderer->tmp_buffer, dom_string_data(attr), dom_string_byte_length(attr)); - add_to_string(&renderer->tmp_buffer, "\033[0m=\"\033[0;35m"); - add_bytes_to_string(&renderer->tmp_buffer, dom_string_data(attr_value), dom_string_byte_length(attr_value)); - add_to_string(&renderer->tmp_buffer, "\033[0m\""); - - /* Finished with the attr dom_string */ - dom_string_unref(attr); - dom_string_unref(attr_value); - - return true; -} - -/** - * Print a line in a DOM structure dump for an element - * - * \param node The node to dump - * \param depth The node's depth - * \return true on success, or false on error - */ -static bool -dump_dom_element(struct source_renderer *renderer, dom_node *node, int depth) -{ - dom_exception exc; - dom_string *node_name = NULL; - dom_node_type type; - dom_namednodemap *attrs; - - /* Only interested in element nodes */ - exc = dom_node_get_node_type(node, &type); - - if (exc != DOM_NO_ERR) { - DBG("Exception raised for node_get_node_type\n"); - return false; - } else { - if (type == DOM_TEXT_NODE) { - dom_string *str; - - exc = dom_node_get_text_content(node, &str); - - if (exc == DOM_NO_ERR && str != NULL) { - int length = dom_string_byte_length(str); - const char *string = dom_string_data(str); - - if (!((length == 1) && (*string == '\n'))) { - add_bytes_to_string(&renderer->tmp_buffer, string, length); - } - dom_string_unref(str); - } - return true; - } - if (type != DOM_ELEMENT_NODE) { - /* Nothing to print */ - return true; - } - } - - /* Get element name */ - exc = dom_node_get_node_name(node, &node_name); - if (exc != DOM_NO_ERR) { - DBG("Exception raised for get_node_name\n"); - return false; - } else if (node_name == NULL) { - DBG("Broken: root_name == NULL\n"); - return false; - } - - /* Get string data and print element name */ - add_to_string(&renderer->tmp_buffer, "<\033[0;32m"); - add_bytes_to_string(&renderer->tmp_buffer, dom_string_data(node_name), dom_string_byte_length(node_name)); - add_to_string(&renderer->tmp_buffer, "\033[0m"); - - exc = dom_node_get_attributes(node, &attrs); - - if (exc == DOM_NO_ERR) { - int length; - - exc = dom_namednodemap_get_length(attrs, &length); - - if (exc == DOM_NO_ERR) { - int i; - - for (i = 0; i < length; ++i) { - dom_node *attr; - - exc = dom_namednodemap_item(attrs, i, &attr); - - if (exc == DOM_NO_ERR) { - dump_node_element_attribute(renderer, attr); - dom_node_unref(attr); - } - } - } - dom_node_unref(attrs); - } - add_char_to_string(&renderer->tmp_buffer, '>'); - - /* Finished with the node_name dom_string */ - dom_string_unref(node_name); - - return true; -} - -/** - * Print a closing element - * - * \param node The node to dump - * \return true on success, or false on error - */ -static bool -dump_dom_element_closing(struct source_renderer *renderer, dom_node *node) -{ - dom_exception exc; - dom_string *node_name = NULL; - dom_node_type type; - - /* Only interested in element nodes */ - exc = dom_node_get_node_type(node, &type); - - if (exc != DOM_NO_ERR) { - DBG("Exception raised for node_get_node_type\n"); - return false; - } else { - if (type != DOM_ELEMENT_NODE) { - /* Nothing to print */ - return true; - } - } - - /* Get element name */ - exc = dom_node_get_node_name(node, &node_name); - if (exc != DOM_NO_ERR) { - DBG("Exception raised for get_node_name\n"); - return false; - } else if (node_name == NULL) { - DBG("Broken: root_name == NULL\n"); - return false; - } - - /* Get string data and print element name */ - add_to_string(&renderer->tmp_buffer, "tmp_buffer, dom_string_data(node_name), dom_string_byte_length(node_name)); - add_to_string(&renderer->tmp_buffer, "\033[0m>"); - - /* Finished with the node_name dom_string */ - dom_string_unref(node_name); - - return true; -} - - -/** - * Walk though a DOM (sub)tree, in depth first order, printing DOM structure. - * - * \param node The root node to start from - * \param depth The depth of 'node' in the (sub)tree - */ -static bool -dump_dom_structure(struct source_renderer *renderer, dom_node *node, int depth) -{ - dom_exception exc; - dom_node *child; - - /* Print this node's entry */ - if (dump_dom_element(renderer, node, depth) == false) { - /* There was an error; return */ - return false; - } - - /* Get the node's first child */ - exc = dom_node_get_first_child(node, &child); - if (exc != DOM_NO_ERR) { - DBG("Exception raised for node_get_first_child\n"); - return false; - } else if (child != NULL) { - /* node has children; decend to children's depth */ - depth++; - - /* Loop though all node's children */ - do { - dom_node *next_child; - - /* Visit node's descendents */ - if (dump_dom_structure(renderer, child, depth) == false) { - /* There was an error; return */ - dom_node_unref(child); - return false; - } - - /* Go to next sibling */ - exc = dom_node_get_next_sibling(child, &next_child); - if (exc != DOM_NO_ERR) { - DBG("Exception raised for " - "node_get_next_sibling\n"); - dom_node_unref(child); - return false; - } - - dom_node_unref(child); - child = next_child; - } while (child != NULL); /* No more children */ - } - - dump_dom_element_closing(renderer, node); - - return true; -} - -/** - * Main entry point from OS. - */ -static int -libdom_main(struct source_renderer *renderer) -{ - dom_exception exc; /* returned by libdom functions */ - dom_document *doc = NULL; /* document, loaded into libdom */ - dom_node *root = NULL; /* root element of document */ - - /* Load up the input HTML file */ - doc = create_doc_dom_from_buffer(renderer); - if (doc == NULL) { - DBG("Failed to load document.\n"); - return EXIT_FAILURE; - } - - /* Get root element */ - exc = dom_document_get_document_element(doc, &root); - if (exc != DOM_NO_ERR) { - DBG("Exception raised for get_document_element\n"); - dom_node_unref(doc); - return EXIT_FAILURE; - } else if (root == NULL) { - DBG("Broken: root == NULL\n"); - dom_node_unref(doc); - return EXIT_FAILURE; - } - - /* Dump DOM structure */ - if (dump_dom_structure(renderer, root, 0) == false) { - DBG("Failed to complete DOM structure dump.\n"); - dom_node_unref(root); - dom_node_unref(doc); - return EXIT_FAILURE; - } - - dom_node_unref(root); - - /* Finished with the dom_document */ - dom_node_unref(doc); - - return EXIT_SUCCESS; -} - -void -render_source_document(struct cache_entry *cached, struct document *document, - struct string *buffer) -{ - struct source_renderer renderer; - char *head = empty_string_or_(cached->head); - - (void)get_convert_table(head, document->options.cp, - document->options.assume_cp, - &document->cp, - &document->cp_status, - document->options.hard_assume); - - init_string(&renderer.tmp_buffer); - renderer.source = buffer; - renderer.enc = get_cp_mime_name(document->cp); - libdom_main(&renderer); - render_plain_document(cached, document, &renderer.tmp_buffer); - done_string(&renderer.tmp_buffer); -} diff --git a/src/document/libdom/renderer.h b/src/document/libdom/renderer.h deleted file mode 100644 index 0445fc7a..00000000 --- a/src/document/libdom/renderer.h +++ /dev/null @@ -1,19 +0,0 @@ - -#ifndef EL__DOCUMENT_LIBDOM_RENDERER_H -#define EL__DOCUMENT_LIBDOM_RENDERER_H - -#ifdef __cplusplus -extern "C" { -#endif - -struct cache_entry; -struct document; -struct string; - -void render_source_document(struct cache_entry *cached, struct document *document, struct string *buffer); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/document/meson.build b/src/document/meson.build index 65d29271..4857fcff 100644 --- a/src/document/meson.build +++ b/src/document/meson.build @@ -4,9 +4,6 @@ endif if conf_data.get('CONFIG_DOM') subdir('dom') endif -if conf_data.get('CONFIG_LIBDOM') - subdir('libdom') -endif subdir('html') subdir('plain') srcs += files('docdata.c', 'document.c', 'format.c', 'forms.c', 'options.c', 'refresh.c', 'renderer.c') diff --git a/src/document/renderer.c b/src/document/renderer.c index 41fa4f24..f9751cbe 100644 --- a/src/document/renderer.c +++ b/src/document/renderer.c @@ -18,7 +18,6 @@ #include "document/dom/renderer.h" #include "document/html/frames.h" #include "document/html/renderer.h" -#include "document/libdom/renderer.h" #include "document/plain/renderer.h" #include "document/renderer.h" #include "document/view.h" @@ -249,14 +248,6 @@ render_encoded_document(struct cache_entry *cached, struct document *document) } } -#ifdef CONFIG_LIBDOM - if (document->options.plain && cached->content_type - && (!c_strcasecmp("text/html", cached->content_type) - || !c_strcasecmp("application/xhtml+xml", cached->content_type))) { - render_source_document(cached, document, &buffer); - } - else -#endif if (document->options.plain) { #ifdef CONFIG_DOM if (cached->content_type