- for (i=0; (i<BLOG->num_msgs); ++i) {
- if (BLOG->msgs[i].msgnum > 0L) {
- wc_printf("Message %d, #%ld, id %d, refs %d<br>\n",
- i,
- BLOG->msgs[i].msgnum,
- BLOG->msgs[i].id,
- BLOG->msgs[i].refs
- );
+/*
+ * All blogpost entries are now in the hash list.
+ * Sort them, select the desired range, and render what we want to see.
+ */
+int blogview_render(SharedMessageStatus *Stat, void **ViewSpecific, long oper)
+{
+ BLOG *BL = (BLOG*) *ViewSpecific;
+ HashPos *it;
+ const char *Key;
+ void *Data;
+ long len;
+ int i;
+ struct blogpost **blogposts = NULL;
+ int num_blogposts = 0;
+ int num_blogposts_alloc = 0;
+ int with_comments = 0;
+ int firstp = 0;
+ int maxp = 0;
+
+ /* Comments are shown if we are only viewing a single blog post */
+ if (atoi(BSTR("p"))) with_comments = 1;
+
+ firstp = atoi(BSTR("firstp")); /* start reading at... */
+ maxp = atoi(BSTR("maxp")); /* max posts to show... */
+ if (maxp < 1) maxp = 5; /* default; move somewhere else? */
+
+ /* Iterate through the hash list and copy the data pointers into an array */
+ it = GetNewHashPos(BL->BLOG, 0);
+ while (GetNextHashPos(BL->BLOG, it, &len, &Key, &Data)) {
+ if (num_blogposts >= num_blogposts_alloc) {
+ if (num_blogposts_alloc == 0) {
+ num_blogposts_alloc = 100;
+ }
+ else {
+ num_blogposts_alloc *= 2;
+ }
+ blogposts = realloc(blogposts, (num_blogposts_alloc * sizeof (struct blogpost *)));