/[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.2 by sysadm, Wed May 28 07:41:46 2025 UTC Revision 1.7 by sysadm, Thu May 29 02:45:23 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 42  static int section_list_draw_items(SECTI Line 44  static int section_list_draw_items(SECTI
44          int eol;          int eol;
45          int len;          int len;
46          int i;          int i;
47            char article_flag;
48            time_t tm_now;
49    
50            time(&tm_now);
51    
52          clrline(4, 23);          clrline(4, 23);
53    
54          for (i = 0; i < article_count; i++)          for (i = 0; i < article_count; i++)
55          {          {
56                    article_flag = ' ';
57    
58                    if (p_articles[i]->excerption)
59                    {
60                            article_flag = 'm';
61                    }
62                    else if (p_articles[i]->lock)
63                    {
64                            article_flag = 'x';
65                    }
66    
67                  localtime_r(&p_articles[i]->sub_dt, &tm_sub);                  localtime_r(&p_articles[i]->sub_dt, &tm_sub);
68                  strftime(str_time, sizeof(str_time), "%b %e", &tm_sub);                  if (tm_now - p_articles[i]->sub_dt < 3600 * 24 * 365)
69                  strncpy(title_f, p_articles[i]->title, sizeof(title_f) - 1);                  {
70                            strftime(str_time, sizeof(str_time), "%b %e ", &tm_sub);
71                    }
72                    else
73                    {
74                            strftime(str_time, sizeof(str_time), "%m/%Y", &tm_sub);
75                    }
76    
77                    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                  len = split_line(title_f, (p_articles[i]->tid == 0 ? 46 : 49), &eol, &title_f_len);                  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)));
81                    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 %s%*s %s  %s%s",                  prints("  %7d %c %s%*s %s %s",
89                             p_articles[i]->aid,                             p_articles[i]->aid,
90                             p_articles[i]->username,                             article_flag,
91                             BBS_username_max_len - (int)strnlen(p_articles[i]->username, sizeof(p_articles[i]->username)),                             (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
92                               (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] 阅读[\033[1;32m→\033[0;37m,\033[1;32mENTER\033[0;37m]\033[m 昵称[\033[1;32mn\033[0;37m]\033[m");
117          moveto(3, 0);          moveto(3, 0);
118          prints("\033[44;37m  \033[1;37m 编 号  发 布 者     日  期  文 章 标 题                                      \033[m");          if (display_nickname)
119          show_bottom("");          {
120                    prints("\033[44;37m  \033[1;37m 编  号   发 布 者 昵 称       日  期  文 章 标 题                            \033[m");
121            }
122            else
123            {
124                    prints("\033[44;37m  \033[1;37m 编  号   发 布 者     日  期  文 章 标 题                                    \033[m");
125            }
126    
127          return 0;          return 0;
128  }  }
# Line 124  static enum select_cmd_t section_list_se Line 158  static enum select_cmd_t section_list_se
158                                  return EXIT_SECTION; // exit section                                  return EXIT_SECTION; // exit section
159                          }                          }
160                          continue;                          continue;
161                    case 'n':
162                            return CHANGE_NAME_DISPLAY;
163                  case CR:                  case CR:
164                          igetch_reset();                          igetch_reset();
165                  case KEY_RIGHT:                  case KEY_RIGHT:
# Line 207  static enum select_cmd_t section_list_se Line 243  static enum select_cmd_t section_list_se
243    
244  int section_list_display(const char *sname)  int section_list_display(const char *sname)
245  {  {
246            static int display_nickname = 0;
247    
248          SECTION_LIST *p_section;          SECTION_LIST *p_section;
249            char stitle[BBS_section_title_max_len + 1];
250            char master_list[(BBS_username_max_len + 1) * 3 + 1];
251            char page_info_str[LINE_BUFFER_LEN];
252          ARTICLE *p_articles[BBS_article_limit_per_page];          ARTICLE *p_articles[BBS_article_limit_per_page];
253          int article_count;          int article_count;
254            int page_count;
255          int page_id = 0;          int page_id = 0;
256          int selected_index = 0;          int selected_index = 0;
257          int ret;          int ret;
# Line 221  int section_list_display(const char *sna Line 263  int section_list_display(const char *sna
263                  return -1;                  return -1;
264          }          }
265    
266          if (section_list_draw_screen(p_section) < 0)          if ((ret = section_list_rd_lock(p_section)) < 0)
267            {
268                    log_error("section_list_rd_lock(sid = 0) error\n");
269                    return -2;
270            }
271    
272            strncpy(stitle, p_section->stitle, sizeof(stitle) - 1);
273            stitle[sizeof(stitle) - 1] = '\0';
274            strncpy(master_list, p_section->master_list, sizeof(master_list) - 1);
275            master_list[sizeof(master_list) - 1] = '\0';
276    
277            if ((ret = section_list_rd_unlock(p_section)) < 0)
278            {
279                    log_error("section_list_rd_unlock(sid = 0) error\n");
280                    return -2;
281            }
282    
283            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
284          {          {
285                  log_error("section_list_draw_screen() error\n");                  log_error("section_list_draw_screen() error\n");
286                  return -2;                  return -2;
287          }          }
288    
289          if (p_section->visible_article_count > 0)          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);
290            if (ret < 0)
291          {          {
292                  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);
293                  if (ret < 0)                  return -3;
                 {  
                         log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);  
                         return -3;  
                 }  
294          }          }
295          else // empty section  
296            if (article_count == 0) // empty section
297          {          {
                 article_count = 0;  
298                  selected_index = 0;                  selected_index = 0;
299          }          }
300    
301          while (!SYS_server_exit)          while (!SYS_server_exit)
302          {          {
303                  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);
304                  if (ret < 0)                  if (ret < 0)
305                  {                  {
306                          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);
307                          return -4;                          return -4;
308                  }                  }
309    
310                    snprintf(page_info_str, sizeof(page_info_str),
311                                     "\033[33m[第\033[36m%d\033[33m/\033[36m%d\033[33m页]",
312                                     page_id + 1, MAX(page_count, 1));
313                    
314                    show_bottom(page_info_str);
315                  iflush();                  iflush();
316    
317                  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);
318                  switch (ret)                  switch (ret)
319                  {                  {
320                  case EXIT_SECTION:                  case EXIT_SECTION:
321                          return 0;                          return 0;
322                  case CHANGE_PAGE:                  case CHANGE_PAGE:
323                          if (p_section->visible_article_count > 0)                          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);
324                            if (ret < 0)
325                          {                          {
326                                  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);
327                                  if (ret < 0)                                  return -3;
                                 {  
                                         log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);  
                                         return -3;  
                                 }  
328                          }                          }
329                          else // empty section                          if (article_count == 0) // empty section
330                          {                          {
                                 article_count = 0;  
331                                  selected_index = 0;                                  selected_index = 0;
332                          }                          }
333                          if (selected_index >= article_count)                          else if (selected_index >= article_count)
334                          {                          {
335                                  selected_index = article_count - 1;                                  selected_index = article_count - 1;
336                          }                          }
# Line 280  int section_list_display(const char *sna Line 338  int section_list_display(const char *sna
338                  case VIEW_ARTICLE:                  case VIEW_ARTICLE:
339                          log_std("Debug: article %d selected\n", p_articles[selected_index]->aid);                          log_std("Debug: article %d selected\n", p_articles[selected_index]->aid);
340                  case REFRESH_SCREEN:                  case REFRESH_SCREEN:
341                          if (section_list_draw_screen(p_section) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
342                            {
343                                    log_error("section_list_draw_screen() error\n");
344                                    return -2;
345                            }
346                            break;
347                    case CHANGE_NAME_DISPLAY:
348                            display_nickname = !display_nickname;
349                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
350                          {                          {
351                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
352                                  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