/[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.1 by sysadm, Wed May 28 07:30:23 2025 UTC Revision 1.5 by sysadm, Thu May 29 00:52:09 2025 UTC
# Line 31  enum select_cmd_t Line 31  enum select_cmd_t
31          VIEW_ARTICLE = 1,          VIEW_ARTICLE = 1,
32          CHANGE_PAGE = 2,          CHANGE_PAGE = 2,
33          REFRESH_SCREEN = 3,          REFRESH_SCREEN = 3,
34            CHANGE_NAME_DISPLAY = 4,
35  };  };
36    
37  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)
38  {  {
39          char str_time[LINE_BUFFER_LEN];          char str_time[LINE_BUFFER_LEN];
40          struct tm tm_sub;          struct tm tm_sub;
# Line 42  static int section_list_draw_items(SECTI Line 43  static int section_list_draw_items(SECTI
43          int eol;          int eol;
44          int len;          int len;
45          int i;          int i;
46            char article_flag;
47            time_t tm_now;
48    
49            time(&tm_now);
50    
51          clrline(4, 23);          clrline(4, 23);
52    
53          for (i = 0; i < article_count; i++)          for (i = 0; i < article_count; i++)
54          {          {
55                    article_flag = ' ';
56    
57                    if (p_articles[i]->excerption)
58                    {
59                            article_flag = 'm';
60                    }
61                    else if (p_articles[i]->lock)
62                    {
63                            article_flag = 'x';
64                    }
65    
66                  localtime_r(&p_articles[i]->sub_dt, &tm_sub);                  localtime_r(&p_articles[i]->sub_dt, &tm_sub);
67                  strftime(str_time, sizeof(str_time), "%b %e", &tm_sub);                  if (tm_now - p_articles[i]->sub_dt < 3600 * 24 * 365)
68                  strncpy(title_f, p_articles[i]->title, sizeof(title_f) - 1);                  {
69                            strftime(str_time, sizeof(str_time), "%b %e ", &tm_sub);
70                    }
71                    else
72                    {
73                            strftime(str_time, sizeof(str_time), "%m/%Y", &tm_sub);
74                    }
75    
76                    strncpy(title_f, (p_articles[i]->tid == 0 ? "● " : ""), sizeof(title_f) - 1);
77                  title_f[sizeof(title_f) - 1] = '\0';                  title_f[sizeof(title_f) - 1] = '\0';
78                  len = split_line(title_f, (p_articles[i]->tid == 0 ? 40 : 37), &eol, &title_f_len);                  strncat(title_f, (p_articles[i]->transship ? "[转载]" : ""), sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
79                    strncat(title_f, p_articles[i]->title, sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
80                    len = split_line(title_f, 47 - (display_nickname ? 8 : 0), &eol, &title_f_len);
81                  if (title_f[len] != '\0')                  if (title_f[len] != '\0')
82                  {                  {
83                          title_f[len] = '\0';                          title_f[len] = '\0';
84                  }                  }
85    
86                  moveto(4 + i, 1);                  moveto(4 + i, 1);
87                  prints("  %7d %s%*s %s  %s%s",                  prints("  %7d %c %s%*s %s %s",
88                             p_articles[i]->aid,                             p_articles[i]->aid,
89                             p_articles[i]->username,                             article_flag,
90                             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),
91                               (display_nickname ? BBS_nickname_max_len - (int)strnlen(p_articles[i]->nickname, sizeof(p_articles[i]->nickname))
92                                                                     : BBS_username_max_len - (int)strnlen(p_articles[i]->username, sizeof(p_articles[i]->username))),
93                             "",                             "",
94                             str_time,                             str_time,
                            (p_articles[i]->tid == 0 ? "● " : ""),  
95                             title_f);                             title_f);
96          }          }
97    
98          return 0;          return 0;
99  }  }
100    
101  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)
102  {  {
103          char str_section_master[LINE_BUFFER_LEN] = "诚征版主中";          char str_section_master[LINE_BUFFER_LEN] = "诚征版主中";
104          char str_section_name[LINE_BUFFER_LEN];          char str_section_name[LINE_BUFFER_LEN];
105    
106          if (p_section->master_list[0] != '\0')          if (master_list[0] != '\0')
107          {          {
108                  snprintf(str_section_master, sizeof(str_section_master), "版主:%s", p_section->master_list);                  snprintf(str_section_master, sizeof(str_section_master), "版主:%s", master_list);
109          }          }
110          snprintf(str_section_name, sizeof(str_section_name), "讨论区 [%s]", p_section->sname);          snprintf(str_section_name, sizeof(str_section_name), "讨论区 [%s]", sname);
111    
112          clearscr();          clearscr();
113          show_top(str_section_master, p_section->stitle, str_section_name);          show_top(str_section_master, stitle, str_section_name);
114          moveto(2, 0);          moveto(2, 0);
115          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");
116          moveto(3, 0);          moveto(3, 0);
117          prints("\033[44;37m  \033[1;37m 编 号  发 布 者     日  期  文 章 标 题                                      \033[m");          if (display_nickname)
118            {
119                    prints("\033[44;37m  \033[1;37m 编  号   发 布 者 昵 称       日  期  文 章 标 题                            \033[m");
120            }
121            else
122            {
123                    prints("\033[44;37m  \033[1;37m 编  号   发 布 者     日  期  文 章 标 题                                    \033[m");
124            }
125          show_bottom("");          show_bottom("");
126    
127          return 0;          return 0;
# 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          ARTICLE *p_articles[BBS_article_limit_per_page];          ARTICLE *p_articles[BBS_article_limit_per_page];
252          int article_count;          int article_count;
253          int page_id = 0;          int page_id = 0;
# Line 221  int section_list_display(const char *sna Line 261  int section_list_display(const char *sna
261                  return -1;                  return -1;
262          }          }
263    
264          if (section_list_draw_screen(p_section) < 0)          if ((ret = section_list_rd_lock(p_section)) < 0)
265            {
266                    log_error("section_list_rd_lock(sid = 0) error\n");
267                    return -2;
268            }
269    
270            strncpy(stitle, p_section->stitle, sizeof(stitle) - 1);
271            stitle[sizeof(stitle) - 1] = '\0';
272            strncpy(master_list, p_section->master_list, sizeof(master_list) - 1);
273            master_list[sizeof(master_list) - 1] = '\0';
274    
275            if ((ret = section_list_rd_unlock(p_section)) < 0)
276            {
277                    log_error("section_list_rd_unlock(sid = 0) error\n");
278                    return -2;
279            }
280    
281            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
282          {          {
283                  log_error("section_list_draw_screen() error\n");                  log_error("section_list_draw_screen() error\n");
284                  return -2;                  return -2;
285          }          }
286    
287          if (p_section->visible_article_count > 0)          ret = query_section_articles(p_section, page_id, p_articles, &article_count);
288            if (ret < 0)
289          {          {
290                  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);
291                  if (ret < 0)                  return -3;
                 {  
                         log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);  
                         return -3;  
                 }  
