/*
- * html.c -- Functions which handle translation between HTML and plain text
* $Id$
+ *
+ * Functions which handle translation between HTML and plain text
*/
#include "sysdep.h"
#include <stdio.h>
#include <fcntl.h>
#include <signal.h>
-#include <time.h>
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+# include <sys/time.h>
+# else
+# include <time.h>
+# endif
+#endif
+
#include <ctype.h>
#include <string.h>
#include <errno.h>
#include <limits.h>
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
#include <syslog.h>
#include "citadel.h"
#include "server.h"
/*
* Convert HTML to plain text.
+ *
+ * inputmsg = pointer to raw HTML message
+ * screenwidth = desired output screenwidth
+ * do_citaformat = set to 1 to indent newlines with spaces
*/
-char *html_to_ascii(char *inputmsg, int screenwidth) {
- char inbuf[256];
- char outbuf[256];
+char *html_to_ascii(char *inputmsg, int screenwidth, int do_citaformat) {
+ char inbuf[SIZ];
+ char outbuf[SIZ];
char tag[1024];
int done_reading = 0;
char *inptr;
strcpy(inbuf, "");
strcpy(outbuf, "");
- outptr = mallok(strlen(inptr) + 256);
+ outptr = mallok(strlen(inptr) + SIZ);
if (outptr == NULL) return NULL;
strcpy(outptr, "");
outlen = 0;
/* Fill the input buffer */
if ( (done_reading == 0) && (strlen(inbuf) < 128) ) {
- /* FIX ... genericize this */
ch = *inputmsg++;
if (ch > 0) {
inbuf[strlen(inbuf)+1] = 0;
strcat(outbuf, "\n\n");
}
+ if (!strcasecmp(tag, "/DIV")) {
+ strcat(outbuf, "\n\n");
+ }
+
else if (!strcasecmp(tag, "H1")) {
strcat(outbuf, "\n\n");
}
if (strlen(outbuf)>0)
for (i = 0; i<strlen(outbuf); ++i) {
if ( (i<(screenwidth-2)) && (outbuf[i]=='\n')) {
-
strncat(outptr, outbuf, i+1);
-
+ strcat(outptr, "\n");
+ if (do_citaformat)
+ strcat(outptr, " ");
strcpy(outbuf, &outbuf[i+1]);
i = 0;
did_out = 1;
if (outbuf[i]==32) rb = i;
}
if (rb>=0) {
-
strncat(outptr, outbuf, rb);
strcat(outptr, "\n");
-
+ if (do_citaformat)
+ strcat(outptr, " ");
strcpy(outbuf, &outbuf[rb+1]);
} else {
strncat(outptr, outbuf, screenwidth-2);
strcat(outptr, "\n");
-
+ if (do_citaformat)
+ strcat(outptr, " ");
strcpy(outbuf, &outbuf[screenwidth-2]);
}
}