/[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.66 by sysadm, Mon Nov 3 07:14:25 2025 UTC Revision 1.81 by sysadm, Wed Dec 17 03:47:00 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     */
8  /***************************************************************************  
9   *                                                                         *  #ifdef HAVE_CONFIG_H
10   *   This program is free software; you can redistribute it and/or modify  *  #include "config.h"
11   *   it under the terms of the GNU General Public License as published by  *  #endif
  *   the Free Software Foundation; either version 3 of the License, or     *  
  *   (at your option) any later version.                                   *  
  *                                                                         *  
  ***************************************************************************/  
12    
13  #include "article_cache.h"  #include "article_cache.h"
14  #include "article_favor.h"  #include "article_favor.h"
# Line 39  Line 35 
35  #include <time.h>  #include <time.h>
36  #include <sys/param.h>  #include <sys/param.h>
37    
38  #define TITLE_SEARCH_MAX_LEN 60  enum _section_list_display_constant_t
39    {
40            TITLE_SEARCH_MAX_LEN = 60,
41    };
42    
43  static int32_t section_aid_locations[BBS_max_section] = {0};  static int32_t section_aid_locations[BBS_max_section] = {0};
44  static int section_topic_view_mode = 0;  static int section_topic_view_mode = 0;
# Line 61  enum select_cmd_t Line 60  enum select_cmd_t
60          UNSET_FAVOR_ARTICLE,          UNSET_FAVOR_ARTICLE,
61          FIRST_TOPIC_ARTICLE,          FIRST_TOPIC_ARTICLE,
62          LAST_TOPIC_ARTICLE,          LAST_TOPIC_ARTICLE,
63            LAST_SECTION_ARTICLE,
64          SCAN_NEW_ARTICLE,          SCAN_NEW_ARTICLE,
65          SCAN_ARTICLE_BACKWARD_BY_USER,          SCAN_ARTICLE_BACKWARD_BY_USER,
66          SCAN_ARTICLE_FORWARD_BY_USER,          SCAN_ARTICLE_FORWARD_BY_USER,
# Line 71  enum select_cmd_t Line 71  enum select_cmd_t
71          SEARCH_USER,          SEARCH_USER,
72  };  };
73    
74  static int section_list_draw_items(int page_id, ARTICLE *p_articles[], int article_count, int display_nickname, int ontop_start_offset)  static int section_list_draw_items(int page_id, const ARTICLE *p_articles[], int article_count, int display_nickname, int ontop_start_offset)
75  {  {
76          char str_time[LINE_BUFFER_LEN];          char str_time[LINE_BUFFER_LEN];
77          struct tm tm_sub;          struct tm tm_sub;
# Line 225  static int section_list_draw_screen(cons Line 225  static int section_list_draw_screen(cons
225    
226          if (master_list[0] != '\0')          if (master_list[0] != '\0')
227          {          {
228                  snprintf(str_section_master, sizeof(str_section_master), "版主:%s", master_list);                  snprintf(str_section_master, sizeof(str_section_master), "版主: %s", master_list);
229          }          }
230          snprintf(str_section_name, sizeof(str_section_name), "讨论区 [%s]", sname);          snprintf(str_section_name, sizeof(str_section_name), "讨论区 [%s]", sname);
231    
# Line 270  static enum select_cmd_t section_list_se Line 270  static enum select_cmd_t section_list_se
270                  if (ch != KEY_NULL && ch != KEY_TIMEOUT)                  if (ch != KEY_NULL && ch != KEY_TIMEOUT)
271                  {                  {
272                          BBS_last_access_tm = time(NULL);                          BBS_last_access_tm = time(NULL);
273    
274                            // Refresh current action
275                            if (user_online_update(NULL) < 0)
276                            {
277                                    log_error("user_online_update(NULL) error\n");
278                            }
279                  }                  }
280    
281                  switch (ch)                  switch (ch)
282                  {                  {
283                  case KEY_NULL: // broken pipe                  case KEY_NULL: // broken pipe
284    #ifdef _DEBUG
285                          log_error("KEY_NULL\n");                          log_error("KEY_NULL\n");
286    #endif
287                          return EXIT_SECTION;                          return EXIT_SECTION;
288                  case KEY_TIMEOUT:                  case KEY_TIMEOUT:
289                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                          if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time)
290                          {                          {
291                                  log_error("User input timeout\n");                                  log_error("User input timeout\n");
292                                  return EXIT_SECTION;                                  return EXIT_SECTION;
# Line 368  static enum select_cmd_t section_list_se Line 376  static enum select_cmd_t section_list_se
376                          break;                          break;
377                  case '$':                  case '$':
378                  case KEY_END:                  case KEY_END:
379                            if (*p_page_id + 1 == total_page && *p_selected_index + 1 == item_count) // Press END at end of list
380                            {
381                                    return LAST_SECTION_ARTICLE;
382                            }
383                          if (total_page > 0)                          if (total_page > 0)
384                          {                          {
385                                  *p_page_id = total_page - 1;                                  *p_page_id = total_page - 1;
# Line 580  int section_list_display(const char *sna Line 592  int section_list_display(const char *sna
592          char stitle[BBS_section_title_max_len + 1];          char stitle[BBS_section_title_max_len + 1];
593          char master_list[(BBS_username_max_len + 1) * 3 + 1];          char master_list[(BBS_username_max_len + 1) * 3 + 1];
594          char page_info_str[LINE_BUFFER_LEN];          char page_info_str[LINE_BUFFER_LEN];
595          ARTICLE *p_articles[BBS_article_limit_per_page];          const ARTICLE *p_articles[BBS_article_limit_per_page];
596          int article_count;          int article_count;
597          int page_count;          int page_count;
598          int ontop_start_offset;          int ontop_start_offset;
# Line 708  int section_list_display(const char *sna Line 720  int section_list_display(const char *sna
720                  {                  {
721                  case EXIT_SECTION:                  case EXIT_SECTION:
722                          // Update current aid location                          // Update current aid location
723                          if (p_articles[selected_index] != NULL)                          if (selected_index < article_count && p_articles[selected_index] != NULL)
724                          {                          {
725                                  section_aid_locations[section_index] = p_articles[selected_index]->aid;                                  if (selected_index >= ontop_start_offset)
726                          }                                  {
727                          else                                          ret = last_article_in_section(p_section, &p_article_locate);
728                          {                                          if (ret < 0)
729                                  log_error("p_articles[selected_index=%d] is NULL when exit section [%s]\n", selected_index, sname);                                          {
730                                                    log_error("last_article_in_section(sid=%d) error\n", p_section->sid);
731                                                    return -3;
732                                            }
733                                            else if (ret == 0)
734                                            {
735                                                    section_aid_locations[section_index] = 0;
736                                            }
737                                            else // ret > 0
738                                            {
739                                                    section_aid_locations[section_index] = p_article_locate->aid;
740                                            }
741                                    }
742                                    else
743                                    {
744                                            section_aid_locations[section_index] = (p_articles[selected_index]->visible ? p_articles[selected_index]->aid : 0);
745                                    }
746                          }                          }
747                          return 0;                          return 0;
748                  case CHANGE_PAGE:                  case CHANGE_PAGE:
# Line 860  int section_list_display(const char *sna Line 888  int section_list_display(const char *sna
888                                          {                                          {
889                                                  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);
890                                          }                                          }
891                                            else if (ret > 0) // Article replied
892                                            {
893                                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
894                                                    if (ret < 0)
895                                                    {
896                                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
897                                                            return -3;
898                                                    }
899                                            }
900                                          loop = 1;                                          loop = 1;
901                                          break;                                          break;
902                                  case '=':  // First topic article                                  case '=':  // First topic article
# Line 923  int section_list_display(const char *sna Line 960  int section_list_display(const char *sna
960                                  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);
961                                  if (ret < 0)                                  if (ret < 0)
962                                  {                                  {
963                                          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);
964                                          return -3;                                          return -3;
965                                  }                                  }
966                          }                          }
# Line 949  int section_list_display(const char *sna Line 986  int section_list_display(const char *sna
986                          {                          {
987                                  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);
988                          }                          }
989                            else if (ret > 0) // Article modified
990                            {
991                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
992                                    if (ret < 0)
993                                    {
994                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
995                                            return -3;
996                                    }
997                            }
998                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
999                          {                          {
1000                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
# Line 967  int section_list_display(const char *sna Line 1013  int section_list_display(const char *sna
1013                          }                          }
1014                          else if (ret > 0) // Article deleted                          else if (ret > 0) // Article deleted
1015                          {                          {
1016                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);                                  do
                                 if (ret < 0)  
1017                                  {                                  {
1018                                          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);
1019                                          return -3;                                          if (ret >= 0 && selected_index > article_count - 1)
1020                                  }                                          {
1021                                                    selected_index = article_count - 1;
1022                                                    break;
1023                                            }
1024                                            else if (ret < 0 && page_id > 0)
1025                                            {
1026                                                    page_id--;
1027                                                    selected_index = BBS_article_limit_per_page - 1;
1028                                            }
1029                                            else if (ret < 0 && page_id <= 0)
1030                                            {
1031                                                    selected_index = 0;
1032                                                    break;
1033                                            }
1034                                    } while (ret < 0);
1035                          }                          }
1036                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
1037                          {                          {
# Line 1058  int section_list_display(const char *sna Line 1117  int section_list_display(const char *sna
1117                                  }                                  }
1118                          }                          }
1119                          break;                          break;
1120                    case LAST_SECTION_ARTICLE:
1121                            page_id_cur = page_id;
1122                            ret = last_article_in_section(p_section, &p_article_locate);
1123                            if (ret < 0)
1124                            {
1125                                    log_error("last_article_in_section(sid=%d) error\n", p_section->sid);
1126                                    return -3;
1127                            }
1128                            else if (ret == 0)
1129                            {
1130                                    break;
1131                            }
1132                            ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
1133                                                                                            &page_id, &selected_index, &article_count);
1134                            if (ret < 0)
1135                            {
1136                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
1137                                                      p_section->sid, p_article_locate->aid);
1138                                    return -3;
1139                            }
1140                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
1141                            {
1142                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
1143                                    if (ret < 0)
1144                                    {
1145                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
1146                                            return -3;
1147                                    }
1148                            }
1149                            break;
1150                  case SCAN_NEW_ARTICLE:                  case SCAN_NEW_ARTICLE:
1151                          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);
1152                          if (ret < 0)                          if (ret < 0)
# Line 1099  int section_list_display(const char *sna Line 1188  int section_list_display(const char *sna
1188                          moveto(SCREEN_ROWS, 1);                          moveto(SCREEN_ROWS, 1);
1189                          clrtoeol();                          clrtoeol();
1190                          get_data(SCREEN_ROWS, 1,                          get_data(SCREEN_ROWS, 1,
1191                                           (direction == 1 ? "向下搜寻作者: " : "向上搜寻作者: "),                                           (direction == 1 ? "↓搜寻作者: " : "↑搜寻作者: "),
1192                                           username, sizeof(username), BBS_username_max_len);                                           username, sizeof(username), BBS_username_max_len);
1193    
1194                          if (username[0] == '\0')                          if (username[0] == '\0')
# Line 1110  int section_list_display(const char *sna Line 1199  int section_list_display(const char *sna
1199                          // Verify format                          // Verify format
1200                          for (i = 0, ok = 1; ok && username[i] != '\0'; i++)                          for (i = 0, ok = 1; ok && username[i] != '\0'; i++)
1201                          {                          {
1202                                  if (!(isalpha(username[i]) || (i > 0 && (isdigit(username[i]) || username[i] == '_'))))                                  if (!(isalpha((int)username[i]) || (i > 0 && (isdigit((int)username[i]) || username[i] == '_'))))
1203                                  {                                  {
1204                                          ok = 0;                                          ok = 0;
1205                                  }                                  }
# Line 1188  int section_list_display(const char *sna Line 1277  int section_list_display(const char *sna
1277                          moveto(SCREEN_ROWS, 1);                          moveto(SCREEN_ROWS, 1);
1278                          clrtoeol();                          clrtoeol();
1279                          get_data(SCREEN_ROWS, 1,                          get_data(SCREEN_ROWS, 1,
1280                                           (direction == 1 ? "向下搜寻标题: " : "向上搜寻标题: "),                                           (direction == 1 ? "↓搜寻标题: " : "↑搜寻标题: "),
1281                                           title, sizeof(title), TITLE_SEARCH_MAX_LEN);                                           title, sizeof(title), TITLE_SEARCH_MAX_LEN);
1282    
1283                          if (title[0] == '\0')                          if (title[0] == '\0')
# Line 1276  int section_list_ex_dir_display(SECTION_ Line 1365  int section_list_ex_dir_display(SECTION_
1365  {  {
1366          MENU_SET ex_menu_set;          MENU_SET ex_menu_set;
1367          int ch = 0;          int ch = 0;
1368            int loop;
1369    
1370          if (p_section == NULL)          if (p_section == NULL)
1371          {          {
# Line 1308  int section_list_ex_dir_display(SECTION_ Line 1398  int section_list_ex_dir_display(SECTION_
1398    
1399          if (display_menu(&ex_menu_set) == 0)          if (display_menu(&ex_menu_set) == 0)
1400          {          {
1401                  while (!SYS_server_exit)                  for (loop = 1; !SYS_server_exit && loop;)
1402                  {                  {
1403                          iflush();                          iflush();
1404                          ch = igetch(100);                          ch = igetch(100);
# Line 1316  int section_list_ex_dir_display(SECTION_ Line 1406  int section_list_ex_dir_display(SECTION_
1406                          if (ch != KEY_NULL && ch != KEY_TIMEOUT)                          if (ch != KEY_NULL && ch != KEY_TIMEOUT)
1407                          {                          {
1408                                  BBS_last_access_tm = time(NULL);                                  BBS_last_access_tm = time(NULL);
1409    
1410                                    // Refresh current action
1411                                    if (user_online_update(NULL) < 0)
1412                                    {
1413                                            log_error("user_online_update(NULL) error\n");
1414                                    }
1415                          }                          }
1416    
1417                          switch (ch)                          switch (ch)
1418                          {                          {
1419                          case KEY_NULL: // broken pipe                          case KEY_NULL: // broken pipe
1420    #ifdef _DEBUG
1421                                  log_error("KEY_NULL\n");                                  log_error("KEY_NULL\n");
1422                                  return 0;  #endif
1423                                    loop = 0;
1424                                    break;
1425                          case KEY_TIMEOUT:                          case KEY_TIMEOUT:
1426                                  if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                                  if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time)
1427                                  {                                  {
1428                                          log_error("User input timeout\n");                                          log_error("User input timeout\n");
1429                                          return 0;                                          loop = 0;
1430                                            break;
1431                                  }                                  }
1432                                  continue;                                  continue;
1433                          case CR:                          case CR:
# Line 1335  int section_list_ex_dir_display(SECTION_ Line 1435  int section_list_ex_dir_display(SECTION_
1435                                  switch (menu_control(&ex_menu_set, ch))                                  switch (menu_control(&ex_menu_set, ch))
1436                                  {                                  {
1437                                  case EXITMENU:                                  case EXITMENU:
1438                                          ch = EXITMENU;                                          loop = 0;
1439                                          break;                                          break;
1440                                  case REDRAW:                                  case REDRAW:
1441                                          clearscr();                                          clearscr();
# Line 1348  int section_list_ex_dir_display(SECTION_ Line 1448  int section_list_ex_dir_display(SECTION_
1448                                          break;                                          break;
1449                                  }                                  }
1450                          }                          }
   
                         if (ch == EXITMENU)  
                         {  
                                 break;  
                         }  
1451                  }                  }
1452          }          }
1453    


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

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