]> code.citadel.org Git - citadel.git/blobdiff - citadel/html.c
* strlen holy war: loops. in loops it's very evil. the easy ones go away now.
[citadel.git] / citadel / html.c
index d7e986153e7fd861ca0eda5aa0cb40dc4625ce41..afc97e964a37a8d0570d40380330f7ef112f6dd5 100644 (file)
@@ -30,7 +30,6 @@
 #include <limits.h>
 #include "citadel.h"
 #include "server.h"
-#include "serv_extensions.h"
 #include "control.h"
 #include "sysdep_decls.h"
 #include "support.h"
@@ -60,6 +59,8 @@ char *html_to_ascii(char *inputmsg, int msglen, int screenwidth, int do_citaform
        int i, j, ch, did_out, rb, scanch;
        int nest = 0;           /* Bracket nesting level */
        int blockquote = 0;     /* BLOCKQUOTE nesting level */
+       int styletag = 0;       /* STYLE tag nesting level */
+       int styletag_start = 0;
        int bytes_processed = 0;
        char nl[128];
 
@@ -96,10 +97,10 @@ char *html_to_ascii(char *inputmsg, int msglen, int screenwidth, int do_citaform
                }
 
                /* Do some parsing */
-               if (strlen(inbuf)>0) {
+               if (!IsEmptyStr(inbuf)) {
 
                    /* Fold in all the spacing */
-                   for (i=0; i<strlen(inbuf); ++i) {
+                   for (i=0; !IsEmptyStr(&inbuf[i]); ++i) {
                        if (inbuf[i]==10) inbuf[i]=32;
                        if (inbuf[i]==13) inbuf[i]=32;
                        if (inbuf[i]==9) inbuf[i]=32;
@@ -108,12 +109,12 @@ char *html_to_ascii(char *inputmsg, int msglen, int screenwidth, int do_citaform
                                inbuf[i] = '?';
                        } */
                    }
-                   for (i=0; i<strlen(inbuf); ++i) {
+                   for (i=0; !IsEmptyStr(&inbuf[i]); ++i) {
                        while ((inbuf[i]==32)&&(inbuf[i+1]==32))
                                strcpy(&inbuf[i], &inbuf[i+1]);
                    }
 
-                   for (i=0; i<strlen(inbuf); ++i) {
+                   for (i=0; !IsEmptyStr(&inbuf[i]); ++i) {
 
                        ch = inbuf[i];
 
@@ -207,7 +208,6 @@ char *html_to_ascii(char *inputmsg, int msglen, int screenwidth, int do_citaform
                                }
 
                                else if (!strcasecmp(tag, "BLOCKQUOTE")) {
-                                       strcat(outbuf, nl);
                                        ++blockquote;
                                        strcpy(nl, "\n");
                                        for (j=0; j<blockquote; ++j) strcat(nl, ">");
@@ -220,7 +220,20 @@ char *html_to_ascii(char *inputmsg, int msglen, int screenwidth, int do_citaform
                                        strcpy(nl, "\n");
                                        for (j=0; j<blockquote; ++j) strcat(nl, ">");
                                        strcat(outbuf, nl);
-                                       strcat(outbuf, nl);
+                               }
+
+                               else if (!strcasecmp(tag, "STYLE")) {
+                                       ++styletag;
+                                       if (styletag == 1) {
+                                               styletag_start = strlen(outbuf);
+                                       }
+                               }
+
+                               else if (!strcasecmp(tag, "/STYLE")) {
+                                       --styletag;
+                                       if (styletag == 0) {
+                                               outbuf[styletag_start] = 0;
+                                       }
                                }
 
                        }
@@ -239,7 +252,7 @@ char *html_to_ascii(char *inputmsg, int msglen, int screenwidth, int do_citaform
                }
 
                /* Convert &; tags to the forbidden characters */
-               if (strlen(outbuf)>0) for (i=0; i<strlen(outbuf); ++i) {
+               if (!IsEmptyStr(outbuf)) for (i=0; !IsEmptyStr(&outbuf[i]); ++i) {
 
                        /* Character entity references */
                        if (!strncasecmp(&outbuf[i], "&nbsp;", 6)) {
@@ -354,6 +367,66 @@ char *html_to_ascii(char *inputmsg, int msglen, int screenwidth, int do_citaform
                                strcpy(&outbuf[i+3], &outbuf[i+7]);
                        }
 
+                       else if (!strncmp(&outbuf[i], "&Ccedil;", 8)) {
+                               outbuf[i] = 'C';
+                               strcpy(&outbuf[i+1], &outbuf[i+8]);
+                       }
+
+                       else if (!strncasecmp(&outbuf[i], "&ccedil;", 8)) {
+                               outbuf[i] = 'c';
+                               strcpy(&outbuf[i+1], &outbuf[i+8]);
+                       }
+
+                       else if (!strncmp(&outbuf[i], "&Egrave;", 8)) {
+                               outbuf[i] = 'E';
+                               strcpy(&outbuf[i+1], &outbuf[i+8]);
+                       }
+
+                       else if (!strncasecmp(&outbuf[i], "&egrave;", 8)) {
+                               outbuf[i] = 'e';
+                               strcpy(&outbuf[i+1], &outbuf[i+8]);
+                       }
+
+                       else if (!strncmp(&outbuf[i], "&Ecirc;", 7)) {
+                               outbuf[i] = 'E';
+                               strcpy(&outbuf[i+1], &outbuf[i+7]);
+                       }
+
+                       else if (!strncasecmp(&outbuf[i], "&ecirc;", 7)) {
+                               outbuf[i] = 'e';
+                               strcpy(&outbuf[i+1], &outbuf[i+7]);
+                       }
+
+                       else if (!strncmp(&outbuf[i], "&Eacute;", 8)) {
+                               outbuf[i] = 'E';
+                               strcpy(&outbuf[i+1], &outbuf[i+8]);
+                       }
+
+                       else if (!strncasecmp(&outbuf[i], "&eacute;", 8)) {
+                               outbuf[i] = 'e';
+                               strcpy(&outbuf[i+1], &outbuf[i+8]);
+                       }
+
+                       else if (!strncmp(&outbuf[i], "&Agrave;", 8)) {
+                               outbuf[i] = 'A';
+                               strcpy(&outbuf[i+1], &outbuf[i+8]);
+                       }
+
+                       else if (!strncasecmp(&outbuf[i], "&agrave;", 8)) {
+                               outbuf[i] = 'a';
+                               strcpy(&outbuf[i+1], &outbuf[i+8]);
+                       }
+
+                       else if (!strncasecmp(&outbuf[i], "&ldquo;", 7)) {
+                               outbuf[i] = '\"';
+                               strcpy(&outbuf[i+1], &outbuf[i+7]);
+                       }
+
+                       else if (!strncasecmp(&outbuf[i], "&rdquo;", 7)) {
+                               outbuf[i] = '\"';
+                               strcpy(&outbuf[i+1], &outbuf[i+7]);
+                       }
+
                        /* two-digit decimal equivalents */
                        else if ((!strncmp(&outbuf[i], "&#", 2))
                              && (outbuf[i+4] == ';') ) {
@@ -384,8 +457,8 @@ char *html_to_ascii(char *inputmsg, int msglen, int screenwidth, int do_citaform
                /* Output any lines terminated with hard line breaks */
                do {
                        did_out = 0;
-                       if (strlen(outbuf)>0) {
-                           for (i = 0; i<strlen(outbuf); ++i) {
+                       if (!IsEmptyStr(outbuf)) {
+                           for (i = 0; !IsEmptyStr(&outbuf[i]); ++i) {
                                if ( (i<(screenwidth-2)) && (outbuf[i]=='\n')) {
 
                                        strncpy(&outptr[output_len],