/[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.53 by sysadm, Wed Oct 15 01:05:18 2025 UTC Revision 1.77 by sysadm, Wed Nov 19 14:34:45 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 30  Line 26 
26  #include "section_list_loader.h"  #include "section_list_loader.h"
27  #include "screen.h"  #include "screen.h"
28  #include "str_process.h"  #include "str_process.h"
29    #include "user_info_display.h"
30    #include "user_list_display.h"
31  #include "user_priv.h"  #include "user_priv.h"
32    #include <ctype.h>
33    #include <errno.h>
34  #include <string.h>  #include <string.h>
35  #include <time.h>  #include <time.h>
36  #include <sys/param.h>  #include <sys/param.h>
37    
38  static int section_aid_locations[BBS_max_section] = {0};  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};
44  static int section_topic_view_mode = 0;  static int section_topic_view_mode = 0;
45  static int section_topic_view_tid = -1;  static int section_topic_view_tid = -1;
46    
# Line 50  enum select_cmd_t Line 55  enum select_cmd_t
55          EDIT_ARTICLE,          EDIT_ARTICLE,
56          DELETE_ARTICLE,          DELETE_ARTICLE,
57          QUERY_ARTICLE,          QUERY_ARTICLE,
58            QUERY_USER,
59          SET_FAVOR_ARTICLE,          SET_FAVOR_ARTICLE,
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,
66            SCAN_ARTICLE_FORWARD_BY_USER,
67            SCAN_ARTICLE_BACKWARD_BY_TITLE,
68            SCAN_ARTICLE_FORWARD_BY_TITLE,
69          VIEW_EX_DIR,          VIEW_EX_DIR,
70          SHOW_TOP10,          SHOW_TOP10,
71            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, ARTICLE *p_articles[], int article_count, int display_nickname, int ontop_start_offset)
# Line 213  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 255  static enum select_cmd_t section_list_se Line 267  static enum select_cmd_t section_list_se
267          {          {
268                  ch = igetch(100);                  ch = igetch(100);
269    
270                  switch (ch)                  if (ch != KEY_NULL && ch != KEY_TIMEOUT)
271                  {                  {
                 case KEY_ESC:  
                 case KEY_LEFT:  
272                          BBS_last_access_tm = time(NULL);                          BBS_last_access_tm = time(NULL);
273                  case KEY_NULL:                   // broken pipe                  }
274                          return EXIT_SECTION; // exit section  
275                    switch (ch)
276                    {
277                    case KEY_NULL: // broken pipe
278                            log_error("KEY_NULL\n");
279                            return EXIT_SECTION;
280                  case KEY_TIMEOUT:                  case KEY_TIMEOUT:
281                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                          if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time)
282                          {                          {
283                                  return EXIT_SECTION; // exit section                                  log_error("User input timeout\n");
284                                    return EXIT_SECTION;
285                          }                          }
286                          continue;                          continue;
287                    case KEY_ESC:
288                    case KEY_LEFT:
289                            return EXIT_SECTION;
290                  case 'n':                  case 'n':
                         BBS_last_access_tm = time(NULL);  
291                          return CHANGE_NAME_DISPLAY;                          return CHANGE_NAME_DISPLAY;
292                  case CR:                  case CR:
                         igetch_reset();  
293                  case 'r':                  case 'r':
294                  case KEY_RIGHT:                  case KEY_RIGHT:
295                          if (item_count > 0)                          if (item_count > 0)
296                          {                          {
                                 BBS_last_access_tm = time(NULL);  
297                                  return VIEW_ARTICLE;                                  return VIEW_ARTICLE;
298                          }                          }
299                          break;                          break;
# Line 301  static enum select_cmd_t section_list_se Line 317  static enum select_cmd_t section_list_se
317                                  return QUERY_ARTICLE;                                  return QUERY_ARTICLE;
318                          }                          }
319                          break;                          break;
320                    case Ctrl('A'):
321                            if (item_count > 0)
322                            {
323                                    return QUERY_USER;
324                            }
325                            break;
326                  case 'F':                  case 'F':
327                          if (item_count > 0)                          if (item_count > 0)
328                          {                          {
# Line 346  static enum select_cmd_t section_list_se Line 368  static enum select_cmd_t section_list_se
368                          break;                          break;
369                  case '$':                  case '$':
370                  case KEY_END:                  case KEY_END:
371                            if (*p_page_id + 1 == total_page && *p_selected_index + 1 == item_count) // Press END at end of list
372                            {
373                                    return LAST_SECTION_ARTICLE;
374                            }
375                          if (total_page > 0)                          if (total_page > 0)
376                          {                          {
377                                  *p_page_id = total_page - 1;                                  *p_page_id = total_page - 1;
# Line 394  static enum select_cmd_t section_list_se Line 420  static enum select_cmd_t section_list_se
420                                  return SCAN_NEW_ARTICLE;                                  return SCAN_NEW_ARTICLE;
421                          }                          }
422                          break;                          break;
423                    case 'A':
424                            if (item_count > 0)
425                            {
426                                    return SCAN_ARTICLE_BACKWARD_BY_USER;
427                            }
428                            break;
429                    case 'a':
430                            if (item_count > 0)
431                            {
432                                    return SCAN_ARTICLE_FORWARD_BY_USER;
433                            }
434                            break;
435                    case '?':
436                            if (item_count > 0)
437                            {
438                                    return SCAN_ARTICLE_BACKWARD_BY_TITLE;
439                            }
440                            break;
441                    case '/':
442                            if (item_count > 0)
443                            {
444                                    return SCAN_ARTICLE_FORWARD_BY_TITLE;
445                            }
446                            break;
447                    case 'u':
448                            return SEARCH_USER;
449                  case 'h':                  case 'h':
450                          return SHOW_HELP;                          return SHOW_HELP;
451                  case 'x':                  case 'x':
# Line 401  static enum select_cmd_t section_list_se Line 453  static enum select_cmd_t section_list_se
453                  case 'H':                  case 'H':
454                          return SHOW_TOP10;                          return SHOW_TOP10;
455                  default:                  default:
456                            break;
457                  }                  }
458    
459                  if (old_page_id != *p_page_id)                  if (old_page_id != *p_page_id)
# Line 425  static enum select_cmd_t section_list_se Line 478  static enum select_cmd_t section_list_se
478                          old_selected_index = *p_selected_index;                          old_selected_index = *p_selected_index;
479                  }                  }
480    
                 BBS_last_access_tm = time(NULL);  
