From d41b28bd027affe67bfd8032a2041241df8be823 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 30 Jan 2025 12:26:23 +0100 Subject: url-mode+config: wip: add url.regex option --- url-mode.c | 57 ++++----------------------------------------------------- 1 file changed, 4 insertions(+), 53 deletions(-) (limited to 'url-mode.c') diff --git a/url-mode.c b/url-mode.c index 36dc0250..9ba07d14 100644 --- a/url-mode.c +++ b/url-mode.c @@ -380,54 +380,7 @@ regex_detected(const struct terminal *term, enum url_action action, url_list_t * } } - /* - * Based on https://gist.github.com/gruber/249502, but modified: - * - Do not allow {} at all - * - Do allow matched [] - */ - regex_t preg; - const char *regex_string = - "(" - "[a-z][[:alnum:]-]+:" // protocol - "(" - "/{1,3}|[a-z0-9%]" // slashes (what's the OR part for?) - ")" - "|" - "www[:digit:]{0,3}[.]" - "|" - "[a-z0-9.\\-]+[.][a-z]{2,4}/" - ")" - "(" - "[^[:space:](){}<>]+" - "|" - "\\(([^[:space:](){}<>]+|(\\([^[:space:](){}<>]+\\)))*\\)" - "|" - "\\[([^]\\[[:space:](){}<>]+|(\\[[^]\\[[:space:](){}<>]+\\]))*\\]" - ")+" - "(" - "\\(([^[:space:](){}<>]+|(\\([^[:space:](){}<>]+\\)))*\\)" - "|" - "\\[([^]\\[[:space:](){}<>]+|(\\[[^]\\[[:space:](){}<>]+\\]))*\\]" - "|" - "[^]\\[[:space:]`!(){};:'\".,<>?«»“”‘’]" - ")" - ; - - int r = regcomp(&preg, regex_string, REG_EXTENDED); - - if (r != 0) { - char err_buf[1024]; - regerror(r, &preg, err_buf, sizeof(err_buf)); - LOG_ERR("failed to compile regular expression: %s", err_buf); - - for (size_t i = 0; i < ALEN(vlines); i++) { - const struct vline *v = &vlines[i]; - free(v->utf8); - free(v->map); - } - - return; - } + const regex_t *preg = &term->conf->url.preg; for (size_t i = 0; i < ALEN(vlines); i++) { const struct vline *v = &vlines[i]; @@ -436,9 +389,8 @@ regex_detected(const struct terminal *term, enum url_action action, url_list_t * const char *search_string = v->utf8; while (true) { - - regmatch_t matches[preg.re_nsub + 1]; - r = regexec(&preg, search_string, preg.re_nsub + 1, matches, 0); + regmatch_t matches[preg->re_nsub + 1]; + int r = regexec(preg, search_string, preg->re_nsub + 1, matches, 0); if (r == REG_NOMATCH) break; @@ -470,9 +422,8 @@ regex_detected(const struct terminal *term, enum url_action action, url_list_t * free(v->utf8); free(v->map); } - - regfree(&preg); } + static void osc8_uris(const struct terminal *term, enum url_action action, url_list_t *urls) { -- cgit v1.3