2 * html.c -- Functions which handle translation between HTML and plain text
14 * Convert HTML to plain text.
16 void html_to_ascii(int screenwidth) {
23 int nest = 0; /* Bracket nesting level */
29 /* Fill the input buffer */
30 if ( (done_reading == 0) && (strlen(inbuf) < 128) ) {
31 /* FIX ... genericize this */
32 ptr = fgets(&inbuf[strlen(inbuf)], 127, stdin);
33 if (ptr == NULL) done_reading = 1;
37 if (strlen(inbuf)>0) {
39 /* Fold in all the spacing */
40 for (i=0; i<strlen(inbuf); ++i) {
41 if (inbuf[i]==10) inbuf[i]=32;
42 if (inbuf[i]==13) inbuf[i]=32;
43 if (inbuf[i]==9) inbuf[i]=32;
44 if ((inbuf[i]<32) || (inbuf[i]>126))
45 strcpy(&inbuf[i], &inbuf[i+1]);
46 while ((inbuf[i]==32)&&(inbuf[i+1]==32))
47 strcpy(&inbuf[i], &inbuf[i+1]);
50 for (i=0; i<strlen(inbuf); ++i) {
62 if (!strcasecmp(tag, "P")) {
63 strcat(outbuf, "\n\n");
66 if (!strcasecmp(tag, "HR")) {
67 strcat(outbuf, "\n ----- \n");
70 if (!strcasecmp(tag, "BR")) {
74 if (!strcasecmp(tag, "TR")) {
78 if (!strcasecmp(tag, "/TABLE")) {
84 else if ((nest > 0) && (strlen(tag)<(sizeof(tag)-1))) {
85 tag[strlen(tag)+1] = 0;
86 tag[strlen(tag)] = ch;
90 outbuf[strlen(outbuf)+1] = 0;
91 outbuf[strlen(outbuf)] = ch;
94 strcpy(inbuf, &inbuf[i]);
97 /* Convert &; tags to the forbidden characters */
98 if (strlen(outbuf)>0) for (i=0; i<strlen(outbuf); ++i) {
100 if (!strncasecmp(&outbuf[i], " ", 6)) {
102 strcpy(&outbuf[i+1], &outbuf[i+6]);
105 else if (!strncasecmp(&outbuf[i], "&lb;", 4)) {
107 strcpy(&outbuf[i+1], &outbuf[i+4]);
110 else if (!strncasecmp(&outbuf[i], "&rb;", 4)) {
112 strcpy(&outbuf[i+1], &outbuf[i+4]);
115 else if (!strncasecmp(&outbuf[i], "&", 5)) {
116 strcpy(&outbuf[i+1], &outbuf[i+5]);
119 else if (!strncasecmp(&outbuf[i], """, 6)) {
121 strcpy(&outbuf[i+1], &outbuf[i+6]);
126 /* Output our finely-crafted plain ASCII */
127 printf("%s", outbuf); /* FIX ... genericize this */
130 } while (done_reading == 0);
136 * Temporary main loop for testing