aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Beppu <beppu@lbox.org>2000-09-28 17:49:59 +0000
committerJohn Beppu <beppu@lbox.org>2000-09-28 17:49:59 +0000
commit8d369e98a5f0fb7612b3d09ff889394bf7ec4f5c (patch)
tree3f9863bb63760dec705764681f9e733fec6a5692
parentc0321f9bc67e0a90dbd12f4d7b39d6991c9899cd (diff)
downloadbusybox-w32-8d369e98a5f0fb7612b3d09ff889394bf7ec4f5c.tar.gz
busybox-w32-8d369e98a5f0fb7612b3d09ff889394bf7ec4f5c.tar.bz2
busybox-w32-8d369e98a5f0fb7612b3d09ff889394bf7ec4f5c.zip
+ shortened main() a little, and a few aesthetic cleanups here & there.
-rw-r--r--coreutils/sort.c40
-rw-r--r--sort.c40
2 files changed, 38 insertions, 42 deletions
diff --git a/coreutils/sort.c b/coreutils/sort.c
index 3fe4c7756..d6c3e9a5b 100644
--- a/coreutils/sort.c
+++ b/coreutils/sort.c
@@ -99,13 +99,13 @@ static Line *line_release(Line * self)
99/* ascii order */ 99/* ascii order */
100static int compare_ascii(const void *a, const void *b) 100static int compare_ascii(const void *a, const void *b)
101{ 101{
102 Line **doh; 102 Line **val;
103 Line *x, *y; 103 Line *x, *y;
104 104
105 doh = (Line **) a; 105 val = (Line **) a;
106 x = *doh; 106 x = *val;
107 doh = (Line **) b; 107 val = (Line **) b;
108 y = *doh; 108 y = *val;
109 109
110 // fprintf(stdout, "> %p: %s< %p: %s", x, x->data, y, y->data); 110 // fprintf(stdout, "> %p: %s< %p: %s", x, x->data, y, y->data);
111 return APPLY_REVERSE(strcmp(x->data, y->data)); 111 return APPLY_REVERSE(strcmp(x->data, y->data));
@@ -114,14 +114,14 @@ static int compare_ascii(const void *a, const void *b)
114/* numeric order */ 114/* numeric order */
115static int compare_numeric(const void *a, const void *b) 115static int compare_numeric(const void *a, const void *b)
116{ 116{
117 Line **doh; 117 Line **val;
118 Line *x, *y; 118 Line *x, *y;
119 int xint, yint; 119 int xint, yint;
120 120
121 doh = (Line **) a; 121 val = (Line **) a;
122 x = *doh; 122 x = *val;
123 doh = (Line **) b; 123 val = (Line **) b;
124 y = *doh; 124 y = *val;
125 125
126 xint = strtoul(x->data, NULL, 10); 126 xint = strtoul(x->data, NULL, 10);
127 yint = strtoul(y->data, NULL, 10); 127 yint = strtoul(y->data, NULL, 10);
@@ -255,19 +255,16 @@ int sort_main(int argc, char **argv)
255 } 255 }
256 } 256 }
257 257
258 /* this could be factored better */
259
260 /* work w/ stdin */
261 if (i >= argc) { 258 if (i >= argc) {
259
260 /* work w/ stdin */
262 while ((l = line_newFromFile(stdin))) { 261 while ((l = line_newFromFile(stdin))) {
263 list_insert(&list, l); 262 list_insert(&list, l);
264 } 263 }
265 list_sort(&list, compare);
266 list_writeToFile(&list, stdout);
267 list_release(&list);
268 264
269 /* work w/ what's left in argv[] */
270 } else { 265 } else {
266
267 /* work w/ what's left in argv[] */
271 FILE *src; 268 FILE *src;
272 269
273 for (; i < argc; i++) { 270 for (; i < argc; i++) {
@@ -280,12 +277,13 @@ int sort_main(int argc, char **argv)
280 } 277 }
281 fclose(src); 278 fclose(src);
282 } 279 }
283 list_sort(&list, compare); 280
284 list_writeToFile(&list, stdout);
285 list_release(&list);
286 } 281 }
282 list_sort(&list, compare);
283 list_writeToFile(&list, stdout);
284 list_release(&list);
287 285
288 return(0); 286 return(0);
289} 287}
290 288
291/* $Id: sort.c,v 1.22 2000/09/25 21:45:58 andersen Exp $ */ 289/* $Id: sort.c,v 1.23 2000/09/28 17:49:59 beppu Exp $ */
diff --git a/sort.c b/sort.c
index 3fe4c7756..d6c3e9a5b 100644
--- a/sort.c
+++ b/sort.c
@@ -99,13 +99,13 @@ static Line *line_release(Line * self)
99/* ascii order */ 99/* ascii order */
100static int compare_ascii(const void *a, const void *b) 100static int compare_ascii(const void *a, const void *b)
101{ 101{
102 Line **doh; 102 Line **val;
103 Line *x, *y; 103 Line *x, *y;
104 104
105 doh = (Line **) a; 105 val = (Line **) a;
106 x = *doh; 106 x = *val;
107 doh = (Line **) b; 107 val = (Line **) b;
108 y = *doh; 108 y = *val;
109 109
110 // fprintf(stdout, "> %p: %s< %p: %s", x, x->data, y, y->data); 110 // fprintf(stdout, "> %p: %s< %p: %s", x, x->data, y, y->data);
111 return APPLY_REVERSE(strcmp(x->data, y->data)); 111 return APPLY_REVERSE(strcmp(x->data, y->data));
@@ -114,14 +114,14 @@ static int compare_ascii(const void *a, const void *b)
114/* numeric order */ 114/* numeric order */
115static int compare_numeric(const void *a, const void *b) 115static int compare_numeric(const void *a, const void *b)
116{ 116{
117 Line **doh; 117 Line **val;
118 Line *x, *y; 118 Line *x, *y;
119 int xint, yint; 119 int xint, yint;
120 120
121 doh = (Line **) a; 121 val = (Line **) a;
122 x = *doh; 122 x = *val;
123 doh = (Line **) b; 123 val = (Line **) b;
124 y = *doh; 124 y = *val;
125 125
126 xint = strtoul(x->data, NULL, 10); 126 xint = strtoul(x->data, NULL, 10);
127 yint = strtoul(y->data, NULL, 10); 127 yint = strtoul(y->data, NULL, 10);
@@ -255,19 +255,16 @@ int sort_main(int argc, char **argv)
255 } 255 }
256 } 256 }
257 257
258 /* this could be factored better */
259
260 /* work w/ stdin */
261 if (i >= argc) { 258 if (i >= argc) {
259
260 /* work w/ stdin */
262 while ((l = line_newFromFile(stdin))) { 261 while ((l = line_newFromFile(stdin))) {
263 list_insert(&list, l); 262 list_insert(&list, l);
264 } 263 }
265 list_sort(&list, compare);
266 list_writeToFile(&list, stdout);
267 list_release(&list);
268 264
269 /* work w/ what's left in argv[] */
270 } else { 265 } else {
266
267 /* work w/ what's left in argv[] */
271 FILE *src; 268 FILE *src;
272 269
273 for (; i < argc; i++) { 270 for (; i < argc; i++) {
@@ -280,12 +277,13 @@ int sort_main(int argc, char **argv)
280 } 277 }
281 fclose(src); 278 fclose(src);
282 } 279 }
283 list_sort(&list, compare); 280
284 list_writeToFile(&list, stdout);
285 list_release(&list);
286 } 281 }
282 list_sort(&list, compare);
283 list_writeToFile(&list, stdout);
284 list_release(&list);
287 285
288 return(0); 286 return(0);
289} 287}
290 288
291/* $Id: sort.c,v 1.22 2000/09/25 21:45:58 andersen Exp $ */ 289/* $Id: sort.c,v 1.23 2000/09/28 17:49:59 beppu Exp $ */