An attempt to fix paging
This commit is contained in:
parent
fc3d99fa82
commit
b6fe021d8d
10
src/main.c
10
src/main.c
@ -125,10 +125,9 @@ print_submit_form()
|
|||||||
"</form>\n", cgiOut);
|
"</form>\n", cgiOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* each page stores comments with ids in [P * (page - 1), P * page)
|
/* each page stores comments with ids in [P * (page - 1) + 1, P * page + 1)
|
||||||
* if page is not specified, then we'll just print last P comments (for now)
|
* if page is not specified, then we'll just print last P comments (for now)
|
||||||
* TODO: print errors in div
|
* TODO: print errors in div
|
||||||
* FIXME: NOW PAGING IS FAULTY, FIX IT
|
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
print_page()
|
print_page()
|
||||||
@ -149,14 +148,15 @@ print_page()
|
|||||||
id_end = max_id;
|
id_end = max_id;
|
||||||
id_begin = (max_id > COMMENTS_PER_PAGE ? max_id - COMMENTS_PER_PAGE : 1);
|
id_begin = (max_id > COMMENTS_PER_PAGE ? max_id - COMMENTS_PER_PAGE : 1);
|
||||||
} else {
|
} else {
|
||||||
/* max_id >= COMMENTS_PER_PAGE * page
|
/* max_id > COMMENTS_PER_PAGE * (page - 1) + 1
|
||||||
|
* max_id - 1 > COMMENTS_PER_PAGE * (page - 1)
|
||||||
* perform this check without overflow
|
* perform this check without overflow
|
||||||
*/
|
*/
|
||||||
if (max_id / page < COMMENTS_PER_PAGE) {
|
if ((max_id + COMMENTS_PER_PAGE - 1) / COMMENTS_PER_PAGE <= (page - 1)) {
|
||||||
fprintf(cgiOut, "There is no such page\n");
|
fprintf(cgiOut, "There is no such page\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
id_begin = COMMENTS_PER_PAGE * (page - 1);
|
id_begin = COMMENTS_PER_PAGE * (page - 1) + 1;
|
||||||
id_end = id_begin + COMMENTS_PER_PAGE;
|
id_end = id_begin + COMMENTS_PER_PAGE;
|
||||||
if (id_end > max_id) {
|
if (id_end > max_id) {
|
||||||
id_end = max_id;
|
id_end = max_id;
|
||||||
|
Loading…
Reference in New Issue
Block a user