]> git.mikk.net Git - liburl/commitdiff
Merged text module initialization, updated regexps.
authorchris mikkelson <chris@mikk.net>
Thu, 11 Mar 2010 20:53:25 +0000 (14:53 -0600)
committerchris mikkelson <chris@mikk.net>
Thu, 11 Mar 2010 20:53:25 +0000 (14:53 -0600)
text.c

diff --git a/text.c b/text.c
index 19f39d6bfa43e0d3aca460eafafb12272b416d65..8c77eb20959c0b27e5a7dc653d91fc47cc9a6a58 100644 (file)
--- a/text.c
+++ b/text.c
@@ -4,30 +4,31 @@
  */
 
 #include <pcre.h>
+#include <err.h>
 #include "re_stream.h"
 
 #include "msgproc.h"
 
-static const char *text_url_pattern = "https?://\\S+";
+static const char *text_url_pattern = "https?://[^\\s]+(?=\\s|$|\\))";
 static pcre *text_url_re;
-static const char *html_url_pattern = "<(a href|img src)=\"https?://[^\"]+";
+static const char *html_url_pattern = "(?<=<a href=\")https?://[^\"]+(?=\")"; 
 static pcre *html_url_re;
 
 static void
-text_plain_init(void) {
+text_init(void) {
        const char *etxt; int epos;
+       static int initialized = 0;
+
+       if (initialized) return;
+       initialized = 1;
+
        text_url_re = pcre_compile(text_url_pattern, 0, &etxt, &epos, 0);
        if (!text_url_re) {
-               /* die */
+               errx(1, "text_url_pattern compile error\n");
        }
-}
-
-static void
-text_html_init(void) {
-       const char *etxt; int epos;
        html_url_re = pcre_compile(html_url_pattern, 0, &etxt, &epos, 0);
        if (!html_url_re) {
-               /* die */
+               errx(1, "html_url_pattern compile error\n");
        }
 }
 
@@ -80,7 +81,7 @@ text_finish(msgproc *m)
 
 msgproc_module msgproc_text = {
        MSGPROC_TEXT,                   /* type */
-       text_plain_init,                /* module init */
+       text_init,                      /* module init */
        NULL,                           /* set module parameter */
        text_plain_start,               /* start module instance */
        NULL,                           /* set module instance parameter */
@@ -91,7 +92,7 @@ msgproc_module msgproc_text = {
 
 msgproc_module msgproc_html = {
        MSGPROC_HTML,                   /* type */
-       text_html_init,                 /* module init */
+       text_init,                      /* module init */
        NULL,                           /* set module parameter */
        text_html_start,                /* start module instance */
        NULL,                           /* set module instance parameter */