/[LeafOK_CVS]/lbbs/src/screen.c
ViewVC logotype

Diff of /lbbs/src/screen.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.58 by sysadm, Sat May 17 11:30:09 2025 UTC Revision 1.60 by sysadm, Sat May 17 12:28:47 2025 UTC
# Line 505  int show_bottom(const char *msg) Line 505  int show_bottom(const char *msg)
505    
506  int show_active_board()  int show_active_board()
507  {  {
508          char filename[FILE_PATH_LEN];          static int line_current = 0;
509          char buffer[LINE_BUFFER_LEN];          static const void *p_file_shm = NULL;
510          FILE *fin;          static const void *p_data;
511          static int line;          static size_t data_len;
512          int len;          static long line_total;
513          int end_of_line;          static const long *p_line_offsets;
         int display_len;  
   
         clrline(3, 2 + ACTIVE_BOARD_HEIGHT);  
514    
515          if ((fin = fopen(DATA_ACTIVE_BOARD, "r")) == NULL)          char buffer[LINE_BUFFER_LEN];
516          {          long int len;
                 log_error("Unable to open file %s\n", filename);  
                 return -1;  
         }  
517    
518          for (int i = 0; i < line; i++)          if (p_file_shm == NULL)
519          {          {
520                  if (fgets(buffer, sizeof(buffer), fin) == NULL)                  if ((p_file_shm = get_file_shm(DATA_ACTIVE_BOARD)) == NULL)
521                  {                  {
522                          line = 0;                          log_error("get_file_shm(%s) error\n", DATA_ACTIVE_BOARD);
523                          rewind(fin);                          return KEY_NULL;
                         break;  
524                  }                  }
525    
526                    data_len = *((size_t *)p_file_shm);
527                    line_total = *((long *)(p_file_shm + sizeof(size_t)));
528                    p_data = p_file_shm + sizeof(data_len) + sizeof(line_total);
529                    p_line_offsets = p_data + data_len + 1;
530          }          }
531    
532            clrline(3, 2 + ACTIVE_BOARD_HEIGHT);
533    
534          for (int i = 0; i < ACTIVE_BOARD_HEIGHT; i++)          for (int i = 0; i < ACTIVE_BOARD_HEIGHT; i++)
535          {          {
536                  if (fgets(buffer, sizeof(buffer), fin) == NULL)                  len = p_line_offsets[line_current + 1] - p_line_offsets[line_current];
537                    if (len >= LINE_BUFFER_LEN)
538                  {                  {
539                          line = 0;                          log_error("Error length exceeds buffer size: %d\n", len);
540                          break;                          len = LINE_BUFFER_LEN - 1;
541                  }                  }
542                  line++;  
543                  len = split_line(buffer, SCREEN_COLS, &end_of_line, &display_len);                  memcpy(buffer, (const char *)p_data + p_line_offsets[line_current], (size_t)len);
544                  buffer[len] = '\0'; // Truncate over-length line                  buffer[len] = '\0';
545    
546                  moveto(3 + i, 0);                  moveto(3 + i, 0);
547                  prints("%s", buffer);                  prints("%s", buffer);
548    
549                    line_current++;
550                    if (line_current >= line_total)
551                    {
552                            line_current = 0;
553                            break;
554                    }
555          }          }
556          iflush();          iflush();
557    
         fclose(fin);  
   
558          return 0;          return 0;
559  }  }


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

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