/[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.54 by sysadm, Thu Oct 16 11:26:16 2025 UTC Revision 1.59 by sysadm, Sun Nov 2 08:13:50 2025 UTC
# Line 30  Line 30 
30  #include "section_list_loader.h"  #include "section_list_loader.h"
31  #include "screen.h"  #include "screen.h"
32  #include "str_process.h"  #include "str_process.h"
33    #include "user_info_display.h"
34  #include "user_priv.h"  #include "user_priv.h"
35    #include <errno.h>
36  #include <string.h>  #include <string.h>
37  #include <time.h>  #include <time.h>
38  #include <sys/param.h>  #include <sys/param.h>
39    
40  static int section_aid_locations[BBS_max_section] = {0};  static int32_t section_aid_locations[BBS_max_section] = {0};
41  static int section_topic_view_mode = 0;  static int section_topic_view_mode = 0;
42  static int section_topic_view_tid = -1;  static int section_topic_view_tid = -1;
43    
# Line 50  enum select_cmd_t Line 52  enum select_cmd_t
52          EDIT_ARTICLE,          EDIT_ARTICLE,
53          DELETE_ARTICLE,          DELETE_ARTICLE,
54          QUERY_ARTICLE,          QUERY_ARTICLE,
55            QUERY_USER,
56          SET_FAVOR_ARTICLE,          SET_FAVOR_ARTICLE,
57          UNSET_FAVOR_ARTICLE,          UNSET_FAVOR_ARTICLE,
58          FIRST_TOPIC_ARTICLE,          FIRST_TOPIC_ARTICLE,
# Line 262  static enum select_cmd_t section_list_se Line 265  static enum select_cmd_t section_list_se
265    
266                  switch (ch)                  switch (ch)
267                  {                  {
268                  case KEY_NULL:                   // broken pipe                  case KEY_NULL: // broken pipe
269                          log_error("KEY_NULL\n");                          log_error("KEY_NULL\n");
270                          return EXIT_SECTION;                          return EXIT_SECTION;
271                  case KEY_TIMEOUT:                  case KEY_TIMEOUT:
# Line 278  static enum select_cmd_t section_list_se Line 281  static enum select_cmd_t section_list_se
281                  case 'n':                  case 'n':
282                          return CHANGE_NAME_DISPLAY;                          return CHANGE_NAME_DISPLAY;
283                  case CR:                  case CR:
                         igetch_reset();  
284                  case 'r':                  case 'r':
285                  case KEY_RIGHT:                  case KEY_RIGHT:
286                          if (item_count > 0)                          if (item_count > 0)
# Line 306  static enum select_cmd_t section_list_se Line 308  static enum select_cmd_t section_list_se
308                                  return QUERY_ARTICLE;                                  return QUERY_ARTICLE;
309                          }                          }
310                          break;                          break;
311                    case Ctrl('A'):
312                            if (item_count > 0)
313                            {
314                                    return QUERY_USER;
315                            }
316                            break;
317                  case 'F':                  case 'F':
318                          if (item_count > 0)                          if (item_count > 0)
319                          {                          {
# Line 406  static enum select_cmd_t section_list_se Line 414  static enum select_cmd_t section_list_se
414                  case 'H':                  case 'H':
415                          return SHOW_TOP10;                          return SHOW_TOP10;
416                  default:                  default:
417                            break;
418                  }                  }
419    
420                  if (old_page_id != *p_page_id)                  if (old_page_id != *p_page_id)
# Line 549  int section_list_display(const char *sna Line 558  int section_list_display(const char *sna
558          ARTICLE article_new;          ARTICLE article_new;
559          int page_id_cur;          int page_id_cur;
560          const ARTICLE *p_article_locate;          const ARTICLE *p_article_locate;
561            USER_INFO user_info;
562    
563          p_section = section_list_find_by_name(sname);          p_section = section_list_find_by_name(sname);
564          if (p_section == NULL)          if (p_section == NULL)
# Line 566  int section_list_display(const char *sna Line 576  int section_list_display(const char *sna
576    
577          section_index = get_section_index(p_section);          section_index = get_section_index(p_section);
578    
579          if ((ret = section_list_rd_lock(p_section)) < 0)          if (get_section_info(p_section, NULL, stitle, master_list) < 0)
580          {          {
581                  log_error("section_list_rd_lock(sid = 0) error\n");                  log_error("get_section_info(sid=%d) error\n", p_section->sid);
582                  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;  
583          }          }
584    
585          if (aid == 0)          if (aid == 0)
# Line 943  int section_list_display(const char *sna Line 942  int section_list_display(const char *sna
942                                  return -2;                                  return -2;
943                          }                          }
944                          break;                          break;
945                    case QUERY_USER:
946                            if ((ret = query_user_info_by_uid(p_articles[selected_index]->uid, &user_info)) < 0)
947                            {
948                                    log_error("query_user_info_by_uid(uid=%d) error\n", p_articles[selected_index]->uid);
949                                    return -2;
950                            }
951                            else if (ret == 0)
952                            {
953                                    clearscr();
954                                    prints("该用户已升天");
955                                    press_any_key();
956                            }
957                            else if (user_info_display(&user_info) < 0) // && ret > 0
958                            {
959                                    log_error("user_info_display(uid=%d) error\n", p_articles[selected_index]->uid);
960                            }
961    
962                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
963                            {
964                                    log_error("section_list_draw_screen() error\n");
965                                    return -2;
966                            }
967                            break;
968                  case SET_FAVOR_ARTICLE:                  case SET_FAVOR_ARTICLE:
969                          ret = article_favor_set(p_articles[selected_index]->tid == 0                          ret = article_favor_set(p_articles[selected_index]->tid == 0
970                                                                                  ? p_articles[selected_index]->aid                                                                                  ? p_articles[selected_index]->aid
# Line 1113  int section_list_ex_dir_display(SECTION_ Line 1135  int section_list_ex_dir_display(SECTION_
1135                                  }                                  }
1136                                  continue;                                  continue;
1137                          case CR:                          case CR:
                                 igetch_reset();  
