diff options
author | Tomas Heinrich <heinrich.tomas@gmail.com> | 2010-03-26 11:46:07 +0300 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-03-26 11:46:07 +0300 |
commit | 968951fd0ced7d0d4b81c0ee4466eada93ae4128 (patch) | |
tree | be41b25123722927a266cd960140a82ae4ed5db5 /coreutils/expand.c | |
parent | 1abc07dcca237e6b5c98fea740e59d59c801c9e2 (diff) |
unexpand: fix "a b"\n" input case
Signed-off-by: Tomas Heinrich <heinrich.tomas@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils/expand.c')
-rw-r--r-- | coreutils/expand.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/coreutils/expand.c b/coreutils/expand.c index 60ac9f568..cfb1e25d9 100644 --- a/coreutils/expand.c +++ b/coreutils/expand.c @@ -81,12 +81,13 @@ static void unexpand(FILE *file, unsigned tab_size, unsigned opt) while (*ptr) { unsigned n; - unsigned len; + unsigned len = 0; while (*ptr == ' ') { - column++; ptr++; + len++; } + column += len; if (*ptr == '\t') { column += tab_size - (column % tab_size); ptr++; @@ -94,16 +95,18 @@ static void unexpand(FILE *file, unsigned tab_size, unsigned opt) } n = column / tab_size; - column = column % tab_size; - while (n--) - putchar('\t'); + if (n) { + len = column = column % tab_size; + while (n--) + putchar('\t'); + } if ((opt & OPT_INITIAL) && ptr != line) { - printf("%*s%s", column, "", ptr); + printf("%*s%s", len, "", ptr); break; } n = strcspn(ptr, "\t "); - printf("%*s%.*s", column, "", n, ptr); + printf("%*s%.*s", len, "", n, ptr); # if ENABLE_FEATURE_ASSUME_UNICODE { char c; |