/[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.44 by sysadm, Wed Oct 1 08:58:25 2025 UTC Revision 1.49 by sysadm, Mon Oct 13 07:40:35 2025 UTC
# Line 24  Line 24 
24  #include "log.h"  #include "log.h"
25  #include "login.h"  #include "login.h"
26  #include "menu.h"  #include "menu.h"
27    #include "menu_proc.h"
28  #include "section_list_display.h"  #include "section_list_display.h"
29  #include "section_list_loader.h"  #include "section_list_loader.h"
30  #include "screen.h"  #include "screen.h"
# Line 33  Line 34 
34  #include <time.h>  #include <time.h>
35  #include <sys/param.h>  #include <sys/param.h>
36    
37    static int section_aid_locations[BBS_max_section] = {0};
38  static int section_topic_view_mode = 0;  static int section_topic_view_mode = 0;
39  static int section_topic_view_tid = -1;  static int section_topic_view_tid = -1;
40    
# Line 49  enum select_cmd_t Line 51  enum select_cmd_t
51          QUERY_ARTICLE,          QUERY_ARTICLE,
52          FIRST_TOPIC_ARTICLE,          FIRST_TOPIC_ARTICLE,
53          LAST_TOPIC_ARTICLE,          LAST_TOPIC_ARTICLE,
54            SCAN_NEW_ARTICLE,
55          VIEW_EX_DIR,          VIEW_EX_DIR,
56            SHOW_TOP10,
57  };  };
58    
59  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 352  static enum select_cmd_t section_list_se Line 356  static enum select_cmd_t section_list_se
356                                  return LAST_TOPIC_ARTICLE;                                  return LAST_TOPIC_ARTICLE;
357                          }                          }
358                          break;                          break;
359                    case 'S':
360                            if (item_count > 0)
361                            {
362                                    return SCAN_NEW_ARTICLE;
363                            }
364                            break;
365                  case 'h':                  case 'h':
366                          return SHOW_HELP;                          return SHOW_HELP;
367                  case 'x':                  case 'x':
368                          return VIEW_EX_DIR;                          return VIEW_EX_DIR;
369                    case 'H':
370                            return SHOW_TOP10;
371                  default:                  default:
372                  }                  }
373    
# Line 478  static int display_article_key_handler(i Line 490  static int display_article_key_handler(i
490          return 0;          return 0;
491  }  }
492    
493  int section_list_display(const char *sname)  int section_list_display(const char *sname, int32_t aid)
494  {  {
495          static int display_nickname = 0;          static int display_nickname = 0;
496    
497          SECTION_LIST *p_section;          SECTION_LIST *p_section;
498            int64_t section_index;
499            int32_t aid_location;
500          char stitle[BBS_section_title_max_len + 1];          char stitle[BBS_section_title_max_len + 1];
501          char master_list[(BBS_username_max_len + 1) * 3 + 1];          char master_list[(BBS_username_max_len + 1) * 3 + 1];
502          char page_info_str[LINE_BUFFER_LEN];          char page_info_str[LINE_BUFFER_LEN];
# Line 498  int section_list_display(const char *sna Line 512  int section_list_display(const char *sna
512          int direction;          int direction;
513          ARTICLE article_new;          ARTICLE article_new;
514          int page_id_cur;          int page_id_cur;
515            const ARTICLE *p_article_locate;
516    
517          p_section = section_list_find_by_name(sname);          p_section = section_list_find_by_name(sname, &section_index);
518          if (p_section == NULL)          if (p_section == NULL)
519          {          {
520                  log_error("Section %s not found\n", sname);                  log_error("Section %s not found\n", sname);
# Line 523  int section_list_display(const char *sna Line 538  int section_list_display(const char *sna
538                  return -2;                  return -2;
539          }          }
540    
541            if (aid == 0)
542            {
543                    aid_location = section_aid_locations[section_index];
544            }
545            else
546            {
547                    aid_location = aid;
548            }      
549    
550            // Locate at article with aid_locate
551            if (aid_location > 0)
552            {
553                    p_article_locate = article_block_find_by_aid(aid_location);
554                    if (p_article_locate == NULL)
555                    {
556                            log_error("article_block_find_by_aid(%d) error\n", aid_location);
557                            return -3;
558                    }
559    
560                    ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
561                                                                                    &page_id, &selected_index, &article_count);
562                    if (ret < 0)
563                    {
564                            log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
565                                              p_section->sid, p_article_locate->aid);
566                            return -3;
567                    }
568            }
569    
570          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
571          {          {
572                  log_error("section_list_draw_screen() error\n");                  log_error("section_list_draw_screen() error\n");
# Line 536  int section_list_display(const char *sna Line 580  int section_list_display(const char *sna
580                  return -3;                  return -3;
581          }          }
582    
583            section_topic_view_tid = -1;
584    
585          if (article_count == 0) // empty section          if (article_count == 0) // empty section
586          {          {
587                  selected_index = 0;                  selected_index = 0;
588          }          }
589            else if (aid > 0)
590            {
591                    // Update current topic
592                    section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
593    
594                    // Update current aid location
595                    section_aid_locations[section_index] = p_articles[selected_index]->aid;
596            }
597    
598          while (!SYS_server_exit)          while (!SYS_server_exit)
599          {          {
# Line 744  int section_list_display(const char *sna Line 798  int section_list_display(const char *sna
798                          // Update current topic                          // Update current topic
799                          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);
800    
801                            // Update current aid location
802                            section_aid_locations[section_index] = p_articles[selected_index]->aid;
803    
804                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
805                          {                          {
806                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
# Line 863  int section_list_display(const char *sna Line 920  int section_list_display(const char *sna
920                                  }                                  }
921                          }                          }
922                          break;                          break;
923                    case SCAN_NEW_ARTICLE:
924                            ret = scan_unread_article_in_section(p_section, p_articles[selected_index], &p_article_locate);
925                            if (ret < 0)
926                            {
927                                    log_error("scan_unread_article_in_section(sid=%d, aid=%d) error\n",
928                                                      p_section->sid, p_articles[selected_index]->aid);
929                                    return -3;
930                            }
931                            else if (ret == 0) // not found
932                            {
933                                    break;
934                            }
935                            page_id_cur = page_id;
936                            ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
937                                                                                            &page_id, &selected_index, &article_count);
938                            if (ret < 0)
939                            {
940                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
941                                                      p_section->sid, p_article_locate->aid);
942                                    return -3;
943                            }
944                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
945                            {
946                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
947                                    if (ret < 0)
948                                    {
949                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
950                                            return -3;
951                                    }
952                            }
953                            break;
954                  case SHOW_HELP:                  case SHOW_HELP:
955                          // Display help information                          // Display help information
956                          display_file(DATA_READ_HELP, 1);                          display_file(DATA_READ_HELP, 1);
# Line 880  int section_list_display(const char *sna Line 968  int section_list_display(const char *sna
968                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
969                          {                          {
970                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
971                                    return -2;
972                            }
973                            break;
974                    case SHOW_TOP10:
975                            show_top10_menu(NULL);
976                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
977                            {
978                                    log_error("section_list_draw_screen() error\n");
979                                  return -2;                                  return -2;
980                          }                          }
981                          break;                          break;


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

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