/[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.58 by sysadm, Wed Oct 29 01:48:46 2025 UTC Revision 1.60 by sysadm, Sun Nov 2 08:35:23 2025 UTC
# Line 32  Line 32 
32  #include "str_process.h"  #include "str_process.h"
33  #include "user_info_display.h"  #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 660  int section_list_display(const char *sna Line 661  int section_list_display(const char *sna
661                  }                  }
662    
663                  ret = section_list_select(page_count, article_count, &page_id, &selected_index);                  ret = section_list_select(page_count, article_count, &page_id, &selected_index);
664    
665                    // Update current aid location
666                    section_aid_locations[section_index] = p_articles[selected_index]->aid;
667    
668                  switch (ret)                  switch (ret)
669                  {                  {
670                  case EXIT_SECTION:                  case EXIT_SECTION:
# Line 841  int section_list_display(const char *sna Line 846  int section_list_display(const char *sna
846                          // Update current topic                          // Update current topic
847                          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);
848    
                         // Update current aid location  
                         section_aid_locations[section_index] = p_articles[selected_index]->aid;  
   
849                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
850                          {                          {
851                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
# Line 1163  int section_list_ex_dir_display(SECTION_ Line 1165  int section_list_ex_dir_display(SECTION_
1165    
1166          return 0;          return 0;
1167  }  }
1168    
1169    int section_aid_locations_save(int uid)
1170    {
1171            char filename[FILE_PATH_LEN];
1172            FILE *fp;
1173            int i;
1174            int ret = 0;
1175    
1176            snprintf(filename, sizeof(filename), "%s/%d", VAR_SECTION_AID_LOC_DIR, uid);
1177    
1178            if ((fp = fopen(filename, "wb")) == NULL)
1179            {
1180                    log_error("fopen(%s, wb) error: %d\n", filename, errno);
1181                    return -1;
1182            }
1183    
1184            for (i = 0; i < p_section_list_pool->section_count; i++)
1185            {
1186                    if (fwrite(&(p_section_list_pool->sections[i].sid), sizeof(p_section_list_pool->sections[i].sid), 1, fp) != 1)
1187                    {
1188                            log_error("fwrite(%s, sid) error\n", filename);
1189                            ret = -2;
1190                            break;
1191                    }
1192    
1193                    if (fwrite(&(section_aid_locations[i]), sizeof(section_aid_locations[i]), 1, fp) != 1)
1194                    {
1195                            log_error("fwrite(%s, aid) error\n", filename);
1196                            ret = -2;
1197                            break;
1198                    }
1199            }
1200    
1201            if (fclose(fp) < 0)
1202            {
1203                    log_error("fclose(%s) error: %d\n", filename, errno);
1204                    ret = -1;
1205            }
1206    
1207            return ret;
1208    }
1209    
1210    int section_aid_locations_load(int uid)
1211    {
1212            char filename[FILE_PATH_LEN];
1213            FILE *fp;
1214            int i;
1215            int32_t sid;
1216            int32_t aid;
1217            SECTION_LIST *p_section;
1218            int ret = 0;
1219    
1220            snprintf(filename, sizeof(filename), "%s/%d", VAR_SECTION_AID_LOC_DIR, uid);
1221    
1222            if ((fp = fopen(filename, "rb")) == NULL)
1223            {
1224                    if (errno == ENOENT) // file not exist
1225                    {
1226                            return 0;
1227                    }
1228                    log_error("fopen(%s, rb) error: %d\n", filename, errno);
1229                    return -1;
1230            }
1231    
1232            while (!feof(fp))
1233            {
1234                    if (fread(&sid, sizeof(sid), 1, fp) != 1)
1235                    {
1236                            if (ferror(fp) == 0)
1237                            {
1238                                    break;
1239                            }
1240                            log_error("fread(%s, sid) error: %d\n", filename, ferror(fp));
1241                            ret = -2;
1242                            break;
1243                    }
1244    
1245                    if (fread(&aid, sizeof(aid), 1, fp) != 1)
1246                    {
1247                            if (ferror(fp) == 0)
1248                            {
1249                                    break;
1250                            }
1251                            log_error("fread(%s, aid) error: %d\n", filename, ferror(fp));
1252                            ret = -2;
1253                            break;
1254                    }
1255    
1256                    p_section = section_list_find_by_sid(sid);
1257                    if (p_section == NULL)
1258                    {
1259                            continue; // skip section no longer exist
1260                    }
1261    
1262                    i = get_section_index(p_section);
1263                    if (i < 0)
1264                    {
1265                            log_error("get_section_index(sid=%d) error\n", sid);
1266                            ret = -3;
1267                            break;
1268                    }
1269                    section_aid_locations[i] = aid;
1270            }
1271    
1272            if (fclose(fp) < 0)
1273            {
1274                    log_error("fclose(%s) error: %d\n", filename, errno);
1275                    ret = -1;
1276            }
1277    
1278            return ret;
1279    }


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

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