/[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.129 by sysadm, Tue Nov 11 00:28:05 2025 UTC Revision 1.140 by sysadm, Sun Jan 18 09:14:57 2026 UTC
# Line 3  Line 3 
3   * screen   * screen
4   *   - advanced telnet-based user interactive input / output features   *   - advanced telnet-based user interactive input / output features
5   *   *
6   * Copyright (C) 2004-2025  Leaflet <leaflet@leafok.com>   * Copyright (C) 2004-2026  Leaflet <leaflet@leafok.com>
7   */   */
8    
9  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
# Line 28  Line 28 
28  #include <wchar.h>  #include <wchar.h>
29  #include <sys/param.h>  #include <sys/param.h>
30  #include <sys/stat.h>  #include <sys/stat.h>
 #include <sys/shm.h>  
31  #include <sys/types.h>  #include <sys/types.h>
32    
33  const char CTRL_SEQ_CLR_LINE[] = "\033[K";  const char CTRL_SEQ_CLR_LINE[] = "\033[K";
# Line 89  void clrtobot(int line_begin) Line 88  void clrtobot(int line_begin)
88  void clearscr()  void clearscr()
89  {  {
90          prints("\033[2J");          prints("\033[2J");
91          moveto(0, 0);          moveto(1, 1);
92  }  }
93    
94  inline int press_any_key()  inline int press_any_key()
# Line 99  inline int press_any_key() Line 98  inline int press_any_key()
98    
99  int press_any_key_ex(const char *msg, int sec)  int press_any_key_ex(const char *msg, int sec)
100  {  {
         int ch = 0;  
         int duration = 0;  
         time_t t_begin = time(NULL);  
   
101          moveto(SCREEN_ROWS, 0);          moveto(SCREEN_ROWS, 0);
102          clrtoeol();          clrtoeol();
103    
104          prints(msg);          prints(msg);
105          iflush();          iflush();
106    
107            return press_any_key_no_prompt(sec);
108    }
109    
110    inline int press_any_key_no_prompt(int sec)
111    {
112            int ch = 0;
113            int duration = 0;
114            time_t t_begin = time(NULL);
115    
116          igetch_reset();          igetch_reset();
117    
118          do          do
# Line 166  static int _str_input(char *buffer, int Line 170  static int _str_input(char *buffer, int
170                  {                  {
171                          continue;                          continue;
172                  }                  }
173                  else if (ch == BACKSPACE)                  else if (ch == BACKSPACE || ch == KEY_DEL)
174                  {                  {
175                          if (offset > 0)                          if (offset > 0)
176                          {                          {
# Line 210  static int _str_input(char *buffer, int Line 214  static int _str_input(char *buffer, int
214                                  ch = igetch(100);                                                // 0.1 second                                  ch = igetch(100);                                                // 0.1 second
215                                  if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Ignore received bytes if no futher input                                  if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Ignore received bytes if no futher input
216                                  {                                  {
217  #ifdef _DEBUG                                          log_debug("Ignore %d bytes of incomplete UTF8 character", str_len);
                                         log_error("Ignore %d bytes of incomplete UTF8 character\n", str_len);  
 #endif  
218                                          str_len = 0;                                          str_len = 0;
219                                          break;                                          break;
220                                  }                                  }
# Line 226  static int _str_input(char *buffer, int Line 228  static int _str_input(char *buffer, int
228    
229                          if (mbstowcs(wcs, input_str, 1) == (size_t)-1)                          if (mbstowcs(wcs, input_str, 1) == (size_t)-1)
230                          {                          {
231                                  log_error("mbstowcs() error\n");                                  log_error("mbstowcs() error");
232                          }                          }
233                          if (offset + str_len > buf_size - 1 || display_len + (UTF8_fixed_width ? 2 : wcwidth(wcs[0])) > max_display_len) // No enough space for Chinese character                          if (offset + str_len > buf_size - 1 || display_len + (UTF8_fixed_width ? 2 : wcwidth(wcs[0])) > max_display_len) // No enough space for Chinese character
234                          {                          {
# Line 359  int get_data(int row, int col, char *pro Line 361  int get_data(int row, int col, char *pro
361    
362                                          if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1)                                          if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1)
363                                          {                                          {
364                                                  log_error("mbstowcs() error\n");                                                  log_error("mbstowcs() error");
365                                          }                                          }
366                                          wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0]));                                          wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0]));
367    
# Line 433  int get_data(int row, int col, char *pro Line 435  int get_data(int row, int col, char *pro
435    
436                                          if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1)                                          if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1)
437                                          {                                          {
438                                                  log_error("mbstowcs() error\n");                                                  log_error("mbstowcs() error");
439                                          }                                          }
440                                          wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0]));                                          wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0]));
441    
# Line 465  int get_data(int row, int col, char *pro Line 467  int get_data(int row, int col, char *pro
467    
468                                          if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1)                                          if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1)
469                                          {                                          {
470                                                  log_error("mbstowcs() error\n");                                                  log_error("mbstowcs() error");
471                                          }                                          }
472                                          wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0]));                                          wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0]));
473    
# Line 534  int get_data(int row, int col, char *pro Line 536  int get_data(int row, int col, char *pro
536                                  ch = igetch(100);                                                // 0.1 second                                  ch = igetch(100);                                                // 0.1 second
537                                  if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Ignore received bytes if no futher input                                  if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Ignore received bytes if no futher input
538                                  {                                  {
539  #ifdef _DEBUG                                          log_debug("Ignore %d bytes of incomplete UTF8 character", str_len);
                                         log_error("Ignore %d bytes of incomplete UTF8 character\n", str_len);  
 #endif  
540                                          str_len = 0;                                          str_len = 0;
541                                          break;                                          break;
542                                  }                                  }
# Line 550  int get_data(int row, int col, char *pro Line 550  int get_data(int row, int col, char *pro
550    
551                          if (mbstowcs(wcs, input_str, 1) == (size_t)-1)                          if (mbstowcs(wcs, input_str, 1) == (size_t)-1)
552                          {                          {
553                                  log_error("mbstowcs() error\n");                                  log_error("mbstowcs() error");
554                          }                          }
555                          wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0]));                          wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0]));
556    
# Line 704  int display_data(const void *p_data, lon Line 704  int display_data(const void *p_data, lon
704                                  if (ch != KEY_NULL && ch != KEY_TIMEOUT)                                  if (ch != KEY_NULL && ch != KEY_TIMEOUT)
705                                  {                                  {
706                                          BBS_last_access_tm = time(NULL);                                          BBS_last_access_tm = time(NULL);
707    
708                                            // Refresh current action
709                                            if (user_online_update(NULL) < 0)
710                                            {
711                                                    log_error("user_online_update(NULL) error");
712                                            }
713                                  }                                  }
714    
715                                  // extended key handler                                  // extended key handler
# Line 715  int display_data(const void *p_data, lon Line 721  int display_data(const void *p_data, lon
721                                  switch (ch)                                  switch (ch)
722                                  {                                  {
723                                  case KEY_NULL:                                  case KEY_NULL:
724                                          log_error("KEY_NULL\n");                                          log_debug("KEY_NULL");
725                                          goto cleanup;                                          goto cleanup;
726                                  case KEY_TIMEOUT:                                  case KEY_TIMEOUT:
727                                          log_error("User input timeout\n");                                          log_debug("User input timeout");
728                                          goto cleanup;                                          goto cleanup;
729                                  case KEY_HOME:                                  case KEY_HOME:
730                                          if (line_current - output_current_row < 0) // Reach begin                                          if (line_current - output_current_row < 0) // Reach begin
# Line 828  int display_data(const void *p_data, lon Line 834  int display_data(const void *p_data, lon
834                  len = p_line_offsets[line_current + 1] - p_line_offsets[line_current];                  len = p_line_offsets[line_current + 1] - p_line_offsets[line_current];
835                  if (len >= sizeof(buffer))                  if (len >= sizeof(buffer))
836                  {                  {
837                          log_error("Buffer overflow: len=%ld(%ld - %ld) line=%ld \n",                          log_error("Buffer overflow: len=%ld(%ld - %ld) line=%ld ",
838                                            len, p_line_offsets[line_current + 1], p_line_offsets[line_current], line_current);                                            len, p_line_offsets[line_current + 1], p_line_offsets[line_current], line_current);
839                          len = sizeof(buffer) - 1;                          len = sizeof(buffer) - 1;
840                  }                  }
841                  else if (len < 0)                  else if (len < 0)
842                  {                  {
843                          log_error("Incorrect line offsets: len=%ld(%ld - %ld) line=%ld \n",                          log_error("Incorrect line offsets: len=%ld(%ld - %ld) line=%ld ",
844                                            len, p_line_offsets[line_current + 1], p_line_offsets[line_current], line_current);                                            len, p_line_offsets[line_current + 1], p_line_offsets[line_current], line_current);
845                          len = 0;                          len = 0;
846                  }                  }
# Line 871  int display_file_key_handler(int *p_key, Line 877  int display_file_key_handler(int *p_key,
877  int display_file(const char *filename, int eof_exit)  int display_file(const char *filename, int eof_exit)
878  {  {
879          int ret;          int ret;
880          const void *p_shm;          void *p_shm;
881          size_t data_len;          size_t data_len;
882          long line_total;          long line_total;
883          const void *p_data;          const void *p_data;
# Line 879  int display_file(const char *filename, i Line 885  int display_file(const char *filename, i
885    
886          if ((p_shm = get_file_shm_readonly(filename, &data_len, &line_total, &p_data, &p_line_offsets)) == NULL)          if ((p_shm = get_file_shm_readonly(filename, &data_len, &line_total, &p_data, &p_line_offsets)) == NULL)
887          {          {
888                  log_error("get_file_shm(%s) error\n", filename);                  log_error("get_file_shm(%s) error", filename);
889                  return KEY_NULL;                  return KEY_NULL;
890          }          }
891    
892          if (user_online_update("VIEW_FILE") < 0)          if (user_online_update("VIEW_FILE") < 0)
893          {          {
894                  log_error("user_online_update(VIEW_FILE) error\n");                  log_error("user_online_update(VIEW_FILE) error");
895          }          }
896    
897          ret = display_data(p_data, line_total, p_line_offsets, eof_exit, display_file_key_handler, DATA_READ_HELP);          ret = display_data(p_data, line_total, p_line_offsets, eof_exit, display_file_key_handler, DATA_READ_HELP);
898    
899          if (detach_file_shm(p_shm) < 0)          if (detach_file_shm(p_shm) < 0)
900          {          {
901                  log_error("detach_file_shm(%s) error\n", filename);                  log_error("detach_file_shm(%s) error", filename);
902          }          }
903    
904          return ret;          return ret;
# Line 1005  int show_active_board() Line 1011  int show_active_board()
1011          {          {
1012                  if ((p_shm = get_file_shm_readonly(DATA_ACTIVE_BOARD, &data_len, &line_total, &p_data, &p_line_offsets)) == NULL)                  if ((p_shm = get_file_shm_readonly(DATA_ACTIVE_BOARD, &data_len, &line_total, &p_data, &p_line_offsets)) == NULL)
1013                  {                  {
1014                          log_error("get_file_shm(%s) error\n", DATA_ACTIVE_BOARD);                          log_error("get_file_shm(%s) error", DATA_ACTIVE_BOARD);
1015                          return KEY_NULL;                          return KEY_NULL;
1016                  }                  }
1017          }          }
# Line 1027  int show_active_board() Line 1033  int show_active_board()
1033                  len = p_line_offsets[line_current + 1] - p_line_offsets[line_current];                  len = p_line_offsets[line_current + 1] - p_line_offsets[line_current];
1034                  if (len >= LINE_BUFFER_LEN)                  if (len >= LINE_BUFFER_LEN)
1035                  {                  {
1036                          log_error("buffer overflow: len=%ld(%ld - %ld) line=%ld \n",                          log_error("buffer overflow: len=%ld(%ld - %ld) line=%ld ",
1037                                            len, p_line_offsets[line_current + 1], p_line_offsets[line_current], line_current);                                            len, p_line_offsets[line_current + 1], p_line_offsets[line_current], line_current);
1038                          len = LINE_BUFFER_LEN - 1;                          len = LINE_BUFFER_LEN - 1;
1039                  }                  }


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

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