static int print_encode(struct html *h, const char *p, int norecurse) { size_t sz; int c, len, nospace; const char *seq; enum mandoc_esc esc; static const char rejs[9] = { '\\', '<', '>', '&', '"', ASCII_NBRSP, ASCII_HYPH, ASCII_BREAK, '\0' }; nospace = 0; while ('\0' != *p) { if (HTML_SKIPCHAR & h->flags && '\\' != *p) { h->flags &= ~HTML_SKIPCHAR; p++; continue; } sz = strcspn(p, rejs); fwrite(p, 1, sz, stdout); p += (int)sz; if ('\0' == *p) break; if (print_escape(*p++)) continue; esc = mandoc_escape(&p, &seq, &len); if (ESCAPE_ERROR == esc) break; switch (esc) { case ESCAPE_FONT: case ESCAPE_FONTPREV: case ESCAPE_FONTBOLD: case ESCAPE_FONTITALIC: case ESCAPE_FONTBI: case ESCAPE_FONTROMAN: if (0 == norecurse) print_metaf(h, esc); continue; case ESCAPE_SKIPCHAR: h->flags |= HTML_SKIPCHAR; continue; default: break; } if (h->flags & HTML_SKIPCHAR) { h->flags &= ~HTML_SKIPCHAR; continue; } switch (esc) { case ESCAPE_UNICODE: /* Skip past "u" header. */ c = mchars_num2uc(seq + 1, len - 1); break; case ESCAPE_NUMBERED: c = mchars_num2char(seq, len); if (c < 0) continue; break; case ESCAPE_SPECIAL: c = mchars_spec2cp(seq, len); if (c <= 0) continue; break; case ESCAPE_NOSPACE: if ('\0' == *p) nospace = 1; continue; case ESCAPE_OVERSTRIKE: if (len == 0) continue; c = seq[len - 1]; break; default: continue; } if ((c < 0x20 && c != 0x09) || (c > 0x7E && c < 0xA0)) c = 0xFFFD; if (c > 0x7E) printf("&#%d;", c); else if ( ! print_escape(c)) putchar(c); } return nospace; }
static int print_encode(struct html *h, const char *p, int norecurse) { size_t sz; int c, len, nospace; const char *seq; enum mandoc_esc esc; static const char rejs[6] = { '\\', '<', '>', '&', ASCII_HYPH, '\0' }; nospace = 0; while ('\0' != *p) { if (HTML_SKIPCHAR & h->flags && '\\' != *p) { h->flags &= ~HTML_SKIPCHAR; p++; continue; } sz = strcspn(p, rejs); fwrite(p, 1, sz, stdout); p += (int)sz; if ('\0' == *p) break; switch (*p++) { case ('<'): printf("<"); continue; case ('>'): printf(">"); continue; case ('&'): printf("&"); continue; case (ASCII_HYPH): putchar('-'); continue; default: break; } esc = mandoc_escape(&p, &seq, &len); if (ESCAPE_ERROR == esc) break; switch (esc) { case (ESCAPE_FONT): /* FALLTHROUGH */ case (ESCAPE_FONTPREV): /* FALLTHROUGH */ case (ESCAPE_FONTBOLD): /* FALLTHROUGH */ case (ESCAPE_FONTITALIC): /* FALLTHROUGH */ case (ESCAPE_FONTBI): /* FALLTHROUGH */ case (ESCAPE_FONTROMAN): if (0 == norecurse) print_metaf(h, esc); continue; case (ESCAPE_SKIPCHAR): h->flags |= HTML_SKIPCHAR; continue; default: break; } if (h->flags & HTML_SKIPCHAR) { h->flags &= ~HTML_SKIPCHAR; continue; } switch (esc) { case (ESCAPE_UNICODE): /* Skip passed "u" header. */ c = mchars_num2uc(seq + 1, len - 1); if ('\0' != c) printf("&#x%x;", c); break; case (ESCAPE_NUMBERED): c = mchars_num2char(seq, len); if ('\0' != c) putchar(c); break; case (ESCAPE_SPECIAL): c = mchars_spec2cp(h->symtab, seq, len); if (c > 0) printf("&#%d;", c); else if (-1 == c && 1 == len) putchar((int)*seq); break; case (ESCAPE_NOSPACE): if ('\0' == *p) nospace = 1; break; default: break; } } return(nospace); }
static int print_encode(struct html *h, const char *p, int norecurse) { size_t sz; int len, nospace; const char *seq; enum roffdeco deco; static const char rejs[6] = { '\\', '<', '>', '&', ASCII_HYPH, '\0' }; nospace = 0; for (; *p; p++) { sz = strcspn(p, rejs); fwrite(p, 1, sz, stdout); p += /* LINTED */ sz; if ('<' == *p) { printf("<"); continue; } else if ('>' == *p) { printf(">"); continue; } else if ('&' == *p) { printf("&"); continue; } else if (ASCII_HYPH == *p) { /* * Note: "soft hyphens" aren't graphically * displayed when not breaking the text; we want * them to be displayed. */ /*printf("­");*/ putchar('-'); continue; } else if ('\0' == *p) break; seq = ++p; len = a2roffdeco(&deco, &seq, &sz); switch (deco) { case (DECO_RESERVED): print_res(h, seq, sz); break; case (DECO_SSPECIAL): /* FALLTHROUGH */ case (DECO_SPECIAL): print_spec(h, deco, seq, sz); break; case (DECO_PREVIOUS): /* FALLTHROUGH */ case (DECO_BOLD): /* FALLTHROUGH */ case (DECO_ITALIC): /* FALLTHROUGH */ case (DECO_ROMAN): if (norecurse) break; print_metaf(h, deco); break; default: break; } p += len - 1; if (DECO_NOSPACE == deco && '\0' == *(p + 1)) nospace = 1; } return(nospace); }