/[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.35 by sysadm, Mon Jun 23 08:38:01 2025 UTC Revision 1.47 by sysadm, Mon Oct 13 02:36:35 2025 UTC
# Line 15  Line 15 
15   ***************************************************************************/   ***************************************************************************/
16    
17  #include "article_cache.h"  #include "article_cache.h"
18    #include "article_op.h"
19  #include "article_post.h"  #include "article_post.h"
20  #include "article_view_log.h"  #include "article_view_log.h"
21  #include "article_del.h"  #include "article_del.h"
# Line 22  Line 23 
23  #include "io.h"  #include "io.h"
24  #include "log.h"  #include "log.h"
25  #include "login.h"  #include "login.h"
26    #include "menu.h"
27  #include "section_list_display.h"  #include "section_list_display.h"
28  #include "section_list_loader.h"  #include "section_list_loader.h"
29  #include "screen.h"  #include "screen.h"
# Line 31  Line 33 
33  #include <time.h>  #include <time.h>
34  #include <sys/param.h>  #include <sys/param.h>
35    
36    static int section_aid_locations[BBS_max_section] = {0};
37  static int section_topic_view_mode = 0;  static int section_topic_view_mode = 0;
38  static int section_topic_view_tid = -1;  static int section_topic_view_tid = -1;
39    
40  enum select_cmd_t  enum select_cmd_t
41  {  {
42          EXIT_SECTION = 0,          EXIT_SECTION = 0,
43          VIEW_ARTICLE = 1,          VIEW_ARTICLE,
44          CHANGE_PAGE = 2,          CHANGE_PAGE,
45          SHOW_HELP = 3,          SHOW_HELP,
46          CHANGE_NAME_DISPLAY = 4,          CHANGE_NAME_DISPLAY,
47          POST_ARTICLE = 5,          POST_ARTICLE,
48          EDIT_ARTICLE = 6,          EDIT_ARTICLE,
49          DELETE_ARTICLE = 7,          DELETE_ARTICLE,
50          FIRST_TOPIC_ARTICLE = 8,          QUERY_ARTICLE,
51          LAST_TOPIC_ARTICLE = 9,          FIRST_TOPIC_ARTICLE,
52            LAST_TOPIC_ARTICLE,
53            SCAN_NEW_ARTICLE,
54            VIEW_EX_DIR,
55  };  };
56    
57  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, int ontop_start_offset)
58  {  {
59          char str_time[LINE_BUFFER_LEN];          char str_time[LINE_BUFFER_LEN];
60          struct tm tm_sub;          struct tm tm_sub;
# Line 57  static int section_list_draw_items(int p Line 63  static int section_list_draw_items(int p
63          int eol;          int eol;
64          int len;          int len;
65          int i;          int i;
66            size_t j;
67          char article_flag;          char article_flag;
68          int is_viewed;          int is_viewed;
69          time_t tm_now;          time_t tm_now;
# Line 104  static int section_list_draw_items(int p Line 111  static int section_list_draw_items(int p
111                          strftime(str_time, sizeof(str_time), "%m/%Y", &tm_sub);                          strftime(str_time, sizeof(str_time), "%m/%Y", &tm_sub);
112                  }                  }
113    
114                  strncpy(title_f, (p_articles[i]->tid == 0 ? " " : ""), sizeof(title_f) - 1);                  strncpy(title_f, (p_articles[i]->tid == 0 ? "● " : ""), sizeof(title_f) - 1);
115                  title_f[sizeof(title_f) - 1] = '\0';                  title_f[sizeof(title_f) - 1] = '\0';
116                  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)));
117                  strncat(title_f, p_articles[i]->title, sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));  
118                    // Rewrite title with "Re: Re: " prefix into "Re: ... "
119                    j = 0;
120                    if (p_articles[i]->tid != 0)
121                    {
122                            while (strncmp(p_articles[i]->title + j, "Re: ", strlen("Re: ")) == 0)
123                            {
124                                    j += strlen("Re: ");
125                            }
126                            if (j >= strlen("Re: Re: "))
127                            {
128                                    strncat(title_f, "Re: ... ", sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
129                            }
130                            else
131                            {
132                                    j = 0;
133                            }
134                    }
135                    strncat(title_f, p_articles[i]->title + j, sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
136    
137                  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);
138                  if (title_f[len] != '\0')                  if (title_f[len] != '\0')
139                  {                  {
# Line 115  static int section_list_draw_items(int p Line 141  static int section_list_draw_items(int p
141                  }                  }
142    
143                  moveto(4 + i, 1);                  moveto(4 + i, 1);
144                  prints("  %s%7d\033[m %c %s%*s %s %s%s\033[m",                  if (i >= ontop_start_offset)
145                             (p_articles[i]->ontop                  {
146                                          ? "\033[47;30m"                          prints("   \033[1;33m[提示]\033[m %c %s%*s %s %s%s\033[m",
147                                          : (p_articles[i]->aid == section_topic_view_tid                                     article_flag,
148                                                     ? "\033[1;33m"                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
149                                                     : (p_articles[i]->tid == section_topic_view_tid                                     (display_nickname ? BBS_nickname_max_len / 2 - str_length(p_articles[i]->nickname, 1)
150                                                                    ? "\033[1;36m"                                                                           : BBS_username_max_len - str_length(p_articles[i]->username, 1)),
151                                                                    : ""))),                                     "",
152                             p_articles[i]->aid,                                     str_time,
153                             article_flag,                                     (p_articles[i]->aid == section_topic_view_tid
154                             (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),                                                  ? "\033[1;33m"
155                             (display_nickname ? BBS_nickname_max_len - (int)strnlen(p_articles[i]->nickname, sizeof(p_articles[i]->nickname))                                                  : (p_articles[i]->tid == section_topic_view_tid
156                                                                   : BBS_username_max_len - (int)strnlen(p_articles[i]->username, sizeof(p_articles[i]->username))),                                                             ? "\033[1;36m"
157                             "",                                                             : "")),
158                             str_time,                                     title_f);
159                             (p_articles[i]->aid == section_topic_view_tid                  }
160                                          ? "\033[1;33m"                  else
161                                          : (p_articles[i]->tid == section_topic_view_tid                  {
162                                                     ? "\033[1;36m"                          prints("  %s%7d\033[m %c %s%*s %s %s%s\033[m",
163                                                     : "")),                                     (p_articles[i]->aid == section_topic_view_tid
164                             title_f);                                                  ? "\033[1;33m"
165                                                    : (p_articles[i]->tid == section_topic_view_tid
166                                                               ? "\033[1;36m"
167                                                               : "")),
168                                       p_articles[i]->aid,
169                                       article_flag,
170                                       (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
171                                       (display_nickname ? BBS_nickname_max_len / 2 - str_length(p_articles[i]->nickname, 1)
172                                                                             : BBS_username_max_len - str_length(p_articles[i]->username, 1)),
173                                       "",
174                                       str_time,
175                                       (p_articles[i]->aid == section_topic_view_tid
176                                                    ? "\033[1;33m"
177                                                    : (p_articles[i]->tid == section_topic_view_tid
178                                                               ? "\033[1;36m"
179                                                               : "")),
180                                       title_f);
181                    }
182          }          }
183    
184          return 0;          return 0;
# Line 143  static int section_list_draw_items(int p Line 186  static int section_list_draw_items(int p
186    
187  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)
188  {  {
189          char str_section_master[LINE_BUFFER_LEN] = "";          char str_section_master[LINE_BUFFER_LEN] = "诚征版主中";
190          char str_section_name[LINE_BUFFER_LEN];          char str_section_name[LINE_BUFFER_LEN];
191    
192          if (master_list[0] != '\0')          if (master_list[0] != '\0')
193          {          {
194                  snprintf(str_section_master, sizeof(str_section_master), "%s", master_list);                  snprintf(str_section_master, sizeof(str_section_master), "版主:%s", master_list);
195          }          }
196          snprintf(str_section_name, sizeof(str_section_name), " [%s]", sname);          snprintf(str_section_name, sizeof(str_section_name), "讨论区 [%s]", sname);
197    
198          clearscr();          clearscr();
199          show_top(str_section_master, stitle, str_section_name);          show_top(str_section_master, stitle, str_section_name);
200          moveto(2, 0);          moveto(2, 0);
201          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] "
202                     "Ķ[\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] "
203                     "%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",
204                     (display_nickname ? "ʾû" : "ʾdz"));                     (display_nickname ? "用户名" : "昵称"));
205          moveto(3, 0);          moveto(3, 0);
206          if (display_nickname)          if (display_nickname)
207          {          {
208                  prints("\033[44;37m  \033[1;37m     dz              ±                               \033[m");                  prints("\033[44;37m  \033[1;37m 编  号   发布者昵称           日  期  文章标题                               \033[m");
209          }          }
210          else          else
211          {          {
212                  prints("\033[44;37m  \033[1;37m            ±                                       \033[m");                  prints("\033[44;37m  \033[1;37m 编  号   发 布 者     日  期  文章标题                                       \033[m");
213          }          }
214    
215          return 0;          return 0;
# Line 219  static enum select_cmd_t section_list_se Line 262  static enum select_cmd_t section_list_se
262                  case Ctrl('P'):                  case Ctrl('P'):
263                          return POST_ARTICLE;                          return POST_ARTICLE;
264                  case 'E':                  case 'E':
265                          return EDIT_ARTICLE;                          if (item_count > 0)
266                            {
267                                    return EDIT_ARTICLE;
268                            }
269                            break;
270                  case 'd':                  case 'd':
271                          return DELETE_ARTICLE;                          if (item_count > 0)
272                            {
273                                    return DELETE_ARTICLE;
274                            }
275                            break;
276                    case Ctrl('Q'):
277                            if (item_count > 0)
278                            {
279                                    return QUERY_ARTICLE;
280                            }
281                            break;
282                  case KEY_HOME:                  case KEY_HOME:
283                          *p_page_id = 0;                          *p_page_id = 0;
284                  case 'P':                  case 'P':
# Line 236  static enum select_cmd_t section_list_se Line 293  static enum select_cmd_t section_list_se
293                                          (*p_page_id)--;                                          (*p_page_id)--;
294                                          *p_selected_index = BBS_article_limit_per_page - 1;                                          *p_selected_index = BBS_article_limit_per_page - 1;
295                                  }                                  }
296                                    else if (ch == KEY_UP || ch == 'k') // Rotate to the tail of section list
297                                    {
298                                            if (total_page > 0)
299                                            {
300                                                    *p_page_id = total_page - 1;
301                                            }
302                                            if (item_count > 0)
303                                            {
304                                                    *p_selected_index = item_count - 1;
305                                            }
306                                    }
307                          }                          }
308                          else                          else
309                          {                          {
# Line 263  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 = 0;                                          *p_selected_index = 0;
333                                  }                                  }
334                                  else // end of last page                                  else if (ch == KEY_DOWN || ch == 'j') // Rotate to the head of section list
335                                  {                                  {
336                                          return CHANGE_PAGE; // force refresh pages                                          *p_page_id = 0;
337                                            *p_selected_index = 0;
338                                  }                                  }
339                          }                          }
340                          else                          else
# Line 274  static enum select_cmd_t section_list_se Line 343  static enum select_cmd_t section_list_se
343                          }                          }
344                          break;                          break;
345                  case '=':                  case '=':
346                          return FIRST_TOPIC_ARTICLE;                          if (item_count > 0)
347                            {
348                                    return FIRST_TOPIC_ARTICLE;
349                            }
350                            break;
351                  case '\\':                  case '\\':
352                          return LAST_TOPIC_ARTICLE;                          if (item_count > 0)
353                            {
354                                    return LAST_TOPIC_ARTICLE;
355                            }
356                            break;
357                    case 'S':
358                            if (item_count > 0)
359                            {
360                                    return SCAN_NEW_ARTICLE;
361                            }
362                            break;
363                  case 'h':                  case 'h':
364                          return SHOW_HELP;                          return SHOW_HELP;
365                    case 'x':
366                            return VIEW_EX_DIR;
367                  default:                  default:
368                  }                  }
369    
# Line 325  static int display_article_key_handler(i Line 410  static int display_article_key_handler(i
410                  if (section_topic_view_mode)                  if (section_topic_view_mode)
411                  {                  {
412                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),
413                                           "| [\033[32m\033[33m,\033[32mESC\033[33m] "                                           "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] "
414                                           "ͬĶ[\033[32m\033[33m/\033[32m\033[33m] "                                           "同主题阅读[\033[32m↑\033[33m/\033[32m↓\033[33m] "
415                                           "л[\033[32mp\033[33m] ظ[\033[32mr\033[33m] [\033[32mh\033[33m] |");                                           "切换[\033[32mp\033[33m] 回复[\033[32mr\033[33m] 帮助[\033[32mh\033[33m] |");
416                  }                  }
417                  else                  else
418                  {                  {
419                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),
420                                           "| [\033[32m\033[33m,\033[32mESC\033[33m] "                                           "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] "
421                                           "ƶ[\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] "
422                                           "л[\033[32mp\033[33m] ظ[\033[32mr\033[33m] [\033[32mh\033[33m] |");                                           "切换[\033[32mp\033[33m] 回复[\033[32mr\033[33m] 帮助[\033[32mh\033[33m] |");
423                  }                  }
424                  *p_key = 0;                  *p_key = 0;
425                  break;                  break;
# Line 401  static int display_article_key_handler(i Line 486  static int display_article_key_handler(i
486          return 0;          return 0;
487  }  }
488    
489  int section_list_display(const char *sname)  int section_list_display(const char *sname, int32_t aid)
490  {  {
491          static int display_nickname = 0;          static int display_nickname = 0;
492    
493          SECTION_LIST *p_section;          SECTION_LIST *p_section;
494            int64_t section_index;
495            int32_t aid_location;
496          char stitle[BBS_section_title_max_len + 1];          char stitle[BBS_section_title_max_len + 1];
497          char master_list[(BBS_username_max_len + 1) * 3 + 1];          char master_list[(BBS_username_max_len + 1) * 3 + 1];
498          char page_info_str[LINE_BUFFER_LEN];          char page_info_str[LINE_BUFFER_LEN];
499          ARTICLE *p_articles[BBS_article_limit_per_page];          ARTICLE *p_articles[BBS_article_limit_per_page];
500          int article_count;          int article_count;
501          int page_count;          int page_count;
502            int ontop_start_offset;
503          int page_id = 0;          int page_id = 0;
504          int selected_index = 0;          int selected_index = 0;
505          ARTICLE_CACHE cache;          ARTICLE_CACHE cache;
# Line 420  int section_list_display(const char *sna Line 508  int section_list_display(const char *sna
508          int direction;          int direction;
509          ARTICLE article_new;          ARTICLE article_new;
510          int page_id_cur;          int page_id_cur;
511            const ARTICLE *p_article_locate;
512    
513          p_section = section_list_find_by_name(sname);          p_section = section_list_find_by_name(sname, &section_index);
514          if (p_section == NULL)          if (p_section == NULL)
515          {          {
516                  log_error("Section %s not found\n", sname);                  log_error("Section %s not found\n", sname);
# Line 445  int section_list_display(const char *sna Line 534  int section_list_display(const char *sna
534                  return -2;                  return -2;
535          }          }
536    
537            if (aid == 0)
538            {
539                    aid_location = section_aid_locations[section_index];
540            }
541            else
542            {
543                    aid_location = aid;
544            }      
545    
546            // Locate at article with aid_locate
547            if (aid_location > 0)
548            {
549                    p_article_locate = article_block_find_by_aid(aid_location);
550                    if (p_article_locate == NULL)
551                    {
552                            log_error("article_block_find_by_aid(%d) error\n", aid_location);
553                            return -3;
554                    }
555    
556                    ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
557                                                                                    &page_id, &selected_index, &article_count);
558                    if (ret < 0)
559                    {
560                            log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
561                                              p_section->sid, p_article_locate->aid);
562                            return -3;
563                    }
564            }
565    
566          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
567          {          {
568                  log_error("section_list_draw_screen() error\n");                  log_error("section_list_draw_screen() error\n");
569                  return -2;                  return -2;
570          }          }
571    
572          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, &ontop_start_offset);
573          if (ret < 0)          if (ret < 0)
574          {          {
575                  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\n", p_section->sid, page_id);
576                  return -3;                  return -3;
577          }          }
578    
579            section_topic_view_tid = -1;
580    
581          if (article_count == 0) // empty section          if (article_count == 0) // empty section
582          {          {
583                  selected_index = 0;                  selected_index = 0;
584          }          }
585            else if (aid > 0)
586            {
587                    // Update current topic
588                    section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
589    
590                    // Update current aid location
591                    section_aid_locations[section_index] = p_articles[selected_index]->aid;
592            }
593    
594          while (!SYS_server_exit)          while (!SYS_server_exit)
595          {          {
596                  ret = section_list_draw_items(page_id, p_articles, article_count, display_nickname);                  ret = section_list_draw_items(page_id, p_articles, article_count, display_nickname, ontop_start_offset);
597                  if (ret < 0)                  if (ret < 0)
598                  {                  {
599                          log_error("section_list_draw_items(sid=%d, page_id=%d) error\n", p_section->sid, page_id);                          log_error("section_list_draw_items(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
# Line 473  int section_list_display(const char *sna Line 601  int section_list_display(const char *sna
601                  }                  }
602    
603                  snprintf(page_info_str, sizeof(page_info_str),                  snprintf(page_info_str, sizeof(page_info_str),
604                                   "\033[33m[\033[36m%d\033[33m/\033[36m%d\033[33mҳ]",                                   "\033[33m[第\033[36m%d\033[33m/\033[36m%d\033[33m页]",
605                                   page_id + 1, MAX(page_count, 1));                                   page_id + 1, MAX(page_count, 1));
606    
607                  show_bottom(page_info_str);                  show_bottom(page_info_str);
# Line 490  int section_list_display(const char *sna Line 618  int section_list_display(const char *sna
618                  case EXIT_SECTION:                  case EXIT_SECTION:
619                          return 0;                          return 0;
620                  case CHANGE_PAGE:                  case CHANGE_PAGE:
621                          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, &ontop_start_offset);
622                          if (ret < 0)                          if (ret < 0)
623                          {                          {
624                                  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\n", p_section->sid, page_id);
# Line 546  int section_list_display(const char *sna Line 674  int section_list_display(const char *sna
674                                                          page_id--;                                                          page_id--;
675                                                          selected_index = BBS_article_limit_per_page - 1;                                                          selected_index = BBS_article_limit_per_page - 1;
676    
677                                                          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, &ontop_start_offset);
678                                                          if (ret < 0)                                                          if (ret < 0)
679                                                          {                                                          {
680                                                                  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\n", p_section->sid, page_id);
# Line 577  int section_list_display(const char *sna Line 705  int section_list_display(const char *sna
705                                                          page_id++;                                                          page_id++;
706                                                          selected_index = 0;                                                          selected_index = 0;
707    
708                                                          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, &ontop_start_offset);
709                                                          if (ret < 0)                                                          if (ret < 0)
710                                                          {                                                          {
711                                                                  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\n", p_section->sid, page_id);
# Line 613  int section_list_display(const char *sna Line 741  int section_list_display(const char *sna
741                                          }                                          }
742                                          else if (ret > 0) // found                                          else if (ret > 0) // found
743                                          {                                          {
744                                                  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, &ontop_start_offset);
745                                                  if (ret < 0)                                                  if (ret < 0)
746                                                  {                                                  {
747                                                          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\n", p_section->sid, page_id);
# Line 650  int section_list_display(const char *sna Line 778  int section_list_display(const char *sna
778                                          {                                          {
779                                                  if (page_id != page_id_cur) // page changed                                                  if (page_id != page_id_cur) // page changed
780                                                  {                                                  {
781                                                          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, &ontop_start_offset);
782                                                          if (ret < 0)                                                          if (ret < 0)
783                                                          {                                                          {
784                                                                  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\n", p_section->sid, page_id);
# Line 666  int section_list_display(const char *sna Line 794  int section_list_display(const char *sna
794                          // Update current topic                          // Update current topic
795                          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);
796    
797                            // Update current aid location
798                            section_aid_locations[section_index] = p_articles[selected_index]->aid;
799    
800                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
801                          {                          {
802                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
# Line 692  int section_list_display(const char *sna Line 823  int section_list_display(const char *sna
823                          }                          }
824                          else if (ret > 0) // New article posted                          else if (ret > 0) // New article posted
825                          {                          {
826                                  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, &ontop_start_offset);
827                                  if (ret < 0)                                  if (ret < 0)
828                                  {                                  {
829                                          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\n", p_section->sid, page_id);
# Line 739  int section_list_display(const char *sna Line 870  int section_list_display(const char *sna
870                          }                          }
871                          else if (ret > 0) // Article deleted                          else if (ret > 0) // Article deleted
872                          {                          {
873                                  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, &ontop_start_offset);
874                                  if (ret < 0)                                  if (ret < 0)
875                                  {                                  {
876                                          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\n", p_section->sid, page_id);
# Line 752  int section_list_display(const char *sna Line 883  int section_list_display(const char *sna
883                                  return -2;                                  return -2;
884                          }                          }
885                          break;                          break;
886                    case QUERY_ARTICLE:
887                            if ((ret = display_article_meta(p_articles[selected_index]->aid)) < 0)
888                            {
889                                    log_error("display_article_meta(aid=%d) error\n", p_articles[selected_index]->aid);
890                            }
891                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
892                            {
893                                    log_error("section_list_draw_screen() error\n");
894                                    return -2;
895                            }
896                            break;
897                  case FIRST_TOPIC_ARTICLE:                  case FIRST_TOPIC_ARTICLE:
898                  case LAST_TOPIC_ARTICLE:                  case LAST_TOPIC_ARTICLE:
899                          page_id_cur = page_id;                          page_id_cur = page_id;
# Line 766  int section_list_display(const char *sna Line 908  int section_list_display(const char *sna
908                          }                          }
909                          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
910                          {                          {
911                                  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, &ontop_start_offset);
912                                    if (ret < 0)
913                                    {
914                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
915                                            return -3;
916                                    }
917                            }
918                            break;
919                    case SCAN_NEW_ARTICLE:
920                            ret = scan_unread_article_in_section(p_section, p_articles[selected_index], &p_article_locate);
921                            if (ret < 0)
922                            {
923                                    log_error("scan_unread_article_in_section(sid=%d, aid=%d) error\n",
924                                                      p_section->sid, p_articles[selected_index]->aid);
925                                    return -3;
926                            }
927                            else if (ret == 0) // not found
928                            {
929                                    break;
930                            }
931                            page_id_cur = page_id;
932                            ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
933                                                                                            &page_id, &selected_index, &article_count);
934                            if (ret < 0)
935                            {
936                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
937                                                      p_section->sid, p_article_locate->aid);
938                                    return -3;
939                            }
940                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
941                            {
942                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
943                                  if (ret < 0)                                  if (ret < 0)
944                                  {                                  {
945                                          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\n", p_section->sid, page_id);
# Line 783  int section_list_display(const char *sna Line 956  int section_list_display(const char *sna
956                                  return -2;                                  return -2;
957                          }                          }
958                          break;                          break;
959                    case VIEW_EX_DIR:
960                            if (section_list_ex_dir_display(p_section) < 0)
961                            {
962                                    log_error("section_list_ex_dir_display(sid=%d) error\n", p_section->sid);
963                            }
964                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
965                            {
966                                    log_error("section_list_draw_screen() error\n");
967                                    return -2;
968                            }
969                            break;
970                  default:                  default:
971                          log_error("Unknown command %d\n", ret);                          log_error("Unknown command %d\n", ret);
972                  }                  }
# Line 790  int section_list_display(const char *sna Line 974  int section_list_display(const char *sna
974    
975          return 0;          return 0;
976  }  }
977    
978    int section_list_ex_dir_display(SECTION_LIST *p_section)
979    {
980            MENU_SET ex_menu_set;
981            int ch = 0;
982    
983            if (p_section == NULL)
984            {
985                    log_error("NULL pointer error\n");
986                    return -1;
987            }
988    
989            if (p_section->ex_menu_tm == 0) // N/A
990            {
991                    moveto(2, 1);
992                    clrtoeol();
993                    prints("该版块精华区未开放");
994                    press_any_key();
995                    return 0;
996            }
997    
998            if (get_section_ex_menu_set(p_section, &ex_menu_set) < 0)
999            {
1000                    log_error("get_section_ex_menu_set(sid=%d) error\n", p_section->sid);
1001                    return -3;
1002            }
1003            if (get_menu_shm_readonly(&ex_menu_set) < 0)
1004            {
1005                    log_error("get_menu_shm_readonly(sid=%d) error\n", p_section->sid);
1006                    return -3;
1007            }
1008    
1009            clearscr();
1010            show_bottom("");
1011    
1012            if (display_menu(&ex_menu_set) == 0)
1013            {
1014                    while (!SYS_server_exit)
1015                    {
1016                            iflush();
1017                            ch = igetch(100);
1018                            switch (ch)
1019                            {
1020                            case KEY_NULL: // broken pipe
1021                                    return 0;
1022                            case KEY_TIMEOUT:
1023                                    if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
1024                                    {
1025                                            return 0;
1026                                    }
1027                                    continue;
1028                            case CR:
1029                                    igetch_reset();
1030                            default:
1031                                    switch (menu_control(&ex_menu_set, ch))
1032                                    {
1033                                    case EXITMENU:
1034                                            ch = EXITMENU;
1035                                            break;
1036                                    case REDRAW:
1037                                            clearscr();
1038                                            show_bottom("");
1039                                            display_menu(&ex_menu_set);
1040                                            break;
1041                                    case NOREDRAW:
1042                                    case UNKNOWN_CMD:
1043                                    default:
1044                                            break;
1045                                    }
1046                            }
1047    
1048                            BBS_last_access_tm = time(NULL);
1049    
1050                            if (ch == EXITMENU)
1051                            {
1052                                    break;
1053                            }
1054                    }
1055            }
1056    
1057            detach_menu_shm(&ex_menu_set);
1058    
1059            return 0;
1060    }


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

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