1138                          default:                          default:
1139                                  switch (menu_control(&ex_menu_set, ch))                                  switch (menu_control(&ex_menu_set, ch))
1140                                  {                                  {
# Line 1143  int section_list_ex_dir_display(SECTION_ Line 1164  int section_list_ex_dir_display(SECTION_
1164    
1165          return 0;          return 0;
1166  }  }
1167    
1168    int section_aid_locations_save(int uid)
1169    {
1170            char filename[FILE_PATH_LEN];
1171            FILE *fp;
1172            int i;
1173            int ret = 0;
1174    
1175            snprintf(filename, sizeof(filename), "%s/%d", VAR_SECTION_AID_LOC_DIR, uid);
1176    
1177            if ((fp = fopen(filename, "wb")) == NULL)
1178            {
1179                    log_error("fopen(%s, wb) error: %d\n", filename, errno);
1180                    return -1;
1181            }
1182    
1183            for (i = 0; i < p_section_list_pool->section_count; i++)
1184            {
1185                    if (fwrite(&(p_section_list_pool->sections[i].sid), sizeof(p_section_list_pool->sections[i].sid), 1, fp) != 1)
1186                    {
1187                            log_error("fwrite(%s, sid) error\n", filename);
1188                            ret = -2;
1189                            break;
1190                    }
1191    
1192                    if (fwrite(&(section_aid_locations[i]), sizeof(section_aid_locations[i]), 1, fp) != 1)
1193                    {
1194                            log_error("fwrite(%s, aid) error\n", filename);
1195                            ret = -2;
1196                            break;
1197                    }
1198            }
1199    
1200            if (fclose(fp) < 0)
1201            {
1202                    log_error("fclose(%s) error: %d\n", filename, errno);
1203                    ret = -1;
1204            }
1205    
1206            return ret;
1207    }
1208    
1209    int section_aid_locations_load(int uid)
1210    {
1211            char filename[FILE_PATH_LEN];
1212            FILE *fp;
1213            int i;
1214            int32_t sid;
1215            int32_t aid;
1216            SECTION_LIST *p_section;
1217            int ret = 0;
1218    
1219            snprintf(filename, sizeof(filename), "%s/%d", VAR_SECTION_AID_LOC_DIR, uid);
1220    
1221            if ((fp = fopen(filename, "rb")) == NULL)
1222            {
1223                    if (errno == ENOENT) // file not exist
1224                    {
1225                            return 0;
1226                    }
1227                    log_error("fopen(%s, rb) error: %d\n", filename, errno);
1228                    return -1;
1229            }
1230    
1231            while (!feof(fp))
1232            {
1233                    if (fread(&sid, sizeof(sid), 1, fp) != 1)
1234                    {
1235                            if (ferror(fp) == 0)
1236                            {
1237                                    break;
1238                            }
1239                            log_error("fread(%s, sid) error: %d\n", filename, ferror(fp));
1240                            ret = -2;
1241                            break;
1242                    }
1243    
1244                    if (fread(&aid, sizeof(aid), 1, fp) != 1)
1245                    {
1246                            if (ferror(fp) == 0)
1247                            {
1248                                    break;
1249                            }
1250                            log_error("fread(%s, aid) error: %d\n", filename, ferror(fp));
1251                            ret = -2;
1252                            break;
1253                    }
1254    
1255                    p_section = section_list_find_by_sid(sid);
1256                    if (p_section == NULL)
1257                    {
1258                            continue; // skip section no longer exist
1259                    }
1260    
1261                    i = get_section_index(p_section);
1262                    if (i < 0)
1263                    {
1264                            log_error("get_section_index(sid=%d) error\n", sid);
1265                            ret = -3;
1266                            break;
1267                    }
1268                    section_aid_locations[i] = aid;
1269            }
1270    
1271            if (fclose(fp) < 0)
1272            {
1273                    log_error("fclose(%s) error: %d\n", filename, errno);
1274                    ret = -1;
1275            }
1276    
1277            return ret;
1278    }


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

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