]> err.no Git - util-linux/commitdiff
more: fix underlining for multibyte chars
authorKarel Zak <kzak@redhat.com>
Tue, 14 Aug 2007 09:51:19 +0000 (11:51 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 14 Aug 2007 09:51:19 +0000 (11:51 +0200)
Try:
$ printf "aaa _\bŽ_\bŽ_\bŽ bbb\n" | more
aaa ŽŽŽ bbb

(ŽŽŽ has to be three underlined chars on terminal).

Signed-off-by: Karel Zak <kzak@redhat.com>
text-utils/more.c

index db2fa4d2046a13fc1846befbe538b064ebd96ec7..19c441789fa06ed2978eaf3e4b15b0825b368447 100644 (file)
@@ -1052,7 +1052,23 @@ void prbuf (register char *s, register int n)
                    my_putstring(state ? ULenter : ULexit);
            }
            if (c != ' ' || pstate == 0 || state != 0 || ulglitch == 0)
+#ifdef ENABLE_WIDECHAR
+           {
+               wchar_t wc;
+               size_t mblength;
+               mbstate_t state;
+               memset (&state, '\0', sizeof (mbstate_t));
+               s--; n++;
+               mblength = mbrtowc (&wc, s, n, &state);
+               if (mblength == (size_t) -2 || mblength == (size_t) -1)
+                       mblength = 1;
+               while (mblength--)
+                       putchar (*s++);
+               n += mblength;
+           }
+#else
                putchar(c);
+#endif /* ENABLE_WIDECHAR */
            if (state && *chUL) {
                putsout(chBS);
                my_putstring(chUL);