/* Print a buffer of n characters */ static void prbuf(register char *s, register int n) { register char c; /* next output character */ register int state; /* next output char's UL state */ #define wouldul(s,n) ((n) >= 2 && (((s)[0] == '_' && (s)[1] == '\b') || ((s)[1] == '\b' && (s)[2] == '_'))) while (--n >= 0) if (!ul_opt) putchar(*s++); else { if (*s == ' ' && pstate == 0 && ulglitch && wouldul(s + 1, n - 1)) { s++; continue; } if ((state = wouldul(s, n)) != 0) { c = (*s == '_') ? s[2] : *s; n -= 2; s += 3; } else c = *s++; if (state != pstate) { if (c == ' ' && state == 0 && ulglitch && wouldul(s, n - 1)) state = 1; else putstring(state ? ULenter : ULexit); } if (c != ' ' || pstate == 0 || state != 0 || ulglitch == 0) #ifdef HAVE_WIDECHAR { wchar_t wc; size_t mblength; mbstate_t mbstate; memset(&mbstate, '\0', sizeof(mbstate_t)); s--; n++; mblength = xmbrtowc(&wc, s, n, &mbstate); while (mblength--) putchar(*s++); n += mblength; } #else putchar(c); #endif /* HAVE_WIDECHAR */ if (state && *chUL) { putsout(chBS); putstring(chUL); } pstate = state; } }
/* * Print a buffer of n characters. */ void prbuf(char *s, int n) { char c; /* next output character */ int state; /* next output char's UL state */ #define wouldul(s,n) ((n) >= 2 && (((s)[0] == '_' && (s)[1] == '\b') || ((s)[1] == '\b' && (s)[2] == '_'))) while (--n >= 0) { if (!ul_opt) putchar(*s++); else { if (*s == ' ' && pstate == 0 && ulglitch && wouldul(s + 1, n - 1)) { s++; continue; } if ((state = wouldul(s, n))) { c = (*s == '_')? s[2] : *s ; n -= 2; s += 3; } else c = *s++; if (state != pstate) { if (c == ' ' && state == 0 && ulglitch && wouldul(s, n - 1)) state = 1; else tputs(state ? ULenter : ULexit, 1, putch); } if (c != ' ' || pstate == 0 || state != 0 || ulglitch == 0) putchar(c); if (state && *chUL) { fputs(chBS, stdout); tputs(chUL, 1, putch); } pstate = state; } } }