481                  if (BBS_last_access_tm - last_refresh_tm >= BBS_section_list_load_interval)                  if (BBS_last_access_tm - last_refresh_tm >= BBS_section_list_load_interval)
482                  {                  {
483                          return CHANGE_PAGE; // force section list refresh                          return CHANGE_PAGE; // force section list refresh
# Line 545  int section_list_display(const char *sna Line 597  int section_list_display(const char *sna
597          ARTICLE article_new;          ARTICLE article_new;
598          int page_id_cur;          int page_id_cur;
599          const ARTICLE *p_article_locate;          const ARTICLE *p_article_locate;
600            USER_INFO user_info;
601            char user_intro[BBS_user_intro_max_len + 1];
602            char username[BBS_username_max_len + 1];
603            char username_list[1][BBS_username_max_len + 1];
604            int32_t uid;
605            int i;
606            int ok;
607            char title[BBS_article_title_max_len + 1] = "\0";
608    
609          p_section = section_list_find_by_name(sname);          p_section = section_list_find_by_name(sname);
610          if (p_section == NULL)          if (p_section == NULL)
# Line 562  int section_list_display(const char *sna Line 622  int section_list_display(const char *sna
622    
623          section_index = get_section_index(p_section);          section_index = get_section_index(p_section);
624    
625          if ((ret = section_list_rd_lock(p_section)) < 0)          if (get_section_info(p_section, NULL, stitle, master_list) < 0)
626          {          {
627                  log_error("section_list_rd_lock(sid = 0) error\n");                  log_error("get_section_info(sid=%d) error\n", p_section->sid);
628                  return -2;                  return -4;
         }  
   
         strncpy(stitle, p_section->stitle, sizeof(stitle) - 1);  
         stitle[sizeof(stitle) - 1] = '\0';  
         strncpy(master_list, p_section->master_list, sizeof(master_list) - 1);  
         master_list[sizeof(master_list) - 1] = '\0';  
   
         if ((ret = section_list_rd_unlock(p_section)) < 0)  
         {  
                 log_error("section_list_rd_unlock(sid = 0) error\n");  
                 return -2;  
629          }          }
630    
631          if (aid == 0)          if (aid == 0)
# Line 658  int section_list_display(const char *sna Line 707  int section_list_display(const char *sna
707                  }                  }
708    
709                  ret = section_list_select(page_count, article_count, &page_id, &selected_index);                  ret = section_list_select(page_count, article_count, &page_id, &selected_index);
710    
711                  switch (ret)                  switch (ret)
712                  {                  {
713                  case EXIT_SECTION:                  case EXIT_SECTION:
714                            // Update current aid location
715                            if (selected_index < article_count && p_articles[selected_index] != NULL)
716                            {
717                                    if (selected_index >= ontop_start_offset)
718                                    {
719                                            ret = last_article_in_section(p_section, &p_article_locate);
720                                            if (ret < 0)
721                                            {
722                                                    log_error("last_article_in_section(sid=%d) error\n", p_section->sid);
723                                                    return -3;
724                                            }
725                                            else if (ret == 0)
726                                            {
727                                                    section_aid_locations[section_index] = 0;
728                                            }
729                                            else // ret > 0
730                                            {
731                                                    section_aid_locations[section_index] = p_article_locate->aid;
732                                            }
733                                    }
734                                    else
735                                    {
736                                            section_aid_locations[section_index] = (p_articles[selected_index]->visible ? p_articles[selected_index]->aid : 0);
737                                    }
738                            }
739                          return 0;                          return 0;
740                  case CHANGE_PAGE:                  case CHANGE_PAGE:
741                          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);
# Line 805  int section_list_display(const char *sna Line 880  int section_list_display(const char *sna
880                                          {                                          {
881                                                  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);
882                                          }                                          }
883                                            else if (ret > 0) // Article replied
884                                            {
885                                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
886                                                    if (ret < 0)
887                                                    {
888                                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
889                                                            return -3;
890                                                    }
891                                            }
892                                          loop = 1;                                          loop = 1;
893                                          break;                                          break;
894                                  case '=':  // First topic article                                  case '=':  // First topic article
# Line 839  int section_list_display(const char *sna Line 923  int section_list_display(const char *sna
923                          // Update current topic                          // Update current topic
924                          section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);                          section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
925    
                         // Update current aid location  
                         section_aid_locations[section_index] = p_articles[selected_index]->aid;  
   
