| 14 |
* * |
* * |
| 15 |
***************************************************************************/ |
***************************************************************************/ |
| 16 |
|
|
|
#define _POSIX_C_SOURCE 200809L |
|
|
|
|
| 17 |
#include "section_list_display.h" |
#include "section_list_display.h" |
| 18 |
#include "section_list_loader.h" |
#include "section_list_loader.h" |
| 19 |
#include "article_cache.h" |
#include "article_cache.h" |
| 43 |
POST_ARTICLE = 5, |
POST_ARTICLE = 5, |
| 44 |
EDIT_ARTICLE = 6, |
EDIT_ARTICLE = 6, |
| 45 |
DELETE_ARTICLE = 7, |
DELETE_ARTICLE = 7, |
| 46 |
|
FIRST_TOPIC_ARTICLE = 8, |
| 47 |
|
LAST_TOPIC_ARTICLE = 9, |
| 48 |
}; |
}; |
| 49 |
|
|
| 50 |
static int section_list_draw_items(int page_id, ARTICLE *p_articles[], int article_count, int display_nickname) |
static int section_list_draw_items(int page_id, ARTICLE *p_articles[], int article_count, int display_nickname) |
| 260 |
(*p_selected_index)++; |
(*p_selected_index)++; |
| 261 |
} |
} |
| 262 |
break; |
break; |
| 263 |
|
case '=': |
| 264 |
|
return FIRST_TOPIC_ARTICLE; |
| 265 |
|
case '\\': |
| 266 |
|
return LAST_TOPIC_ARTICLE; |
| 267 |
case 'h': |
case 'h': |
| 268 |
return SHOW_HELP; |
return SHOW_HELP; |
| 269 |
default: |
default: |
| 327 |
break; |
break; |
| 328 |
case 'r': // Reply article |
case 'r': // Reply article |
| 329 |
return 1; |
return 1; |
| 330 |
|
case '=': // First topic article |
| 331 |
|
return 1; |
| 332 |
|
case '\\': // Last topic article |
| 333 |
|
return 1; |
| 334 |
case KEY_UP: |
case KEY_UP: |
| 335 |
case KEY_PGUP: |
case KEY_PGUP: |
| 336 |
case KEY_HOME: |
case KEY_HOME: |
| 406 |
int loop; |
int loop; |
| 407 |
int direction; |
int direction; |
| 408 |
ARTICLE article_new; |
ARTICLE article_new; |
| 409 |
|
int page_id_cur; |
| 410 |
|
|
| 411 |
p_section = section_list_find_by_name(sname); |
p_section = section_list_find_by_name(sname); |
| 412 |
if (p_section == NULL) |
if (p_section == NULL) |
| 580 |
case KEY_PGUP: |
case KEY_PGUP: |
| 581 |
case KEY_PGDN: |
case KEY_PGDN: |
| 582 |
direction = (ret == KEY_PGUP ? -1 : 1); |
direction = (ret == KEY_PGUP ? -1 : 1); |
| 583 |
ret = locate_article_in_section(p_section, p_articles[selected_index], direction, &page_id, &selected_index, &page_count); |
ret = locate_article_in_section(p_section, p_articles[selected_index], direction, 1, |
| 584 |
|
&page_id, &selected_index, &article_count); |
| 585 |
if (ret < 0) |
if (ret < 0) |
| 586 |
{ |
{ |
| 587 |
log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d) error\n", |
log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=1) error\n", |
| 588 |
p_section->sid, p_articles[selected_index]->aid, direction); |
p_section->sid, p_articles[selected_index]->aid, direction); |
| 589 |
return -3; |
return -3; |
| 590 |
} |
} |
| 591 |
else if (ret > 0) |
else if (ret > 0) // found |
| 592 |
{ |
{ |
| 593 |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count); |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count); |
| 594 |
if (ret < 0) |
if (ret < 0) |
| 606 |
} |
} |
| 607 |
loop = 1; |
loop = 1; |
| 608 |
break; |
break; |
| 609 |
|
case '=': // First topic article |
| 610 |
|
case '\\': // Last topic article |
| 611 |
|
page_id_cur = page_id; |
| 612 |
|
direction = (ret == '=' ? -1 : 1); |
| 613 |
|
ret = locate_article_in_section(p_section, p_articles[selected_index], direction, BBS_article_limit_per_section, |
| 614 |
|
&page_id, &selected_index, &article_count); |
| 615 |
|
if (ret < 0) |
| 616 |
|
{ |
| 617 |
|
log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=%d) error\n", |
| 618 |
|
p_section->sid, p_articles[selected_index]->aid, direction, BBS_article_limit_per_section); |
| 619 |
|
return -3; |
| 620 |
|
} |
| 621 |
|
else if (ret > 0) // found |
| 622 |
|
{ |
| 623 |
|
if (page_id != page_id_cur) // page changed |
| 624 |
|
{ |
| 625 |
|
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count); |
| 626 |
|
if (ret < 0) |
| 627 |
|
{ |
| 628 |
|
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 629 |
|
return -3; |
| 630 |
|
} |
| 631 |
|
} |
| 632 |
|
loop = 1; |
| 633 |
|
} |
| 634 |
|
break; |
| 635 |
} |
} |
| 636 |
} while (loop); |
} while (loop); |
| 637 |
|
|
| 706 |
return -2; |
return -2; |
| 707 |
} |
} |
| 708 |
break; |
break; |
| 709 |
|
case FIRST_TOPIC_ARTICLE: |
| 710 |
|
case LAST_TOPIC_ARTICLE: |
| 711 |
|
page_id_cur = page_id; |
| 712 |
|
direction = (ret == FIRST_TOPIC_ARTICLE ? -1 : 1); |
| 713 |
|
ret = locate_article_in_section(p_section, p_articles[selected_index], direction, BBS_article_limit_per_section, |
| 714 |
|
&page_id, &selected_index, &article_count); |
| 715 |
|
if (ret < 0) |
| 716 |
|
{ |
| 717 |
|
log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=%d) error\n", |
| 718 |
|
p_section->sid, p_articles[selected_index]->aid, direction, BBS_article_limit_per_section); |
| 719 |
|
return -3; |
| 720 |
|
} |
| 721 |
|
else if (ret > 0 && page_id != page_id_cur) // found and page changed |
| 722 |
|
{ |
| 723 |
|
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count); |
| 724 |
|
if (ret < 0) |
| 725 |
|
{ |
| 726 |
|
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 727 |
|
return -3; |
| 728 |
|
} |
| 729 |
|
} |
| 730 |
|
break; |
| 731 |
case SHOW_HELP: |
case SHOW_HELP: |
| 732 |
// Display help information |
// Display help information |
| 733 |
display_file(DATA_READ_HELP, 1); |
display_file(DATA_READ_HELP, 1); |