prev", (currentpage == 1) ? pagecount : currentpage-1);
strncat(bar, buff, freespace);
for (int i = 1; i < pagecount; i++)
{
// FIXME: this doesn't need to be an if/else..
if (currentpage == i)
{
freespace -= snprintf(buff, freespace, "
%d ", i, i);
}
else
{
freespace -= snprintf(buff, freespace, "
%d ", i, i);
}
strncat(bar, buff, freespace);
}
freespace -= snprintf(buff, freespace, "
next", (currentpage == pagecount) ? 1 : currentpage+1);
strncat(bar, buff, freespace);
printf("%s: %ld pages = %d\n", bar, freespace, pagecount);
return bar;
}
int
postspage(int flags)
{
/*
* TODO: document
*/
/* get all files in the directory that are .txt */
int posts[512]; // logical maximum number of posts
size_t totalposts = 0;
DIR *dir;
struct dirent *ent;
if ((dir = opendir(posts_content)) != NULL)
{
while ((ent = readdir(dir)) != NULL)
{
if (strstr(ent->d_name, ".txt") != NULL)
{
int ign = 0;
/* check if post should be ignored */
for (int i = 0; i < sizeof(ignore)/sizeof(ignore[0]); i++)
{
if (atoi(ent->d_name) == ignore[i])
{
printf("ignoring post %d\n", atoi(ent->d_name));
ign = 1;
}
}
if (ign)
continue;
posts[totalposts] = atoi(ent->d_name); // gross
totalposts++;
}
}
closedir(dir);
}
else
{
/* could not open directory */
fprintf(stderr, "Error opening directory: %s\n", strerror(errno));
fprintf(stderr, "unable to open file '%s', unrecoverable failure\n", posts_content);
return 0;
}
/* sort posts */
qsort(posts, totalposts, sizeof(int), postscompare);
/* create direct link pages */
if (!createdirectpages(posts, totalposts))
{
fprintf(stderr, "unable to create direct post pages, unrecoverable failure\n");
return 0;
}
char pagebar[1024] = {0};
generatepagebar(pagebar, 1024, posts, totalposts, 1);
return 1;
}