+ if ((BBS->num_msgs % Stat->maxmsgs) == 0) {
+ BBS->num_pages = BBS->num_msgs / Stat->maxmsgs;
+ }
+ else {
+ BBS->num_pages = (BBS->num_msgs / Stat->maxmsgs) + 1;
+ }
+
+ /* If the requested page number is -4,
+ * it means "whichever page on which msg#xxxxx starts"
+ * Change to the page number which contains that message.
+ */
+ if (BBS->requested_page == (-4)) {
+ if (BBS->num_msgs == 0) {
+ BBS->requested_page = 0;
+ }
+ else {
+ for (i=0; i<BBS->num_msgs; ++i) {
+ if (
+ (BBS->msgs[i] >= BBS->start_reading_at)
+ && (BBS->requested_page == (-4))
+ ) {
+ BBS->requested_page = (i / Stat->maxmsgs) ;
+ }
+ }
+ }
+ }
+
+ /* If the requested page number is -3,
+ * it means "whichever page on which new messages start"
+ * Change that to an actual page number now.
+ */
+ if (BBS->requested_page == (-3)) {
+ if (BBS->num_msgs == 0) {
+ BBS->requested_page = 0;
+ }
+ else {
+ for (i=0; i<BBS->num_msgs; ++i) {
+ if (
+ (BBS->msgs[i] > BBS->lastseen)
+ && ( (i == 0) || (BBS->msgs[i-1] <= BBS->lastseen) )
+ ) {
+ BBS->requested_page = (i / Stat->maxmsgs) ;
+ }
+ }
+ }
+ }
+
+ /* Still set to -3 ? If so, that probably means that there are no new messages,
+ * so we'll go to the *end* of the final page.
+ */
+ if (BBS->requested_page == (-3)) {
+ if (BBS->num_msgs == 0) {
+ BBS->requested_page = 0;
+ }
+ else {
+ BBS->requested_page = BBS->num_pages - 1;
+ }
+ }
+
+ /* keep the requested page within bounds */
+ if (BBS->requested_page < 0) BBS->requested_page = 0;
+ if (BBS->requested_page >= BBS->num_pages) BBS->requested_page = BBS->num_pages - 1;
+