/[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.61 by sysadm, Sun May 18 06:57:56 2025 UTC
# Line 232  int display_file_ex(const char *filename Line 232  int display_file_ex(const char *filename
232          int ch = KEY_NULL;          int ch = KEY_NULL;
233          int input_ok, line, max_lines;          int input_ok, line, max_lines;
234          long int line_current = 0;          long int line_current = 0;
235          const void *p_file_shm;          const void *p_shm;
         const void *p_data;  
236          size_t data_len;          size_t data_len;
237          long line_total;          long line_total;
238            const void *p_data;
239          const long *p_line_offsets;          const long *p_line_offsets;
240          long int len;          long int len;
241          long int percentile;          long int percentile;
242          int loop;          int loop;
243    
244          if ((p_file_shm = get_file_shm(filename)) == NULL)          if ((p_shm = get_file_shm(filename, &data_len, &line_total, &p_data, &p_line_offsets)) == NULL)
245          {          {
246                  log_error("get_file_shm(%s) error\n", filename);                  log_error("get_file_shm(%s) error\n", filename);
247                  return KEY_NULL;                  return KEY_NULL;
248          }          }
249    
         data_len = *((size_t *)p_file_shm);  
         line_total = *((long *)(p_file_shm + sizeof(size_t)));  
         p_data = p_file_shm + sizeof(data_len) + sizeof(line_total);  
         p_line_offsets = p_data + data_len + 1;  
   
250          clrline(begin_line, SCREEN_ROWS);          clrline(begin_line, SCREEN_ROWS);
251          line = begin_line;          line = begin_line;
252          max_lines = SCREEN_ROWS - 1;          max_lines = SCREEN_ROWS - 1;
# Line 423  int display_file_ex(const char *filename Line 418  int display_file_ex(const char *filename
418          }          }
419    
420  cleanup:  cleanup:
         if (shmdt(p_file_shm) == -1)  
         {  
                 log_error("shmdt() error (%d)\n", errno);  
         }  
   
421          return ch;          return ch;
422  }  }
423    
# Line 505  int show_bottom(const char *msg) Line 495  int show_bottom(const char *msg)
495    
496  int show_active_board()  int show_active_board()
497  {  {
498          char filename[FILE_PATH_LEN];          static int line_current = 0;
499          char buffer[LINE_BUFFER_LEN];          static const void *p_shm = NULL;
500          FILE *fin;          static size_t data_len;
501          static int line;          static long line_total;
502          int len;          static const void *p_data;
503          int end_of_line;          static const long *p_line_offsets;
         int display_len;  
504    
505          clrline(3, 2 + ACTIVE_BOARD_HEIGHT);          char buffer[LINE_BUFFER_LEN];
506            long int len;
         if ((fin = fopen(DATA_ACTIVE_BOARD, "r")) == NULL)  
         {  
                 log_error("Unable to open file %s\n", filename);  
                 return -1;  
         }  
507    
508          for (int i = 0; i < line; i++)          if (p_shm == NULL)
509          {          {
510                  if (fgets(buffer, sizeof(buffer), fin) == NULL)                  if ((p_shm = get_file_shm(DATA_ACTIVE_BOARD, &data_len, &line_total, &p_data, &p_line_offsets)) == NULL)
511                  {                  {
512                          line = 0;                          log_error("get_file_shm(%s) error\n", DATA_ACTIVE_BOARD);
513                          rewind(fin);                          return KEY_NULL;
                         break;  
514                  }                  }
515          }          }
516    
517            clrline(3, 2 + ACTIVE_BOARD_HEIGHT);
518    
519          for (int i = 0; i < ACTIVE_BOARD_HEIGHT; i++)          for (int i = 0; i < ACTIVE_BOARD_HEIGHT; i++)
520          {          {
521                  if (fgets(buffer, sizeof(buffer), fin) == NULL)                  len = p_line_offsets[line_current + 1] - p_line_offsets[line_current];
522                    if (len >= LINE_BUFFER_LEN)
523                  {                  {
524                          line = 0;                          log_error("Error length exceeds buffer size: %d\n", len);
525                          break;                          len = LINE_BUFFER_LEN - 1;
526                  }                  }
527                  line++;  
528                  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);
529                  buffer[len] = '\0'; // Truncate over-length line                  buffer[len] = '\0';
530    
531                  moveto(3 + i, 0);                  moveto(3 + i, 0);
532                  prints("%s", buffer);                  prints("%s", buffer);
533    
534                    line_current++;
535                    if (line_current >= line_total)
536                    {
537                            line_current = 0;
538                            break;
539                    }
540          }          }
541          iflush();          iflush();
542    
         fclose(fin);  
   
543          return 0;          return 0;
544  }  }


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

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