From 015d703040d5fcd72b87ce3afc0338cc5c96c5b7 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Fri, 3 Jun 2011 13:43:28 -0400 Subject: [PATCH] Sorting the blog posts in newest-to-oldest order now works. Big thanks to whoever wrote http://www.c.happycodings.com/Sorting_Searching/code14.html --- webcit/blogview_renderer.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/webcit/blogview_renderer.c b/webcit/blogview_renderer.c index d6ddf9c25..83fcc19bd 100644 --- a/webcit/blogview_renderer.c +++ b/webcit/blogview_renderer.c @@ -222,21 +222,18 @@ int blogview_LoadMsgFromServer(SharedMessageStatus *Stat, /* * Sort a list of 'struct blogpost' objects by newest-to-oldest msgnum. + * With big thanks to whoever wrote http://www.c.happycodings.com/Sorting_Searching/code14.html */ -int blogview_sortfunc(const void *s1, const void *s2) { - struct blogpost *l1 = (struct blogpost *)(s1); - struct blogpost *l2 = (struct blogpost *)(s2); +static int blogview_sortfunc(const void *a, const void *b) { + struct blogpost * const *one = a; + struct blogpost * const *two = b; - wc_printf("Sort function called on %d, %d
\n", l1->top_level_id, l2->top_level_id); - return(0); - - if (l1->msgs[0] > l2->msgs[0]) return(-1); - if (l1->msgs[0] < l2->msgs[0]) return(+1); + if ( (*one)->msgs[0] > (*two)->msgs[0] ) return(-1); + if ( (*one)->msgs[0] < (*two)->msgs[0] ) return(+1); return(0); } - /* * All blogpost entries are now in the hash list. * Sort them, (FIXME cull by date range if needed,) and render what we want to see. @@ -270,10 +267,8 @@ int blogview_render(SharedMessageStatus *Stat, void **ViewSpecific, long oper) DeleteHashPos(&it); if (num_blogposts > 0) { - qsort(blogposts, num_blogposts, sizeof(struct blogpost *), blogview_sortfunc); + qsort(blogposts, num_blogposts, sizeof(void *), blogview_sortfunc); for (i=0; itop_level_id); - wc_printf("; top level msgnum is %ld", blogposts[i]->msgs[0]); blogpost_render(blogposts[i]); } free(blogposts); -- 2.30.2