926                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
927                          {                          {
928                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
# Line 871  int section_list_display(const char *sna Line 952  int section_list_display(const char *sna
952                                  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);
953                                  if (ret < 0)                                  if (ret < 0)
954                                  {                                  {
955                                          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);
956                                          return -3;                                          return -3;
957                                  }                                  }
958                          }                          }
# Line 897  int section_list_display(const char *sna Line 978  int section_list_display(const char *sna
978                          {                          {
979                                  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);
980                          }                          }
981                            else if (ret > 0) // Article modified
982                            {
983                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
984                                    if (ret < 0)
985                                    {
986                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
987                                            return -3;
988                                    }
989                            }
990                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
991                          {                          {
992                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
# Line 915  int section_list_display(const char *sna Line 1005  int section_list_display(const char *sna
1005                          }                          }
1006                          else if (ret > 0) // Article deleted                          else if (ret > 0) // Article deleted
1007                          {                          {
1008                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);                                  do
                                 if (ret < 0)  
1009                                  {                                  {
1010                                          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);
1011                                          return -3;                                          if (ret >= 0 && selected_index > article_count - 1)
1012                                  }                                          {
1013                                                    selected_index = article_count - 1;
1014                                                    break;
1015                                            }
1016                                            else if (ret < 0 && page_id > 0)
1017                                            {
1018                                                    page_id--;
1019                                                    selected_index = BBS_article_limit_per_page - 1;
1020                                            }
1021                                            else if (ret < 0 && page_id <= 0)
1022                                            {
1023                                                    selected_index = 0;
1024                                                    break;
1025                                            }
1026                                    } while (ret < 0);
1027                          }                          }
1028                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
1029                          {                          {
# Line 939  int section_list_display(const char *sna Line 1042  int section_list_display(const char *sna
1042                                  return -2;                                  return -2;
1043                          }                          }
1044                          break;                          break;
1045                    case QUERY_USER:
1046                            if ((ret = query_user_info_by_uid(p_articles[selected_index]->uid, &user_info, user_intro, sizeof(user_intro))) < 0)
1047                            {
1048                                    log_error("query_user_info_by_uid(uid=%d) error\n", p_articles[selected_index]->uid);
1049                                    return -2;
1050                            }
1051                            else if (ret == 0)
1052                            {
1053                                    clearscr();
1054                                    prints("该用户已升天");
1055                                    press_any_key();
1056                            }
1057                            else if (user_info_display(&user_info) < 0) // && ret > 0
1058                            {
1059                                    log_error("user_info_display(uid=%d) error\n", p_articles[selected_index]->uid);
1060                            }
1061    
1062                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
1063                            {
1064                                    log_error("section_list_draw_screen() error\n");
1065                                    return -2;
1066                            }
1067                            break;
1068                  case SET_FAVOR_ARTICLE:                  case SET_FAVOR_ARTICLE:
1069                          ret = article_favor_set(p_articles[selected_index]->tid == 0                          ret = article_favor_set(p_articles[selected_index]->tid == 0
1070                                                                                  ? p_articles[selected_index]->aid                                                                                  ? p_articles[selected_index]->aid
# Line 983  int section_list_display(const char *sna Line 1109  int section_list_display(const char *sna
1109                                  }                                  }
1110                          }                          }
1111                          break;                          break;
1112                    case LAST_SECTION_ARTICLE:
1113                            page_id_cur = page_id;
1114                            ret = last_article_in_section(p_section, &p_article_locate);
1115                            if (ret < 0)
1116                            {
1117                                    log_error("last_article_in_section(sid=%d) error\n", p_section->sid);
1118                                    return -3;
1119                            }
1120                            else if (ret == 0)
1121                            {
1122                                    break;
1123                            }
1124                            ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
1125                                                                                            &page_id, &selected_index, &article_count);
1126                            if (ret < 0)
1127                            {
1128                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
1129                                                      p_section->sid, p_article_locate->aid);
1130                                    return -3;
1131                            }
1132                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
1133                            {
1134                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
1135                                    if (ret < 0)
1136                                    {
1137                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
1138                                            return -3;
1139                                    }
1140                            }
1141                            break;
1142                  case SCAN_NEW_ARTICLE:                  case SCAN_NEW_ARTICLE:
1143                          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);
1144                          if (ret < 0)                          if (ret < 0)
# Line 1014  int section_list_display(const char *sna Line 1170  int section_list_display(const char *sna
1170                                  }                                  }
1171                          }                          }
1172                          break;                          break;
1173                    case SCAN_ARTICLE_BACKWARD_BY_USER:
1174                    case SCAN_ARTICLE_FORWARD_BY_USER:
1175                            direction = (ret == SCAN_ARTICLE_FORWARD_BY_USER ? 1 : -1);
1176                            strncpy(username, p_articles[selected_index]->username, sizeof(username) - 1);
1177                            username[sizeof(username) - 1] = '\0';
1178                            uid = 0;
1179    
1180                            moveto(SCREEN_ROWS, 1);
1181                            clrtoeol();
1182                            get_data(SCREEN_ROWS, 1,
1183                                             (direction == 1 ? "↓搜寻作者: " : "↑搜寻作者: "),
1184                                             username, sizeof(username), BBS_username_max_len);
1185    
1186                            if (username[0] == '\0')
1187                            {
1188                                    break;
1189                            }
1190    
1191                            // Verify format
1192                            for (i = 0, ok = 1; ok && username[i] != '\0'; i++)
1193                            {
1194                                    if (!(isalpha((int)username[i]) || (i > 0 && (isdigit((int)username[i]) || username[i] == '_'))))
1195                                    {
1196                                            ok = 0;
1197                                    }
1198                            }
1199                            if (ok && i > BBS_username_max_len)
1200                            {
1201                                    ok = 0;
1202                            }
1203                            if (!ok)
1204                            {
1205                                    break;
1206                            }
1207    
1208                            ret = query_user_info_by_username(username, 1, &uid, username_list);
1209                            if (ret < 0)
1210                            {
1211                                    log_error("query_user_info_by_username(%s) error\n", username);
1212                                    break;
1213                            }
1214    
1215                            if (uid > 0)
1216                            {
1217                                    ret = scan_article_in_section_by_uid(p_section, p_articles[selected_index],
1218                                                                                                             direction, uid, &p_article_locate);
1219                                    if (ret < 0)
1220                                    {
1221                                            log_error("scan_article_in_section_by_uid(sid=%d, aid=%d, direction=%d, uid=%d) error\n",
1222                                                              p_section->sid, p_articles[selected_index]->aid, direction, uid);
1223                                            return -3;
1224                                    }
1225                                    else if (ret == 0) // not found
1226                                    {
1227                                            break;
1228                                    }
1229                            }
1230                            else // uid == 0
1231                            {
1232                                    ret = scan_article_in_section_by_username(p_section, p_articles[selected_index],
1233                                                                                                                      direction, username, &p_article_locate);
1234                                    if (ret < 0)
1235                                    {
1236                                            log_error("scan_article_in_section_by_username(sid=%d, aid=%d, direction=%d, username=%s) error\n",
1237                                                              p_section->sid, p_articles[selected_index]->aid, direction, username);
1238                                            return -3;
1239                                    }
1240                                    else if (ret == 0) // not found
1241                                    {
1242                                            break;
1243                                    }
1244                            }
1245    
1246                            page_id_cur = page_id;
1247                            ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
1248                                                                                            &page_id, &selected_index, &article_count);
1249                            if (ret < 0)
1250                            {
1251                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
1252                                                      p_section->sid, p_article_locate->aid);
1253                                    return -3;
1254                            }
1255                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
1256                            {
1257                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
1258                                    if (ret < 0)
1259                                    {
1260                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
1261                                            return -3;
1262                                    }
1263                            }
1264                            break;
1265                    case SCAN_ARTICLE_BACKWARD_BY_TITLE:
1266                    case SCAN_ARTICLE_FORWARD_BY_TITLE:
1267                            direction = (ret == SCAN_ARTICLE_FORWARD_BY_TITLE ? 1 : -1);
1268    
1269                            moveto(SCREEN_ROWS, 1);
1270                            clrtoeol();
1271                            get_data(SCREEN_ROWS, 1,
1272                                             (direction == 1 ? "↓搜寻标题: " : "↑搜寻标题: "),
1273                                             title, sizeof(title), TITLE_SEARCH_MAX_LEN);
1274    
1275                            if (title[0] == '\0')
1276                            {
1277                                    break;
1278                            }
1279    
1280                            ret = scan_article_in_section_by_title(p_section, p_articles[selected_index],
1281                                                                                                       direction, title, &p_article_locate);
1282                            if (ret < 0)
1283                            {
1284                                    log_error("scan_article_in_section_by_title(sid=%d, aid=%d, direction=%d, title=%s) error\n",
1285                                                      p_section->sid, p_articles[selected_index]->aid, direction, title);
1286                                    return -3;
1287                            }
1288                            else if (ret == 0) // not found
1289                            {
1290                                    break;
1291                            }
1292    
1293                            page_id_cur = page_id;
1294                            ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
1295                                                                                            &page_id, &selected_index, &article_count);
1296                            if (ret < 0)
1297                            {
1298                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
1299                                                      p_section->sid, p_article_locate->aid);
1300                                    return -3;
1301                            }
1302                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
1303                            {
1304                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
1305                                    if (ret < 0)
1306                                    {
1307                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
1308                                            return -3;
1309                                    }
1310                            }
1311                            break;
1312                    case SEARCH_USER:
1313                            user_list_search();
1314                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
1315                            {
1316                                    log_error("section_list_draw_screen() error\n");
1317                                    return -2;
1318                            }
1319                            break;
1320                  case SHOW_HELP:                  case SHOW_HELP:
1321                          // Display help information                          // Display help information
1322                          display_file(DATA_READ_HELP, 1);                          display_file(DATA_READ_HELP, 1);
# Line 1090  int section_list_ex_dir_display(SECTION_ Line 1393  int section_list_ex_dir_display(SECTION_
1393                  {                  {
1394                          iflush();                          iflush();
1395                          ch = igetch(100);                          ch = igetch(100);
1396    
1397                            if (ch != KEY_NULL && ch != KEY_TIMEOUT)
1398                            {
1399                                    BBS_last_access_tm = time(NULL);
1400                            }
1401    
1402                          switch (ch)                          switch (ch)
1403                          {                          {
1404                          case KEY_NULL: // broken pipe                          case KEY_NULL: // broken pipe
1405                                    log_error("KEY_NULL\n");
1406                                  return 0;                                  return 0;
1407                          case KEY_TIMEOUT:                          case KEY_TIMEOUT:
1408                                  if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                                  if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time)
1409                                  {                                  {
1410                                            log_error("User input timeout\n");
1411                                          return 0;                                          return 0;
1412                                  }                                  }
1413                                  continue;                                  continue;
1414                          case CR:                          case CR:
                                 igetch_reset();  
1415                          default:                          default:
1416                                  switch (menu_control(&ex_menu_set, ch))                                  switch (menu_control(&ex_menu_set, ch))
1417                                  {                                  {
# Line 1120  int section_list_ex_dir_display(SECTION_ Line 1430  int section_list_ex_dir_display(SECTION_
1430                                  }                                  }
1431                          }                          }
1432    
                         BBS_last_access_tm = time(NULL);  
   
1433                          if (ch == EXITMENU)                          if (ch == EXITMENU)
1434                          {                          {
1435                                  break;                                  break;
# Line 1133  int section_list_ex_dir_display(SECTION_ Line 1441  int section_list_ex_dir_display(SECTION_
1441    
1442          return 0;          return 0;
1443  }  }
1444    
1445    int section_aid_locations_save(int uid)
1446    {
1447            char filename[FILE_PATH_LEN];
1448            FILE *fp;
1449            int i;
1450            int ret = 0;
1451    
1452            snprintf(filename, sizeof(filename), "%s/%d", VAR_SECTION_AID_LOC_DIR, uid);
1453    
1454            if ((fp = fopen(filename, "wb")) == NULL)
1455            {
1456                    log_error("fopen(%s, wb) error: %d\n", filename, errno);
1457                    return -1;
1458            }
1459    
1460            for (i = 0; i < p_section_list_pool->section_count; i++)
1461            {
1462                    if (fwrite(&(p_section_list_pool->sections[i].sid), sizeof(p_section_list_pool->sections[i].sid), 1, fp) != 1)
1463                    {
1464                            log_error("fwrite(%s, sid) error\n", filename);
1465                            ret = -2;
1466                            break;
1467                    }
1468    
1469                    if (fwrite(&(section_aid_locations[i]), sizeof(section_aid_locations[i]), 1, fp) != 1)
1470                    {
1471                            log_error("fwrite(%s, aid) error\n", filename);
1472                            ret = -2;
1473                            break;
1474                    }
1475            }
1476    
1477            if (fclose(fp) < 0)
1478            {
1479                    log_error("fclose(%s) error: %d\n", filename, errno);
1480                    ret = -1;
1481            }
1482    
1483            return ret;
1484    }
1485    
1486    int section_aid_locations_load(int uid)
1487    {
1488            char filename[FILE_PATH_LEN];
1489            FILE *fp;
1490            int i;
1491            int32_t sid;
1492            int32_t aid;
1493            SECTION_LIST *p_section;
1494            int ret = 0;
1495    
1496            snprintf(filename, sizeof(filename), "%s/%d", VAR_SECTION_AID_LOC_DIR, uid);
1497    
1498            if ((fp = fopen(filename, "rb")) == NULL)
1499            {
1500                    if (errno == ENOENT) // file not exist
1501                    {
1502                            return 0;
1503                    }
1504                    log_error("fopen(%s, rb) error: %d\n", filename, errno);
1505                    return -1;
1506            }
1507    
1508            while (!feof(fp))
1509            {
1510                    if (fread(&sid, sizeof(sid), 1, fp) != 1)
1511                    {
1512                            if (ferror(fp) == 0)
1513                            {
1514                                    break;
1515                            }
1516                            log_error("fread(%s, sid) error: %d\n", filename, ferror(fp));
1517                            ret = -2;
1518                            break;
1519                    }
1520    
1521                    if (fread(&aid, sizeof(aid), 1, fp) != 1)
1522                    {
1523                            if (ferror(fp) == 0)
1524                            {
1525                                    break;
1526                            }
1527                            log_error("fread(%s, aid) error: %d\n", filename, ferror(fp));
1528                            ret = -2;
1529                            break;
1530                    }
1531    
1532                    p_section = section_list_find_by_sid(sid);
1533                    if (p_section == NULL)
1534                    {
1535                            continue; // skip section no longer exist
1536                    }
1537    
1538                    i = get_section_index(p_section);
1539                    if (i < 0)
1540                    {
1541                            log_error("get_section_index(sid=%d) error\n", sid);
1542                            ret = -3;
1543                            break;
1544                    }
1545                    section_aid_locations[i] = aid;
1546            }
1547    
1548            if (fclose(fp) < 0)
1549            {
1550                    log_error("fclose(%s) error: %d\n", filename, errno);
1551                    ret = -1;
1552            }
1553    
1554            return ret;
1555    }


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

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