richtext.c - rohrpost - A commandline mail client to change the world as we see it.
 (HTM) git clone git://r-36.net/rohrpost
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       richtext.c (1186B)
       ---
            1 /*
            2  * Copy me if you can.
            3  * by 20h
            4  */
            5 
            6 #include <unistd.h>
            7 #include <stdlib.h>
            8 #include <stdio.h>
            9 #include <string.h>
           10 
           11 #include "ind.h"
           12 
           13 /*
           14  * There is no reason for encoding support.
           15  */
           16 
           17 /*
           18  * Decoding based on Appendix D in RFC 1341.
           19  */
           20 
           21 /*
           22  * UNTESTED
           23  */
           24 
           25 char *
           26 richtextdec(char *str, int *len, int ishdr)
           27 {
           28         char *ret, *tend, *token, *addstr;
           29         int i, alen, rlen, commct;
           30 
           31         ret = NULL;
           32         commct = 0;
           33 
           34         for (i = 0, rlen = 0; i < len; i++) {
           35                 addstr = NULL;
           36                 if (str[i] == '<') {
           37                         tend = strchr(&str[i], '>');
           38                         if (tend == NULL)
           39                                 break;
           40                         token = memdupz(&str[i+1], tend - &str[i+1]);
           41 
           42                         if (!strcasecmp(token, "lt")) {
           43                                 addstr = memdupz("<", 1);
           44                         } else if (!strcasecmp(token, "nl")) {
           45                                 addstr = memdupz("\n", 1);
           46                         } else if (!strcasecmp(token, "/paragraph")) {
           47                                 addstr = memdupz("\n\n", 2);
           48                         } else if (!strcasecmp(token, "/comment")) {
           49                                 commct--;
           50                         } else if (!strcasecmp(token, "comment")) {
           51                                 commct++;
           52                         }
           53                         free(token);
           54                 } else {
           55                         addstr = memdupz(&str[i], 1);
           56                 }
           57 
           58                 if (addstr == NULL || commct)
           59                         continue;
           60 
           61                 alen = strlen(addstr);
           62                 ret = memdupcat(ret, rlen, addstr, alen+1);
           63                 rlen += alen;
           64 
           65                 free(addstr);
           66         }
           67 
           68         return ret;
           69 }
           70