/* * See encode(). * Do this for a single (probably unicode) value. * Does not check for non-decorated glyphs. */ static void encode1(struct termp *p, int c) { enum termfont f; if (TERMP_SKIPCHAR & p->flags) { p->flags &= ~TERMP_SKIPCHAR; return; } if (p->col + 6 >= p->maxcols) adjbuf(p, p->col + 6); f = term_fonttop(p); if (TERMFONT_UNDER == f || TERMFONT_BI == f) { p->buf[p->col++] = '_'; p->buf[p->col++] = 8; } if (TERMFONT_BOLD == f || TERMFONT_BI == f) { if (ASCII_HYPH == c) p->buf[p->col++] = '-'; else p->buf[p->col++] = c; p->buf[p->col++] = 8; } p->buf[p->col++] = c; }
static void encode(struct termp *p, const char *word, size_t sz) { enum termfont f; int i, len; /* LINTED */ len = sz; /* * Encode and buffer a string of characters. If the current * font mode is unset, buffer directly, else encode then buffer * character by character. */ if (TERMFONT_NONE == (f = term_fonttop(p))) { if (p->col + len >= p->maxcols) adjbuf(p, p->col + len); for (i = 0; i < len; i++) p->buf[p->col++] = word[i]; return; } /* Pre-buffer, assuming worst-case. */ if (p->col + 1 + (len * 3) >= p->maxcols) adjbuf(p, p->col + 1 + (len * 3)); for (i = 0; i < len; i++) { if (ASCII_HYPH != word[i] && ! isgraph((unsigned char)word[i])) { p->buf[p->col++] = word[i]; continue; } if (TERMFONT_UNDER == f) p->buf[p->col++] = '_'; else if (ASCII_HYPH == word[i]) p->buf[p->col++] = '-'; else p->buf[p->col++] = word[i]; p->buf[p->col++] = 8; p->buf[p->col++] = word[i]; } }
/* * See encode(). * Do this for a single (probably unicode) value. * Does not check for non-decorated glyphs. */ static void encode1(struct termp *p, int c) { enum termfont f; if (p->col + 4 >= p->maxcols) adjbuf(p, p->col + 4); f = term_fonttop(p); if (TERMFONT_NONE == f) { p->buf[p->col++] = c; return; } else if (TERMFONT_UNDER == f) { p->buf[p->col++] = '_'; } else p->buf[p->col++] = c; p->buf[p->col++] = 8; p->buf[p->col++] = c; }
static void encode(struct termp *p, const char *word, size_t sz) { size_t i; if (TERMP_SKIPCHAR & p->flags) { p->flags &= ~TERMP_SKIPCHAR; return; } /* * Encode and buffer a string of characters. If the current * font mode is unset, buffer directly, else encode then buffer * character by character. */ if (TERMFONT_NONE == term_fonttop(p)) { if (p->col + sz >= p->maxcols) adjbuf(p, p->col + sz); for (i = 0; i < sz; i++) p->buf[p->col++] = word[i]; return; } /* Pre-buffer, assuming worst-case. */ if (p->col + 1 + (sz * 5) >= p->maxcols) adjbuf(p, p->col + 1 + (sz * 5)); for (i = 0; i < sz; i++) { if (ASCII_HYPH == word[i] || isgraph((unsigned char)word[i])) encode1(p, word[i]); else p->buf[p->col++] = word[i]; } }