/[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.64 by sysadm, Mon Nov 3 06:43:55 2025 UTC Revision 1.72 by sysadm, Wed Nov 5 04:19:21 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /* SPDX-License-Identifier: GPL-3.0-or-later */
2                                          section_list_display.c  -  description  /*
3                                                           -------------------   * section_list_display
4          Copyright            : (C) 2004-2025 by Leaflet   *   - user interactive feature of section articles list
5          Email                : leaflet@leafok.com   *
6   ***************************************************************************/   * Copyright (C) 2004-2025  Leaflet <leaflet@leafok.com>
7     */
 /***************************************************************************  
  *                                                                         *  
  *   This program is free software; you can redistribute it and/or modify  *  
  *   it under the terms of the GNU General Public License as published by  *  
  *   the Free Software Foundation; either version 3 of the License, or     *  
  *   (at your option) any later version.                                   *  
  *                                                                         *  
  ***************************************************************************/  
8    
9  #include "article_cache.h"  #include "article_cache.h"
10  #include "article_favor.h"  #include "article_favor.h"
# Line 33  Line 25 
25  #include "user_info_display.h"  #include "user_info_display.h"
26  #include "user_list_display.h"  #include "user_list_display.h"
27  #include "user_priv.h"  #include "user_priv.h"
28    #include <ctype.h>
29  #include <errno.h>  #include <errno.h>
30  #include <string.h>  #include <string.h>
31  #include <time.h>  #include <time.h>
32  #include <sys/param.h>  #include <sys/param.h>
33    
34    enum _section_list_display_constant_t
35    {
36            TITLE_SEARCH_MAX_LEN = 60,
37    };
38    
39  static int32_t section_aid_locations[BBS_max_section] = {0};  static int32_t section_aid_locations[BBS_max_section] = {0};
40  static int section_topic_view_mode = 0;  static int section_topic_view_mode = 0;
41  static int section_topic_view_tid = -1;  static int section_topic_view_tid = -1;
# Line 58  enum select_cmd_t Line 56  enum select_cmd_t
56          UNSET_FAVOR_ARTICLE,          UNSET_FAVOR_ARTICLE,
57          FIRST_TOPIC_ARTICLE,          FIRST_TOPIC_ARTICLE,
58          LAST_TOPIC_ARTICLE,          LAST_TOPIC_ARTICLE,
59            LAST_SECTION_ARTICLE,
60          SCAN_NEW_ARTICLE,          SCAN_NEW_ARTICLE,
61          SCAN_ARTICLE_BACKWARD_BY_USER,          SCAN_ARTICLE_BACKWARD_BY_USER,
62          SCAN_ARTICLE_FORWARD_BY_USER,          SCAN_ARTICLE_FORWARD_BY_USER,
63            SCAN_ARTICLE_BACKWARD_BY_TITLE,
64            SCAN_ARTICLE_FORWARD_BY_TITLE,
65          VIEW_EX_DIR,          VIEW_EX_DIR,
66          SHOW_TOP10,          SHOW_TOP10,
67          SEARCH_USER,          SEARCH_USER,
# Line 273  static enum select_cmd_t section_list_se Line 274  static enum select_cmd_t section_list_se
274                          log_error("KEY_NULL\n");                          log_error("KEY_NULL\n");
275                          return EXIT_SECTION;                          return EXIT_SECTION;
276                  case KEY_TIMEOUT:                  case KEY_TIMEOUT:
277                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                          if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time)
278                          {                          {
279                                  log_error("User input timeout\n");                                  log_error("User input timeout\n");
280                                  return EXIT_SECTION;                                  return EXIT_SECTION;
# Line 363  static enum select_cmd_t section_list_se Line 364  static enum select_cmd_t section_list_se
364                          break;                          break;
365                  case '$':                  case '$':
366                  case KEY_END:                  case KEY_END:
367                            if (*p_page_id + 1 == total_page && *p_selected_index + 1 == item_count) // Press END at end of list
368                            {
369                                    return LAST_SECTION_ARTICLE;
370                            }
371                          if (total_page > 0)                          if (total_page > 0)
372                          {                          {
373                                  *p_page_id = total_page - 1;                                  *p_page_id = total_page - 1;
# Line 423  static enum select_cmd_t section_list_se Line 428  static enum select_cmd_t section_list_se
428                                  return SCAN_ARTICLE_FORWARD_BY_USER;                                  return SCAN_ARTICLE_FORWARD_BY_USER;
429                          }                          }
430                          break;                          break;
431                    case '?':
432                            if (item_count > 0)
433                            {
434                                    return SCAN_ARTICLE_BACKWARD_BY_TITLE;
435                            }
436                            break;
437                    case '/':
438                            if (item_count > 0)
439                            {
440                                    return SCAN_ARTICLE_FORWARD_BY_TITLE;
441                            }
442                            break;
443                  case 'u':                  case 'u':
444                          return SEARCH_USER;                          return SEARCH_USER;
445                  case 'h':                  case 'h':
# Line 577  int section_list_display(const char *sna Line 594  int section_list_display(const char *sna
594          int page_id_cur;          int page_id_cur;
595          const ARTICLE *p_article_locate;          const ARTICLE *p_article_locate;
596          USER_INFO user_info;          USER_INFO user_info;
597          char user_intro[BBS_user_intro_max_len];          char user_intro[BBS_user_intro_max_len + 1];
598          char username[BBS_username_max_len + 1];          char username[BBS_username_max_len + 1];
599          char username_list[1][BBS_username_max_len + 1];          char username_list[1][BBS_username_max_len + 1];
600          int32_t uid;          int32_t uid;
601          int i;          int i;
602          int ok;          int ok;
603            char title[BBS_article_title_max_len + 1] = "\0";
604    
605          p_section = section_list_find_by_name(sname);          p_section = section_list_find_by_name(sname);
606          if (p_section == NULL)          if (p_section == NULL)
# Line 692  int section_list_display(const char *sna Line 710  int section_list_display(const char *sna
710                          // Update current aid location                          // Update current aid location
711                          if (p_articles[selected_index] != NULL)                          if (p_articles[selected_index] != NULL)
712                          {                          {
713                                  section_aid_locations[section_index] = p_articles[selected_index]->aid;                                  if (selected_index >= ontop_start_offset)
714                          }                                  {
715                          else                                          ret = last_article_in_section(p_section, &p_article_locate);
716                          {                                          if (ret < 0)
717                                  log_error("p_articles[selected_index=%d] is NULL when exit section [%s]\n", selected_index, sname);                                          {
718                                                    log_error("last_article_in_section(sid=%d) error\n", p_section->sid);
719                                                    return -3;
720                                            }
721                                            else if (ret == 0)
722                                            {
723                                                    section_aid_locations[section_index] = 0;
724                                            }
725                                            else // ret > 0
726                                            {
727                                                    section_aid_locations[section_index] = p_article_locate->aid;
728                                            }
729                                    }
730                                    else
731                                    {
732                                            section_aid_locations[section_index] = (p_articles[selected_index]->visible ? p_articles[selected_index]->aid : 0);
733                                    }
734                          }                          }
735                          return 0;                          return 0;
736                  case CHANGE_PAGE:                  case CHANGE_PAGE:
# Line 842  int section_list_display(const char *sna Line 876  int section_list_display(const char *sna
876                                          {                                          {
877                                                  log_error("article_reply(aid=%d) error\n", p_articles[selected_index]->aid);                                                  log_error("article_reply(aid=%d) error\n", p_articles[selected_index]->aid);
878                                          }                                          }
879                                            else if (ret > 0) // Article replied
880                                            {
881                                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
882                                                    if (ret < 0)
883                                                    {
884                                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
885                                                            return -3;
886                                                    }
887                                            }
888                                          loop = 1;                                          loop = 1;
889                                          break;                                          break;
890                                  case '=':  // First topic article                                  case '=':  // First topic article
# Line 905  int section_list_display(const char *sna Line 948  int section_list_display(const char *sna
948                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
949                                  if (ret < 0)                                  if (ret < 0)
950                                  {                                  {
951                                          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: %d\n", p_section->sid, page_id, ret);
952                                          return -3;                                          return -3;
953                                  }                                  }
954                          }                          }
# Line 931  int section_list_display(const char *sna Line 974  int section_list_display(const char *sna
974                          {                          {
975                                  log_error("article_modify(aid=%d) error\n", p_articles[selected_index]->aid);                                  log_error("article_modify(aid=%d) error\n", p_articles[selected_index]->aid);
976                          }                          }
977                            else if (ret > 0) // Article modified
978                            {
979                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
980                                    if (ret < 0)
981                                    {
982                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
983                                            return -3;
984                                    }
985                            }
986                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
987                          {                          {
988                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
# Line 949  int section_list_display(const char *sna Line 1001  int section_list_display(const char *sna
1001                          }                          }
1002                          else if (ret > 0) // Article deleted                          else if (ret > 0) // Article deleted
1003                          {                          {
1004                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);                                  do
                                 if (ret < 0)  
1005                                  {                                  {
1006                                          log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);                                          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
1007                                          return -3;                                          if (ret >= 0 && selected_index > article_count - 1)
1008                                  }                                          {
1009                                                    selected_index = article_count - 1;
1010                                                    break;
1011                                            }
1012                                            else if (ret < 0 && page_id > 0)
1013                                            {
1014                                                    page_id--;
1015                                                    selected_index = BBS_article_limit_per_page - 1;
1016                                            }
1017                                            else if (ret < 0 && page_id <= 0)
1018                                            {
1019                                                    selected_index = 0;
1020                                                    break;
1021                                            }
1022                                    } while (ret < 0);
1023                          }                          }
1024                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
1025                          {                          {
# Line 1040  int section_list_display(const char *sna Line 1105  int section_list_display(const char *sna
1105                                  }                                  }
1106                          }                          }
1107                          break;                          break;
1108                    case LAST_SECTION_ARTICLE:
1109                            page_id_cur = page_id;
1110                            ret = last_article_in_section(p_section, &p_article_locate);
1111                            if (ret < 0)
1112                            {
1113                                    log_error("last_article_in_section(sid=%d) error\n", p_section->sid);
1114                                    return -3;
1115                            }
1116                            else if (ret == 0)
1117                            {
1118                                    break;
1119                            }
1120                            ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
1121                                                                                            &page_id, &selected_index, &article_count);
1122                            if (ret < 0)
1123                            {
1124                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
1125                                                      p_section->sid, p_article_locate->aid);
1126                                    return -3;
1127                            }
1128                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
1129                            {
1130                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
1131                                    if (ret < 0)
1132                                    {
1133                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
1134                                            return -3;
1135                                    }
1136                            }
1137                            break;
1138                  case SCAN_NEW_ARTICLE:                  case SCAN_NEW_ARTICLE:
1139                          ret = scan_unread_article_in_section(p_section, p_articles[selected_index], &p_article_locate);                          ret = scan_unread_article_in_section(p_section, p_articles[selected_index], &p_article_locate);
1140                          if (ret < 0)                          if (ret < 0)
# Line 1163  int section_list_display(const char *sna Line 1258  int section_list_display(const char *sna
1258                                  }                                  }
1259                          }                          }
1260                          break;                          break;
1261                    case SCAN_ARTICLE_BACKWARD_BY_TITLE:
1262                    case SCAN_ARTICLE_FORWARD_BY_TITLE:
1263                            direction = (ret == SCAN_ARTICLE_FORWARD_BY_TITLE ? 1 : -1);
1264    
1265                            moveto(SCREEN_ROWS, 1);
1266                            clrtoeol();
1267                            get_data(SCREEN_ROWS, 1,
1268                                             (direction == 1 ? "向下搜寻标题: " : "向上搜寻标题: "),
1269                                             title, sizeof(title), TITLE_SEARCH_MAX_LEN);
1270    
1271                            if (title[0] == '\0')
1272                            {
1273                                    break;
1274                            }
1275    
1276                            ret = scan_article_in_section_by_title(p_section, p_articles[selected_index],
1277                                                                                                       direction, title, &p_article_locate);
1278                            if (ret < 0)
1279                            {
1280                                    log_error("scan_article_in_section_by_title(sid=%d, aid=%d, direction=%d, title=%s) error\n",
1281                                                      p_section->sid, p_articles[selected_index]->aid, direction, title);
1282                                    return -3;
1283                            }
1284                            else if (ret == 0) // not found
1285                            {
1286                                    break;
1287                            }
1288    
1289                            page_id_cur = page_id;
1290                            ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
1291                                                                                            &page_id, &selected_index, &article_count);
1292                            if (ret < 0)
1293                            {
1294                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
1295                                                      p_section->sid, p_article_locate->aid);
1296                                    return -3;
1297                            }
1298                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
1299                            {
1300                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
1301                                    if (ret < 0)
1302                                    {
1303                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
1304                                            return -3;
1305                                    }
1306                            }
1307                            break;
1308                  case SEARCH_USER:                  case SEARCH_USER:
1309                          user_list_search();                          user_list_search();
1310                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
# Line 1259  int section_list_ex_dir_display(SECTION_ Line 1401  int section_list_ex_dir_display(SECTION_
1401                                  log_error("KEY_NULL\n");                                  log_error("KEY_NULL\n");
1402                                  return 0;                                  return 0;
1403                          case KEY_TIMEOUT:                          case KEY_TIMEOUT:
1404                                  if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                                  if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time)
1405                                  {                                  {
1406                                          log_error("User input timeout\n");                                          log_error("User input timeout\n");
1407                                          return 0;                                          return 0;


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

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