diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-13 14:30:33 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-13 14:30:33 +0000 |
commit | 3b92eaac53e1557ea923d6a395f753224a73d676 (patch) | |
tree | 8d347a473b8be1b9fb8d27954cb39e7d50b2ae25 | |
parent | 75cddd8eb514082c8f9945ae1976f97c4b0413b4 (diff) | |
download | busybox-w32-3b92eaac53e1557ea923d6a395f753224a73d676.tar.gz busybox-w32-3b92eaac53e1557ea923d6a395f753224a73d676.tar.bz2 busybox-w32-3b92eaac53e1557ea923d6a395f753224a73d676.zip |
sort: -z outputs NUL terminated lines. Closes bug 1591.
-rw-r--r-- | coreutils/sort.c | 5 | ||||
-rw-r--r-- | testsuite/README | 3 | ||||
-rwxr-xr-x | testsuite/runtest | 3 | ||||
-rwxr-xr-x | testsuite/sort.tests | 6 |
4 files changed, 12 insertions, 5 deletions
diff --git a/coreutils/sort.c b/coreutils/sort.c index 1d6c59970..d8df4c532 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c | |||
@@ -32,7 +32,7 @@ enum { | |||
32 | FLAG_u = 8, /* Unique */ | 32 | FLAG_u = 8, /* Unique */ |
33 | FLAG_c = 0x10, /* Check: no output, exit(!ordered) */ | 33 | FLAG_c = 0x10, /* Check: no output, exit(!ordered) */ |
34 | FLAG_s = 0x20, /* Stable sort, no ascii fallback at end */ | 34 | FLAG_s = 0x20, /* Stable sort, no ascii fallback at end */ |
35 | FLAG_z = 0x40, /* Input is null terminated, not \n */ | 35 | FLAG_z = 0x40, /* Input and output is NUL terminated, not \n */ |
36 | /* These can be applied to search keys, the previous four can't */ | 36 | /* These can be applied to search keys, the previous four can't */ |
37 | FLAG_b = 0x80, /* Ignore leading blanks */ | 37 | FLAG_b = 0x80, /* Ignore leading blanks */ |
38 | FLAG_r = 0x100, /* Reverse */ | 38 | FLAG_r = 0x100, /* Reverse */ |
@@ -396,8 +396,9 @@ int sort_main(int argc, char **argv) | |||
396 | if (linecount) linecount = flag+1; | 396 | if (linecount) linecount = flag+1; |
397 | } | 397 | } |
398 | /* Print it */ | 398 | /* Print it */ |
399 | flag = (option_mask32 & FLAG_z) ? '\0' : '\n'; | ||
399 | for (i = 0; i < linecount; i++) | 400 | for (i = 0; i < linecount; i++) |
400 | fprintf(outfile, "%s\n", lines[i]); | 401 | fprintf(outfile, "%s%c", lines[i], flag); |
401 | 402 | ||
402 | fflush_stdout_and_exit(EXIT_SUCCESS); | 403 | fflush_stdout_and_exit(EXIT_SUCCESS); |
403 | } | 404 | } |
diff --git a/testsuite/README b/testsuite/README index a44846dbb..b4719e64c 100644 --- a/testsuite/README +++ b/testsuite/README | |||
@@ -1,6 +1,3 @@ | |||
1 | Update: doesn't work as described. Try "make check" from parent dir... | ||
2 | * * * | ||
3 | |||
4 | To run the test suite, change to this directory and run "./runtest". It will | 1 | To run the test suite, change to this directory and run "./runtest". It will |
5 | run all of the test cases, and list those with unexpected outcomes. Adding the | 2 | run all of the test cases, and list those with unexpected outcomes. Adding the |
6 | -v option will cause it to show expected outcomes as well. To only run the test | 3 | -v option will cause it to show expected outcomes as well. To only run the test |
diff --git a/testsuite/runtest b/testsuite/runtest index 93d5ed6e1..fc8392ac5 100755 --- a/testsuite/runtest +++ b/testsuite/runtest | |||
@@ -1,5 +1,8 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | 2 | ||
3 | # Usage: | ||
4 | # runtest [applet1] [applet2...] | ||
5 | |||
3 | # Run one old-style test. | 6 | # Run one old-style test. |
4 | # Tests are stored in applet/testcase shell scripts. | 7 | # Tests are stored in applet/testcase shell scripts. |
5 | # They are run using "sh -x -e applet/testcase". | 8 | # They are run using "sh -x -e applet/testcase". |
diff --git a/testsuite/sort.tests b/testsuite/sort.tests index 1db7870d4..f700dc0c1 100755 --- a/testsuite/sort.tests +++ b/testsuite/sort.tests | |||
@@ -107,6 +107,12 @@ a c | |||
107 | b c | 107 | b c |
108 | " "" | 108 | " "" |
109 | 109 | ||
110 | testing "sort -z outputs NUL terminated lines" "sort -z input" "\ | ||
111 | one\0three\0two\0\ | ||
112 | " "\ | ||
113 | one\0two\0three\0\ | ||
114 | " "" | ||
115 | |||
110 | testing "sort key doesn't strip leading blanks, disables fallback global sort" \ | 116 | testing "sort key doesn't strip leading blanks, disables fallback global sort" \ |
111 | "sort -n -k2 -t ' '" " a \n 1 \n 2 \n" "" " 2 \n 1 \n a \n" | 117 | "sort -n -k2 -t ' '" " a \n 1 \n 2 \n" "" " 2 \n 1 \n a \n" |
112 | 118 | ||