| 49 |
QUERY_ARTICLE, |
QUERY_ARTICLE, |
| 50 |
FIRST_TOPIC_ARTICLE, |
FIRST_TOPIC_ARTICLE, |
| 51 |
LAST_TOPIC_ARTICLE, |
LAST_TOPIC_ARTICLE, |
| 52 |
|
SCAN_NEW_ARTICLE, |
| 53 |
VIEW_EX_DIR, |
VIEW_EX_DIR, |
| 54 |
}; |
}; |
| 55 |
|
|
| 62 |
int eol; |
int eol; |
| 63 |
int len; |
int len; |
| 64 |
int i; |
int i; |
| 65 |
|
size_t j; |
| 66 |
char article_flag; |
char article_flag; |
| 67 |
int is_viewed; |
int is_viewed; |
| 68 |
time_t tm_now; |
time_t tm_now; |
| 113 |
strncpy(title_f, (p_articles[i]->tid == 0 ? "● " : ""), sizeof(title_f) - 1); |
strncpy(title_f, (p_articles[i]->tid == 0 ? "● " : ""), sizeof(title_f) - 1); |
| 114 |
title_f[sizeof(title_f) - 1] = '\0'; |
title_f[sizeof(title_f) - 1] = '\0'; |
| 115 |
strncat(title_f, (p_articles[i]->transship ? "[转载]" : ""), sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f))); |
strncat(title_f, (p_articles[i]->transship ? "[转载]" : ""), sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f))); |
| 116 |
strncat(title_f, p_articles[i]->title, sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f))); |
|
| 117 |
|
// Rewrite title with "Re: Re: " prefix into "Re: ... " |
| 118 |
|
j = 0; |
| 119 |
|
if (p_articles[i]->tid != 0) |
| 120 |
|
{ |
| 121 |
|
while (strncmp(p_articles[i]->title + j, "Re: ", strlen("Re: ")) == 0) |
| 122 |
|
{ |
| 123 |
|
j += strlen("Re: "); |
| 124 |
|
} |
| 125 |
|
if (j >= strlen("Re: Re: ")) |
| 126 |
|
{ |
| 127 |
|
strncat(title_f, "Re: ... ", sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f))); |
| 128 |
|
} |
| 129 |
|
else |
| 130 |
|
{ |
| 131 |
|
j = 0; |
| 132 |
|
} |
| 133 |
|
} |
| 134 |
|
strncat(title_f, p_articles[i]->title + j, sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f))); |
| 135 |
|
|
| 136 |
len = split_line(title_f, 47 - (display_nickname ? 8 : 0), &eol, &title_f_len, 1); |
len = split_line(title_f, 47 - (display_nickname ? 8 : 0), &eol, &title_f_len, 1); |
| 137 |
if (title_f[len] != '\0') |
if (title_f[len] != '\0') |
| 138 |
{ |
{ |
| 145 |
prints(" \033[1;33m[提示]\033[m %c %s%*s %s %s%s\033[m", |
prints(" \033[1;33m[提示]\033[m %c %s%*s %s %s%s\033[m", |
| 146 |
article_flag, |
article_flag, |
| 147 |
(display_nickname ? p_articles[i]->nickname : p_articles[i]->username), |
(display_nickname ? p_articles[i]->nickname : p_articles[i]->username), |
| 148 |
(display_nickname ? BBS_nickname_max_len - (int)strnlen(p_articles[i]->nickname, sizeof(p_articles[i]->nickname)) |
(display_nickname ? BBS_nickname_max_len / 2 - str_length(p_articles[i]->nickname, 1) |
| 149 |
: BBS_username_max_len - (int)strnlen(p_articles[i]->username, sizeof(p_articles[i]->username))), |
: BBS_username_max_len - str_length(p_articles[i]->username, 1)), |
| 150 |
"", |
"", |
| 151 |
str_time, |
str_time, |
| 152 |
(p_articles[i]->aid == section_topic_view_tid |
(p_articles[i]->aid == section_topic_view_tid |
| 167 |
p_articles[i]->aid, |
p_articles[i]->aid, |
| 168 |
article_flag, |
article_flag, |
| 169 |
(display_nickname ? p_articles[i]->nickname : p_articles[i]->username), |
(display_nickname ? p_articles[i]->nickname : p_articles[i]->username), |
| 170 |
(display_nickname ? BBS_nickname_max_len - (int)strnlen(p_articles[i]->nickname, sizeof(p_articles[i]->nickname)) |
(display_nickname ? BBS_nickname_max_len / 2 - str_length(p_articles[i]->nickname, 1) |
| 171 |
: BBS_username_max_len - (int)strnlen(p_articles[i]->username, sizeof(p_articles[i]->username))), |
: BBS_username_max_len - str_length(p_articles[i]->username, 1)), |
| 172 |
"", |
"", |
| 173 |
str_time, |
str_time, |
| 174 |
(p_articles[i]->aid == section_topic_view_tid |
(p_articles[i]->aid == section_topic_view_tid |
| 292 |
(*p_page_id)--; |
(*p_page_id)--; |
| 293 |
*p_selected_index = BBS_article_limit_per_page - 1; |
*p_selected_index = BBS_article_limit_per_page - 1; |
| 294 |
} |
} |
| 295 |
|
else if (ch == KEY_UP || ch == 'k') // Rotate to the tail of section list |
| 296 |
|
{ |
| 297 |
|
if (total_page > 0) |
| 298 |
|
{ |
| 299 |
|
*p_page_id = total_page - 1; |
| 300 |
|
} |
| 301 |
|
if (item_count > 0) |
| 302 |
|
{ |
| 303 |
|
*p_selected_index = item_count - 1; |
| 304 |
|
} |
| 305 |
|
} |
| 306 |
} |
} |
| 307 |
else |
else |
| 308 |
{ |
{ |
| 330 |
(*p_page_id)++; |
(*p_page_id)++; |
| 331 |
*p_selected_index = 0; |
*p_selected_index = 0; |
| 332 |
} |
} |
| 333 |
else // end of last page |
else if (ch == KEY_DOWN || ch == 'j') // Rotate to the head of section list |
| 334 |
{ |
{ |
| 335 |
return CHANGE_PAGE; // force refresh pages |
*p_page_id = 0; |
| 336 |
|
*p_selected_index = 0; |
| 337 |
} |
} |
| 338 |
} |
} |
| 339 |
else |
else |
| 353 |
return LAST_TOPIC_ARTICLE; |
return LAST_TOPIC_ARTICLE; |
| 354 |
} |
} |
| 355 |
break; |
break; |
| 356 |
|
case 'S': |
| 357 |
|
if (item_count > 0) |
| 358 |
|
{ |
| 359 |
|
return SCAN_NEW_ARTICLE; |
| 360 |
|
} |
| 361 |
|
break; |
| 362 |
case 'h': |
case 'h': |
| 363 |
return SHOW_HELP; |
return SHOW_HELP; |
| 364 |
case 'x': |
case 'x': |
| 505 |
int direction; |
int direction; |
| 506 |
ARTICLE article_new; |
ARTICLE article_new; |
| 507 |
int page_id_cur; |
int page_id_cur; |
| 508 |
|
const ARTICLE *p_article_unread; |
| 509 |
|
|
| 510 |
p_section = section_list_find_by_name(sname); |
p_section = section_list_find_by_name(sname); |
| 511 |
if (p_section == NULL) |
if (p_section == NULL) |
| 862 |
return -3; |
return -3; |
| 863 |
} |
} |
| 864 |
else if (ret > 0 && page_id != page_id_cur) // found and page changed |
else if (ret > 0 && page_id != page_id_cur) // found and page changed |
| 865 |
|
{ |
| 866 |
|
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
| 867 |
|
if (ret < 0) |
| 868 |
|
{ |
| 869 |
|
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 870 |
|
return -3; |
| 871 |
|
} |
| 872 |
|
} |
| 873 |
|
break; |
| 874 |
|
case SCAN_NEW_ARTICLE: |
| 875 |
|
ret = scan_unread_article_in_section(p_section, p_articles[selected_index], &p_article_unread); |
| 876 |
|
if (ret < 0) |
| 877 |
|
{ |
| 878 |
|
log_error("scan_unread_article_in_section(sid=%d, aid=%d) error\n", |
| 879 |
|
p_section->sid, p_articles[selected_index]->aid); |
| 880 |
|
return -3; |
| 881 |
|
} |
| 882 |
|
else if (ret == 0) // not found |
| 883 |
|
{ |
| 884 |
|
break; |
| 885 |
|
} |
| 886 |
|
page_id_cur = page_id; |
| 887 |
|
ret = locate_article_in_section(p_section, p_article_unread, 0, 0, |
| 888 |
|
&page_id, &selected_index, &article_count); |
| 889 |
|
if (ret < 0) |
| 890 |
|
{ |
| 891 |
|
log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n", |
| 892 |
|
p_section->sid, p_article_unread->aid); |
| 893 |
|
return -3; |
| 894 |
|
} |
| 895 |
|
else if (ret > 0 && page_id != page_id_cur) // found and page changed |
| 896 |
{ |
{ |
| 897 |
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); |
| 898 |
if (ret < 0) |
if (ret < 0) |