#include <limits.h>
#include "citadel.h"
#include "server.h"
-#include "serv_extensions.h"
#include "control.h"
#include "sysdep_decls.h"
#include "support.h"
int i, j, ch, did_out, rb, scanch;
int nest = 0; /* Bracket nesting level */
int blockquote = 0; /* BLOCKQUOTE nesting level */
+ int styletag = 0; /* STYLE tag nesting level */
+ int styletag_start = 0;
int bytes_processed = 0;
+ char nl[128];
+ strcpy(nl, "\n");
inptr = inputmsg;
strcpy(inbuf, "");
strcpy(outbuf, "");
}
/* Do some parsing */
- if (strlen(inbuf)>0) {
+ if (!IsEmptyStr(inbuf)) {
/* Fold in all the spacing */
- for (i=0; i<strlen(inbuf); ++i) {
+ for (i=0; !IsEmptyStr(&inbuf[i]); ++i) {
if (inbuf[i]==10) inbuf[i]=32;
if (inbuf[i]==13) inbuf[i]=32;
if (inbuf[i]==9) inbuf[i]=32;
inbuf[i] = '?';
} */
}
- for (i=0; i<strlen(inbuf); ++i) {
+ for (i=0; !IsEmptyStr(&inbuf[i]); ++i) {
while ((inbuf[i]==32)&&(inbuf[i+1]==32))
strcpy(&inbuf[i], &inbuf[i+1]);
}
- for (i=0; i<strlen(inbuf); ++i) {
+ for (i=0; !IsEmptyStr(&inbuf[i]); ++i) {
ch = inbuf[i];
}
if (!strcasecmp(tag, "P")) {
- strcat(outbuf, "\n\n");
+ strcat(outbuf, nl);
+ strcat(outbuf, nl);
}
if (!strcasecmp(tag, "/DIV")) {
- strcat(outbuf, "\n\n");
+ strcat(outbuf, nl);
+ strcat(outbuf, nl);
}
if (!strcasecmp(tag, "LI")) {
- strcat(outbuf, "\n * ");
+ strcat(outbuf, nl);
+ strcat(outbuf, " * ");
}
else if (!strcasecmp(tag, "/UL")) {
- strcat(outbuf, "\n\n");
+ strcat(outbuf, nl);
+ strcat(outbuf, nl);
}
else if (!strcasecmp(tag, "H1")) {
- strcat(outbuf, "\n\n");
+ strcat(outbuf, nl);
+ strcat(outbuf, nl);
}
else if (!strcasecmp(tag, "H2")) {
- strcat(outbuf, "\n\n");
+ strcat(outbuf, nl);
+ strcat(outbuf, nl);
}
else if (!strcasecmp(tag, "H3")) {
- strcat(outbuf, "\n\n");
+ strcat(outbuf, nl);
+ strcat(outbuf, nl);
}
else if (!strcasecmp(tag, "H4")) {
- strcat(outbuf, "\n\n");
+ strcat(outbuf, nl);
+ strcat(outbuf, nl);
}
else if (!strcasecmp(tag, "/H1")) {
- strcat(outbuf, "\n");
+ strcat(outbuf, nl);
}
else if (!strcasecmp(tag, "/H2")) {
- strcat(outbuf, "\n");
+ strcat(outbuf, nl);
}
else if (!strcasecmp(tag, "/H3")) {
- strcat(outbuf, "\n");
+ strcat(outbuf, nl);
}
else if (!strcasecmp(tag, "/H4")) {
- strcat(outbuf, "\n");
+ strcat(outbuf, nl);
}
else if (!strcasecmp(tag, "HR")) {
- strcat(outbuf, "\n ");
+ strcat(outbuf, nl);
+ strcat(outbuf, " ");
for (j=0; j<screenwidth-2; ++j)
strcat(outbuf, "-");
- strcat(outbuf, "\n");
+ strcat(outbuf, nl);
}
else if (!strcasecmp(tag, "BR")) {
- strcat(outbuf, "\n");
+ strcat(outbuf, nl);
}
else if (!strcasecmp(tag, "TR")) {
- strcat(outbuf, "\n");
+ strcat(outbuf, nl);
}
else if (!strcasecmp(tag, "/TABLE")) {
- strcat(outbuf, "\n");
+ strcat(outbuf, nl);
}
else if (!strcasecmp(tag, "BLOCKQUOTE")) {
- strcat(outbuf, "\n\n <<\n");
++blockquote;
+ strcpy(nl, "\n");
+ for (j=0; j<blockquote; ++j) strcat(nl, ">");
+ strcat(outbuf, nl);
}
else if (!strcasecmp(tag, "/BLOCKQUOTE")) {
- strcat(outbuf, "\n >>\n\n");
+ strcat(outbuf, "\n");
--blockquote;
+ strcpy(nl, "\n");
+ for (j=0; j<blockquote; ++j) strcat(nl, ">");
+ strcat(outbuf, nl);
+ }
+
+ else if (!strcasecmp(tag, "STYLE")) {
+ ++styletag;
+ if (styletag == 1) {
+ styletag_start = strlen(outbuf);
+ }
+ }
+
+ else if (!strcasecmp(tag, "/STYLE")) {
+ --styletag;
+ if (styletag == 0) {
+ outbuf[styletag_start] = 0;
+ }
}
}
}
/* Convert &; tags to the forbidden characters */
- if (strlen(outbuf)>0) for (i=0; i<strlen(outbuf); ++i) {
+ if (!IsEmptyStr(outbuf)) for (i=0; !IsEmptyStr(&outbuf[i]); ++i) {
/* Character entity references */
if (!strncasecmp(&outbuf[i], " ", 6)) {
strcpy(&outbuf[i+3], &outbuf[i+7]);
}
+ else if (!strncmp(&outbuf[i], "Ç", 8)) {
+ outbuf[i] = 'C';
+ strcpy(&outbuf[i+1], &outbuf[i+8]);
+ }
+
+ else if (!strncasecmp(&outbuf[i], "ç", 8)) {
+ outbuf[i] = 'c';
+ strcpy(&outbuf[i+1], &outbuf[i+8]);
+ }
+
+ else if (!strncmp(&outbuf[i], "È", 8)) {
+ outbuf[i] = 'E';
+ strcpy(&outbuf[i+1], &outbuf[i+8]);
+ }
+
+ else if (!strncasecmp(&outbuf[i], "è", 8)) {
+ outbuf[i] = 'e';
+ strcpy(&outbuf[i+1], &outbuf[i+8]);
+ }
+
+ else if (!strncmp(&outbuf[i], "Ê", 7)) {
+ outbuf[i] = 'E';
+ strcpy(&outbuf[i+1], &outbuf[i+7]);
+ }
+
+ else if (!strncasecmp(&outbuf[i], "ê", 7)) {
+ outbuf[i] = 'e';
+ strcpy(&outbuf[i+1], &outbuf[i+7]);
+ }
+
+ else if (!strncmp(&outbuf[i], "É", 8)) {
+ outbuf[i] = 'E';
+ strcpy(&outbuf[i+1], &outbuf[i+8]);
+ }
+
+ else if (!strncasecmp(&outbuf[i], "é", 8)) {
+ outbuf[i] = 'e';
+ strcpy(&outbuf[i+1], &outbuf[i+8]);
+ }
+
+ else if (!strncmp(&outbuf[i], "À", 8)) {
+ outbuf[i] = 'A';
+ strcpy(&outbuf[i+1], &outbuf[i+8]);
+ }
+
+ else if (!strncasecmp(&outbuf[i], "à", 8)) {
+ outbuf[i] = 'a';
+ strcpy(&outbuf[i+1], &outbuf[i+8]);
+ }
+
+ 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] == ';') ) {
/* Output any lines terminated with hard line breaks */
do {
did_out = 0;
- if (strlen(outbuf)>0) {
- for (i = 0; i<strlen(outbuf); ++i) {
+ if (!IsEmptyStr(outbuf)) {
+ for (i = 0; !IsEmptyStr(&outbuf[i]); ++i) {
if ( (i<(screenwidth-2)) && (outbuf[i]=='\n')) {
strncpy(&outptr[output_len],
if (rb>=0) {
strncpy(&outptr[output_len], outbuf, rb);
output_len += rb;
- strcpy(&outptr[output_len], "\n");
- output_len += 1;
+ strcpy(&outptr[output_len], nl);
+ output_len += strlen(nl);
if (do_citaformat) {
strcpy(&outptr[output_len], " ");
++output_len;
strncpy(&outptr[output_len], outbuf,
screenwidth-2);
output_len += (screenwidth-2);
- strcpy(&outptr[output_len], "\n");
- output_len += 1;
+ strcpy(&outptr[output_len], nl);
+ output_len += strlen(nl);
if (do_citaformat) {
strcpy(&outptr[output_len], " ");
++output_len;