/[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.59 by sysadm, Sat May 17 12:20:12 2025 UTC Revision 1.65 by sysadm, Mon May 19 06:55:06 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 458  int show_top(const char *status) Line 449  int show_top(const char *status)
449          moveto(1, 0);          moveto(1, 0);
450          clrtoeol();          clrtoeol();
451          prints("\033[1;44;33m%s\033[37m%*s%*s\033[33m ÌÖÂÛÇø [%s]\033[m",          prints("\033[1;44;33m%s\033[37m%*s%*s\033[33m ÌÖÂÛÇø [%s]\033[m",
452                     status_f, 32, BBS_name, 26, "", BBS_current_section_name);                     status_f, 44 - status_len, BBS_name, 26 - section_name_len, "", BBS_current_section_name);
         iflush();  
453    
454          return 0;          return 0;
455  }  }
# Line 498  int show_bottom(const char *msg) Line 488  int show_bottom(const char *msg)
488                     "[\033[36m%1d\033[33m:\033[36m%2d\033[33m:\033[36m%2d\033[33m]\033[m",                     "[\033[36m%1d\033[33m:\033[36m%2d\033[33m:\033[36m%2d\033[33m]\033[m",
489                     str_time, 21, msg_f, 13 - len_username, "", BBS_username,                     str_time, 21, msg_f, 13 - len_username, "", BBS_username,
490                     tm_online->tm_mday - 1, tm_online->tm_hour, tm_online->tm_min);                     tm_online->tm_mday - 1, tm_online->tm_hour, tm_online->tm_min);
         iflush();  
491    
492          return 0;          return 0;
493  }  }
# Line 506  int show_bottom(const char *msg) Line 495  int show_bottom(const char *msg)
495  int show_active_board()  int show_active_board()
496  {  {
497          static int line_current = 0;          static int line_current = 0;
498          static const void *p_file_shm = NULL;          static const void *p_shm = NULL;
         static const void *p_data;  
499          static size_t data_len;          static size_t data_len;
500          static long line_total;          static long line_total;
501            static const void *p_data;
502          static const long *p_line_offsets;          static const long *p_line_offsets;
503    
504            static time_t t_last_show = 0;
505            static int line_last = 0;
506    
507          char buffer[LINE_BUFFER_LEN];          char buffer[LINE_BUFFER_LEN];
508          long int len;          long int len;
509    
510          if (p_file_shm == NULL)          if (p_shm == NULL)
511          {          {
512                  if ((p_file_shm = get_file_shm(DATA_ACTIVE_BOARD)) == NULL)                  if ((p_shm = get_file_shm(DATA_ACTIVE_BOARD, &data_len, &line_total, &p_data, &p_line_offsets)) == NULL)
513                  {                  {
514                          log_error("get_file_shm(%s) error\n", DATA_ACTIVE_BOARD);                          log_error("get_file_shm(%s) error\n", DATA_ACTIVE_BOARD);
515                          return KEY_NULL;                          return KEY_NULL;
516                  }                  }
517            }
518    
519                  data_len = *((size_t *)p_file_shm);          if (time(0) - t_last_show >= 10)
520                  line_total = *((long *)(p_file_shm + sizeof(size_t)));          {
521                  p_data = p_file_shm + sizeof(data_len) + sizeof(line_total);                  line_last = line_current;
522                  p_line_offsets = p_data + data_len + 1;                  t_last_show = time(0);
523            }
524            else
525            {
526                    line_current = line_last;
527          }          }
528    
529          clrline(3, 2 + ACTIVE_BOARD_HEIGHT);          clrline(2, 2 + ACTIVE_BOARD_HEIGHT);
530    
531          for (int i = 0; i < ACTIVE_BOARD_HEIGHT; i++)          for (int i = 0; i < ACTIVE_BOARD_HEIGHT; i++)
532          {          {
533                  len = p_line_offsets[line_current + 1] - p_line_offsets[line_current];                  len = p_line_offsets[line_current + 1] - p_line_offsets[line_current];
534                  if (len >= LINE_BUFFER_LEN)                  if (len >= LINE_BUFFER_LEN)
535                  {                  {
536                          log_error("Error length exceeds buffer size: %d\n", len);                          log_error("buffer overflow: len=%ld(%ld - %ld) line=%ld \n",
537                                              len, p_line_offsets[line_current + 1], p_line_offsets[line_current], line_current);
538                          len = LINE_BUFFER_LEN - 1;                          len = LINE_BUFFER_LEN - 1;
539                  }                  }
540    
# Line 547  int show_active_board() Line 545  int show_active_board()
545                  prints("%s", buffer);                  prints("%s", buffer);
546    
547                  line_current++;                  line_current++;
548                  if (line_current + 1 >= line_total)                  if (line_current >= line_total)
549                  {                  {
550                          line_current = 0;                          line_current = 0;
551                          break;                          break;
552                  }                  }
553          }          }
         iflush();  
554    
555          return 0;          return 0;
556  }  }


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

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