1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

document/dom: Move URL regexp setup from general code to source renderer

This commit is contained in:
Petr Baudis 2007-08-28 19:40:30 +02:00 committed by Petr Baudis
parent afb9b6daa5
commit 91e512cca8
2 changed files with 20 additions and 22 deletions

View File

@ -4,10 +4,6 @@
#include "config.h"
#endif
#include <sys/types.h> /* FreeBSD needs this before regex.h */
#ifdef HAVE_REGEX_H
#include <regex.h>
#endif
#include <string.h>
#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);
}

View File

@ -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;
}