aboutsummaryrefslogtreecommitdiff
path: root/coreutils/sort.c
diff options
context:
space:
mode:
authormarkw <markw@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-04-17 18:56:18 +0000
committermarkw <markw@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-04-17 18:56:18 +0000
commita3da28877a48a5391a791304d5ea1fc7e40808c1 (patch)
tree1384fdafb928c700cba166f7e3609b516d5b7287 /coreutils/sort.c
parent6821ee60c553c0ac4e73d50d71e4d17cceb17547 (diff)
downloadbusybox-w32-a3da28877a48a5391a791304d5ea1fc7e40808c1.tar.gz
busybox-w32-a3da28877a48a5391a791304d5ea1fc7e40808c1.tar.bz2
busybox-w32-a3da28877a48a5391a791304d5ea1fc7e40808c1.zip
Applied patch from I.Q. to add sort -u as a feature.
git-svn-id: svn://busybox.net/trunk/busybox@2363 69ca8d6d-28ef-0310-b511-8ec308f3f277
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)
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}