int put_chars_conv(struct part *p, unsigned char *c, int l) { static char buffer[CH_BUF]; int bp = 0; int pp = 0; int total = 0; if (format.attr & AT_GRAPHICS) { put_chars(p, c, l); return l; } if (!l) put_chars(p, NULL, 0); while (pp < l) { unsigned char *e; if (c[pp] < 128 && c[pp] != '&') { put_c: buffer[bp++] = c[pp++]; if (bp < CH_BUF) continue; goto flush; } if (c[pp] != '&') { struct conv_table *t; int i; if (!convert_table) goto put_c; t = convert_table; i = pp; decode: if (!t[c[i]].t) { e = t[c[i]].u.str; } else { t = t[c[i++]].u.tbl; if (i >= l) goto put_c; goto decode; } pp = i + 1; } else { int i = pp + 1; if (d_opt->plain) goto put_c; while (i < l && c[i] != ';' && c[i] != '&' && c[i] > ' ') i++; if (!(e = get_entity_string(&c[pp + 1], i - pp - 1, d_opt->cp))) goto put_c; pp = i + (i < l && c[i] == ';'); } if (!e[0]) continue; if (!e[1]) { buffer[bp++] = e[0]; if (bp < CH_BUF) continue; flush: e = ""; goto flush1; } while (*e) { buffer[bp++] = *(e++); if (bp < CH_BUF) continue; flush1: put_chars(p, buffer, bp); total += bp; bp = 0; } } if (bp) put_chars(p, buffer, bp); total += bp; return total; }
int g_put_chars_conv(struct g_part *p, unsigned char *c, int l) { static char buffer[CH_BUF]; int bp = 0; int pp = 0; int total = 0; if (format.attr & AT_GRAPHICS) { g_put_chars(p, c, l); return l; } /*{ debug("\"%.*s\"", l, c); }*/ if (!l) g_put_chars(p, NULL, 0); while (pp < l) { unsigned char *e; if (c[pp] < 128 && c[pp] != '&') { putc: if (!(buffer[bp++] = c[pp++])) buffer[bp - 1] = ' '; if (bp < CH_BUF) continue; goto flush; } if (c[pp] != '&') { struct conv_table *t; int i; if (!convert_table) goto putc; t = convert_table; i = pp; decode: if (!t[c[i]].t) { e = t[c[i]].u.str; } else { t = t[c[i++]].u.tbl; if (i >= l) goto putc; goto decode; } pp = i + 1; } else { int i = pp + 1; if (d_opt->plain & 1) goto putc; while (i < l && c[i] != ';' && c[i] != '&' && c[i] > ' ') i++; if (!(e = get_entity_string(&c[pp + 1], i - pp - 1, d_opt->cp))) goto putc; pp = i + (i < l && c[i] == ';'); } if (!e[0]) continue; if (!e[1]) { buffer[bp++] = e[0]; if (bp < CH_BUF) continue; flush: e = ""; goto flush1; } while (*e) { buffer[bp++] = *(e++); if (bp < CH_BUF) continue; flush1: g_put_chars(p, buffer, bp); while (bp) if ((buffer[--bp] & 0xc0) != 0x80) total++; } } if (bp) g_put_chars(p, buffer, bp); while (bp) if ((buffer[--bp] & 0xc0) != 0x80) total++; return total; }