/[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.62 by sysadm, Sun Nov 2 15:11:47 2025 UTC Revision 1.68 by sysadm, Tue Nov 4 06:36:52 2025 UTC
# Line 31  Line 31 
31  #include "screen.h"  #include "screen.h"
32  #include "str_process.h"  #include "str_process.h"
33  #include "user_info_display.h"  #include "user_info_display.h"
34    #include "user_list_display.h"
35  #include "user_priv.h"  #include "user_priv.h"
36    #include <ctype.h>
37  #include <errno.h>  #include <errno.h>
38  #include <string.h>  #include <string.h>
39  #include <time.h>  #include <time.h>
40  #include <sys/param.h>  #include <sys/param.h>
41    
42    #define TITLE_SEARCH_MAX_LEN 60
43    
44  static int32_t section_aid_locations[BBS_max_section] = {0};  static int32_t section_aid_locations[BBS_max_section] = {0};
45  static int section_topic_view_mode = 0;  static int section_topic_view_mode = 0;
46  static int section_topic_view_tid = -1;  static int section_topic_view_tid = -1;
# Line 57  enum select_cmd_t Line 61  enum select_cmd_t
61          UNSET_FAVOR_ARTICLE,          UNSET_FAVOR_ARTICLE,
62          FIRST_TOPIC_ARTICLE,          FIRST_TOPIC_ARTICLE,
63          LAST_TOPIC_ARTICLE,          LAST_TOPIC_ARTICLE,
64            LAST_SECTION_ARTICLE,
65          SCAN_NEW_ARTICLE,          SCAN_NEW_ARTICLE,
66            SCAN_ARTICLE_BACKWARD_BY_USER,
67            SCAN_ARTICLE_FORWARD_BY_USER,
68            SCAN_ARTICLE_BACKWARD_BY_TITLE,
69            SCAN_ARTICLE_FORWARD_BY_TITLE,
70          VIEW_EX_DIR,          VIEW_EX_DIR,
71          SHOW_TOP10,          SHOW_TOP10,
72            SEARCH_USER,
73  };  };
74    
75  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 359  static enum select_cmd_t section_list_se Line 369  static enum select_cmd_t section_list_se
369                          break;                          break;
370                  case '$':                  case '$':
371                  case KEY_END:                  case KEY_END:
372                            if (*p_page_id + 1 == total_page && *p_selected_index + 1 == item_count) // Press END at end of list
373                            {
374                                    return LAST_SECTION_ARTICLE;
375                            }
376                          if (total_page > 0)                          if (total_page > 0)
377                          {                          {
378                                  *p_page_id = total_page - 1;                                  *p_page_id = total_page - 1;
# Line 407  static enum select_cmd_t section_list_se Line 421  static enum select_cmd_t section_list_se
421                                  return SCAN_NEW_ARTICLE;                                  return SCAN_NEW_ARTICLE;
422                          }                          }
423                          break;                          break;
424                    case 'A':
425                            if (item_count > 0)
426                            {
427                                    return SCAN_ARTICLE_BACKWARD_BY_USER;
428                            }
429                            break;
430                    case 'a':
431                            if (item_count > 0)
432                            {
433                                    return SCAN_ARTICLE_FORWARD_BY_USER;
434                            }
435                            break;
436                    case '?':
437                            if (item_count > 0)
438                            {
439                                    return SCAN_ARTICLE_BACKWARD_BY_TITLE;
440                            }
441                            break;
442                    case '/':
443                            if (item_count > 0)
444                            {
445                                    return SCAN_ARTICLE_FORWARD_BY_TITLE;
446                            }
447                            break;
448                    case 'u':
449                            return SEARCH_USER;
450                  case 'h':                  case 'h':
451                          return SHOW_HELP;                          return SHOW_HELP;
452                  case 'x':                  case 'x':
# Line 559  int section_list_display(const char *sna Line 599  int section_list_display(const char *sna
599          int page_id_cur;          int page_id_cur;
600          const ARTICLE *p_article_locate;          const ARTICLE *p_article_locate;
601          USER_INFO user_info;          USER_INFO user_info;
602          char user_intro[BBS_user_intro_max_len];          char user_intro[BBS_user_intro_max_len + 1];
603            char username[BBS_username_max_len + 1];
604            char username_list[1][BBS_username_max_len + 1];
605            int32_t uid;
606            int i;
607            int ok;
608            char title[BBS_article_title_max_len + 1] = "\0";
609    
610          p_section = section_list_find_by_name(sname);          p_section = section_list_find_by_name(sname);
611          if (p_section == NULL)          if (p_section == NULL)
# Line 669  int section_list_display(const char *sna Line 715  int section_list_display(const char *sna
715                          // Update current aid location                          // Update current aid location
716                          if (p_articles[selected_index] != NULL)                          if (p_articles[selected_index] != NULL)
717                          {                          {
718                                  section_aid_locations[section_index] = p_articles[selected_index]->aid;                                  if (selected_index >= ontop_start_offset)
719                          }                                  {
720                          else                                          ret = last_article_in_section(p_section, &p_article_locate);
721                          {                                          if (ret < 0)
722                                  log_error("p_articles[selected_index=%d] is NULL when exit section [%s]\n", selected_index, sname);                                          {
723                                                    log_error("last_article_in_section(sid=%d) error\n", p_section->sid);
724                                                    return -3;
725                                            }
726                                            else if (ret == 0)
727                                            {
728                                                    section_aid_locations[section_index] = 0;
729                                            }
730                                            else // ret > 0
731                                            {
732                                                    section_aid_locations[section_index] = p_article_locate->aid;
733                                            }
734                                    }
735                                    else
736                                    {
737                                            section_aid_locations[section_index] = (p_articles[selected_index]->visible ? p_articles[selected_index]->aid : 0);
738                                    }
739                          }                          }
740                          return 0;                          return 0;
741                  case CHANGE_PAGE:                  case CHANGE_PAGE:
# Line 819  int section_list_display(const char *sna Line 881  int section_list_display(const char *sna
881                                          {                                          {
882                                                  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);
883                                          }                                          }
884                                            else if (ret > 0) // Article replied
885                                            {
886                                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
887                                                    if (ret < 0)
888                                                    {
889                                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
890                                                            return -3;
891                                                    }
892                                            }
893                                          loop = 1;                                          loop = 1;
894                                          break;                                          break;
895                                  case '=':  // First topic article                                  case '=':  // First topic article
# Line 882  int section_list_display(const char *sna Line 953  int section_list_display(const char *sna
953                                  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);
954                                  if (ret < 0)                                  if (ret < 0)
955                                  {                                  {
956                                          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);
957                                          return -3;                                          return -3;
958                                  }                                  }
959                          }                          }
# Line 908  int section_list_display(const char *sna Line 979  int section_list_display(const char *sna
979                          {                          {
980                                  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);
981                          }                          }
982                            else if (ret > 0) // Article modified
983                            {
984                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
985                                    if (ret < 0)
986                                    {
987                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
988                                            return -3;
989                                    }
990                            }
991                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
992                          {                          {
993                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
# Line 926  int section_list_display(const char *sna Line 1006  int section_list_display(const char *sna
1006                          }                          }
1007                          else if (ret > 0) // Article deleted                          else if (ret > 0) // Article deleted
1008                          {                          {
1009                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);                                  do
                                 if (ret < 0)  
1010                                  {                                  {
1011                                          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);
1012                                          return -3;                                          if (ret >= 0 && selected_index > article_count - 1)
1013                                  }                                          {
1014                                                    selected_index = article_count - 1;
1015                                                    break;
1016                                            }
1017                                            else if (ret < 0 && page_id > 0)
1018                                            {
1019                                                    page_id--;
1020                                                    selected_index = BBS_article_limit_per_page - 1;
1021                                            }
1022                                            else if (ret < 0 && page_id <= 0)
1023                                            {
1024                                                    selected_index = 0;
1025                                                    break;
1026                                            }
1027                                    } while (ret < 0);
1028                          }                          }
1029                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
1030                          {                          {
# Line 1017  int section_list_display(const char *sna Line 1110  int section_list_display(const char *sna
1110                                  }                                  }
1111                          }                          }
1112                          break;                          break;
1113                    case LAST_SECTION_ARTICLE:
1114                            page_id_cur = page_id;
1115                            ret = last_article_in_section(p_section, &p_article_locate);
1116                            if (ret < 0)
1117                            {
1118                                    log_error("last_article_in_section(sid=%d) error\n", p_section->sid);
1119                                    return -3;
1120                            }
1121                            else if (ret == 0)
1122                            {
1123                                    break;
1124                            }
1125                            ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
1126                                                                                            &page_id, &selected_index, &article_count);
1127                            if (ret < 0)
1128                            {
1129                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
1130                                                      p_section->sid, p_article_locate->aid);
1131                                    return -3;
1132                            }
1133                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
1134                            {
1135                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
1136                                    if (ret < 0)
1137                                    {
1138                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
1139                                            return -3;
1140                                    }
1141                            }
1142                            break;
1143                  case SCAN_NEW_ARTICLE:                  case SCAN_NEW_ARTICLE:
1144                          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);
1145                          if (ret < 0)                          if (ret < 0)
# Line 1048  int section_list_display(const char *sna Line 1171  int section_list_display(const char *sna
1171                                  }                                  }
1172                          }                          }
1173                          break;                          break;
1174                    case SCAN_ARTICLE_BACKWARD_BY_USER:
1175                    case SCAN_ARTICLE_FORWARD_BY_USER:
1176                            direction = (ret == SCAN_ARTICLE_FORWARD_BY_USER ? 1 : -1);
1177                            strncpy(username, p_articles[selected_index]->username, sizeof(username) - 1);
1178                            username[sizeof(username) - 1] = '\0';
1179                            uid = 0;
1180    
1181                            moveto(SCREEN_ROWS, 1);
1182                            clrtoeol();
1183                            get_data(SCREEN_ROWS, 1,
1184                                             (direction == 1 ? "向下搜寻作者: " : "向上搜寻作者: "),
1185                                             username, sizeof(username), BBS_username_max_len);
1186    
1187                            if (username[0] == '\0')
1188                            {
1189                                    break;
1190                            }
1191    
1192                            // Verify format
1193                            for (i = 0, ok = 1; ok && username[i] != '\0'; i++)
1194                            {
1195                                    if (!(isalpha(username[i]) || (i > 0 && (isdigit(username[i]) || username[i] == '_'))))
1196                                    {
1197                                            ok = 0;
1198                                    }
1199                            }
1200                            if (ok && i > BBS_username_max_len)
1201                            {
1202                                    ok = 0;
1203                            }
1204                            if (!ok)
1205                            {
1206                                    break;
1207                            }
1208    
1209                            ret = query_user_info_by_username(username, 1, &uid, username_list);
1210                            if (ret < 0)
1211                            {
1212                                    log_error("query_user_info_by_username(%s) error\n", username);
1213                                    break;
1214                            }
1215    
1216                            if (uid > 0)
1217                            {
1218                                    ret = scan_article_in_section_by_uid(p_section, p_articles[selected_index],
1219                                                                                                             direction, uid, &p_article_locate);
1220                                    if (ret < 0)
1221                                    {
1222                                            log_error("scan_article_in_section_by_uid(sid=%d, aid=%d, direction=%d, uid=%d) error\n",
1223                                                              p_section->sid, p_articles[selected_index]->aid, direction, uid);
1224                                            return -3;
1225                                    }
1226                                    else if (ret == 0) // not found
1227                                    {
1228                                            break;
1229                                    }
1230                            }
1231                            else // uid == 0
1232                            {
1233                                    ret = scan_article_in_section_by_username(p_section, p_articles[selected_index],
1234                                                                                                                      direction, username, &p_article_locate);
1235                                    if (ret < 0)
1236                                    {
1237                                            log_error("scan_article_in_section_by_username(sid=%d, aid=%d, direction=%d, username=%s) error\n",
1238                                                              p_section->sid, p_articles[selected_index]->aid, direction, username);
1239                                            return -3;
1240                                    }
1241                                    else if (ret == 0) // not found
1242                                    {
1243                                            break;
1244                                    }
1245                            }
1246    
1247                            page_id_cur = page_id;
1248                            ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
1249                                                                                            &page_id, &selected_index, &article_count);
1250                            if (ret < 0)
1251                            {
1252                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
1253                                                      p_section->sid, p_article_locate->aid);
1254                                    return -3;
1255                            }
1256                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
1257                            {
1258                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
1259                                    if (ret < 0)
1260                                    {
1261                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
1262                                            return -3;
1263                                    }
1264                            }
1265                            break;
1266                    case SCAN_ARTICLE_BACKWARD_BY_TITLE:
1267                    case SCAN_ARTICLE_FORWARD_BY_TITLE:
1268                            direction = (ret == SCAN_ARTICLE_FORWARD_BY_TITLE ? 1 : -1);
1269    
1270                            moveto(SCREEN_ROWS, 1);
1271                            clrtoeol();
1272                            get_data(SCREEN_ROWS, 1,
1273                                             (direction == 1 ? "向下搜寻标题: " : "向上搜寻标题: "),
1274                                             title, sizeof(title), TITLE_SEARCH_MAX_LEN);
1275    
1276                            if (title[0] == '\0')
1277                            {
1278                                    break;
1279                            }
1280    
1281                            ret = scan_article_in_section_by_title(p_section, p_articles[selected_index],
1282                                                                                                       direction, title, &p_article_locate);
1283                            if (ret < 0)
1284                            {
1285                                    log_error("scan_article_in_section_by_title(sid=%d, aid=%d, direction=%d, title=%s) error\n",
1286                                                      p_section->sid, p_articles[selected_index]->aid, direction, title);
1287                                    return -3;
1288                            }
1289                            else if (ret == 0) // not found
1290                            {
1291                                    break;
1292                            }
1293    
1294                            page_id_cur = page_id;
1295                            ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
1296                                                                                            &page_id, &selected_index, &article_count);
1297                            if (ret < 0)
1298                            {
1299                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
1300                                                      p_section->sid, p_article_locate->aid);
1301                                    return -3;
1302                            }
1303                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
1304                            {
1305                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
1306                                    if (ret < 0)
1307                                    {
1308                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
1309                                            return -3;
1310                                    }
1311                            }
1312                            break;
1313                    case SEARCH_USER:
1314                            user_list_search();
1315                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
1316                            {
1317                                    log_error("section_list_draw_screen() error\n");
1318                                    return -2;
1319                            }
1320                            break;
1321                  case SHOW_HELP:                  case SHOW_HELP:
1322                          // Display help information                          // Display help information
1323                          display_file(DATA_READ_HELP, 1);                          display_file(DATA_READ_HELP, 1);


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

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