/[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.63 by sysadm, Sun May 18 08:53:21 2025 UTC
# Line 48  void moveto(int row, int col) Line 48  void moveto(int row, int col)
48    
49  void clrtoeol()  void clrtoeol()
50  {  {
51          prints("\033[K");          prints(CTRL_SEQ_CLR_LINE);
52  }  }
53    
54  void clrline(int line_begin, int line_end)  void clrline(int line_begin, int line_end)
# Line 58  void clrline(int line_begin, int line_en Line 58  void clrline(int line_begin, int line_en
58          for (i = line_begin; i <= line_end; i++)          for (i = line_begin; i <= line_end; i++)
59          {          {
60                  moveto(i, 0);                  moveto(i, 0);
61                  prints("\033[K");                  prints(CTRL_SEQ_CLR_LINE);
62          }          }
63  }  }
64    
# 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 408  int display_file_ex(const char *filename Line 403  int display_file_ex(const char *filename
403                  len = p_line_offsets[line_current + 1] - p_line_offsets[line_current];                  len = p_line_offsets[line_current + 1] - p_line_offsets[line_current];
404                  if (len >= LINE_BUFFER_LEN)                  if (len >= LINE_BUFFER_LEN)
405                  {                  {
406                          log_error("Error length exceeds buffer size: %d\n", len);                          log_error("buffer overflow: len=%ld(%ld - %ld) line=%ld \n",
407                                              len, p_line_offsets[line_current + 1], p_line_offsets[line_current], line_current);
408                          len = LINE_BUFFER_LEN - 1;                          len = LINE_BUFFER_LEN - 1;
409                  }                  }
410    
# Line 423  int display_file_ex(const char *filename Line 419  int display_file_ex(const char *filename
419          }          }
420    
421  cleanup:  cleanup:
         if (shmdt(p_file_shm) == -1)  
         {  
                 log_error("shmdt() error (%d)\n", errno);  
         }  
   
422          return ch;          return ch;
423  }  }
424    
# Line 505  int show_bottom(const char *msg) Line 496  int show_bottom(const char *msg)
496    
497  int show_active_board()  int show_active_board()
498  {  {
499          char filename[FILE_PATH_LEN];          static int line_current = 0;
500          char buffer[LINE_BUFFER_LEN];          static const void *p_shm = NULL;
501          FILE *fin;          static size_t data_len;
502          static int line;          static long line_total;
503          int len;          static const void *p_data;
504          int end_of_line;          static const long *p_line_offsets;
         int display_len;  
505    
506          clrline(3, 2 + ACTIVE_BOARD_HEIGHT);          char buffer[LINE_BUFFER_LEN];
507            long int len;
         if ((fin = fopen(DATA_ACTIVE_BOARD, "r")) == NULL)  
         {  
                 log_error("Unable to open file %s\n", filename);  
                 return -1;  
         }  
508    
509          for (int i = 0; i < line; i++)          if (p_shm == NULL)
510          {          {
511                  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)
512                  {                  {
513                          line = 0;                          log_error("get_file_shm(%s) error\n", DATA_ACTIVE_BOARD);
514                          rewind(fin);                          return KEY_NULL;
                         break;  
515                  }                  }
516          }          }
517    
518            clrline(3, 2 + ACTIVE_BOARD_HEIGHT);
519    
520          for (int i = 0; i < ACTIVE_BOARD_HEIGHT; i++)          for (int i = 0; i < ACTIVE_BOARD_HEIGHT; i++)
521          {          {
522                  if (fgets(buffer, sizeof(buffer), fin) == NULL)                  len = p_line_offsets[line_current + 1] - p_line_offsets[line_current];
523                    if (len >= LINE_BUFFER_LEN)
524                  {                  {
525                          line = 0;                          log_error("buffer overflow: len=%ld(%ld - %ld) line=%ld \n",
526                          break;                                            len, p_line_offsets[line_current + 1], p_line_offsets[line_current], line_current);
527                            len = LINE_BUFFER_LEN - 1;
528                  }                  }
529                  line++;  
530                  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);
531                  buffer[len] = '\0'; // Truncate over-length line                  buffer[len] = '\0';
532    
533                  moveto(3 + i, 0);                  moveto(3 + i, 0);
534                  prints("%s", buffer);                  prints("%s", buffer);
535    
536                    line_current++;
537                    if (line_current >= line_total)
538                    {
539                            line_current = 0;
540                            break;
541                    }
542          }          }
543          iflush();          iflush();
544    
         fclose(fin);  
   
545          return 0;          return 0;
546  }  }


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

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