summaryrefslogtreecommitdiffhomepage
path: root/coreutils
diff options
context:
space:
mode:
authorErik Andersen <andersen@codepoet.org>2000-03-04 21:19:32 +0000
committerErik Andersen <andersen@codepoet.org>2000-03-04 21:19:32 +0000
commit029011b9eeaf491d00fda1d072c4c6094df96c3a (patch)
tree7c49f1fc1547a2f9cee812472f422a5c1a5c448b /coreutils
parent7c4b2f3fe5cb6b9a5c6bd089c18279c5ce29dc21 (diff)
A few updates (including the cp fix the Craig has been looking for)
-Erik
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/cat.c8
-rw-r--r--coreutils/chroot.c9
-rw-r--r--coreutils/df.c8
-rw-r--r--coreutils/du.c71
-rw-r--r--coreutils/ln.c8
-rw-r--r--coreutils/sort.c28
6 files changed, 63 insertions, 69 deletions
diff --git a/coreutils/cat.c b/coreutils/cat.c
index 86f85fe8e..58a1b0f54 100644
--- a/coreutils/cat.c
+++ b/coreutils/cat.c
@@ -59,3 +59,11 @@ extern int cat_main(int argc, char **argv)
}
exit(TRUE);
}
+
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
diff --git a/coreutils/chroot.c b/coreutils/chroot.c
index 6a01be603..3622c26dc 100644
--- a/coreutils/chroot.c
+++ b/coreutils/chroot.c
@@ -65,3 +65,12 @@ int chroot_main(int argc, char **argv)
*argv, strerror(errno));
exit(FALSE);
}
+
+
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
diff --git a/coreutils/df.c b/coreutils/df.c
index 43d5d26e7..bc843f7a2 100644
--- a/coreutils/df.c
+++ b/coreutils/df.c
@@ -108,3 +108,11 @@ extern int df_main(int argc, char **argv)
exit(TRUE);
}
+
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
diff --git a/coreutils/du.c b/coreutils/du.c
index 4dc7ea13a..b6ebaca7a 100644
--- a/coreutils/du.c
+++ b/coreutils/du.c
@@ -36,16 +36,6 @@
typedef void (Display) (long, char *);
-typedef struct inode_type {
- struct inode_type *next;
- ino_t ino;
-} INODETYPE;
-
-#define HASH_SIZE 311 /* Should be prime */
-#define hash_inode(i) ((i) % HASH_SIZE)
-
-static INODETYPE *inode_hash_list[HASH_SIZE];
-
static const char du_usage[] =
"du [OPTION]... [FILE]...\n\n"
"Summarize disk space used for each FILE and/or directory.\n"
@@ -71,52 +61,6 @@ static void print_summary(long size, char *filename)
}
}
-/* Return 1 if inode is in inode hash list, else return 0 */
-static int is_in_list(const ino_t ino)
-{
- INODETYPE *inode;
-
- inode = inode_hash_list[hash_inode(ino)];
- while (inode != NULL) {
- if (inode->ino == ino)
- return 1;
- inode = inode->next;
- }
-
- return 0;
-}
-
-/* Add inode to inode hash list */
-static void add_inode(const ino_t ino)
-{
- int i;
- INODETYPE *inode;
-
- i = hash_inode(ino);
- inode = malloc(sizeof(INODETYPE));
- if (inode == NULL)
- fatalError("du: Not enough memory.");
-
- inode->ino = ino;
- inode->next = inode_hash_list[i];
- inode_hash_list[i] = inode;
-}
-
-/* Clear inode hash list */
-static void reset_inode_list(void)
-{
- int i;
- INODETYPE *inode;
-
- for (i = 0; i < HASH_SIZE; i++) {
- while (inode_hash_list[i] != NULL) {
- inode = inode_hash_list[i]->next;
- free(inode_hash_list[i]);
- inode_hash_list[i] = inode;
- }
- }
-}
-
/* tiny recursive du */
static long du(char *filename)
{
@@ -175,13 +119,13 @@ static long du(char *filename)
}
else if (statbuf.st_nlink > 1 && !count_hardlinks) {
/* Add files with hard links only once */
- if (is_in_list(statbuf.st_ino)) {
+ if (is_in_ino_dev_hashtable(&statbuf, NULL)) {
sum = 0L;
if (du_depth == 1)
print(sum, filename);
}
else {
- add_inode(statbuf.st_ino);
+ add_to_ino_dev_hashtable(&statbuf, NULL);
}
}
du_depth--;
@@ -231,11 +175,18 @@ int du_main(int argc, char **argv)
if (sum && isDirectory(argv[i], FALSE, NULL)) {
print_normal(sum, argv[i]);
}
- reset_inode_list();
+ reset_ino_dev_hashtable();
}
}
exit(0);
}
-/* $Id: du.c,v 1.15 2000/02/21 17:27:17 erik Exp $ */
+/* $Id: du.c,v 1.16 2000/03/04 21:19:32 erik Exp $ */
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
diff --git a/coreutils/ln.c b/coreutils/ln.c
index 0715bfaed..c54026c62 100644
--- a/coreutils/ln.c
+++ b/coreutils/ln.c
@@ -128,3 +128,11 @@ extern int ln_main(int argc, char **argv)
}
exit TRUE;
}
+
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
diff --git a/coreutils/sort.c b/coreutils/sort.c
index 609c5e08c..e6894f6c3 100644
--- a/coreutils/sort.c
+++ b/coreutils/sort.c
@@ -29,7 +29,18 @@
#include <stdio.h>
#include <errno.h>
-static const char sort_usage[] = "sort [OPTION]... [FILE]...\n\n";
+static const char sort_usage[] = "sort [-n]"
+#ifdef BB_FEATURE_SORT_REVERSE
+" [-r]"
+#endif
+" [FILE]...\n\n";
+
+#ifdef BB_FEATURE_SORT_REVERSE
+#define APPLY_REVERSE(x) (reverse ? -(x) : (x))
+static int reverse = 0;
+#else
+#define APPLY_REVERSE(x) (x)
+#endif
/* typedefs _______________________________________________________________ */
@@ -120,7 +131,7 @@ static int compare_ascii(const void *a, const void *b)
y = *doh;
// fprintf(stdout, "> %p: %s< %p: %s", x, x->data, y, y->data);
- return strcmp(x->data, y->data);
+ return APPLY_REVERSE(strcmp(x->data, y->data));
}
/* numeric order */
@@ -138,7 +149,7 @@ static int compare_numeric(const void *a, const void *b)
xint = strtoul(x->data, NULL, 10);
yint = strtoul(y->data, NULL, 10);
- return (xint - yint);
+ return APPLY_REVERSE(xint - yint);
}
@@ -254,20 +265,19 @@ int sort_main(int argc, char **argv)
if (argv[i][0] == '-') {
opt = argv[i][1];
switch (opt) {
- case 'g':
- /* what's the diff between -g && -n? */
- compare = compare_numeric;
- break;
case 'h':
usage(sort_usage);
break;
case 'n':
- /* what's the diff between -g && -n? */
+ /* numeric comparison */
compare = compare_numeric;
break;
+#ifdef BB_FEATURE_SORT_REVERSE
case 'r':
/* reverse */
+ reverse = 1;
break;
+#endif
default:
fprintf(stderr, "sort: invalid option -- %c\n", opt);
usage(sort_usage);
@@ -310,4 +320,4 @@ int sort_main(int argc, char **argv)
exit(0);
}
-/* $Id: sort.c,v 1.11 2000/02/08 19:58:47 erik Exp $ */
+/* $Id: sort.c,v 1.12 2000/03/04 21:19:32 erik Exp $ */