diff options
| author | Tomas Heinrich <heinrich.tomas@gmail.com> | 2010-03-26 09:46:07 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-03-26 09:46:07 +0100 |
| commit | 968951fd0ced7d0d4b81c0ee4466eada93ae4128 (patch) | |
| tree | be41b25123722927a266cd960140a82ae4ed5db5 | |
| parent | 1abc07dcca237e6b5c98fea740e59d59c801c9e2 (diff) | |
| download | busybox-w32-968951fd0ced7d0d4b81c0ee4466eada93ae4128.tar.gz busybox-w32-968951fd0ced7d0d4b81c0ee4466eada93ae4128.tar.bz2 busybox-w32-968951fd0ced7d0d4b81c0ee4466eada93ae4128.zip | |
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>
| -rw-r--r-- | coreutils/expand.c | 17 | ||||
| -rwxr-xr-x | testsuite/unexpand.tests | 3 |
2 files changed, 13 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) | |||
| 81 | 81 | ||
| 82 | while (*ptr) { | 82 | while (*ptr) { |
| 83 | unsigned n; | 83 | unsigned n; |
| 84 | unsigned len; | 84 | unsigned len = 0; |
| 85 | 85 | ||
| 86 | while (*ptr == ' ') { | 86 | while (*ptr == ' ') { |
| 87 | column++; | ||
| 88 | ptr++; | 87 | ptr++; |
| 88 | len++; | ||
| 89 | } | 89 | } |
| 90 | column += len; | ||
| 90 | if (*ptr == '\t') { | 91 | if (*ptr == '\t') { |
| 91 | column += tab_size - (column % tab_size); | 92 | column += tab_size - (column % tab_size); |
| 92 | ptr++; | 93 | ptr++; |
| @@ -94,16 +95,18 @@ static void unexpand(FILE *file, unsigned tab_size, unsigned opt) | |||
| 94 | } | 95 | } |
| 95 | 96 | ||
| 96 | n = column / tab_size; | 97 | n = column / tab_size; |
| 97 | column = column % tab_size; | 98 | if (n) { |
| 98 | while (n--) | 99 | len = column = column % tab_size; |
| 99 | putchar('\t'); | 100 | while (n--) |
| 101 | putchar('\t'); | ||
| 102 | } | ||
| 100 | 103 | ||
| 101 | if ((opt & OPT_INITIAL) && ptr != line) { | 104 | if ((opt & OPT_INITIAL) && ptr != line) { |
| 102 | printf("%*s%s", column, "", ptr); | 105 | printf("%*s%s", len, "", ptr); |
| 103 | break; | 106 | break; |
| 104 | } | 107 | } |
| 105 | n = strcspn(ptr, "\t "); | 108 | n = strcspn(ptr, "\t "); |
| 106 | printf("%*s%.*s", column, "", n, ptr); | 109 | printf("%*s%.*s", len, "", n, ptr); |
| 107 | # if ENABLE_FEATURE_ASSUME_UNICODE | 110 | # if ENABLE_FEATURE_ASSUME_UNICODE |
| 108 | { | 111 | { |
| 109 | char c; | 112 | char c; |
diff --git a/testsuite/unexpand.tests b/testsuite/unexpand.tests index 5c2a29b5f..1af2fdc5f 100755 --- a/testsuite/unexpand.tests +++ b/testsuite/unexpand.tests | |||
| @@ -27,6 +27,9 @@ testing "unexpand case 6" "unexpand" \ | |||
| 27 | testing "unexpand case 7" "unexpand" \ | 27 | testing "unexpand case 7" "unexpand" \ |
| 28 | "123\t 45678\n" "" "123 \t 45678\n" \ | 28 | "123\t 45678\n" "" "123 \t 45678\n" \ |
| 29 | 29 | ||
| 30 | testing "unexpand case 8" "unexpand" \ | ||
| 31 | "a b\n" "" "a b\n" \ | ||
| 32 | |||
| 30 | testing "unexpand with unicode characher 0x394" "unexpand" \ | 33 | testing "unexpand with unicode characher 0x394" "unexpand" \ |
| 31 | "1ΔΔΔ5\t99999\n" "" "1ΔΔΔ5 99999\n" \ | 34 | "1ΔΔΔ5\t99999\n" "" "1ΔΔΔ5 99999\n" \ |
| 32 | 35 | ||
