diff options
| author | Mark Whitley <markw@lineo.com> | 2001-04-17 18:56:18 +0000 |
|---|---|---|
| committer | Mark Whitley <markw@lineo.com> | 2001-04-17 18:56:18 +0000 |
| commit | fccaa3629b89bcfcd2d9b4126255cd31e0f5e174 (patch) | |
| tree | 1384fdafb928c700cba166f7e3609b516d5b7287 | |
| parent | 6e808ca35419ba7ec14dd836f0e013ea35ff0aee (diff) | |
| download | busybox-w32-fccaa3629b89bcfcd2d9b4126255cd31e0f5e174.tar.gz busybox-w32-fccaa3629b89bcfcd2d9b4126255cd31e0f5e174.tar.bz2 busybox-w32-fccaa3629b89bcfcd2d9b4126255cd31e0f5e174.zip | |
Applied patch from I.Q. to add sort -u as a feature.
| -rw-r--r-- | Config.h | 5 | ||||
| -rw-r--r-- | applets/usage.h | 13 | ||||
| -rw-r--r-- | coreutils/sort.c | 28 | ||||
| -rw-r--r-- | include/usage.h | 13 | ||||
| -rw-r--r-- | sort.c | 28 | ||||
| -rw-r--r-- | usage.h | 13 |
6 files changed, 79 insertions, 21 deletions
| @@ -235,9 +235,12 @@ | |||
| 235 | // Enable support for tar -z option (currently only works for inflating) | 235 | // Enable support for tar -z option (currently only works for inflating) |
| 236 | #define BB_FEATURE_TAR_GZIP | 236 | #define BB_FEATURE_TAR_GZIP |
| 237 | // | 237 | // |
| 238 | //// Enable reverse sort | 238 | // Enable reverse sort |
| 239 | #define BB_FEATURE_SORT_REVERSE | 239 | #define BB_FEATURE_SORT_REVERSE |
| 240 | // | 240 | // |
| 241 | // Enable uniqe sort | ||
| 242 | #define BB_FEATURE_SORT_UNIQUE | ||
| 243 | // | ||
| 241 | // Enable command line editing in the shell. | 244 | // Enable command line editing in the shell. |
| 242 | // Only relevant if BB_SH is enabled. On by default. | 245 | // Only relevant if BB_SH is enabled. On by default. |
| 243 | #define BB_FEATURE_COMMAND_EDITING | 246 | #define BB_FEATURE_COMMAND_EDITING |
diff --git a/applets/usage.h b/applets/usage.h index f375dfd19..1e3023d1f 100644 --- a/applets/usage.h +++ b/applets/usage.h | |||
| @@ -1356,15 +1356,24 @@ | |||
| 1356 | "[2 second delay results]\n" | 1356 | "[2 second delay results]\n" |
| 1357 | 1357 | ||
| 1358 | 1358 | ||
| 1359 | #ifdef BB_FEATURE_SORT_UNIQUE | ||
| 1360 | #define USAGE_SORT_UNIQUE(a) a | ||
| 1361 | #else | ||
| 1362 | #define USAGE_SORT_UNIQUE(a) | ||
| 1363 | #endif | ||
| 1359 | #ifdef BB_FEATURE_SORT_REVERSE | 1364 | #ifdef BB_FEATURE_SORT_REVERSE |
| 1360 | #define USAGE_SORT_REVERSE(a) a | 1365 | #define USAGE_SORT_REVERSE(a) a |
| 1361 | #else | 1366 | #else |
| 1362 | #define USAGE_SORT_REVERSE(a) | 1367 | #define USAGE_SORT_REVERSE(a) |
| 1363 | #endif | 1368 | #endif |
| 1364 | #define sort_trivial_usage \ | 1369 | #define sort_trivial_usage \ |
| 1365 | "[-n]" USAGE_SORT_REVERSE(" [-r]") " [FILE]..." | 1370 | "[-n" USAGE_SORT_REVERSE("r") USAGE_SORT_UNIQUE("u") "] [FILE]..." |
| 1366 | #define sort_full_usage \ | 1371 | #define sort_full_usage \ |
| 1367 | "Sorts lines of text in the specified files" | 1372 | "Sorts lines of text in the specified files\n\n"\ |
| 1373 | "Options:\n" \ | ||
| 1374 | USAGE_SORT_UNIQUE("\t-u\tsuppress duplicate lines\n") \ | ||
| 1375 | USAGE_SORT_REVERSE("\t-r\tsort in reverse order\n") \ | ||
| 1376 | "\t-n\tsort numerics" | ||
| 1368 | #define sort_example_usage \ | 1377 | #define sort_example_usage \ |
| 1369 | "$ echo -e \"e\\nf\\nb\\nd\\nc\\na\" | sort\n" \ | 1378 | "$ echo -e \"e\\nf\\nb\\nd\\nc\\na\" | sort\n" \ |
| 1370 | "a\n" \ | 1379 | "a\n" \ |
diff --git a/coreutils/sort.c b/coreutils/sort.c index 5ecca8b8f..4f4979cc5 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c | |||
| @@ -46,8 +46,11 @@ int sort_main(int argc, char **argv) | |||
| 46 | #ifdef BB_FEATURE_SORT_REVERSE | 46 | #ifdef BB_FEATURE_SORT_REVERSE |
| 47 | int reverse = FALSE; | 47 | int reverse = FALSE; |
| 48 | #endif | 48 | #endif |
| 49 | #ifdef BB_FEATURE_SORT_UNIQUE | ||
| 50 | int unique = FALSE; | ||
| 51 | #endif | ||
| 49 | 52 | ||
| 50 | while ((opt = getopt(argc, argv, "nr")) != -1) { | 53 | while ((opt = getopt(argc, argv, "nru")) != -1) { |
| 51 | switch (opt) { | 54 | switch (opt) { |
| 52 | case 'n': | 55 | case 'n': |
| 53 | compare = compare_numeric; | 56 | compare = compare_numeric; |
| @@ -57,6 +60,11 @@ int sort_main(int argc, char **argv) | |||
| 57 | reverse = TRUE; | 60 | reverse = TRUE; |
| 58 | break; | 61 | break; |
| 59 | #endif | 62 | #endif |
| 63 | #ifdef BB_FEATURE_SORT_UNIQUE | ||
| 64 | case 'u': | ||
| 65 | unique = TRUE; | ||
| 66 | break; | ||
| 67 | #endif | ||
| 60 | default: | 68 | default: |
| 61 | show_usage(); | 69 | show_usage(); |
| 62 | } | 70 | } |
| @@ -81,12 +89,18 @@ int sort_main(int argc, char **argv) | |||
| 81 | 89 | ||
| 82 | /* print it */ | 90 | /* print it */ |
| 83 | #ifdef BB_FEATURE_SORT_REVERSE | 91 | #ifdef BB_FEATURE_SORT_REVERSE |
| 84 | if (reverse) | 92 | if (reverse) { |
| 85 | for (i = nlines - 1; 0 <= i; i--) | 93 | for (i = --nlines; 0 <= i; i--) |
| 86 | puts(lines[i]); | 94 | #ifdef BB_FEATURE_SORT_UNIQUE |
| 87 | else | 95 | if((!unique) || (i == nlines) || (strcmp(lines[i + 1], lines[i]))) |
| 96 | #endif | ||
| 97 | puts(lines[i]); | ||
| 98 | } else | ||
| 99 | #endif | ||
| 100 | for (i = 0; i < nlines; i++) | ||
| 101 | #ifdef BB_FEATURE_SORT_UNIQUE | ||
| 102 | if((!unique) || (!i) || (strcmp(lines[i - 1], lines[i]))) | ||
| 88 | #endif | 103 | #endif |
| 89 | for (i = 0; i < nlines; i++) | 104 | puts(lines[i]); |
| 90 | puts(lines[i]); | ||
| 91 | return EXIT_SUCCESS; | 105 | return EXIT_SUCCESS; |
| 92 | } | 106 | } |
diff --git a/include/usage.h b/include/usage.h index f375dfd19..1e3023d1f 100644 --- a/include/usage.h +++ b/include/usage.h | |||
| @@ -1356,15 +1356,24 @@ | |||
| 1356 | "[2 second delay results]\n" | 1356 | "[2 second delay results]\n" |
| 1357 | 1357 | ||
| 1358 | 1358 | ||
| 1359 | #ifdef BB_FEATURE_SORT_UNIQUE | ||
| 1360 | #define USAGE_SORT_UNIQUE(a) a | ||
| 1361 | #else | ||
| 1362 | #define USAGE_SORT_UNIQUE(a) | ||
| 1363 | #endif | ||
| 1359 | #ifdef BB_FEATURE_SORT_REVERSE | 1364 | #ifdef BB_FEATURE_SORT_REVERSE |
| 1360 | #define USAGE_SORT_REVERSE(a) a | 1365 | #define USAGE_SORT_REVERSE(a) a |
| 1361 | #else | 1366 | #else |
| 1362 | #define USAGE_SORT_REVERSE(a) | 1367 | #define USAGE_SORT_REVERSE(a) |
| 1363 | #endif | 1368 | #endif |
| 1364 | #define sort_trivial_usage \ | 1369 | #define sort_trivial_usage \ |
| 1365 | "[-n]" USAGE_SORT_REVERSE(" [-r]") " [FILE]..." | 1370 | "[-n" USAGE_SORT_REVERSE("r") USAGE_SORT_UNIQUE("u") "] [FILE]..." |
| 1366 | #define sort_full_usage \ | 1371 | #define sort_full_usage \ |
| 1367 | "Sorts lines of text in the specified files" | 1372 | "Sorts lines of text in the specified files\n\n"\ |
| 1373 | "Options:\n" \ | ||
| 1374 | USAGE_SORT_UNIQUE("\t-u\tsuppress duplicate lines\n") \ | ||
| 1375 | USAGE_SORT_REVERSE("\t-r\tsort in reverse order\n") \ | ||
| 1376 | "\t-n\tsort numerics" | ||
| 1368 | #define sort_example_usage \ | 1377 | #define sort_example_usage \ |
| 1369 | "$ echo -e \"e\\nf\\nb\\nd\\nc\\na\" | sort\n" \ | 1378 | "$ echo -e \"e\\nf\\nb\\nd\\nc\\na\" | sort\n" \ |
| 1370 | "a\n" \ | 1379 | "a\n" \ |
| @@ -46,8 +46,11 @@ int sort_main(int argc, char **argv) | |||
| 46 | #ifdef BB_FEATURE_SORT_REVERSE | 46 | #ifdef BB_FEATURE_SORT_REVERSE |
| 47 | int reverse = FALSE; | 47 | int reverse = FALSE; |
| 48 | #endif | 48 | #endif |
| 49 | #ifdef BB_FEATURE_SORT_UNIQUE | ||
| 50 | int unique = FALSE; | ||
| 51 | #endif | ||
| 49 | 52 | ||
| 50 | while ((opt = getopt(argc, argv, "nr")) != -1) { | 53 | while ((opt = getopt(argc, argv, "nru")) != -1) { |
| 51 | switch (opt) { | 54 | switch (opt) { |
| 52 | case 'n': | 55 | case 'n': |
| 53 | compare = compare_numeric; | 56 | compare = compare_numeric; |
| @@ -57,6 +60,11 @@ int sort_main(int argc, char **argv) | |||
| 57 | reverse = TRUE; | 60 | reverse = TRUE; |
| 58 | break; | 61 | break; |
| 59 | #endif | 62 | #endif |
| 63 | #ifdef BB_FEATURE_SORT_UNIQUE | ||
| 64 | case 'u': | ||
| 65 | unique = TRUE; | ||
| 66 | break; | ||
| 67 | #endif | ||
| 60 | default: | 68 | default: |
| 61 | show_usage(); | 69 | show_usage(); |
| 62 | } | 70 | } |
| @@ -81,12 +89,18 @@ int sort_main(int argc, char **argv) | |||
| 81 | 89 | ||
| 82 | /* print it */ | 90 | /* print it */ |
| 83 | #ifdef BB_FEATURE_SORT_REVERSE | 91 | #ifdef BB_FEATURE_SORT_REVERSE |
| 84 | if (reverse) | 92 | if (reverse) { |
| 85 | for (i = nlines - 1; 0 <= i; i--) | 93 | for (i = --nlines; 0 <= i; i--) |
| 86 | puts(lines[i]); | 94 | #ifdef BB_FEATURE_SORT_UNIQUE |
| 87 | else | 95 | if((!unique) || (i == nlines) || (strcmp(lines[i + 1], lines[i]))) |
| 96 | #endif | ||
| 97 | puts(lines[i]); | ||
| 98 | } else | ||
| 99 | #endif | ||
| 100 | for (i = 0; i < nlines; i++) | ||
| 101 | #ifdef BB_FEATURE_SORT_UNIQUE | ||
| 102 | if((!unique) || (!i) || (strcmp(lines[i - 1], lines[i]))) | ||
| 88 | #endif | 103 | #endif |
| 89 | for (i = 0; i < nlines; i++) | 104 | puts(lines[i]); |
| 90 | puts(lines[i]); | ||
| 91 | return EXIT_SUCCESS; | 105 | return EXIT_SUCCESS; |
| 92 | } | 106 | } |
| @@ -1356,15 +1356,24 @@ | |||
| 1356 | "[2 second delay results]\n" | 1356 | "[2 second delay results]\n" |
| 1357 | 1357 | ||
| 1358 | 1358 | ||
| 1359 | #ifdef BB_FEATURE_SORT_UNIQUE | ||
| 1360 | #define USAGE_SORT_UNIQUE(a) a | ||
| 1361 | #else | ||
| 1362 | #define USAGE_SORT_UNIQUE(a) | ||
| 1363 | #endif | ||
| 1359 | #ifdef BB_FEATURE_SORT_REVERSE | 1364 | #ifdef BB_FEATURE_SORT_REVERSE |
| 1360 | #define USAGE_SORT_REVERSE(a) a | 1365 | #define USAGE_SORT_REVERSE(a) a |
| 1361 | #else | 1366 | #else |
| 1362 | #define USAGE_SORT_REVERSE(a) | 1367 | #define USAGE_SORT_REVERSE(a) |
| 1363 | #endif | 1368 | #endif |
| 1364 | #define sort_trivial_usage \ | 1369 | #define sort_trivial_usage \ |
| 1365 | "[-n]" USAGE_SORT_REVERSE(" [-r]") " [FILE]..." | 1370 | "[-n" USAGE_SORT_REVERSE("r") USAGE_SORT_UNIQUE("u") "] [FILE]..." |
| 1366 | #define sort_full_usage \ | 1371 | #define sort_full_usage \ |
| 1367 | "Sorts lines of text in the specified files" | 1372 | "Sorts lines of text in the specified files\n\n"\ |
| 1373 | "Options:\n" \ | ||
| 1374 | USAGE_SORT_UNIQUE("\t-u\tsuppress duplicate lines\n") \ | ||
| 1375 | USAGE_SORT_REVERSE("\t-r\tsort in reverse order\n") \ | ||
| 1376 | "\t-n\tsort numerics" | ||
| 1368 | #define sort_example_usage \ | 1377 | #define sort_example_usage \ |
| 1369 | "$ echo -e \"e\\nf\\nb\\nd\\nc\\na\" | sort\n" \ | 1378 | "$ echo -e \"e\\nf\\nb\\nd\\nc\\na\" | sort\n" \ |
| 1370 | "a\n" \ | 1379 | "a\n" \ |
