]> err.no Git - dpkg/commitdiff
Sort the list of filters
authorTollef Fog Heen <tfheen@err.no>
Sun, 20 Jul 2008 16:48:45 +0000 (18:48 +0200)
committerTollef Fog Heen <tfheen@err.no>
Sun, 20 Jul 2008 16:48:45 +0000 (18:48 +0200)
src/filters.c

index 97be941954d81d366894c2bde5950dc42719dfbd..c4e4040da3d9fa63b11641719b7ec8a221b2674a 100644 (file)
@@ -90,12 +90,19 @@ loadfilter(const char *fn)
                ohshite(_("error closing configuration file '%.255s'"), fn);
 }
 
+static int inv_alphasort(const void *a, const void *a) {
+       return -1 * strcoll((char*)a, (char*) b);
+}
+
 void
 loadfilters(void)
 {
        struct dirent *dent;
        char *dirname = CONFIGDIR "/filters.d";
        DIR *dir = opendir(dirname);
+       int names_len = 1024;
+       char **names = m_malloc(names_len * sizeof(char *));
+       int i = 0;
 
        if (!dir) {
                if (errno == ENOENT)
@@ -112,10 +119,22 @@ loadfilters(void)
                sprintf(file, "%s/%s", dirname, dent->d_name);
                if (stat(file, &statbuf) != 0)
                        ohshite(_("error stating file '%s'"), file);
-               if (S_ISREG(statbuf.st_mode))
-                       loadfilter(file);
+               if (S_ISREG(statbuf.st_mode)) {
+                       names[i++] = m_strdup(dent->d_name);
+                       if (i == names_len) {
+                               names_len *= 2;
+                               names = m_realloc(names,
+                                                 names_len * sizeof (char *));
+                       }
+               }
                free(file);
        }
+       qsort(names, i, sizeof(char *), inv_alphasort);
+       while (i > 0) {
+               loadfilter(names[--i]);
+               free(names[i]);
+       }
+       free(names);
        closedir(dir);
 }