/[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.32 by sysadm, Tue Jun 17 13:18:55 2025 UTC
# Line 16  Line 16 
16    
17  #include "section_list_display.h"  #include "section_list_display.h"
18  #include "section_list_loader.h"  #include "section_list_loader.h"
19    #include "article_cache.h"
20    #include "article_post.h"
21    #include "article_del.h"
22  #include "common.h"  #include "common.h"
23  #include "io.h"  #include "io.h"
24  #include "screen.h"  #include "screen.h"
25  #include "log.h"  #include "log.h"
26    #include "user_priv.h"
27    #include "article_view_log.h"
28  #include "str_process.h"  #include "str_process.h"
 #include <time.h>  
 #define _POSIX_C_SOURCE 200809L  
29  #include <string.h>  #include <string.h>
30    #include <time.h>
31    #include <sys/param.h>
32    
33    static int section_topic_view_mode = 0;
34    static int section_topic_view_tid = -1;
35    
36  enum select_cmd_t  enum select_cmd_t
37  {  {
38          EXIT_SECTION = 0,          EXIT_SECTION = 0,
39          VIEW_ARTICLE = 1,          VIEW_ARTICLE = 1,
40          CHANGE_PAGE = 2,          CHANGE_PAGE = 2,
41          REFRESH_SCREEN = 3,          SHOW_HELP = 3,
42            CHANGE_NAME_DISPLAY = 4,
43            POST_ARTICLE = 5,
44            EDIT_ARTICLE = 6,
45            DELETE_ARTICLE = 7,
46            FIRST_TOPIC_ARTICLE = 8,
47            LAST_TOPIC_ARTICLE = 9,
48  };  };
49    
50  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)
51  {  {
52          char str_time[LINE_BUFFER_LEN];          char str_time[LINE_BUFFER_LEN];
53          struct tm tm_sub;          struct tm tm_sub;
# Line 43  static int section_list_draw_items(SECTI Line 57  static int section_list_draw_items(SECTI
57          int len;          int len;
58          int i;          int i;
59          char article_flag;          char article_flag;
60            int is_viewed;
61          time_t tm_now;          time_t tm_now;
62    
63          time(&tm_now);          time(&tm_now);
# Line 51  static int section_list_draw_items(SECTI Line 66  static int section_list_draw_items(SECTI
66    
67          for (i = 0; i < article_count; i++)          for (i = 0; i < article_count; i++)
68          {          {
69                  article_flag = ' ';                  if (p_articles[i]->uid == BBS_priv.uid)
70                    {
71                            is_viewed = 1;
72                    }
73                    else
74                    {
75                            is_viewed = article_view_log_is_viewed(p_articles[i]->aid, &BBS_article_view_log);
76                            if (is_viewed < 0)
77                            {
78                                    log_error("article_view_log_is_viewed(aid=%d) error\n", p_articles[i]->aid);
79                                    is_viewed = 0;
80                            }
81                    }
82    
83                    article_flag = (is_viewed ? ' ' : 'N');
84    
85                  if (p_articles[i]->excerption)                  if (p_articles[i]->excerption)
86                  {                  {
87                          article_flag = 'm';                          article_flag = (is_viewed ? 'm' : 'M');
88                  }                  }
89                  else if (p_articles[i]->lock)                  else if (p_articles[i]->lock && is_viewed)
90                  {                  {
91                          article_flag = 'x';                          article_flag = 'x';
92                  }                  }
# Line 72  static int section_list_draw_items(SECTI Line 101  static int section_list_draw_items(SECTI
101                          strftime(str_time, sizeof(str_time), "%m/%Y", &tm_sub);                          strftime(str_time, sizeof(str_time), "%m/%Y", &tm_sub);
102                  }                  }
103    
104                  strncpy(title_f, (p_articles[i]->transship ? "[转载]" : ""), sizeof(title_f) - 1);                  strncpy(title_f, (p_articles[i]->tid == 0 ? "● " : ""), sizeof(title_f) - 1);
105                  title_f[sizeof(title_f) - 1] = '\0';                  title_f[sizeof(title_f) - 1] = '\0';
106                    strncat(title_f, (p_articles[i]->transship ? "[转载]" : ""), sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
107                  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)));
108                  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, 1);
109                  if (title_f[len] != '\0')                  if (title_f[len] != '\0')
110                  {                  {
111                          title_f[len] = '\0';                          title_f[len] = '\0';
112                  }                  }
113    
114                  moveto(4 + i, 1);                  moveto(4 + i, 1);
115                  prints("  %7d %c %s%*s %s %s%s",                  prints("  %s%7d\033[m %c %s%*s %s %s%s\033[m",
116                               (p_articles[i]->aid == section_topic_view_tid ? "\033[1;33m" : (p_articles[i]->tid == section_topic_view_tid ? "\033[1;36m" : "")),
117                             p_articles[i]->aid,                             p_articles[i]->aid,
118                             article_flag,                             article_flag,
119                             p_articles[i]->username,                             (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
120                             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))
121                                                                     : BBS_username_max_len - (int)strnlen(p_articles[i]->username, sizeof(p_articles[i]->username))),
122                             "",                             "",
123                             str_time,                             str_time,
124                             (p_articles[i]->tid == 0 ? "● " : ""),                             (p_articles[i]->aid == section_topic_view_tid ? "\033[1;33m" : (p_articles[i]->tid == section_topic_view_tid ? "\033[1;36m" : "")),
125                             title_f);                             title_f);
126          }          }
127    
128          return 0;          return 0;
129  }  }
130    
131  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)
132  {  {
133          char str_section_master[LINE_BUFFER_LEN] = "诚征版主中";          char str_section_master[LINE_BUFFER_LEN] = "诚征版主中";
134          char str_section_name[LINE_BUFFER_LEN];          char str_section_name[LINE_BUFFER_LEN];
135    
136          if (p_section->master_list[0] != '\0')          if (master_list[0] != '\0')
137          {          {
138                  snprintf(str_section_master, sizeof(str_section_master), "版主:%s", p_section->master_list);                  snprintf(str_section_master, sizeof(str_section_master), "版主:%s", master_list);
139          }          }
140          snprintf(str_section_name, sizeof(str_section_name), "讨论区 [%s]", p_section->sname);          snprintf(str_section_name, sizeof(str_section_name), "讨论区 [%s]", sname);
141    
142          clearscr();          clearscr();
143          show_top(str_section_master, p_section->stitle, str_section_name);          show_top(str_section_master, stitle, str_section_name);
144          moveto(2, 0);          moveto(2, 0);
145          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] "
146                       "阅读[\033[1;32m→\033[0;37m,\033[1;32mENTER\033[0;37m] 发表[\033[1;32mCtrl-P\033[0;37m] "
147                       "%s[\033[1;32mn\033[0;37m] 帮助[\033[1;32mh\033[0;37m]\033[m",
148                       (display_nickname ? "显示用户名" : "显示昵称"));
149          moveto(3, 0);          moveto(3, 0);
150          prints("\033[44;37m  \033[1;37m 编  号   发 布 者     日  期  文 章 标 题                                    \033[m");          if (display_nickname)
151          show_bottom("");          {
152                    prints("\033[44;37m  \033[1;37m 编  号   发布者昵称           日  期  文章标题                               \033[m");
153            }
154            else
155            {
156                    prints("\033[44;37m  \033[1;37m 编  号   发 布 者     日  期  文章标题                                       \033[m");
157            }
158    
159          return 0;          return 0;
160  }  }
# Line 123  static enum select_cmd_t section_list_se Line 164  static enum select_cmd_t section_list_se
164          int old_page_id = *p_page_id;          int old_page_id = *p_page_id;
165          int old_selected_index = *p_selected_index;          int old_selected_index = *p_selected_index;
166          int ch;          int ch;
167            time_t last_refresh_tm = time(NULL);
         BBS_last_access_tm = time(0);  
