/[LeafOK_CVS]/lbbs/src/section_list_display.c
ViewVC logotype

Diff of /lbbs/src/section_list_display.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.36 by sysadm, Mon Jun 23 13:14:15 2025 UTC Revision 1.56 by sysadm, Sat Oct 18 12:06:10 2025 UTC
# Line 15  Line 15 
15   ***************************************************************************/   ***************************************************************************/
16    
17  #include "article_cache.h"  #include "article_cache.h"
18    #include "article_favor.h"
19    #include "article_op.h"
20  #include "article_post.h"  #include "article_post.h"
21  #include "article_view_log.h"  #include "article_view_log.h"
22  #include "article_del.h"  #include "article_del.h"
# Line 22  Line 24 
24  #include "io.h"  #include "io.h"
25  #include "log.h"  #include "log.h"
26  #include "login.h"  #include "login.h"
27    #include "menu.h"
28    #include "menu_proc.h"
29  #include "section_list_display.h"  #include "section_list_display.h"
30  #include "section_list_loader.h"  #include "section_list_loader.h"
31  #include "screen.h"  #include "screen.h"
# Line 31  Line 35 
35  #include <time.h>  #include <time.h>
36  #include <sys/param.h>  #include <sys/param.h>
37    
38    static int section_aid_locations[BBS_max_section] = {0};
39  static int section_topic_view_mode = 0;  static int section_topic_view_mode = 0;
40  static int section_topic_view_tid = -1;  static int section_topic_view_tid = -1;
41    
42  enum select_cmd_t  enum select_cmd_t
43  {  {
44          EXIT_SECTION = 0,          EXIT_SECTION = 0,
45          VIEW_ARTICLE = 1,          VIEW_ARTICLE,
46          CHANGE_PAGE = 2,          CHANGE_PAGE,
47          SHOW_HELP = 3,          SHOW_HELP,
48          CHANGE_NAME_DISPLAY = 4,          CHANGE_NAME_DISPLAY,
49          POST_ARTICLE = 5,          POST_ARTICLE,
50          EDIT_ARTICLE = 6,          EDIT_ARTICLE,
51          DELETE_ARTICLE = 7,          DELETE_ARTICLE,
52          FIRST_TOPIC_ARTICLE = 8,          QUERY_ARTICLE,
53          LAST_TOPIC_ARTICLE = 9,          SET_FAVOR_ARTICLE,
54            UNSET_FAVOR_ARTICLE,
55            FIRST_TOPIC_ARTICLE,
56            LAST_TOPIC_ARTICLE,
57            SCAN_NEW_ARTICLE,
58            VIEW_EX_DIR,
59            SHOW_TOP10,
60  };  };
61    
62  static int section_list_draw_items(int page_id, ARTICLE *p_articles[], int article_count, int display_nickname, int ontop_start_offset)  static int section_list_draw_items(int page_id, ARTICLE *p_articles[], int article_count, int display_nickname, int ontop_start_offset)
# Line 57  static int section_list_draw_items(int p Line 68  static int section_list_draw_items(int p
68          int eol;          int eol;
69          int len;          int len;
70          int i;          int i;
71            size_t j;
72          char article_flag;          char article_flag;
73          int is_viewed;          int is_viewed;
74            int is_favor;
75          time_t tm_now;          time_t tm_now;
76    
77          time(&tm_now);          time(&tm_now);
# Line 81  static int section_list_draw_items(int p Line 94  static int section_list_draw_items(int p
94                          }                          }
95                  }                  }
96    
97                    if (p_articles[i]->tid == 0)
98                    {
99                            is_favor = article_favor_check(p_articles[i]->aid, &BBS_article_favor);
100                            if (is_favor < 0)
101                            {
102                                    log_error("article_favor_check(aid=%d) error\n", p_articles[i]->aid);
103                                    is_favor = 0;
104                            }
105                    }
106                    else
107                    {
108                            is_favor = 0;
109                    }
110    
111                  if (p_articles[i]->excerption)                  if (p_articles[i]->excerption)
112                  {                  {
113                          article_flag = (is_viewed ? 'm' : 'M');                          article_flag = (is_viewed ? 'm' : 'M');
# Line 104  static int section_list_draw_items(int p Line 131  static int section_list_draw_items(int p
131                          strftime(str_time, sizeof(str_time), "%m/%Y", &tm_sub);                          strftime(str_time, sizeof(str_time), "%m/%Y", &tm_sub);
132                  }                  }
133    
134                  strncpy(title_f, (p_articles[i]->tid == 0 ? " " : ""), sizeof(title_f) - 1);                  strncpy(title_f, (p_articles[i]->tid == 0 ? "● " : ""), sizeof(title_f) - 1);
135                  title_f[sizeof(title_f) - 1] = '\0';                  title_f[sizeof(title_f) - 1] = '\0';
136                  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)));
137                  strncat(title_f, p_articles[i]->title, sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));  
138                  len = split_line(title_f, 47 - (display_nickname ? 8 : 0), &eol, &title_f_len, 1);                  // Rewrite title with "Re: Re: " prefix into "Re: ... "
139                    j = 0;
140                    if (p_articles[i]->tid != 0)
141                    {
142                            while (strncmp(p_articles[i]->title + j, "Re: ", strlen("Re: ")) == 0)
143                            {
144                                    j += strlen("Re: ");
145                            }
146                            if (j >= strlen("Re: Re: "))
147                            {
148                                    strncat(title_f, "Re: ... ", sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
149                            }
150                            else
151                            {
152                                    j = 0;
153                            }
154                    }
155                    strncat(title_f, p_articles[i]->title + j, sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
156    
157                    len = split_line(title_f, 59 - (display_nickname ? BBS_nickname_max_len / 2 : BBS_username_max_len), &eol, &title_f_len, 1);
158                  if (title_f[len] != '\0')                  if (title_f[len] != '\0')
159                  {                  {
160                          title_f[len] = '\0';                          title_f[len] = '\0';
# Line 117  static int section_list_draw_items(int p Line 163  static int section_list_draw_items(int p
163                  moveto(4 + i, 1);                  moveto(4 + i, 1);
164                  if (i >= ontop_start_offset)                  if (i >= ontop_start_offset)
165                  {                  {
166                          prints("   \033[1;33m[ʾ]\033[m %c %s%*s %s %s%s\033[m",                          prints("   \033[1;33m[提示]\033[m%c%c %s%*s %s %s%s\033[m",
167                                       (is_favor ? '@' : ' '),
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
# Line 133  static int section_list_draw_items(int p Line 180  static int section_list_draw_items(int p
180                  }                  }
181                  else                  else
182                  {                  {
183                          prints("  %s%7d\033[m %c %s%*s %s %s%s\033[m",                          prints("  %s%7d\033[m%c%c %s%*s %s %s%s\033[m",
184                                     (p_articles[i]->aid == section_topic_view_tid                                     (p_articles[i]->aid == section_topic_view_tid
185                                                  ? "\033[1;33m"                                                  ? "\033[1;33m"
186                                                  : (p_articles[i]->tid == section_topic_view_tid                                                  : (p_articles[i]->tid == section_topic_view_tid
187                                                             ? "\033[1;36m"                                                             ? "\033[1;36m"
188                                                             : "")),                                                             : "")),
189                                     p_articles[i]->aid,                                     p_articles[i]->aid,
190                                       (is_favor ? '@' : ' '),
191                                     article_flag,                                     article_flag,
192                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
193                                     (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)
194                                                                           : 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)),
195                                     "",                                     "",
196                                     str_time,                                     str_time,
197                                     (p_articles[i]->aid == section_topic_view_tid                                     (p_articles[i]->aid == section_topic_view_tid
# Line 160  static int section_list_draw_items(int p Line 208  static int section_list_draw_items(int p
208    
209  static int section_list_draw_screen(const char *sname, const char *stitle, const char *master_list, int display_nickname)  static int section_list_draw_screen(const char *sname, const char *stitle, const char *master_list, int display_nickname)
210  {  {
211          char str_section_master[LINE_BUFFER_LEN] = "";          char str_section_master[LINE_BUFFER_LEN] = "诚征版主中";
212          char str_section_name[LINE_BUFFER_LEN];          char str_section_name[LINE_BUFFER_LEN];
213    
214          if (master_list[0] != '\0')          if (master_list[0] != '\0')
215          {          {
216                  snprintf(str_section_master, sizeof(str_section_master), "%s", master_list);                  snprintf(str_section_master, sizeof(str_section_master), "版主:%s", master_list);
217          }          }
218          snprintf(str_section_name, sizeof(str_section_name), " [%s]", sname);          snprintf(str_section_name, sizeof(str_section_name), "讨论区 [%s]", sname);
219    
220          clearscr();          clearscr();
221          show_top(str_section_master, stitle, str_section_name);          show_top(str_section_master, stitle, str_section_name);
222          moveto(2, 0);          moveto(2, 0);
223          prints("[\033[1;32m\033[0;37m,\033[1;32mESC\033[0;37m] ѡ[\033[1;32m\033[0;37m,\033[1;32m\033[0;37m] "          prints("返回[\033[1;32m←\033[0;37m,\033[1;32mESC\033[0;37m] 选择[\033[1;32m↑\033[0;37m,\033[1;32m↓\033[0;37m] "
224                     "Ķ[\033[1;32m\033[0;37m,\033[1;32mENTER\033[0;37m] [\033[1;32mCtrl-P\033[0;37m] "                     "阅读[\033[1;32m→\033[0;37m,\033[1;32mENTER\033[0;37m] 发表[\033[1;32mCtrl-P\033[0;37m] "
225                     "%s[\033[1;32mn\033[0;37m] [\033[1;32mh\033[0;37m]\033[m",                     "%s[\033[1;32mn\033[0;37m] 精华区[\033[1;32mx\033[0;37m] 帮助[\033[1;32mh\033[0;37m]\033[m",
226                     (display_nickname ? "ʾû" : "ʾdz"));                     (display_nickname ? "用户名" : "昵称"));
227          moveto(3, 0);          moveto(3, 0);
228          if (display_nickname)          if (display_nickname)
229          {          {
230                  prints("\033[44;37m  \033[1;37m     dz              ±                               \033[m");                  prints("\033[44;37m  \033[1;37m 编  号   发布者昵称           日  期  文章标题                               \033[m");
231          }          }
232          else          else
233          {          {
234                  prints("\033[44;37m  \033[1;37m            ±                                       \033[m");                  prints("\033[44;37m  \033[1;37m 编  号   发 布 者     日  期  文章标题                                       \033[m");
235          }          }
236    
237          return 0;          return 0;
# Line 207  static enum select_cmd_t section_list_se Line 255  static enum select_cmd_t section_list_se
255          {          {
256                  ch = igetch(100);                  ch = igetch(100);
257    
258                  switch (ch)                  if (ch != KEY_NULL && ch != KEY_TIMEOUT)
259                  {                  {
                 case KEY_ESC:  
                 case KEY_LEFT:  
260                          BBS_last_access_tm = time(NULL);                          BBS_last_access_tm = time(NULL);
261                    }
262    
263                    switch (ch)
264                    {
265                  case KEY_NULL:                   // broken pipe                  case KEY_NULL:                   // broken pipe
266                          return EXIT_SECTION; // exit section                          log_error("KEY_NULL\n");
267                            return EXIT_SECTION;
268                  case KEY_TIMEOUT:                  case KEY_TIMEOUT:
269                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
270                          {                          {
271                                  return EXIT_SECTION; // exit section                                  log_error("User input timeout\n");
272                                    return EXIT_SECTION;
273                          }                          }
274                          continue;                          continue;
275                    case KEY_ESC:
276                    case KEY_LEFT:
277                            return EXIT_SECTION;
278                  case 'n':                  case 'n':
                         BBS_last_access_tm = time(NULL);  
279                          return CHANGE_NAME_DISPLAY;                          return CHANGE_NAME_DISPLAY;
280                  case CR:                  case CR:
                         igetch_reset();  
281                  case 'r':                  case 'r':
282                  case KEY_RIGHT:                  case KEY_RIGHT:
283                          if (item_count > 0)                          if (item_count > 0)
284                          {                          {
                                 BBS_last_access_tm = time(NULL);  
285                                  return VIEW_ARTICLE;                                  return VIEW_ARTICLE;
286                          }                          }
287                          break;                          break;
288                  case Ctrl('P'):                  case Ctrl('P'):
289                          return POST_ARTICLE;                          return POST_ARTICLE;
290                  case 'E':                  case 'E':
291                          return EDIT_ARTICLE;                          if (item_count > 0)
292                            {
293                                    return EDIT_ARTICLE;
294                            }
295                            break;
296                  case 'd':                  case 'd':
297                          return DELETE_ARTICLE;                          if (item_count > 0)
298                            {
299                                    return DELETE_ARTICLE;
300                            }
301                            break;
302                    case Ctrl('Q'):
303                            if (item_count > 0)
304                            {
305                                    return QUERY_ARTICLE;
306                            }
307                            break;
308                    case 'F':
309                            if (item_count > 0)
310                            {
311                                    return SET_FAVOR_ARTICLE;
312                            }
313                            break;
314                    case '-':
315                            if (item_count > 0)
316                            {
317                                    return UNSET_FAVOR_ARTICLE;
318                            }
319                            break;
320                  case KEY_HOME:                  case KEY_HOME:
321                          *p_page_id = 0;                          *p_page_id = 0;
322                  case 'P':                  case 'P':
# Line 253  static enum select_cmd_t section_list_se Line 331  static enum select_cmd_t section_list_se
331                                          (*p_page_id)--;                                          (*p_page_id)--;
332                                          *p_selected_index = BBS_article_limit_per_page - 1;                                          *p_selected_index = BBS_article_limit_per_page - 1;
333                                  }                                  }
334                                    else if (ch == KEY_UP || ch == 'k') // Rotate to the tail of section list
335                                    {
336                                            if (total_page > 0)
337                                            {
338                                                    *p_page_id = total_page - 1;
339                                            }
340                                            if (item_count > 0)
341                                            {
342                                                    *p_selected_index = item_count - 1;
343                                            }
344                                    }
345                          }                          }
346                          else                          else
347                          {                          {
# Line 280  static enum select_cmd_t section_list_se Line 369  static enum select_cmd_t section_list_se
369                                          (*p_page_id)++;                                          (*p_page_id)++;
370                                          *p_selected_index = 0;                                          *p_selected_index = 0;
371                                  }                                  }
372                                  else // end of last page                                  else if (ch == KEY_DOWN || ch == 'j') // Rotate to the head of section list
373                                  {                                  {
374                                          return CHANGE_PAGE; // force refresh pages                                          *p_page_id = 0;
375                                            *p_selected_index = 0;
376                                  }                                  }
377                          }                          }
378                          else                          else
# Line 291  static enum select_cmd_t section_list_se Line 381  static enum select_cmd_t section_list_se
381                          }                          }
382                          break;                          break;
383                  case '=':                  case '=':
384                          return FIRST_TOPIC_ARTICLE;                          if (item_count > 0)
385                            {
386                                    return FIRST_TOPIC_ARTICLE;
387                            }
388                            break;
389                  case '\\':                  case '\\':
390                          return LAST_TOPIC_ARTICLE;                          if (item_count > 0)
391                            {
392                                    return LAST_TOPIC_ARTICLE;
393                            }
394                            break;
395                    case 'S':
396                            if (item_count > 0)
397                            {
398                                    return SCAN_NEW_ARTICLE;
399                            }
400                            break;
401                  case 'h':                  case 'h':
402                          return SHOW_HELP;                          return SHOW_HELP;
403                    case 'x':
404                            return VIEW_EX_DIR;
405                    case 'H':
406                            return SHOW_TOP10;
407                  default:                  default:
408                            break;
409                  }                  }
410    
411                  if (old_page_id != *p_page_id)                  if (old_page_id != *p_page_id)
# Line 321  static enum select_cmd_t section_list_se Line 430  static enum select_cmd_t section_list_se
430                          old_selected_index = *p_selected_index;                          old_selected_index = *p_selected_index;
431                  }                  }
432    
                 BBS_last_access_tm = time(NULL);  
433                  if (BBS_last_access_tm - last_refresh_tm >= BBS_section_list_load_interval)                  if (BBS_last_access_tm - last_refresh_tm >= BBS_section_list_load_interval)
434                  {                  {
435                          return CHANGE_PAGE; // force section list refresh                          return CHANGE_PAGE; // force section list refresh
# Line 342  static int display_article_key_handler(i Line 450  static int display_article_key_handler(i
450                  if (section_topic_view_mode)                  if (section_topic_view_mode)
451                  {                  {
452                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),
453                                           "| [\033[32m\033[33m,\033[32mESC\033[33m] "                                           "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] "
454                                           "ͬĶ[\033[32m\033[33m/\033[32m\033[33m] "                                           "同主题阅读[\033[32m↑\033[33m/\033[32m↓\033[33m] "
455                                           "л[\033[32mp\033[33m] ظ[\033[32mr\033[33m] [\033[32mh\033[33m] |");                                           "切换[\033[32mp\033[33m] 回复[\033[32mr\033[33m] 帮助[\033[32mh\033[33m] |");
456                  }                  }
457                  else                  else
458                  {                  {
459                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),
460                                           "| [\033[32m\033[33m,\033[32mESC\033[33m] "                                           "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] "
461                                           "ƶ[\033[32m\033[33m/\033[32m\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] "                                           "移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] "
462                                           "л[\033[32mp\033[33m] ظ[\033[32mr\033[33m] [\033[32mh\033[33m] |");                                           "切换[\033[32mp\033[33m] 回复[\033[32mr\033[33m] 帮助[\033[32mh\033[33m] |");
463                  }                  }
464                  *p_key = 0;                  *p_key = 0;
465                  break;                  break;
# Line 418  static int display_article_key_handler(i Line 526  static int display_article_key_handler(i
526          return 0;          return 0;
527  }  }
528    
529  int section_list_display(const char *sname)  int section_list_display(const char *sname, int32_t aid)
530  {  {
531          static int display_nickname = 0;          static int display_nickname = 0;
532    
533          SECTION_LIST *p_section;          SECTION_LIST *p_section;
534            int64_t section_index;
535            int32_t aid_location;
536          char stitle[BBS_section_title_max_len + 1];          char stitle[BBS_section_title_max_len + 1];
537          char master_list[(BBS_username_max_len + 1) * 3 + 1];          char master_list[(BBS_username_max_len + 1) * 3 + 1];
538          char page_info_str[LINE_BUFFER_LEN];          char page_info_str[LINE_BUFFER_LEN];
# Line 438  int section_list_display(const char *sna Line 548  int section_list_display(const char *sna
548          int direction;          int direction;
549          ARTICLE article_new;          ARTICLE article_new;
550          int page_id_cur;          int page_id_cur;
551            const ARTICLE *p_article_locate;
552    
553          p_section = section_list_find_by_name(sname);          p_section = section_list_find_by_name(sname);
554          if (p_section == NULL)          if (p_section == NULL)
# Line 446  int section_list_display(const char *sna Line 557  int section_list_display(const char *sna
557                  return -1;                  return -1;
558          }          }
559    
560            if (!checkpriv(&BBS_priv, p_section->sid, S_LIST))
561            {
562                    log_error("Forbid access to unauthorized section, sid=%d, uid=%d\n",
563                                      p_section->sid, BBS_priv.uid);
564                    return -1;
565            }
566    
567            section_index = get_section_index(p_section);
568    
569          if ((ret = section_list_rd_lock(p_section)) < 0)          if ((ret = section_list_rd_lock(p_section)) < 0)
570          {          {
571                  log_error("section_list_rd_lock(sid = 0) error\n");                  log_error("section_list_rd_lock(sid = 0) error\n");
# Line 463  int section_list_display(const char *sna Line 583  int section_list_display(const char *sna
583                  return -2;                  return -2;
584          }          }
585    
586            if (aid == 0)
587            {
588                    aid_location = section_aid_locations[section_index];
589            }
590            else
591            {
592                    aid_location = aid;
593            }
594    
595            // Locate at article with aid_locate
596            if (aid_location > 0)
597            {
598                    p_article_locate = article_block_find_by_aid(aid_location);
599                    if (p_article_locate == NULL)
600                    {
601                            log_error("article_block_find_by_aid(%d) error\n", aid_location);
602                            return -3;
603                    }
604    
605                    ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
606                                                                                    &page_id, &selected_index, &article_count);
607                    if (ret < 0)
608                    {
609                            log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
610                                              p_section->sid, p_article_locate->aid);
611                            return -3;
612                    }
613            }
614    
615          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
616          {          {
617                  log_error("section_list_draw_screen() error\n");                  log_error("section_list_draw_screen() error\n");
# Line 476  int section_list_display(const char *sna Line 625  int section_list_display(const char *sna
625                  return -3;                  return -3;
626          }          }
627    
628            section_topic_view_tid = -1;
629    
630          if (article_count == 0) // empty section          if (article_count == 0) // empty section
631          {          {
632                  selected_index = 0;                  selected_index = 0;
633          }          }
634            else if (aid > 0)
635            {
636                    // Update current topic
637                    section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
638    
639                    // Update current aid location
640                    section_aid_locations[section_index] = p_articles[selected_index]->aid;
641            }
642    
643          while (!SYS_server_exit)          while (!SYS_server_exit)
644          {          {
# Line 491  int section_list_display(const char *sna Line 650  int section_list_display(const char *sna
650                  }                  }
651    
652                  snprintf(page_info_str, sizeof(page_info_str),                  snprintf(page_info_str, sizeof(page_info_str),
653                                   "\033[33m[\033[36m%d\033[33m/\033[36m%d\033[33mҳ]",                                   "\033[33m[第\033[36m%d\033[33m/\033[36m%d\033[33m页]",
654                                   page_id + 1, MAX(page_count, 1));                                   page_id + 1, MAX(page_count, 1));
655    
656                  show_bottom(page_info_str);                  show_bottom(page_info_str);
# Line 684  int section_list_display(const char *sna Line 843  int section_list_display(const char *sna
843                          // Update current topic                          // Update current topic
844                          section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);                          section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
845    
846                            // Update current aid location
847                            section_aid_locations[section_index] = p_articles[selected_index]->aid;
848    
849                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
850                          {                          {
851                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
# Line 770  int section_list_display(const char *sna Line 932  int section_list_display(const char *sna
932                                  return -2;                                  return -2;
933                          }                          }
934                          break;                          break;
935                    case QUERY_ARTICLE:
936                            if ((ret = display_article_meta(p_articles[selected_index]->aid)) < 0)
937                            {
938                                    log_error("display_article_meta(aid=%d) error\n", p_articles[selected_index]->aid);
939                            }
940                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
941                            {
942                                    log_error("section_list_draw_screen() error\n");
943                                    return -2;
944                            }
945                            break;
946                    case SET_FAVOR_ARTICLE:
947                            ret = article_favor_set(p_articles[selected_index]->tid == 0
948                                                                                    ? p_articles[selected_index]->aid
949                                                                                    : p_articles[selected_index]->tid,
950                                                                            &BBS_article_favor, 1);
951                            if (ret < 0)
952                            {
953                                    log_error("article_favor_set(aid=%d, 1) error\n",
954                                                      p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
955                            }
956                            break;
957                    case UNSET_FAVOR_ARTICLE:
958                            ret = article_favor_set(p_articles[selected_index]->tid == 0
959                                                                                    ? p_articles[selected_index]->aid
960                                                                                    : p_articles[selected_index]->tid,
961                                                                            &BBS_article_favor, 0);
962                            if (ret < 0)
963                            {
964                                    log_error("article_favor_set(aid=%d, 0) error\n",
965                                                      p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
966                            }
967                            break;
968                  case FIRST_TOPIC_ARTICLE:                  case FIRST_TOPIC_ARTICLE:
969                  case LAST_TOPIC_ARTICLE:                  case LAST_TOPIC_ARTICLE:
970                          page_id_cur = page_id;                          page_id_cur = page_id;
# Line 792  int section_list_display(const char *sna Line 987  int section_list_display(const char *sna
987                                  }                                  }
988                          }                          }
989                          break;                          break;
990                    case SCAN_NEW_ARTICLE:
991                            ret = scan_unread_article_in_section(p_section, p_articles[selected_index], &p_article_locate);
992                            if (ret < 0)
993                            {
994                                    log_error("scan_unread_article_in_section(sid=%d, aid=%d) error\n",
995                                                      p_section->sid, p_articles[selected_index]->aid);
996                                    return -3;
997                            }
998                            else if (ret == 0) // not found
999                            {
1000                                    break;
1001                            }
1002                            page_id_cur = page_id;
1003                            ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
1004                                                                                            &page_id, &selected_index, &article_count);
1005                            if (ret < 0)
1006                            {
1007                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
1008                                                      p_section->sid, p_article_locate->aid);
1009                                    return -3;
1010                            }
1011                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
1012                            {
1013                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
1014                                    if (ret < 0)
1015                                    {
1016                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
1017                                            return -3;
1018                                    }
1019                            }
1020                            break;
1021                  case SHOW_HELP:                  case SHOW_HELP:
1022                          // Display help information                          // Display help information
1023                          display_file(DATA_READ_HELP, 1);                          display_file(DATA_READ_HELP, 1);
# Line 801  int section_list_display(const char *sna Line 1027  int section_list_display(const char *sna
1027                                  return -2;                                  return -2;
1028                          }                          }
1029                          break;                          break;
1030                    case VIEW_EX_DIR:
1031                            if (section_list_ex_dir_display(p_section) < 0)
1032                            {
1033                                    log_error("section_list_ex_dir_display(sid=%d) error\n", p_section->sid);
1034                            }
1035                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
1036                            {
1037                                    log_error("section_list_draw_screen() error\n");
1038                                    return -2;
1039                            }
1040                            break;
1041                    case SHOW_TOP10:
1042                            show_top10_menu(NULL);
1043                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
1044                            {
1045                                    log_error("section_list_draw_screen() error\n");
1046                                    return -2;
1047                            }
1048                            break;
1049                  default:                  default:
1050                          log_error("Unknown command %d\n", ret);                          log_error("Unknown command %d\n", ret);
1051                  }                  }
# Line 808  int section_list_display(const char *sna Line 1053  int section_list_display(const char *sna
1053    
1054          return 0;          return 0;
1055  }  }
1056    
1057    int section_list_ex_dir_display(SECTION_LIST *p_section)
1058    {
1059            MENU_SET ex_menu_set;
1060            int ch = 0;
1061    
1062            if (p_section == NULL)
1063            {
1064                    log_error("NULL pointer error\n");
1065                    return -1;
1066            }
1067    
1068            if (p_section->ex_menu_tm == 0) // N/A
1069            {
1070                    moveto(2, 1);
1071                    clrtoeol();
1072                    prints("该版块精华区未开放");
1073                    press_any_key();
1074                    return 0;
1075            }
1076    
1077            if (get_section_ex_menu_set(p_section, &ex_menu_set) < 0)
1078            {
1079                    log_error("get_section_ex_menu_set(sid=%d) error\n", p_section->sid);
1080                    return -3;
1081            }
1082            if (get_menu_shm_readonly(&ex_menu_set) < 0)
1083            {
1084                    log_error("get_menu_shm_readonly(sid=%d) error\n", p_section->sid);
1085                    return -3;
1086            }
1087    
1088            clearscr();
1089            show_bottom("");
1090    
1091            if (display_menu(&ex_menu_set) == 0)
1092            {
1093                    while (!SYS_server_exit)
1094                    {
1095                            iflush();
1096                            ch = igetch(100);
1097    
1098                            if (ch != KEY_NULL && ch != KEY_TIMEOUT)
1099                            {
1100                                    BBS_last_access_tm = time(NULL);
1101                            }
1102    
1103                            switch (ch)
1104                            {
1105                            case KEY_NULL: // broken pipe
1106                                    log_error("KEY_NULL\n");
1107                                    return 0;
1108                            case KEY_TIMEOUT:
1109                                    if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
1110                                    {
1111                                            log_error("User input timeout\n");
1112                                            return 0;
1113                                    }
1114                                    continue;
1115                            case CR:
1116                            default:
1117                                    switch (menu_control(&ex_menu_set, ch))
1118                                    {
1119                                    case EXITMENU:
1120                                            ch = EXITMENU;
1121                                            break;
1122                                    case REDRAW:
1123                                            clearscr();
1124                                            show_bottom("");
1125                                            display_menu(&ex_menu_set);
1126                                            break;
1127                                    case NOREDRAW:
1128                                    case UNKNOWN_CMD:
1129                                    default:
1130                                            break;
1131                                    }
1132                            }
1133    
1134                            if (ch == EXITMENU)
1135                            {
1136                                    break;
1137                            }
1138                    }
1139            }
1140    
1141            detach_menu_shm(&ex_menu_set);
1142    
1143            return 0;
1144    }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1