summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Beppu2000-09-28 17:49:59 +0000
committerJohn Beppu2000-09-28 17:49:59 +0000
commit8d369e98a5f0fb7612b3d09ff889394bf7ec4f5c (patch)
tree3f9863bb63760dec705764681f9e733fec6a5692
parentc0321f9bc67e0a90dbd12f4d7b39d6991c9899cd (diff)
downloadbusybox-8d369e98a5f0fb7612b3d09ff889394bf7ec4f5c.zip
busybox-8d369e98a5f0fb7612b3d09ff889394bf7ec4f5c.tar.gz
+ 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 3fe4c77..d6c3e9a 100644
--- a/coreutils/sort.c
+++ b/coreutils/sort.c
@@ -99,13 +99,13 @@ static Line *line_release(Line * self)
/* ascii order */
static int compare_ascii(const void *a, const void *b)
{
- Line **doh;
+ Line **val;
Line *x, *y;
- doh = (Line **) a;
- x = *doh;
- doh = (Line **) b;
- y = *doh;
+ val = (Line **) a;
+ x = *val;
+ val = (Line **) b;
+ y = *val;
// fprintf(stdout, "> %p: %s< %p: %s", x, x->data, y, y->data);
return APPLY_REVERSE(strcmp(x->data, y->data));
@@ -114,14 +114,14 @@ static int compare_ascii(const void *a, const void *b)
/* numeric order */
static int compare_numeric(const void *a, const void *b)
{
- Line **doh;
+ Line **val;
Line *x, *y;
int xint, yint;
- doh = (Line **) a;
- x = *doh;
- doh = (Line **) b;
- y = *doh;
+ val = (Line **) a;
+ x = *val;
+ val = (Line **) b;
+ y = *val;
xint = strtoul(x->data, NULL, 10);
yint = strtoul(y->data, NULL, 10);
@@ -255,19 +255,16 @@ int sort_main(int argc, char **argv)
}
}
- /* this could be factored better */
-
- /* work w/ stdin */
if (i >= argc) {
+
+ /* work w/ stdin */
while ((l = line_newFromFile(stdin))) {
list_insert(&list, l);
}
- list_sort(&list, compare);
- list_writeToFile(&list, stdout);
- list_release(&list);
- /* work w/ what's left in argv[] */
} else {
+
+ /* work w/ what's left in argv[] */
FILE *src;
for (; i < argc; i++) {
@@ -280,12 +277,13 @@ int sort_main(int argc, char **argv)
}
fclose(src);
}
- list_sort(&list, compare);
- list_writeToFile(&list, stdout);
- list_release(&list);
+
}
+ list_sort(&list, compare);
+ list_writeToFile(&list, stdout);
+ list_release(&list);
return(0);
}
-/* $Id: sort.c,v 1.22 2000/09/25 21:45:58 andersen Exp $ */
+/* $Id: sort.c,v 1.23 2000/09/28 17:49:59 beppu Exp $ */
diff --git a/sort.c b/sort.c
index 3fe4c77..d6c3e9a 100644
--- a/sort.c
+++ b/sort.c
@@ -99,13 +99,13 @@ static Line *line_release(Line * self)
/* ascii order */
static int compare_ascii(const void *a, const void *b)
{
- Line **doh;
+ Line **val;
Line *x, *y;
- doh = (Line **) a;
- x = *doh;
- doh = (Line **) b;
- y = *doh;
+ val = (Line **) a;
+ x = *val;
+ val = (Line **) b;
+ y = *val;
// fprintf(stdout, "> %p: %s< %p: %s", x, x->data, y, y->data);
return APPLY_REVERSE(strcmp(x->data, y->data));
@@ -114,14 +114,14 @@ static int compare_ascii(const void *a, const void *b)
/* numeric order */
static int compare_numeric(const void *a, const void *b)
{
- Line **doh;
+ Line **val;
Line *x, *y;
int xint, yint;
- doh = (Line **) a;
- x = *doh;
- doh = (Line **) b;
- y = *doh;
+ val = (Line **) a;
+ x = *val;
+ val = (Line **) b;
+ y = *val;
xint = strtoul(x->data, NULL, 10);
yint = strtoul(y->data, NULL, 10);
@@ -255,19 +255,16 @@ int sort_main(int argc, char **argv)
}
}
- /* this could be factored better */
-
- /* work w/ stdin */
if (i >= argc) {
+
+ /* work w/ stdin */
while ((l = line_newFromFile(stdin))) {
list_insert(&list, l);
}
- list_sort(&list, compare);
- list_writeToFile(&list, stdout);
- list_release(&list);
- /* work w/ what's left in argv[] */
} else {
+
+ /* work w/ what's left in argv[] */
FILE *src;
for (; i < argc; i++) {
@@ -280,12 +277,13 @@ int sort_main(int argc, char **argv)
}
fclose(src);
}
- list_sort(&list, compare);
- list_writeToFile(&list, stdout);
- list_release(&list);
+
}
+ list_sort(&list, compare);
+ list_writeToFile(&list, stdout);
+ list_release(&list);
return(0);
}
-/* $Id: sort.c,v 1.22 2000/09/25 21:45:58 andersen Exp $ */
+/* $Id: sort.c,v 1.23 2000/09/28 17:49:59 beppu Exp $ */