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);
|
||||
}
|
||||
|
||||
/* 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)
|
||||
* TODO: print errors in div
|
||||
* FIXME: NOW PAGING IS FAULTY, FIX IT
|
||||
*/
|
||||
void
|
||||
print_page()
|
||||
@ -149,14 +148,15 @@ print_page()
|
||||
id_end = max_id;
|
||||
id_begin = (max_id > COMMENTS_PER_PAGE ? max_id - COMMENTS_PER_PAGE : 1);
|
||||
} 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
|
||||
*/
|
||||
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");
|
||||
return;
|
||||
}
|
||||
id_begin = COMMENTS_PER_PAGE * (page - 1);
|
||||
id_begin = COMMENTS_PER_PAGE * (page - 1) + 1;
|
||||
id_end = id_begin + COMMENTS_PER_PAGE;
|
||||
if (id_end > max_id) {
|
||||
id_end = max_id;
|
||||
|
Loading…
Reference in New Issue
Block a user