/[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.3 by sysadm, Wed May 28 10:27:12 2025 UTC Revision 1.8 by sysadm, Thu May 29 03:05:02 2025 UTC
# Line 22  Line 22 
22  #include "log.h"  #include "log.h"
23  #include "str_process.h"  #include "str_process.h"
24  #include <time.h>  #include <time.h>
25    #include <sys/param.h>
26  #define _POSIX_C_SOURCE 200809L  #define _POSIX_C_SOURCE 200809L
27  #include <string.h>  #include <string.h>
28    
# Line 31  enum select_cmd_t Line 32  enum select_cmd_t
32          VIEW_ARTICLE = 1,          VIEW_ARTICLE = 1,
33          CHANGE_PAGE = 2,          CHANGE_PAGE = 2,
34          REFRESH_SCREEN = 3,          REFRESH_SCREEN = 3,
35            CHANGE_NAME_DISPLAY = 4,
36  };  };
37    
38  static int section_list_draw_items(SECTION_LIST *p_section, int page_id, ARTICLE *p_articles[], int article_count)  static int section_list_draw_items(int page_id, ARTICLE *p_articles[], int article_count, int display_nickname)
39  {  {
40          char str_time[LINE_BUFFER_LEN];          char str_time[LINE_BUFFER_LEN];
41          struct tm tm_sub;          struct tm tm_sub;
# Line 72  static int section_list_draw_items(SECTI Line 74  static int section_list_draw_items(SECTI
74                          strftime(str_time, sizeof(str_time), "%m/%Y", &tm_sub);                          strftime(str_time, sizeof(str_time), "%m/%Y", &tm_sub);
75                  }                  }
76    
77                  strncpy(title_f, (p_articles[i]->transship ? "[转载]" : ""), sizeof(title_f) - 1);                  strncpy(title_f, (p_articles[i]->tid == 0 ? "● " : ""), sizeof(title_f) - 1);
78                  title_f[sizeof(title_f) - 1] = '\0';                  title_f[sizeof(title_f) - 1] = '\0';
79                    strncat(title_f, (p_articles[i]->transship ? "[转载]" : ""), sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
80                  strncat(title_f, p_articles[i]->title, sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));                  strncat(title_f, p_articles[i]->title, sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
81                  len = split_line(title_f, (p_articles[i]->tid == 0 ? 46 : 49), &eol, &title_f_len);                  len = split_line(title_f, 47 - (display_nickname ? 8 : 0), &eol, &title_f_len);
82                  if (title_f[len] != '\0')                  if (title_f[len] != '\0')
83                  {                  {
84                          title_f[len] = '\0';                          title_f[len] = '\0';
85                  }                  }
86    
87                  moveto(4 + i, 1);                  moveto(4 + i, 1);
88                  prints("  %7d %c %s%*s %s %s%s",                  prints("  %7d %c %s%*s %s %s",
89                             p_articles[i]->aid,                             p_articles[i]->aid,
90                             article_flag,                             article_flag,
91                             p_articles[i]->username,                             (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
92                             BBS_username_max_len - (int)strnlen(p_articles[i]->username, sizeof(p_articles[i]->username)),                             (display_nickname ? BBS_nickname_max_len - (int)strnlen(p_articles[i]->nickname, sizeof(p_articles[i]->nickname))
93                                                                     : BBS_username_max_len - (int)strnlen(p_articles[i]->username, sizeof(p_articles[i]->username))),
94                             "",                             "",
95                             str_time,                             str_time,
                            (p_articles[i]->tid == 0 ? "● " : ""),  
96                             title_f);                             title_f);
97          }          }
98    
99          return 0;          return 0;
100  }  }
101    
102  static int section_list_draw_screen(SECTION_LIST *p_section)  static int section_list_draw_screen(const char *sname, const char *stitle, const char *master_list, int display_nickname)
103  {  {
104          char str_section_master[LINE_BUFFER_LEN] = "诚征版主中";          char str_section_master[LINE_BUFFER_LEN] = "诚征版主中";
105          char str_section_name[LINE_BUFFER_LEN];          char str_section_name[LINE_BUFFER_LEN];
106    
107          if (p_section->master_list[0] != '\0')          if (master_list[0] != '\0')
108          {          {
109                  snprintf(str_section_master, sizeof(str_section_master), "版主:%s", p_section->master_list);                  snprintf(str_section_master, sizeof(str_section_master), "版主:%s", master_list);
110          }          }
111          snprintf(str_section_name, sizeof(str_section_name), "讨论区 [%s]", p_section->sname);          snprintf(str_section_name, sizeof(str_section_name), "讨论区 [%s]", sname);
112    
113          clearscr();          clearscr();
114          show_top(str_section_master, p_section->stitle, str_section_name);          show_top(str_section_master, stitle, str_section_name);
115          moveto(2, 0);          moveto(2, 0);
116          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] 阅读[\033[1;32m→\033[0;37m,\033[1;32mENTER\033[0;37m]\033[m");          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] "
117                       "阅读[\033[1;32m→\033[0;37m,\033[1;32mENTER\033[0;37m]\033[m %s[\033[1;32mn\033[0;37m]\033[m",
118                       (display_nickname ? "显示用户名" : "显示昵称"));
119          moveto(3, 0);          moveto(3, 0);
120          prints("\033[44;37m  \033[1;37m 编  号   发 布 者     日  期  文 章 标 题                                    \033[m");          if (display_nickname)
121          show_bottom("");          {
122                    prints("\033[44;37m  \033[1;37m 编  号   发布者昵称           日  期  文章标题                               \033[m");
123            }
124            else
125            {
126                    prints("\033[44;37m  \033[1;37m 编  号   发 布 者     日  期  文章标题                                       \033[m");
127            }
128    
129          return 0;          return 0;
130  }  }
# Line 149  static enum select_cmd_t section_list_se Line 160  static enum select_cmd_t section_list_se
160                                  return EXIT_SECTION; // exit section                                  return EXIT_SECTION; // exit section
161                          }                          }
162                          continue;                          continue;
163                    case 'n':
164                            return CHANGE_NAME_DISPLAY;
165                  case CR:                  case CR:
166                          igetch_reset();                          igetch_reset();
167                  case KEY_RIGHT:                  case KEY_RIGHT:
# Line 232  static enum select_cmd_t section_list_se Line 245  static enum select_cmd_t section_list_se
245    
246  int section_list_display(const char *sname)  int section_list_display(const char *sname)
247  {  {
248            static int display_nickname = 0;
249    
250          SECTION_LIST *p_section;          SECTION_LIST *p_section;
251            char stitle[BBS_section_title_max_len + 1];
252            char master_list[(BBS_username_max_len + 1) * 3 + 1];
253            char page_info_str[LINE_BUFFER_LEN];
254          ARTICLE *p_articles[BBS_article_limit_per_page];          ARTICLE *p_articles[BBS_article_limit_per_page];
255          int article_count;          int article_count;
256            int page_count;
257          int page_id = 0;          int page_id = 0;
258          int selected_index = 0;          int selected_index = 0;
259          int ret;          int ret;
# Line 246  int section_list_display(const char *sna Line 265  int section_list_display(const char *sna
265                  return -1;                  return -1;
266          }          }
267    
268          if (section_list_draw_screen(p_section) < 0)          if ((ret = section_list_rd_lock(p_section)) < 0)
269            {
270                    log_error("section_list_rd_lock(sid = 0) error\n");
271                    return -2;
272            }
273    
274            strncpy(stitle, p_section->stitle, sizeof(stitle) - 1);
275            stitle[sizeof(stitle) - 1] = '\0';
276            strncpy(master_list, p_section->master_list, sizeof(master_list) - 1);
277            master_list[sizeof(master_list) - 1] = '\0';
278    
279            if ((ret = section_list_rd_unlock(p_section)) < 0)
280            {
281                    log_error("section_list_rd_unlock(sid = 0) error\n");
282                    return -2;
283            }
284    
285            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
286          {          {
287                  log_error("section_list_draw_screen() error\n");                  log_error("section_list_draw_screen() error\n");
288                  return -2;                  return -2;
289          }          }
290    
291          if (p_section->visible_article_count > 0)          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);
292            if (ret < 0)
293          {          {
294                  ret = query_section_articles(p_section, page_id, p_articles, &article_count);                  log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
295                  if (ret < 0)                  return -3;
                 {  
                         log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);  
                         return -3;  
                 }  
296          }          }
297          else // empty section  
298            if (article_count == 0) // empty section
299          {          {
                 article_count = 0;  
300                  selected_index = 0;                  selected_index = 0;
301          }          }
302    
303          while (!SYS_server_exit)          while (!SYS_server_exit)
304          {          {
305                  ret = section_list_draw_items(p_section, page_id, p_articles, article_count);                  ret = section_list_draw_items(page_id, p_articles, article_count, display_nickname);
306                  if (ret < 0)                  if (ret < 0)
307                  {                  {
308                          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);
309                          return -4;                          return -4;
310                  }                  }
311    
312                    snprintf(page_info_str, sizeof(page_info_str),
313                                     "\033[33m[第\033[36m%d\033[33m/\033[36m%d\033[33m页]",
314                                     page_id + 1, MAX(page_count, 1));
315    
316                    show_bottom(page_info_str);
317                  iflush();                  iflush();
318    
319                  ret = section_list_select(p_section->page_count, article_count, &page_id, &selected_index);                  ret = section_list_select(page_count, article_count, &page_id, &selected_index);
320                  switch (ret)                  switch (ret)
321                  {                  {
322                  case EXIT_SECTION:                  case EXIT_SECTION:
323                          return 0;                          return 0;
324                  case CHANGE_PAGE:                  case CHANGE_PAGE:
325                          if (p_section->visible_article_count > 0)                          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);
326                            if (ret < 0)
327                          {                          {
328                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count);                                  log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
329                                  if (ret < 0)                                  return -3;
                                 {  
                                         log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);  
                                         return -3;  
                                 }  
330                          }                          }
331                          else // empty section                          if (article_count == 0) // empty section
332                          {                          {
                                 article_count = 0;  
333                                  selected_index = 0;                                  selected_index = 0;
334                          }                          }
335                          if (selected_index >= article_count)                          else if (selected_index >= article_count)
336                          {                          {
337                                  selected_index = article_count - 1;                                  selected_index = article_count - 1;
338                          }                          }
# Line 305  int section_list_display(const char *sna Line 340  int section_list_display(const char *sna
340                  case VIEW_ARTICLE:                  case VIEW_ARTICLE:
341                          log_std("Debug: article %d selected\n", p_articles[selected_index]->aid);                          log_std("Debug: article %d selected\n", p_articles[selected_index]->aid);
342                  case REFRESH_SCREEN:                  case REFRESH_SCREEN:
343                          if (section_list_draw_screen(p_section) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
344                            {
345                                    log_error("section_list_draw_screen() error\n");
346                                    return -2;
347                            }
348                            break;
349                    case CHANGE_NAME_DISPLAY:
350                            display_nickname = !display_nickname;
351                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
352                          {                          {
353                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
354                                  return -2;                                  return -2;


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

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