From 91e512cca85b592cba61fc25da2b50fbbc92b208 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Tue, 28 Aug 2007 19:40:30 +0200 Subject: [PATCH] document/dom: Move URL regexp setup from general code to source renderer --- src/document/dom/renderer.c | 22 ---------------------- src/document/dom/source.c | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/document/dom/renderer.c b/src/document/dom/renderer.c index 7f63f4c0c..385be210f 100644 --- a/src/document/dom/renderer.c +++ b/src/document/dom/renderer.c @@ -4,10 +4,6 @@ #include "config.h" #endif -#include /* FreeBSD needs this before regex.h */ -#ifdef HAVE_REGEX_H -#include -#endif #include #include "elinks.h" @@ -33,10 +29,6 @@ #include "util/string.h" -#define URL_REGEX "(file://|((f|ht|nt)tp(s)?|smb)://[[:alnum:]]+([-@:.]?[[:alnum:]])*\\.[[:alpha:]]{2,4}(:[[:digit:]]+)?)(/(%[[:xdigit:]]{2}|[-_~&=;?.a-z0-9])*)*" -#define URL_REGFLAGS (REG_ICASE | REG_EXTENDED) - - static inline void init_dom_renderer(struct dom_renderer *renderer, struct document *document, struct string *buffer, struct conv_table *convert_table) @@ -50,25 +42,11 @@ init_dom_renderer(struct dom_renderer *renderer, struct document *document, renderer->end = buffer->source + buffer->length; renderer->position = renderer->source; renderer->base_uri = get_uri_reference(document->uri); - -#ifdef HAVE_REGEX_H - if (renderer->document->options.plain_display_links) { - if (regcomp(&renderer->url_regex, URL_REGEX, URL_REGFLAGS)) { - regfree(&renderer->url_regex); - } else { - renderer->find_url = 1; - } - } -#endif } static inline void done_dom_renderer(struct dom_renderer *renderer) { -#ifdef HAVE_REGEX_H - if (renderer->find_url) - regfree(&renderer->url_regex); -#endif done_uri(renderer->base_uri); } diff --git a/src/document/dom/source.c b/src/document/dom/source.c index 0bdc7b3e8..0c0bfd23e 100644 --- a/src/document/dom/source.c +++ b/src/document/dom/source.c @@ -43,6 +43,11 @@ assertm(check_dom_node_source(renderer, str, len), "renderer[%p : %p] str[%p : %p]", \ (renderer)->source, (renderer)->end, (str), (str) + (len)) + +#define URL_REGEX "(file://|((f|ht|nt)tp(s)?|smb)://[[:alnum:]]+([-@:.]?[[:alnum:]])*\\.[[:alpha:]]{2,4}(:[[:digit:]]+)?)(/(%[[:xdigit:]]{2}|[-_~&=;?.a-z0-9])*)*" +#define URL_REGFLAGS (REG_ICASE | REG_EXTENDED) + + static inline void render_dom_flush(struct dom_renderer *renderer, unsigned char *string) { @@ -351,6 +356,16 @@ render_dom_document_start(struct dom_stack *stack, struct dom_node *node, void * selector ? &selector->properties : NULL); } +#ifdef HAVE_REGEX_H + if (renderer->document->options.plain_display_links) { + if (regcomp(&renderer->url_regex, URL_REGEX, URL_REGFLAGS)) { + regfree(&renderer->url_regex); + } else { + renderer->find_url = 1; + } + } +#endif + return DOM_CODE_OK; } @@ -366,6 +381,11 @@ render_dom_document_end(struct dom_stack *stack, struct dom_node *node, void *da render_dom_flush(renderer, renderer->end); } +#ifdef HAVE_REGEX_H + if (renderer->find_url) + regfree(&renderer->url_regex); +#endif + return DOM_CODE_OK; }