Commit 49df3747 authored by Kim Vandry's avatar Kim Vandry

refactor: move sort_message_list to mairix.c from dirscan.c

This will avoid sorting the list more than once in case there are
multiple input folder types. It will also allow IMAP messages
(which will not be handled in dirscan.c) be sorted together with
the others.
parent 5f89b34b
......@@ -348,21 +348,6 @@ static void scan_directory(char *folder_base, char *this_folder, enum folder_typ
}
/*}}}*/
#endif
static int message_compare(const void *a, const void *b)/*{{{*/
{
/* FIXME : Is this a sensible way to do this with mbox messages in the picture? */
struct msgpath *aa = (struct msgpath *) a;
struct msgpath *bb = (struct msgpath *) b;
if (aa->type < bb->type) return -1;
if (aa->type > bb->type) return 1;
return strcmp(aa->src.mpf.path, bb->src.mpf.path);
}
/*}}}*/
static void sort_message_list(struct msgpath_array *arr)/*{{{*/
{
qsort(arr->paths, arr->n, sizeof(struct msgpath), message_compare);
}
/*}}}*/
/*{{{ void build_message_list */
void build_message_list(char *folder_base, char *folders, enum folder_type ft,
struct msgpath_array *msgs,
......@@ -392,7 +377,6 @@ void build_message_list(char *folder_base, char *folders, enum folder_type ft,
if (paths) free(paths);
sort_message_list(msgs);
return;
}
/*}}}*/
......
......@@ -269,6 +269,23 @@ static void parse_rc_file(char *name)/*{{{*/
if (used_default_name) free(name);
}
/*}}}*/
static int message_compare(const void *a, const void *b)/*{{{*/
{
/* FIXME : Is this a sensible way to do this with mbox messages in the picture? */
struct msgpath *aa = (struct msgpath *) a;
struct msgpath *bb = (struct msgpath *) b;
if (aa->type < bb->type) return -1;
if (aa->type > bb->type) return 1;
return strcmp(aa->src.mpf.path, bb->src.mpf.path);
}
/*}}}*/
static void sort_message_list(struct msgpath_array *arr)/*{{{*/
{
qsort(arr->paths, arr->n, sizeof(struct msgpath), message_compare);
}
/*}}}*/
static int compare_strings(const void *a, const void *b)/*{{{*/
{
const char **aa = (const char **) a;
......@@ -725,6 +742,7 @@ int main (int argc, char **argv)/*{{{*/
if (mh_folders) {
build_message_list(folder_base, mh_folders, FT_MH, msgs, omit_globs);
}
sort_message_list(msgs);
/* The next call sorts the msgs array as part of looking for duplicates. */
if (check_message_list_for_duplicates(msgs)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment