Added all of the MH sources, including RCS files, in
[mmh] / docs / historical / mh-6.8.5 / miscellany / multi-media / misc / rt2raw.c
1 /* taken straight from the MIME specification, to use with multi-media MH, do:
2
3         mhn-show-text/richtext: rt2raw < %f | fmt -78 | more
4
5    in your .mhn_profile.
6
7    Note that MTR doesn't use this program.  He uses NB's richtext program
8    instead (the one that comes with MetaMail).  See RICHTEXT.setup for the
9    details.
10  */
11
12 #include <stdio.h>
13 #include <ctype.h>
14 main() {
15     int c, i;
16     char token[50];
17
18     while((c = getc(stdin)) != EOF) {
19         if (c == '<') {
20             for (i=0; (c = getc(stdin)) != '>'
21                       && c != EOF; ++i) {
22                 token[i] = isupper(c) ? tolower(c) : c;
23             }
24             if (c == EOF) break;
25             token[i] = NULL;
26             if (!strcmp(token, "lt")) {
27                 putc('<', stdout);
28             } else if (!strcmp(token, "nl")) {
29                 putc('\n', stdout);
30             } else if (!strcmp(token, "/paragraph")) {
31                 puts("\n\n", stdout);
32             } else if (!strcmp(token, "comment")) {
33                 int commct=1;
34                 while (commct > 0) {
35                     while ((c = getc(stdin)) != '<'
36                      && c != EOF) ;
37                     if (c == EOF) break;
38                     for (i=0; (c = getc(stdin)) != '>'
39                        && c != EOF; ++i) {
40                         token[i] = isupper(c) ?
41                          tolower(c) : c;
42                     }
43                     if (c== EOF) break;
44                     token[i] = NULL;
45                     if (!strcmp(token, "/comment")) --commct;
46                     if (!strcmp(token, "comment"))  ++commct;
47                 }
48             } /* Ignore all other tokens */
49         } else if (c != '\n') {
50             putc(c, stdout);
51         } else putc (' ', stdout);
52     }
53     putc('\n', stdout); /* for good measure */
54     exit(0);
55 }