168    
169          if (item_count > 0 && *p_selected_index >= 0)          if (item_count > 0 && *p_selected_index >= 0)
170          {          {
# Line 139  static enum select_cmd_t section_list_se Line 179  static enum select_cmd_t section_list_se
179    
180                  switch (ch)                  switch (ch)
181                  {                  {
                 case KEY_NULL: // broken pipe  
182                  case KEY_ESC:                  case KEY_ESC:
183                  case KEY_LEFT:                  case KEY_LEFT:
184                            BBS_last_access_tm = time(NULL);
185                    case KEY_NULL:                   // broken pipe
186                          return EXIT_SECTION; // exit section                          return EXIT_SECTION; // exit section
187                  case KEY_TIMEOUT:                  case KEY_TIMEOUT:
188                          if (time(0) - BBS_last_access_tm >= MAX_DELAY_TIME)                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
189                          {                          {
190                                  return EXIT_SECTION; // exit section                                  return EXIT_SECTION; // exit section
191                          }                          }
192                          continue;                          continue;
193                    case 'n':
194                            BBS_last_access_tm = time(NULL);
195                            return CHANGE_NAME_DISPLAY;
196                  case CR:                  case CR:
197                          igetch_reset();                          igetch_reset();
198                    case 'r':
199                  case KEY_RIGHT:                  case KEY_RIGHT:
200                          if (item_count > 0)                          if (item_count > 0)
201                          {                          {
202                                    BBS_last_access_tm = time(NULL);
203                                  return VIEW_ARTICLE;                                  return VIEW_ARTICLE;
204                          }                          }
205                          break;                          break;
206                    case Ctrl('P'):
207                            return POST_ARTICLE;
208                    case 'E':
209                            return EDIT_ARTICLE;
210                    case 'd':
211                            return DELETE_ARTICLE;
212                  case KEY_HOME:                  case KEY_HOME:
213                          *p_page_id = 0;                          *p_page_id = 0;
214                    case 'P':
215                  case KEY_PGUP:                  case KEY_PGUP:
216                          *p_selected_index = 0;                          *p_selected_index = 0;
217                    case 'k':
218                  case KEY_UP:                  case KEY_UP:
219                          if (*p_selected_index <= 0)                          if (*p_selected_index <= 0)
220                          {                          {
# Line 175  static enum select_cmd_t section_list_se Line 229  static enum select_cmd_t section_list_se
229                                  (*p_selected_index)--;                                  (*p_selected_index)--;
230                          }                          }
231                          break;                          break;
232                    case '$':
233                  case KEY_END:                  case KEY_END:
234                          if (total_page > 0)                          if (total_page > 0)
235                          {                          {
236                                  *p_page_id = total_page - 1;                                  *p_page_id = total_page - 1;
237                          }                          }
238                    case 'N':
239                  case KEY_PGDN:                  case KEY_PGDN:
240                          if (item_count > 0)                          if (item_count > 0)
241                          {                          {
242                                  *p_selected_index = item_count - 1;                                  *p_selected_index = item_count - 1;
243                          }                          }
244                    case 'j':
245                  case KEY_DOWN:                  case KEY_DOWN:
246                          if (*p_selected_index + 1 >= item_count) // next page                          if (*p_selected_index + 1 >= item_count) // next page
247                          {                          {
# Line 193  static enum select_cmd_t section_list_se Line 250  static enum select_cmd_t section_list_se
250                                          (*p_page_id)++;                                          (*p_page_id)++;
251                                          *p_selected_index = 0;                                          *p_selected_index = 0;
252                                  }                                  }
253                                    else // end of last page
254                                    {
255                                            return CHANGE_PAGE; // force refresh pages
256                                    }
257                          }                          }
258                          else                          else
259                          {                          {
260                                  (*p_selected_index)++;                                  (*p_selected_index)++;
261                          }                          }
262                          break;                          break;
263                    case '=':
264                            return FIRST_TOPIC_ARTICLE;
265                    case '\\':
266                            return LAST_TOPIC_ARTICLE;
267                    case 'h':
268                            return SHOW_HELP;
269                  default:                  default:
270                  }                  }
271    
# Line 224  static enum select_cmd_t section_list_se Line 291  static enum select_cmd_t section_list_se
291                          old_selected_index = *p_selected_index;                          old_selected_index = *p_selected_index;
292                  }                  }
293    
294                  BBS_last_access_tm = time(0);                  BBS_last_access_tm = time(NULL);
295                    if (BBS_last_access_tm - last_refresh_tm >= BBS_section_list_load_interval)
296                    {
297                            return CHANGE_PAGE; // force section list refresh
298                    }
299          }          }
300    
301          return EXIT_SECTION;          return EXIT_SECTION;
302  }  }
303    
304    static int display_article_key_handler(int *p_key, DISPLAY_CTX *p_ctx)
305    {
306            switch (*p_key)
307            {
308            case 'p':
309            case Ctrl('X'):
310                    section_topic_view_mode = !section_topic_view_mode;
311            case 0: // Set msg
312                    if (section_topic_view_mode)
313                    {
314                            snprintf(p_ctx->msg, sizeof(p_ctx->msg),
315                                             "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] "
316                                             "同主题阅读[\033[32m↑\033[33m/\033[32m↓\033[33m] "
317                                             "切换[\033[32mp\033[33m] 回复[\033[32mr\033[33m] 帮助[\033[32mh\033[33m] |");
318                    }
319                    else
320                    {
321                            snprintf(p_ctx->msg, sizeof(p_ctx->msg),
322                                             "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] "
323                                             "移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] "
324                                             "切换[\033[32mp\033[33m] 回复[\033[32mr\033[33m] 帮助[\033[32mh\033[33m] |");
325                    }
326                    *p_key = 0;
327                    break;
328            case 'r': // Reply article
329                    return 1;
330            case '=': // First topic article
331                    return 1;
332            case '\\': // Last topic article
333                    return 1;
334            case KEY_UP:
335            case KEY_PGUP:
336            case KEY_HOME:
337                    if (p_ctx->reach_begin)
338                    {
339                            if (section_topic_view_mode)
340                            {
341                                    *p_key = KEY_PGUP;
342                            }
343                            else
344                            {
345                                    *p_key = KEY_UP;
346                            }
347                            return 1;
348                    }
349                    break;
350            case 'k':
351                    if (section_topic_view_mode)
352                    {
353                            *p_key = KEY_PGUP;
354                    }
355                    else
356                    {
357                            *p_key = KEY_UP;
358                    }
359                    return 1;
360            case KEY_DOWN:
361            case KEY_PGDN:
362            case KEY_END:
363                    if (p_ctx->reach_end)
364                    {
365                            if (section_topic_view_mode)
366                            {
367                                    *p_key = KEY_PGDN;
368                            }
369                            else
370                            {
371                                    *p_key = KEY_DOWN;
372                            }
373                            return 1;
374                    }
375                    break;
376            case 'j':
377                    if (section_topic_view_mode)
378                    {
379                            *p_key = KEY_PGDN;
380                    }
381                    else
382                    {
383                            *p_key = KEY_DOWN;
384                    }
385                    return 1;
386            }
387    
388            return 0;
389    }
390    
391  int section_list_display(const char *sname)  int section_list_display(const char *sname)
392  {  {
393            static int display_nickname = 0;
394    
395          SECTION_LIST *p_section;          SECTION_LIST *p_section;
396            char stitle[BBS_section_title_max_len + 1];
397            char master_list[(BBS_username_max_len + 1) * 3 + 1];
398            char page_info_str[LINE_BUFFER_LEN];
399          ARTICLE *p_articles[BBS_article_limit_per_page];          ARTICLE *p_articles[BBS_article_limit_per_page];
400          int article_count;          int article_count;
401            int page_count;
402          int page_id = 0;          int page_id = 0;
403          int selected_index = 0;          int selected_index = 0;
404            ARTICLE_CACHE cache;
405          int ret;          int ret;
406            int loop;
407            int direction;
408            ARTICLE article_new;
409            int page_id_cur;
410    
411          p_section = section_list_find_by_name(sname);          p_section = section_list_find_by_name(sname);
412          if (p_section == NULL)          if (p_section == NULL)
# Line 246  int section_list_display(const char *sna Line 415  int section_list_display(const char *sna
415                  return -1;                  return -1;
416          }          }
417    
418          if (section_list_draw_screen(p_section) < 0)          if ((ret = section_list_rd_lock(p_section)) < 0)
419            {
420                    log_error("section_list_rd_lock(sid = 0) error\n");
421                    return -2;
422            }
423    
424            strncpy(stitle, p_section->stitle, sizeof(stitle) - 1);
425            stitle[sizeof(stitle) - 1] = '\0';
426            strncpy(master_list, p_section->master_list, sizeof(master_list) - 1);
427            master_list[sizeof(master_list) - 1] = '\0';
428    
429            if ((ret = section_list_rd_unlock(p_section)) < 0)
430            {
431                    log_error("section_list_rd_unlock(sid = 0) error\n");
432                    return -2;
433            }
434    
435            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
436          {          {
437                  log_error("section_list_draw_screen() error\n");                  log_error("section_list_draw_screen() error\n");
438                  return -2;                  return -2;
439          }          }
440    
441          if (p_section->visible_article_count > 0)          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);
442            if (ret < 0)
443          {          {
444                  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);
445                  if (ret < 0)                  return -3;
                 {  
                         log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);  
                         return -3;  
                 }  