292          }          }
293          else // empty section  
294            if (article_count == 0) // empty section
295          {          {
                 article_count = 0;  
296                  selected_index = 0;                  selected_index = 0;
297          }          }
298    
299          while (!SYS_server_exit)          while (!SYS_server_exit)
300          {          {
301                  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);
302                  if (ret < 0)                  if (ret < 0)
303                  {                  {
304                          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 258  int section_list_display(const char *sna Line 312  int section_list_display(const char *sna
312                  case EXIT_SECTION:                  case EXIT_SECTION:
313                          return 0;                          return 0;
314                  case CHANGE_PAGE:                  case CHANGE_PAGE:
315                          if (p_section->visible_article_count > 0)                          ret = query_section_articles(p_section, page_id, p_articles, &article_count);
316                            if (ret < 0)
317                          {                          {
318                                  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);
319                                  if (ret < 0)                                  return -3;
                                 {  
                                         log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);  
                                         return -3;  
                                 }  
320                          }                          }
321                          else // empty section                          if (article_count == 0) // empty section
322                          {                          {
                                 article_count = 0;  
323                                  selected_index = 0;                                  selected_index = 0;
324                          }                          }
325                          if (selected_index >= article_count)                          else if (selected_index >= article_count)
326                          {                          {
327                                  selected_index = article_count - 1;                                  selected_index = article_count - 1;
328                          }                          }
# Line 280  int section_list_display(const char *sna Line 330  int section_list_display(const char *sna
330                  case VIEW_ARTICLE:                  case VIEW_ARTICLE:
331                          log_std("Debug: article %d selected\n", p_articles[selected_index]->aid);                          log_std("Debug: article %d selected\n", p_articles[selected_index]->aid);
332                  case REFRESH_SCREEN:                  case REFRESH_SCREEN:
333                          if (section_list_draw_screen(p_section) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
334                            {
335                                    log_error("section_list_draw_screen() error\n");
336                                    return -2;
337                            }
338                            break;
339                    case CHANGE_NAME_DISPLAY:
340                            display_nickname = !display_nickname;
341                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
342                          {                          {
343                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
344                                  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