# HG changeset patch # User Josef 'Jeff' Sipek # Date 1233868543 18000 # Node ID 9be67550f0bfa87549b4f73be5ef18ca566b5422 # Parent 692da62026334ede518658aec6e2fa6bc5b7c2a6 index display 10 stories diff -r 692da6202633 -r 9be67550f0bf config.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/config.h Thu Feb 05 16:15:43 2009 -0500 @@ -0,0 +1,7 @@ +#ifndef __CONFIG_H +#define __CONFIG_H + +#define HTML_INDEX_STORIES 10 + +#endif + diff -r 692da6202633 -r 9be67550f0bf dir.c --- a/dir.c Thu Feb 05 15:59:55 2009 -0500 +++ b/dir.c Thu Feb 05 16:15:43 2009 -0500 @@ -27,7 +27,7 @@ int sorted_readdir_loop(DIR *dir, struct post *post, void(*f)(struct post*, char*, void*), void *data, - int updown) + int updown, int limit) { struct dirent *de; char **list = NULL; @@ -58,9 +58,12 @@ else qsort(list, count, sizeof(char*), cmp_desc); - for(i=0; i #include +#include "config.h" #include "sar.h" #include "html.h" #include "dir.h" @@ -75,6 +76,42 @@ } /************************************************************************/ +/* INDEX */ +/************************************************************************/ +static void __each_index_helper(struct post *post, char *name, void *data) +{ + int postid = atoi(name); + struct post p; + + memset(&p, 0, sizeof(struct post)); + p.out = post->out; + + if (load_post(postid, &p)) + return; + + cat(&p, NULL, "templates/story-top.html", repltab_story_html); + cat(&p, NULL, "templates/story-middle.html", repltab_story_html); + cat_post(&p); + cat(&p, NULL, "templates/story-bottom.html", NULL); + + destroy_post(&p); +} + +void html_index(struct post *post) +{ + DIR *dir; + + dir = opendir("data/posts"); + if (!dir) + return; + + sorted_readdir_loop(dir, post, __each_index_helper, NULL, SORT_DESC, + HTML_INDEX_STORIES); + + closedir(dir); +} + +/************************************************************************/ /* POST COMMENTS */ /************************************************************************/ static void __html_comment(struct post *post, struct comment *comm) @@ -137,7 +174,7 @@ if (!dir) return; - sorted_readdir_loop(dir, post, __each_cat_helper, plist, SORT_ASC); + sorted_readdir_loop(dir, post, __each_cat_helper, plist, SORT_ASC, -1); closedir(dir); } @@ -157,7 +194,7 @@ if (!dir) return; - sorted_readdir_loop(dir, post, __cb_wrap, f, SORT_DESC); + sorted_readdir_loop(dir, post, __cb_wrap, f, SORT_DESC, -1); closedir(dir); } diff -r 692da6202633 -r 9be67550f0bf html.h --- a/html.h Thu Feb 05 15:59:55 2009 -0500 +++ b/html.h Thu Feb 05 16:15:43 2009 -0500 @@ -4,6 +4,7 @@ #include "post.h" extern void html_story(struct post *post); +extern void html_index(struct post *post); extern void html_comments(struct post *post); extern void html_sidebar(struct post *post); extern void html_header(struct post *post); diff -r 692da6202633 -r 9be67550f0bf index.c --- a/index.c Thu Feb 05 15:59:55 2009 -0500 +++ b/index.c Thu Feb 05 16:15:43 2009 -0500 @@ -21,6 +21,7 @@ fprintf(post.out, "Content-Type: text/html\n\n"); html_header(&post); + html_index(&post); html_sidebar(&post); html_footer(&post); diff -r 692da6202633 -r 9be67550f0bf post.c --- a/post.c Thu Feb 05 15:59:55 2009 -0500 +++ b/post.c Thu Feb 05 16:15:43 2009 -0500 @@ -228,7 +228,7 @@ if (!dir) return; - sorted_readdir_loop(dir, post, __each_comment_helper, f, SORT_ASC); + sorted_readdir_loop(dir, post, __each_comment_helper, f, SORT_ASC, -1); closedir(dir); } diff -r 692da6202633 -r 9be67550f0bf xattr.c --- a/xattr.c Thu Feb 05 15:59:55 2009 -0500 +++ b/xattr.c Thu Feb 05 16:15:43 2009 -0500 @@ -22,5 +22,7 @@ return NULL; } + buf[size] = '\0'; + return buf; }