diff options
| author | John Beppu <beppu@lbox.org> | 1999-12-23 22:46:10 +0000 |
|---|---|---|
| committer | John Beppu <beppu@lbox.org> | 1999-12-23 22:46:10 +0000 |
| commit | 00417a38c10f1f5685013d16ad4fb782aa2deddb (patch) | |
| tree | 514a9625b56b5c57f64baf845278b9d64bea062e /coreutils | |
| parent | ee512a3f8620ab535716b8aa016b33610010920c (diff) | |
| download | busybox-w32-00417a38c10f1f5685013d16ad4fb782aa2deddb.tar.gz busybox-w32-00417a38c10f1f5685013d16ad4fb782aa2deddb.tar.bz2 busybox-w32-00417a38c10f1f5685013d16ad4fb782aa2deddb.zip | |
sort is good to go.
Diffstat (limited to 'coreutils')
| -rw-r--r-- | coreutils/sort.c | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/coreutils/sort.c b/coreutils/sort.c index 127d68319..0fe7bf99b 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c | |||
| @@ -256,11 +256,19 @@ sort_main(int argc, char **argv) | |||
| 256 | opt = argv[i][1]; | 256 | opt = argv[i][1]; |
| 257 | switch (opt) { | 257 | switch (opt) { |
| 258 | case 'g': | 258 | case 'g': |
| 259 | compare = compare_numeric; | 259 | /* what's the diff between -g && -n? */ |
| 260 | compare = compare_numeric; | ||
| 260 | break; | 261 | break; |
| 261 | case 'h': | 262 | case 'h': |
| 262 | usage(sort_usage); | 263 | usage(sort_usage); |
| 263 | break; | 264 | break; |
| 265 | case 'n': | ||
| 266 | /* what's the diff between -g && -n? */ | ||
| 267 | compare = compare_numeric; | ||
| 268 | break; | ||
| 269 | case 'r': | ||
| 270 | /* reverse */ | ||
| 271 | break; | ||
| 264 | default: | 272 | default: |
| 265 | fprintf(stderr, "sort: invalid option -- %c\n", opt); | 273 | fprintf(stderr, "sort: invalid option -- %c\n", opt); |
| 266 | usage(sort_usage); | 274 | usage(sort_usage); |
| @@ -270,7 +278,9 @@ sort_main(int argc, char **argv) | |||
| 270 | } | 278 | } |
| 271 | } | 279 | } |
| 272 | 280 | ||
| 273 | /* go through remaining args (if any) */ | 281 | /* this could be factored better */ |
| 282 | |||
| 283 | /* work w/ stdin */ | ||
| 274 | if (i >= argc) { | 284 | if (i >= argc) { |
| 275 | while ( (l = line_newFromFile(stdin))) { | 285 | while ( (l = line_newFromFile(stdin))) { |
| 276 | list_insert(&list, l); | 286 | list_insert(&list, l); |
| @@ -278,32 +288,25 @@ sort_main(int argc, char **argv) | |||
| 278 | list_sort(&list, compare); | 288 | list_sort(&list, compare); |
| 279 | list_writeToFile(&list, stdout); | 289 | list_writeToFile(&list, stdout); |
| 280 | list_release(&list); | 290 | list_release(&list); |
| 291 | |||
| 292 | /* work w/ what's left in argv[] */ | ||
| 281 | } else { | 293 | } else { |
| 294 | FILE *src; | ||
| 295 | |||
| 282 | for ( ; i < argc; i++) { | 296 | for ( ; i < argc; i++) { |
| 297 | src = fopen(argv[i], "r"); | ||
| 298 | if (src == NULL) { break; } | ||
| 299 | while ( (l = line_newFromFile(src))) { | ||
| 300 | list_insert(&list, l); | ||
| 301 | } | ||
| 302 | fclose(src); | ||
| 283 | } | 303 | } |
| 304 | list_sort(&list, compare); | ||
| 305 | list_writeToFile(&list, stdout); | ||
| 306 | list_release(&list); | ||
| 284 | } | 307 | } |
| 285 | 308 | ||
| 286 | exit(0); | 309 | exit(0); |
| 287 | } | 310 | } |
| 288 | 311 | ||
| 289 | /* $Id: sort.c,v 1.7 1999/12/23 00:02:49 beppu Exp $ */ | 312 | /* $Id: sort.c,v 1.8 1999/12/23 22:46:10 beppu Exp $ */ |
| 290 | /* | ||
| 291 | * $Log: sort.c,v $ | ||
| 292 | * Revision 1.7 1999/12/23 00:02:49 beppu | ||
| 293 | * implemented numeric sort (sort -g) | ||
| 294 | * | ||
| 295 | * Revision 1.6 1999/12/22 23:02:12 beppu | ||
| 296 | * oops.. qsort(2) misunderstanding on my part. | ||
| 297 | * it's ok, now. | ||
| 298 | * | ||
| 299 | * Revision 1.5 1999/12/22 22:27:01 beppu | ||
| 300 | * playing w/ $Log: sort.c,v $ | ||
| 301 | * playing w/ Revision 1.7 1999/12/23 00:02:49 beppu | ||
| 302 | * playing w/ implemented numeric sort (sort -g) | ||
| 303 | * playing w/ | ||
| 304 | * playing w/ Revision 1.6 1999/12/22 23:02:12 beppu | ||
| 305 | * playing w/ oops.. qsort(2) misunderstanding on my part. | ||
| 306 | * playing w/ it's ok, now. | ||
| 307 | * playing w/ | ||
| 308 | * | ||
| 309 | */ | ||
