aboutsummaryrefslogtreecommitdiff
path: root/coreutils/sort.c
diff options
context:
space:
mode:
authorMark Whitley <markw@lineo.com>2001-04-17 18:56:18 +0000
committerMark Whitley <markw@lineo.com>2001-04-17 18:56:18 +0000
commitfccaa3629b89bcfcd2d9b4126255cd31e0f5e174 (patch)
tree1384fdafb928c700cba166f7e3609b516d5b7287 /coreutils/sort.c
parent6e808ca35419ba7ec14dd836f0e013ea35ff0aee (diff)
downloadbusybox-fccaa3629b89bcfcd2d9b4126255cd31e0f5e174.tar.gz
Applied patch from I.Q. to add sort -u as a feature.
Diffstat (limited to 'coreutils/sort.c')
-rw-r--r--coreutils/sort.c28
1 files changed, 21 insertions, 7 deletions
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)
#ifdef BB_FEATURE_SORT_REVERSE
int reverse = FALSE;
#endif
+#ifdef BB_FEATURE_SORT_UNIQUE
+ int unique = FALSE;
+#endif
- while ((opt = getopt(argc, argv, "nr")) != -1) {
+ while ((opt = getopt(argc, argv, "nru")) != -1) {
switch (opt) {
case 'n':
compare = compare_numeric;
@@ -57,6 +60,11 @@ int sort_main(int argc, char **argv)
reverse = TRUE;
break;
#endif
+#ifdef BB_FEATURE_SORT_UNIQUE
+ case 'u':
+ unique = TRUE;
+ break;
+#endif
default:
show_usage();
}
@@ -81,12 +89,18 @@ int sort_main(int argc, char **argv)
/* print it */
#ifdef BB_FEATURE_SORT_REVERSE
- if (reverse)
- for (i = nlines - 1; 0 <= i; i--)
- puts(lines[i]);
- else
+ if (reverse) {
+ for (i = --nlines; 0 <= i; i--)
+#ifdef BB_FEATURE_SORT_UNIQUE
+ if((!unique) || (i == nlines) || (strcmp(lines[i + 1], lines[i])))
+#endif
+ puts(lines[i]);
+ } else
+#endif
+ for (i = 0; i < nlines; i++)
+#ifdef BB_FEATURE_SORT_UNIQUE
+ if((!unique) || (!i) || (strcmp(lines[i - 1], lines[i])))
#endif
- for (i = 0; i < nlines; i++)
- puts(lines[i]);
+ puts(lines[i]);
return EXIT_SUCCESS;
}