]> code.citadel.org Git - citadel.git/blobdiff - webcit/blogview_renderer.c
Another minor commit
[citadel.git] / webcit / blogview_renderer.c
index d6ddf9c2599e42f94b40e40b8cb33a9fff3ea5e6..8a3d4b64997275962c6a052e1ac45fed05d0d607 100644 (file)
@@ -5,7 +5,7 @@
  *
  * This program is open source software.  You can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 3 of the
+ * published by the Free Software Foundation -- either version 3 of the
  * License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
@@ -181,8 +181,7 @@ int blogview_LoadMsgFromServer(SharedMessageStatus *Stat,
 
        /* FIXME an optimization here -- one we ought to perform -- is to exit this
         * function immediately if the viewer is only interested in a single post and
-        * that message ID is neither the id nor the refs.  Actually, that might *be*
-        * the way to display only a single message (with or without comments).
+        * that message ID is neither the id nor the refs.
         */
 
        if (b.refs == 0) {
@@ -222,21 +221,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<br>\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 +266,10 @@ 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);
+
+               /* FIXME this is where we handle date ranges etc */
                for (i=0; i<num_blogposts; ++i) {
-                       wc_printf("Top level ID is %d", blogposts[i]->top_level_id);
-                       wc_printf("; top level msgnum is %ld", blogposts[i]->msgs[0]);
                        blogpost_render(blogposts[i]);
                }
                free(blogposts);
@@ -293,6 +289,7 @@ int blogview_Cleanup(void **ViewSpecific)
        return 0;
 }
 
+
 void 
 InitModule_BLOGVIEWRENDERERS
 (void)