mod_export void showmsg(char const *msg) { char const *p; int up = 0, cc = 0; ZLE_CHAR_T c; #ifdef MULTIBYTE_SUPPORT char *umsg; int ulen, eol = 0; size_t width; mbstate_t mbs; #endif trashzle(); clearflag = isset(USEZLE) && !termflags && isset(ALWAYSLASTPROMPT); #ifdef MULTIBYTE_SUPPORT umsg = ztrdup(msg); p = unmetafy(umsg, &ulen); memset(&mbs, 0, sizeof mbs); mb_metacharinit(); while (ulen > 0) { char const *n; if (*p == '\n') { ulen--; p++; putc('\n', shout); up += 1 + cc / zterm_columns; cc = 0; } else { /* * Extract the next wide character from the multibyte string. */ size_t cnt = eol ? MB_INVALID : mbrtowc(&c, p, ulen, &mbs); switch (cnt) { case MB_INCOMPLETE: eol = 1; /* FALL THROUGH */ case MB_INVALID: /* * This really shouldn't be happening here, but... * Treat it as a single byte character; it may get * prettified. */ memset(&mbs, 0, sizeof mbs); n = nicechar(*p); cnt = 1; width = strlen(n); break; case 0: cnt = 1; /* FALL THROUGH */ default: /* * Paranoia: only needed if we start in the middle * of a multibyte string and only in some implementations. */ if (cnt > (size_t)ulen) cnt = ulen; n = wcs_nicechar(c, &width, NULL); break; } ulen -= cnt; p += cnt; zputs(n, shout); cc += width; } } free(umsg); #else for(p = msg; (c = *p); p++) { if(c == Meta) c = *++p ^ 32; if(c == '\n') { putc('\n', shout); up += 1 + cc / zterm_columns; cc = 0; } else { char const *n = nicechar(c); zputs(n, shout); cc += strlen(n); } } #endif up += cc / zterm_columns; if (clearflag) { putc('\r', shout); tcmultout(TCUP, TCMULTUP, up + nlnct); } else putc('\n', shout); showinglist = 0; }
void stradd(char *d) { #ifdef MULTIBYTE_SUPPORT char *ums, *ups; int upslen, eol = 0; mbstate_t mbs; memset(&mbs, 0, sizeof mbs); ums = ztrdup(d); ups = unmetafy(ums, &upslen); /* * We now have a raw string of possibly multibyte characters. * Read each character one by one. */ while (upslen > 0) { wchar_t cc; char *pc; size_t cnt = eol ? MB_INVALID : mbrtowc(&cc, ups, upslen, &mbs); switch (cnt) { case MB_INCOMPLETE: eol = 1; /* FALL THROUGH */ case MB_INVALID: /* Bad character. Take the next byte on its own. */ pc = nicechar(*ups); cnt = 1; memset(&mbs, 0, sizeof mbs); break; case 0: cnt = 1; /* FALL THROUGH */ default: /* Take full wide character in one go */ mb_metacharinit(); pc = wcs_nicechar(cc, NULL, NULL); break; } /* Keep output as metafied string. */ addbufspc(strlen(pc)); upslen -= cnt; ups += cnt; /* Put printed representation into the buffer */ while (*pc) *bv->bp++ = *pc++; } free(ums); #else char *ps, *pc; addbufspc(niceztrlen(d)); /* This loop puts the nice representation of the string into the * prompt buffer. */ for (ps = d; *ps; ps++) { for (pc = nicechar(*ps == Meta ? *++ps^32 : *ps); *pc; pc++) *bv->bp++ = *pc; } #endif }