]> git.mikk.net Git - liburl/commitdiff
Merged html.c into text.c -- almost all code overlapped.
authorchris mikkelson <chris@mikk.net>
Thu, 11 Mar 2010 20:29:26 +0000 (14:29 -0600)
committerchris mikkelson <chris@mikk.net>
Thu, 11 Mar 2010 20:29:26 +0000 (14:29 -0600)
Makefile
html.c [deleted file]
text.c

index fa994518b1f0f571d6c772f98af9d75afe9f0584..0377f26b3d3097812bc5b5f52502f209f925d5ce 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -3,9 +3,9 @@ CFLAGS=-g -Wall -Werror -I/usr/local/include
 .c.o:
        $(CC) $(CFLAGS) -c $>
 
-SRCS=msgproc.c base64.c quoted-printable.c re_stream.c html.c text.c \
+SRCS=msgproc.c base64.c quoted-printable.c re_stream.c text.c \
        multipart.c message.c
-OBJS=msgproc.o base64.o quoted-printable.o re_stream.o html.o text.o \
+OBJS=msgproc.o base64.o quoted-printable.o re_stream.o text.o \
        multipart.o message.o
 
 default: liburl.a
diff --git a/html.c b/html.c
deleted file mode 100644 (file)
index e1aea3c..0000000
--- a/html.c
+++ /dev/null
@@ -1,69 +0,0 @@
-/* 
- * Copyright (c) 2009  Christopher L. Mikkelson <chris@mikk.net>
- * All Rights Reserved, for now.
- */
-
-#include <pcre.h>
-#include "re_stream.h"
-
-#include "msgproc.h"
-
-static const char *html_url_pattern = "<(a href|img src)=\"https?://[^\"]+";
-static pcre *html_url_re;
-
-static void
-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 */
-       }
-}
-
-static void
-html_start(msgproc *m)
-{
-       struct stream_re *s = malloc(sizeof(struct stream_re));
-       re_stream_start(s, html_url_re, 0);
-       msgproc_setpriv(m, (void *)s);
-}
-
-static void 
-html_process(msgproc *m, char *buf, size_t size)
-{
-       struct stream_re *sr = (struct stream_re *)msgproc_getpriv(m);
-       int n;
-
-       while (size > 0) {
-               n = re_stream_exec(sr, buf, size);
-               if (re_stream_result(sr) == 1) {
-                       char *url = re_stream_getresult(sr);
-                       if (m->callback)
-                               m->callback(m, url, m->call_data);
-               }
-               size -= n;
-               buf += n;
-       }
-}
-
-static void
-html_finish(msgproc *m)
-{
-       struct stream_re *sr = (struct stream_re *)msgproc_getpriv(m);
-       if (sr) {
-               re_stream_stop(sr);
-               free(sr);
-       }
-       msgproc_free(m);
-}
-
-msgproc_module msgproc_html = {
-       MSGPROC_HTML,                   /* type */
-       html_init,                      /* module init */
-       NULL,                           /* set module parameter */
-       html_start,                     /* start module instance */
-       NULL,                           /* set module instance parameter */
-       html_process,                   /* process data */
-       html_finish,                    /* shut down, free module instance */
-       NULL                            /* shut down, free module */
-};
diff --git a/text.c b/text.c
index 01d97182a2743dafd3a1d39161697a780d367cb9..19f39d6bfa43e0d3aca460eafafb12272b416d65 100644 (file)
--- a/text.c
+++ b/text.c
 
 static const char *text_url_pattern = "https?://\\S+";
 static pcre *text_url_re;
+static const char *html_url_pattern = "<(a href|img src)=\"https?://[^\"]+";
+static pcre *html_url_re;
 
 static void
-text_init(void) {
+text_plain_init(void) {
        const char *etxt; int epos;
        text_url_re = pcre_compile(text_url_pattern, 0, &etxt, &epos, 0);
        if (!text_url_re) {
@@ -21,7 +23,24 @@ text_init(void) {
 }
 
 static void
-text_start(msgproc *m)
+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 */
+       }
+}
+
+static void
+text_plain_start(msgproc *m)
+{
+       struct stream_re *s = malloc(sizeof(struct stream_re));
+       re_stream_start(s, text_url_re, 0);
+       msgproc_setpriv(m, (void *)s);
+}
+
+static void
+text_html_start(msgproc *m)
 {
        struct stream_re *s = malloc(sizeof(struct stream_re));
        re_stream_start(s, text_url_re, 0);
@@ -61,9 +80,20 @@ text_finish(msgproc *m)
 
 msgproc_module msgproc_text = {
        MSGPROC_TEXT,                   /* type */
-       text_init,                      /* module init */
+       text_plain_init,                /* module init */
+       NULL,                           /* set module parameter */
+       text_plain_start,               /* start module instance */
+       NULL,                           /* set module instance parameter */
+       text_process,                   /* process data */
+       text_finish,                    /* shut down, free module instance */
+       NULL                            /* shut down, free module */
+};
+
+msgproc_module msgproc_html = {
+       MSGPROC_HTML,                   /* type */
+       text_html_init,                 /* module init */
        NULL,                           /* set module parameter */
-       text_start,                     /* start module instance */
+       text_html_start,                /* start module instance */
        NULL,                           /* set module instance parameter */
        text_process,                   /* process data */
        text_finish,                    /* shut down, free module instance */