diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2024-12-14 13:58:49 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2024-12-14 13:58:49 +0100 |
| commit | b25ea3f156c6b5927b358f9b12b90f1852f30311 (patch) | |
| tree | cc2e7f2cb4f7b25468377db0c355e90340c0914c | |
| parent | d48400d8fb266526059eb43b318cb95132f61fb3 (diff) | |
| download | busybox-w32-b25ea3f156c6b5927b358f9b12b90f1852f30311.tar.gz busybox-w32-b25ea3f156c6b5927b358f9b12b90f1852f30311.tar.bz2 busybox-w32-b25ea3f156c6b5927b358f9b12b90f1852f30311.zip | |
cut: fix -F n-m to match toybox
function old new delta
cut_main 1339 1391 +52
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | coreutils/cut.c | 10 | ||||
| -rwxr-xr-x | testsuite/cut.tests | 21 |
2 files changed, 28 insertions, 3 deletions
diff --git a/coreutils/cut.c b/coreutils/cut.c index f4cf5401b..3abebe7ad 100644 --- a/coreutils/cut.c +++ b/coreutils/cut.c | |||
| @@ -243,6 +243,16 @@ static void cut_file(FILE *file, const char *delim, const char *odelim, | |||
| 243 | start = next; | 243 | start = next; |
| 244 | continue; | 244 | continue; |
| 245 | } | 245 | } |
| 246 | /* -F N-M preserves intermediate delimiters: */ | ||
| 247 | //printf "1 2 3 4 5 6 7\n" | toybox cut -O: -F2,4-6,7 | ||
| 248 | //2:4 5 6:7 | ||
| 249 | if (opt_REGEX && dcount <= cut_list[cl_pos].endpos) | ||
| 250 | continue; | ||
| 251 | // NB: toybox does the above for -f too, but it's a compatibility bug: | ||
| 252 | //printf "1 2 3 4 5 6 7 8\n" | toybox cut -d' ' -O: -f2,4-6,7 | ||
| 253 | //2:4 5 6:7 // WRONG! | ||
| 254 | //printf "1 2 3 4 5 6 7 8\n" | cut -d' ' --output-delimiter=: -f2,4-6,7 | ||
| 255 | //2:4:5:6:7 // GNU coreutils 9.1 | ||
| 246 | } | 256 | } |
| 247 | #if ENABLE_FEATURE_CUT_REGEX | 257 | #if ENABLE_FEATURE_CUT_REGEX |
| 248 | if (end != start || !opt_REGEX) | 258 | if (end != start || !opt_REGEX) |
diff --git a/testsuite/cut.tests b/testsuite/cut.tests index 52d05fde3..e57b028ac 100755 --- a/testsuite/cut.tests +++ b/testsuite/cut.tests | |||
| @@ -104,6 +104,19 @@ Weather forecast for tonight : dark. | |||
| 104 | Apple: you can buy better, but you can't pay more. | 104 | Apple: you can buy better, but you can't pay more. |
| 105 | Subcalifragilisticexpialidocious. | 105 | Subcalifragilisticexpialidocious. |
| 106 | Auntie Em: Hate you, hate Kansas. Took the dog. Dorothy." | 106 | Auntie Em: Hate you, hate Kansas. Took the dog. Dorothy." |
| 107 | |||
| 108 | optional FEATURE_CUT_REGEX LONG_OPTS | ||
| 109 | testing "cut -F preserves intermediate delimiters" \ | ||
| 110 | "cut --output-delimiter=: -F2,4-6,7" \ | ||
| 111 | "2:4 5 6:7\n" \ | ||
| 112 | "" "1 2 3 4\t\t5 6 7 8\n" | ||
| 113 | SKIP= | ||
| 114 | |||
| 115 | optional LONG_OPTS | ||
| 116 | testing "cut -f does not preserve intermediate delimiters" \ | ||
| 117 | "cut --output-delimiter=: -d' ' -f2,4-6,7" \ | ||
| 118 | "2:4:5:6:7\n" \ | ||
| 119 | "" "1 2 3 4 5 6 7 8\n" | ||
| 107 | SKIP= | 120 | SKIP= |
| 108 | 121 | ||
| 109 | testing "cut empty field" "cut -d ':' -f 1-3" \ | 122 | testing "cut empty field" "cut -d ':' -f 1-3" \ |
| @@ -124,23 +137,25 @@ testing "cut -dNEWLINE" \ | |||
| 124 | "2\n4\n6\n7\n" \ | 137 | "2\n4\n6\n7\n" \ |
| 125 | "" "1\n2\n3\n4\n5\n6\n7" | 138 | "" "1\n2\n3\n4\n5\n6\n7" |
| 126 | 139 | ||
| 140 | optional LONG_OPTS | ||
| 127 | testing "cut -dNEWLINE --output-delimiter" \ | 141 | testing "cut -dNEWLINE --output-delimiter" \ |
| 128 | "cut -d' | 142 | "cut -d' |
| 129 | ' -O@@ -f4,2,6-8" \ | 143 | ' --output-delimiter=@@ -f4,2,6-8" \ |
| 130 | "2@@4@@6@@7\n" \ | 144 | "2@@4@@6@@7\n" \ |
| 131 | "" "1\n2\n3\n4\n5\n6\n7" | 145 | "" "1\n2\n3\n4\n5\n6\n7" |
| 132 | 146 | ||
| 133 | testing "cut -dNEWLINE --output-delimiter 2" \ | 147 | testing "cut -dNEWLINE --output-delimiter 2" \ |
| 134 | "cut -d' | 148 | "cut -d' |
| 135 | ' -O@@ -f4,2,6-8" \ | 149 | ' --output-delimiter=@@ -f4,2,6-8" \ |
| 136 | "2@@4@@6@@7\n" \ | 150 | "2@@4@@6@@7\n" \ |
| 137 | "" "1\n2\n3\n4\n5\n6\n7\n" | 151 | "" "1\n2\n3\n4\n5\n6\n7\n" |
| 138 | 152 | ||
| 139 | testing "cut -dNEWLINE --output-delimiter EMPTY_INPUT" \ | 153 | testing "cut -dNEWLINE --output-delimiter EMPTY_INPUT" \ |
| 140 | "cut -d' | 154 | "cut -d' |
| 141 | ' -O@@ -f4,2,6-8" \ | 155 | ' --output-delimiter=@@ -f4,2,6-8" \ |
| 142 | "" \ | 156 | "" \ |
| 143 | "" "" | 157 | "" "" |
| 158 | SKIP= | ||
| 144 | 159 | ||
| 145 | # This seems to work as if delimiter is never found. | 160 | # This seems to work as if delimiter is never found. |
| 146 | # We test here that -d '' does *not* operate as if there was no -d | 161 | # We test here that -d '' does *not* operate as if there was no -d |
