* Functions which handle translation between HTML and plain text
* Copyright (c) 2000-2010 by the citadel.org team
*
- * This program is free software; you can redistribute it and/or modify
+ * This program is open source software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
* screenwidth = desired output screenwidth
* do_citaformat = set to 1 to indent newlines with spaces
*/
-char *html_to_ascii(char *inputmsg, int msglen, int screenwidth, int do_citaformat) {
+char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth, int do_citaformat) {
char inbuf[SIZ];
int inbuf_len = 0;
char outbuf[SIZ];
char tag[1024];
int done_reading = 0;
- char *inptr;
+ const char *inptr;
char *outptr;
size_t outptr_buffer_size;
size_t output_len = 0;
int bytes_processed = 0;
char nl[128];
+ tag[0] = '\0';
strcpy(nl, "\n");
inptr = inputmsg;
strcpy(inbuf, "");
strcpy(&outbuf[i+1], &outbuf[i+7]);
}
+ else if (!strncasecmp(&outbuf[i], "’", 7)) {
+ outbuf[i] = '\'';
+ strcpy(&outbuf[i+1], &outbuf[i+7]);
+ }
+
+ else if (!strncasecmp(&outbuf[i], "–", 7)) {
+ outbuf[i] = '-';
+ strcpy(&outbuf[i+1], &outbuf[i+7]);
+ }
+
/* two-digit decimal equivalents */
- else if ((!strncmp(&outbuf[i], "&#", 2))
- && (outbuf[i+4] == ';') ) {
+ else if (outbuf[i] == '&' &&
+ outbuf[i + 1] == '#' &&
+ isdigit(outbuf[i + 2]) &&
+ isdigit(outbuf[i + 3]) &&
+ (outbuf[i+4] == ';') )
+ {
scanch = 0;
sscanf(&outbuf[i+2], "%02d", &scanch);
outbuf[i] = scanch;
}
/* three-digit decimal equivalents */
- else if ((!strncmp(&outbuf[i], "&#", 2))
- && (outbuf[i+5] == ';') ) {
+ else if (outbuf[i] == '&' &&
+ outbuf[i + 1] == '#' &&
+ isdigit(outbuf[i + 2]) &&
+ isdigit(outbuf[i + 3]) &&
+ isdigit(outbuf[i + 4]) &&
+ (outbuf[i + 5] == ';') )
+ {
scanch = 0;
sscanf(&outbuf[i+2], "%03d", &scanch);
outbuf[i] = scanch;
strcpy(&outbuf[i+1], &outbuf[i+6]);
}
+ /* four-digit decimal equivalents */
+ else if (outbuf[i] == '&' &&
+ outbuf[i + 1] == '#' &&
+ isdigit(outbuf[i + 2]) &&
+ isdigit(outbuf[i + 3]) &&
+ isdigit(outbuf[i + 4]) &&
+ isdigit(outbuf[i + 5]) &&
+ (outbuf[i + 6] == ';') )
+ {
+ scanch = 0;
+ sscanf(&outbuf[i+2], "%04d", &scanch);
+ outbuf[i] = scanch;
+ strcpy(&outbuf[i+1], &outbuf[i+7]);
+ }
+
}
/* Make sure the output buffer is big enough */