]> thyrsus.com Git - comparator.git/commitdiff
Sort the output.
authorEric S. Raymond <esr@thyrsus.com>
Fri, 29 Aug 2003 22:24:38 +0000 (22:24 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Fri, 29 Aug 2003 22:24:38 +0000 (22:24 +0000)
shredtree.c

index 0419e77d3da2ca2579f0a0ac26a6555754b64dd0..00290b1eb29e7f3e56276af2343ef4ce534d10c4 100644 (file)
@@ -8,10 +8,19 @@
 #include <alloca.h>
 #include "md5.h"
 
-static c_only = 0;
-static rws = 0;
-static debug = 0;
-static shredsize = 5;
+static int c_only = 0;
+static int rws = 0;
+static int debug = 0;
+static int shredsize = 5;
+static int filecount;
+
+struct item
+{
+    char       *file;
+    struct item *next;
+}
+dummy;
+struct item *head = &dummy;
 
 static int eligible(const char *file)
 /* is the specified file eligible to be compared? */ 
@@ -153,17 +162,30 @@ int treewalker(const char *file, const struct stat *sb, int flag)
 /* walk the tree, emitting hash sections for eligible files */
 {
     if (flag == FTW_F && sb->st_size > 0 && eligible(file))
-        shredfile(file);
+    {
+       struct item *new;
+
+       new = (struct item *)malloc(sizeof(new));
+        new->file = strdup(file);
+       new->next = head;
+       head = new;
+       filecount++;
+    }
     return(0);
 }
 
+int stringsort(void *a, void *b)
+{
+    return strcmp(*(char **)a, *(char **)b);
+}
+
 main(int argc, char *argv[])
 {
     extern char        *optarg;        /* set by getopt */
     extern int optind;         /* set by getopt */
 
     int status;
-    char *dir = ".";
+    char **place, **list, *dir = ".";
     while ((status = getopt(argc, argv, "cdhs:w")) != EOF)
     {
        switch (status)
@@ -204,5 +226,19 @@ main(int argc, char *argv[])
     printf("Normalization: %s\n", rws ? "remove_whitespace" : "none");
     puts("%%");
 
+    /* make file list */
     ftw(argv[optind], treewalker, 16);
+
+    printf("Filecount: %d\n", filecount);
+
+    /* now that we know the length, copy into an array */
+    list = place = (char **)calloc(sizeof(char *), filecount);
+    for (; head->next; head = head->next)
+       *place++ = head->file;
+
+    /* the objective -- sort */
+    qsort(list, filecount, sizeof(char *), stringsort);
+
+    for (place = list; place < list + filecount; place++)
+       shredfile(*place);
 }