]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
col: backspacing widechars
authorGrady Martin <admin@nosuck.org>
Wed, 4 Jan 2017 22:01:40 +0000 (22:01 +0000)
committerSami Kerola <kerolasa@iki.fi>
Wed, 4 Jan 2017 22:01:40 +0000 (22:01 +0000)
Until now, backspace characters have not accounted for characters of widths
other than one.  This single line amends that.

Requsted-by: Grady Martin <admin@nosuck.org>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
text-utils/col.c

index 9b0e23058885a826f67872a7420cb3b6d48651e3..7bf3708bd9bbaa15c1a80caf2fde0366b96ea1ee 100644 (file)
@@ -160,7 +160,7 @@ static void __attribute__((__noreturn__)) wrerr(void)
 int main(int argc, char **argv)
 {
        register wint_t ch;
-       CHAR *c;
+       CHAR *c = NULL;
        CSET cur_set;                   /* current character set */
        LINE *l;                        /* current line */
        int extra_lines;                /* # of lines above first line */
@@ -248,7 +248,10 @@ int main(int argc, char **argv)
                        case BS:                /* can't go back further */
                                if (cur_col == 0)
                                        continue;
-                               --cur_col;
+                               if (c)
+                                       cur_col -= c->c_width;
+                               else
+                                       cur_col--;
                                continue;
                        case CR:
                                cur_col = 0;
@@ -369,7 +372,10 @@ int main(int argc, char **argv)
                c = &l->l_line[l->l_line_len++];
                c->c_char = ch;
                c->c_set = cur_set;
-               c->c_column = cur_col;
+               if (0 < cur_col)
+                       c->c_column = cur_col;
+               else
+                       c->c_column = 0;
                c->c_width = wcwidth(ch);
                /*
                 * If things are put in out of order, they will need sorting