From 66ee8158b69525e12060ef558cb5d77feadab1dc Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 7 Dec 2006 00:25:44 +0100 Subject: Imported from util-linux-2.10s tarball. --- text-utils/colrm.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) (limited to 'text-utils/colrm.c') diff --git a/text-utils/colrm.c b/text-utils/colrm.c index 0297ccb53..1b90fe4ab 100644 --- a/text-utils/colrm.c +++ b/text-utils/colrm.c @@ -54,6 +54,8 @@ main(int argc, char **argv) { register int ct, first, last; register wint_t c; + int i, w; + int padding; setlocale(LC_ALL, ""); @@ -71,11 +73,15 @@ loop1: if (feof(stdin)) goto fin; if (c == '\t') - ct = (ct + 8) & ~7; + w = ((ct + 8) & ~7) - ct; else if (c == '\b') - ct = ct ? ct - 1 : 0; - else - ct++; + w = (ct ? ct - 1 : 0) - ct; + else { + w = wcwidth(c); + if (w < 0) + w = 0; + } + ct += w; if (c == '\n') { putwc(c, stdout); goto start; @@ -84,6 +90,8 @@ loop1: putwc(c, stdout); goto loop1; } + for (i = ct-w+1; i < first; i++) + putwc(' ', stdout); /* Loop getting rid of characters */ while (!last || ct < last) { @@ -98,18 +106,31 @@ loop1: ct = (ct + 8) & ~7; else if (c == '\b') ct = ct ? ct - 1 : 0; - else - ct++; + else { + w = wcwidth(c); + if (w < 0) + w = 0; + ct += w; + } } + padding = 0; + /* Output last of the line */ for (;;) { c = getwc(stdin); if (feof(stdin)) break; - putwc(c, stdout); - if (c == '\n') + if (c == '\n') { + putwc(c, stdout); goto start; + } + if (padding == 0 && last < ct) { + for (i = last; i