| 39 |
#include <time.h> |
#include <time.h> |
| 40 |
#include <sys/param.h> |
#include <sys/param.h> |
| 41 |
|
|
| 42 |
|
#define TITLE_SEARCH_MAX_LEN 60 |
| 43 |
|
|
| 44 |
static int32_t section_aid_locations[BBS_max_section] = {0}; |
static int32_t section_aid_locations[BBS_max_section] = {0}; |
| 45 |
static int section_topic_view_mode = 0; |
static int section_topic_view_mode = 0; |
| 46 |
static int section_topic_view_tid = -1; |
static int section_topic_view_tid = -1; |
| 61 |
UNSET_FAVOR_ARTICLE, |
UNSET_FAVOR_ARTICLE, |
| 62 |
FIRST_TOPIC_ARTICLE, |
FIRST_TOPIC_ARTICLE, |
| 63 |
LAST_TOPIC_ARTICLE, |
LAST_TOPIC_ARTICLE, |
| 64 |
|
LAST_SECTION_ARTICLE, |
| 65 |
SCAN_NEW_ARTICLE, |
SCAN_NEW_ARTICLE, |
| 66 |
SCAN_ARTICLE_BACKWARD_BY_USER, |
SCAN_ARTICLE_BACKWARD_BY_USER, |
| 67 |
SCAN_ARTICLE_FORWARD_BY_USER, |
SCAN_ARTICLE_FORWARD_BY_USER, |
| 68 |
|
SCAN_ARTICLE_BACKWARD_BY_TITLE, |
| 69 |
|
SCAN_ARTICLE_FORWARD_BY_TITLE, |
| 70 |
VIEW_EX_DIR, |
VIEW_EX_DIR, |
| 71 |
SHOW_TOP10, |
SHOW_TOP10, |
| 72 |
SEARCH_USER, |
SEARCH_USER, |
| 369 |
break; |
break; |
| 370 |
case '$': |
case '$': |
| 371 |
case KEY_END: |
case KEY_END: |
| 372 |
|
if (*p_page_id + 1 == total_page && *p_selected_index + 1 == item_count) // Press END at end of list |
| 373 |
|
{ |
| 374 |
|
return LAST_SECTION_ARTICLE; |
| 375 |
|
} |
| 376 |
if (total_page > 0) |
if (total_page > 0) |
| 377 |
{ |
{ |
| 378 |
*p_page_id = total_page - 1; |
*p_page_id = total_page - 1; |
| 433 |
return SCAN_ARTICLE_FORWARD_BY_USER; |
return SCAN_ARTICLE_FORWARD_BY_USER; |
| 434 |
} |
} |
| 435 |
break; |
break; |
| 436 |
|
case '?': |
| 437 |
|
if (item_count > 0) |
| 438 |
|
{ |
| 439 |
|
return SCAN_ARTICLE_BACKWARD_BY_TITLE; |
| 440 |
|
} |
| 441 |
|
break; |
| 442 |
|
case '/': |
| 443 |
|
if (item_count > 0) |
| 444 |
|
{ |
| 445 |
|
return SCAN_ARTICLE_FORWARD_BY_TITLE; |
| 446 |
|
} |
| 447 |
|
break; |
| 448 |
case 'u': |
case 'u': |
| 449 |
return SEARCH_USER; |
return SEARCH_USER; |
| 450 |
case 'h': |
case 'h': |
| 599 |
int page_id_cur; |
int page_id_cur; |
| 600 |
const ARTICLE *p_article_locate; |
const ARTICLE *p_article_locate; |
| 601 |
USER_INFO user_info; |
USER_INFO user_info; |
| 602 |
char user_intro[BBS_user_intro_max_len]; |
char user_intro[BBS_user_intro_max_len + 1]; |
| 603 |
char username[BBS_username_max_len + 1]; |
char username[BBS_username_max_len + 1]; |
| 604 |
char username_list[1][BBS_username_max_len + 1]; |
char username_list[1][BBS_username_max_len + 1]; |
| 605 |
int32_t uid; |
int32_t uid; |
| 606 |
int i; |
int i; |
| 607 |
int ok; |
int ok; |
| 608 |
|
char title[BBS_article_title_max_len + 1] = "\0"; |
| 609 |
|
|
| 610 |
p_section = section_list_find_by_name(sname); |
p_section = section_list_find_by_name(sname); |
| 611 |
if (p_section == NULL) |
if (p_section == NULL) |
| 715 |
// Update current aid location |
// Update current aid location |
| 716 |
if (p_articles[selected_index] != NULL) |
if (p_articles[selected_index] != NULL) |
| 717 |
{ |
{ |
| 718 |
section_aid_locations[section_index] = p_articles[selected_index]->aid; |
if (selected_index >= ontop_start_offset) |
| 719 |
} |
{ |
| 720 |
else |
ret = last_article_in_section(p_section, &p_article_locate); |
| 721 |
{ |
if (ret < 0) |
| 722 |
log_error("p_articles[selected_index=%d] is NULL when exit section [%s]\n", selected_index, sname); |
{ |
| 723 |
|
log_error("last_article_in_section(sid=%d) error\n", p_section->sid); |
| 724 |
|
return -3; |
| 725 |
|
} |
| 726 |
|
else if (ret == 0) |
| 727 |
|
{ |
| 728 |
|
section_aid_locations[section_index] = 0; |
| 729 |
|
} |
| 730 |
|
else // ret > 0 |
| 731 |
|
{ |
| 732 |
|
section_aid_locations[section_index] = p_article_locate->aid; |
| 733 |
|
} |
| 734 |
|
} |
| 735 |
|
else |
| 736 |
|
{ |
| 737 |
|
section_aid_locations[section_index] = (p_articles[selected_index]->visible ? p_articles[selected_index]->aid : 0); |
| 738 |
|
} |
| 739 |
} |
} |
| 740 |
return 0; |
return 0; |
| 741 |
case CHANGE_PAGE: |
case CHANGE_PAGE: |
| 881 |
{ |
{ |
| 882 |
log_error("article_reply(aid=%d) error\n", p_articles[selected_index]->aid); |
log_error("article_reply(aid=%d) error\n", p_articles[selected_index]->aid); |
| 883 |
} |
} |
| 884 |
|
else if (ret > 0) // Article replied |
| 885 |
|
{ |
| 886 |
|
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
| 887 |
|
if (ret < 0) |
| 888 |
|
{ |
| 889 |
|
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 890 |
|
return -3; |
| 891 |
|
} |
| 892 |
|
} |
| 893 |
loop = 1; |
loop = 1; |
| 894 |
break; |
break; |
| 895 |
case '=': // First topic article |
case '=': // First topic article |
| 953 |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
| 954 |
if (ret < 0) |
if (ret < 0) |
| 955 |
{ |
{ |
| 956 |
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
log_error("query_section_articles(sid=%d, page_id=%d) error: %d\n", p_section->sid, page_id, ret); |
| 957 |
return -3; |
return -3; |
| 958 |
} |
} |
| 959 |
} |
} |
| 979 |
{ |
{ |
| 980 |
log_error("article_modify(aid=%d) error\n", p_articles[selected_index]->aid); |
log_error("article_modify(aid=%d) error\n", p_articles[selected_index]->aid); |
| 981 |
} |
} |
| 982 |
|
else if (ret > 0) // Article modified |
| 983 |
|
{ |
| 984 |
|
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
| 985 |
|
if (ret < 0) |
| 986 |
|
{ |
| 987 |
|
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 988 |
|
return -3; |
| 989 |
|
} |
| 990 |
|
} |
| 991 |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 992 |
{ |
{ |
| 993 |
log_error("section_list_draw_screen() error\n"); |
log_error("section_list_draw_screen() error\n"); |
| 1006 |
} |
} |
| 1007 |
else if (ret > 0) // Article deleted |
else if (ret > 0) // Article deleted |
| 1008 |
{ |
{ |
| 1009 |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
do |
|
if (ret < 0) |
|
| 1010 |
{ |
{ |
| 1011 |
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
| 1012 |
return -3; |
if (ret >= 0 && selected_index > article_count - 1) |
| 1013 |
} |
{ |
| 1014 |
|
selected_index = article_count - 1; |
| 1015 |
|
break; |
| 1016 |
|
} |
| 1017 |
|
else if (ret < 0 && page_id > 0) |
| 1018 |
|
{ |
| 1019 |
|
page_id--; |
| 1020 |
|
selected_index = BBS_article_limit_per_page - 1; |
| 1021 |
|
} |
| 1022 |
|
else if (ret < 0 && page_id <= 0) |
| 1023 |
|
{ |
| 1024 |
|
selected_index = 0; |
| 1025 |
|
break; |
| 1026 |
|
} |
| 1027 |
|
} while (ret < 0); |
| 1028 |
} |
} |
| 1029 |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 1030 |
{ |
{ |
| 1110 |
} |
} |
| 1111 |
} |
} |
| 1112 |
break; |
break; |
| 1113 |
|
case LAST_SECTION_ARTICLE: |
| 1114 |
|
page_id_cur = page_id; |
| 1115 |
|
ret = last_article_in_section(p_section, &p_article_locate); |
| 1116 |
|
if (ret < 0) |
| 1117 |
|
{ |
| 1118 |
|
log_error("last_article_in_section(sid=%d) error\n", p_section->sid); |
| 1119 |
|
return -3; |
| 1120 |
|
} |
| 1121 |
|
else if (ret == 0) |
| 1122 |
|
{ |
| 1123 |
|
break; |
| 1124 |
|
} |
| 1125 |
|
ret = locate_article_in_section(p_section, p_article_locate, 0, 0, |
| 1126 |
|
&page_id, &selected_index, &article_count); |
| 1127 |
|
if (ret < 0) |
| 1128 |
|
{ |
| 1129 |
|
log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n", |
| 1130 |
|
p_section->sid, p_article_locate->aid); |
| 1131 |
|
return -3; |
| 1132 |
|
} |
| 1133 |
|
else if (ret > 0 && page_id != page_id_cur) // found and page changed |
| 1134 |
|
{ |
| 1135 |
|
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
| 1136 |
|
if (ret < 0) |
| 1137 |
|
{ |
| 1138 |
|
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 1139 |
|
return -3; |
| 1140 |
|
} |
| 1141 |
|
} |
| 1142 |
|
break; |
| 1143 |
case SCAN_NEW_ARTICLE: |
case SCAN_NEW_ARTICLE: |
| 1144 |
ret = scan_unread_article_in_section(p_section, p_articles[selected_index], &p_article_locate); |
ret = scan_unread_article_in_section(p_section, p_articles[selected_index], &p_article_locate); |
| 1145 |
if (ret < 0) |
if (ret < 0) |
| 1245 |
} |
} |
| 1246 |
|
|
| 1247 |
page_id_cur = page_id; |
page_id_cur = page_id; |
| 1248 |
|
ret = locate_article_in_section(p_section, p_article_locate, 0, 0, |
| 1249 |
|
&page_id, &selected_index, &article_count); |
| 1250 |
|
if (ret < 0) |
| 1251 |
|
{ |
| 1252 |
|
log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n", |
| 1253 |
|
p_section->sid, p_article_locate->aid); |
| 1254 |
|
return -3; |
| 1255 |
|
} |
| 1256 |
|
else if (ret > 0 && page_id != page_id_cur) // found and page changed |
| 1257 |
|
{ |
| 1258 |
|
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
| 1259 |
|
if (ret < 0) |
| 1260 |
|
{ |
| 1261 |
|
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 1262 |
|
return -3; |
| 1263 |
|
} |
| 1264 |
|
} |
| 1265 |
|
break; |
| 1266 |
|
case SCAN_ARTICLE_BACKWARD_BY_TITLE: |
| 1267 |
|
case SCAN_ARTICLE_FORWARD_BY_TITLE: |
| 1268 |
|
direction = (ret == SCAN_ARTICLE_FORWARD_BY_TITLE ? 1 : -1); |
| 1269 |
|
|
| 1270 |
|
moveto(SCREEN_ROWS, 1); |
| 1271 |
|
clrtoeol(); |
| 1272 |
|
get_data(SCREEN_ROWS, 1, |
| 1273 |
|
(direction == 1 ? "向下搜寻标题: " : "向上搜寻标题: "), |
| 1274 |
|
title, sizeof(title), TITLE_SEARCH_MAX_LEN); |
| 1275 |
|
|
| 1276 |
|
if (title[0] == '\0') |
| 1277 |
|
{ |
| 1278 |
|
break; |
| 1279 |
|
} |
| 1280 |
|
|
| 1281 |
|
ret = scan_article_in_section_by_title(p_section, p_articles[selected_index], |
| 1282 |
|
direction, title, &p_article_locate); |
| 1283 |
|
if (ret < 0) |
| 1284 |
|
{ |
| 1285 |
|
log_error("scan_article_in_section_by_title(sid=%d, aid=%d, direction=%d, title=%s) error\n", |
| 1286 |
|
p_section->sid, p_articles[selected_index]->aid, direction, title); |
| 1287 |
|
return -3; |
| 1288 |
|
} |
| 1289 |
|
else if (ret == 0) // not found |
| 1290 |
|
{ |
| 1291 |
|
break; |
| 1292 |
|
} |
| 1293 |
|
|
| 1294 |
|
page_id_cur = page_id; |
| 1295 |
ret = locate_article_in_section(p_section, p_article_locate, 0, 0, |
ret = locate_article_in_section(p_section, p_article_locate, 0, 0, |
| 1296 |
&page_id, &selected_index, &article_count); |
&page_id, &selected_index, &article_count); |
| 1297 |
if (ret < 0) |
if (ret < 0) |