From 7f427dc66aba8832f5368d16103e06cdc82d8816 Mon Sep 17 00:00:00 2001 From: Tollef Fog Heen Date: Sun, 20 Jul 2008 18:48:45 +0200 Subject: [PATCH] Sort the list of filters --- src/filters.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/filters.c b/src/filters.c index 97be9419..c4e4040d 100644 --- a/src/filters.c +++ b/src/filters.c @@ -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); } -- 2.39.5