446          }          }
447          else // empty section  
448            if (article_count == 0) // empty section
449          {          {
                 article_count = 0;  
450                  selected_index = 0;                  selected_index = 0;
451          }          }
452    
453          while (!SYS_server_exit)          while (!SYS_server_exit)
454          {          {
455                  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);
456                  if (ret < 0)                  if (ret < 0)
457                  {                  {
458                          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);
459                          return -4;                          return -4;
460                  }                  }
461    
462                    snprintf(page_info_str, sizeof(page_info_str),
463                                     "\033[33m[第\033[36m%d\033[33m/\033[36m%d\033[33m页]",
464                                     page_id + 1, MAX(page_count, 1));
465    
466                    show_bottom(page_info_str);
467                  iflush();                  iflush();
468    
469                  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);
470                  switch (ret)                  switch (ret)
471                  {                  {
472                  case EXIT_SECTION:                  case EXIT_SECTION:
473                          return 0;                          return 0;
474                  case CHANGE_PAGE:                  case CHANGE_PAGE:
475                          if (p_section->visible_article_count > 0)                          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);
476                            if (ret < 0)
477                            {
478                                    log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
479                                    return -3;
480                            }
481                            if (article_count == 0) // empty section
482                            {
483                                    selected_index = 0;
484                            }
485                            else if (selected_index >= article_count)
486                            {
487                                    selected_index = article_count - 1;
488                            }
489                            break;
490                    case VIEW_ARTICLE:
491                            do
492                          {                          {
493                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count);                                  loop = 0;
494    
495                                    if (article_cache_load(&cache, VAR_ARTICLE_CACHE_DIR, p_articles[selected_index]) < 0)
496                                    {
497                                            log_error("article_cache_load(aid=%d, cid=%d) error\n", p_articles[selected_index]->aid, p_articles[selected_index]->cid);
498                                            break;
499                                    }
500    
501                                    ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 0,
502                                                                       display_article_key_handler, DATA_READ_HELP);
503    
504                                    if (article_cache_unload(&cache) < 0)
505                                    {
506                                            log_error("article_cache_unload(aid=%d, cid=%d) error\n", p_articles[selected_index]->aid, p_articles[selected_index]->cid);
507                                            break;
508                                    }
509    
510                                    // Update article_view_log
511                                    if (article_view_log_set_viewed(p_articles[selected_index]->aid, &BBS_article_view_log) < 0)
512                                    {
513                                            log_error("article_view_log_set_viewed(aid=%d) error\n", p_articles[selected_index]->aid);
514                                    }
515    
516                                    switch (ret)
517                                    {
518                                    case KEY_UP:
519                                            if (selected_index <= 0)
520                                            {
521                                                    if (page_id > 0)
522                                                    {
523                                                            page_id--;
524                                                            selected_index = BBS_article_limit_per_page - 1;
525    
526                                                            ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);
527                                                            if (ret < 0)
528                                                            {
529                                                                    log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
530                                                                    return -3;
531                                                            }
532    
533                                                            if (article_count != BBS_article_limit_per_page) // page is not full
534                                                            {
535                                                                    selected_index = MAX(0, article_count - 1);
536                                                            }
537                                                            else
538                                                            {
539                                                                    loop = 1;
540                                                            }
541                                                    }
542                                            }
543                                            else
544                                            {
545                                                    selected_index--;
546                                                    loop = 1;
547                                            }
548                                            break;
549                                    case KEY_DOWN:
550                                            if (selected_index + 1 >= article_count) // next page
551                                            {
552                                                    if (page_id + 1 < page_count)
553                                                    {
554                                                            page_id++;
555                                                            selected_index = 0;
556    
557                                                            ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);
558                                                            if (ret < 0)
559                                                            {
560                                                                    log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
561                                                                    return -3;
562                                                            }
563    
564                                                            if (article_count == 0) // empty page
565                                                            {
566                                                                    selected_index = 0;
567                                                            }
568                                                            else
569                                                            {
570                                                                    loop = 1;
571                                                            }
572                                                    }
573                                            }
574                                            else
575                                            {
576                                                    selected_index++;
577                                                    loop = 1;
578                                            }
579                                            break;
580                                    case KEY_PGUP:
581                                    case KEY_PGDN:
582                                            direction = (ret == KEY_PGUP ? -1 : 1);
583                                            ret = locate_article_in_section(p_section, p_articles[selected_index], direction, 1,
584                                                                                                            &page_id, &selected_index, &article_count);
585                                            if (ret < 0)
586                                            {
587                                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=1) error\n",
588                                                                      p_section->sid, p_articles[selected_index]->aid, direction);
589                                                    return -3;
590                                            }
591                                            else if (ret > 0) // found
592                                            {
593                                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);
594                                                    if (ret < 0)
595                                                    {
596                                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
597                                                            return -3;
598                                                    }
599                                                    loop = 1;
600                                            }
601                                            break;
602                                    case 'r': // Reply article
603                                            if (article_reply(p_section, p_articles[selected_index], &article_new) < 0)
604                                            {
605                                                    log_error("article_post(aid=%d, REPLY) error\n", p_articles[selected_index]->aid);
606                                            }
607                                            loop = 1;
608                                            break;
609                                    case '=':  // First topic article
610                                    case '\\': // Last topic article
611                                            page_id_cur = page_id;
612                                            direction = (ret == '=' ? -1 : 1);
613                                            ret = locate_article_in_section(p_section, p_articles[selected_index], direction, BBS_article_limit_per_section,
614                                                                                                            &page_id, &selected_index, &article_count);
615                                            if (ret < 0)
616                                            {
617                                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=%d) error\n",
618                                                                      p_section->sid, p_articles[selected_index]->aid, direction, BBS_article_limit_per_section);
619                                                    return -3;
620                                            }
621                                            else if (ret > 0) // found
622                                            {
623                                                    if (page_id != page_id_cur) // page changed
624                                                    {
625                                                            ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);
626                                                            if (ret < 0)
627                                                            {
628                                                                    log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
629                                                                    return -3;
630                                                            }
631                                                    }
632                                                    loop = 1;
633                                            }
634                                            break;
635                                    }
636                            } while (loop);
637    
638                            // Update current topic
639                            section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
640                    case CHANGE_NAME_DISPLAY:
641                            display_nickname = !display_nickname;
642                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
643                            {
644                                    log_error("section_list_draw_screen() error\n");
645                                    return -2;
646                            }
647                            break;
648                    case POST_ARTICLE:
649                            if ((ret = article_post(p_section, &article_new)) < 0)
650                            {
651                                    log_error("article_post(sid=%d) error\n", p_section->sid);
652                            }
653                            else if (ret > 0) // New article posted
654                            {
655                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);
656                                  if (ret < 0)                                  if (ret < 0)
657                                  {                                  {
658                                          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);
659                                          return -3;                                          return -3;
660                                  }                                  }
661                          }                          }
662                          else // empty section                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
663                          {                          {
664                                  article_count = 0;                                  log_error("section_list_draw_screen() error\n");
665                                  selected_index = 0;                                  return -2;
666                          }                          }
667                          if (selected_index >= article_count)                          break;
668                    case EDIT_ARTICLE:
669                            if (!checkpriv(&BBS_priv, p_section->sid, S_POST) ||
670                                    p_articles[selected_index]->uid != BBS_priv.uid)
671                          {                          {
672                                  selected_index = article_count - 1;                                  break; // No permission
673                            }
674                            if (article_modify(p_section, p_articles[selected_index], &article_new) < 0)
675                            {
676                                    log_error("article_modify(aid=%d) error\n", p_articles[selected_index]->aid);
677                            }
678                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
679                            {
680                                    log_error("section_list_draw_screen() error\n");
681                                    return -2;
682                          }                          }
683                          break;                          break;
684                  case VIEW_ARTICLE:                  case DELETE_ARTICLE:
685                          log_std("Debug: article %d selected\n", p_articles[selected_index]->aid);                          if (!checkpriv(&BBS_priv, p_section->sid, S_POST) ||
686                  case REFRESH_SCREEN:                                  (!checkpriv(&BBS_priv, p_section->sid, S_MAN_S) && p_articles[selected_index]->uid != BBS_priv.uid))
687                          if (section_list_draw_screen(p_section) < 0)                          {
688                                    break; // No permission
689                            }
690                            if ((ret = article_del(p_section, p_articles[selected_index])) < 0)
691                            {
692                                    log_error("article_del(aid=%d) error\n", p_articles[selected_index]->aid);
693                            }
694                            else if (ret > 0) // Article deleted
695                            {
696                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);
697                                    if (ret < 0)
698                                    {
699                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
700                                            return -3;
701                                    }
702                            }
703                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
704                            {
705                                    log_error("section_list_draw_screen() error\n");
706                                    return -2;
707                            }
708                            break;
709                    case FIRST_TOPIC_ARTICLE:
710                    case LAST_TOPIC_ARTICLE:
711                            page_id_cur = page_id;
712                            direction = (ret == FIRST_TOPIC_ARTICLE ? -1 : 1);
713                            ret = locate_article_in_section(p_section, p_articles[selected_index], direction, BBS_article_limit_per_section,
714                                                                                            &page_id, &selected_index, &article_count);
715                            if (ret < 0)
716                            {
717                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=%d) error\n",
718                                                      p_section->sid, p_articles[selected_index]->aid, direction, BBS_article_limit_per_section);
719                                    return -3;
720                            }
721                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
722                            {
723                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);
724                                    if (ret < 0)
725                                    {
726                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
727                                            return -3;
728                                    }
729                            }
730                            break;
731                    case SHOW_HELP:
732                            // Display help information
733                            display_file(DATA_READ_HELP, 1);
734                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
735                          {                          {
736                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
737                                  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