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

Diff of /lbbs/src/editor.c

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

Revision 1.24 by sysadm, Mon Jun 16 01:36:56 2025 UTC Revision 1.29 by sysadm, Tue Jun 17 13:25:49 2025 UTC
# Line 24  Line 24 
24  #include <stdlib.h>  #include <stdlib.h>
25  #include <sys/param.h>  #include <sys/param.h>
26  #include <strings.h>  #include <strings.h>
   
 #define _POSIX_C_SOURCE 200809L  
27  #include <string.h>  #include <string.h>
28    
29  #define EDITOR_ESC_DISPLAY_STR "\033[32m*\033[m"  #define EDITOR_ESC_DISPLAY_STR "\033[32m*\033[m"
# Line 138  EDITOR_DATA *editor_data_load(const char Line 136  EDITOR_DATA *editor_data_load(const char
136                  p_data_line[current_data_line_length] = '\0';                  p_data_line[current_data_line_length] = '\0';
137          }          }
138    
139          bzero(p_editor_data->p_display_lines + p_editor_data->display_line_total, MAX_EDITOR_DATA_LINES - (size_t)p_editor_data->display_line_total);          memset(p_editor_data->p_display_lines + p_editor_data->display_line_total, 0, MAX_EDITOR_DATA_LINES - (size_t)p_editor_data->display_line_total);
140    
141          return p_editor_data;          return p_editor_data;
142  }  }
# Line 281  int editor_data_insert(EDITOR_DATA *p_ed Line 279  int editor_data_insert(EDITOR_DATA *p_ed
279          {          {
280                  if (p_editor_data->display_line_total >= MAX_EDITOR_DATA_LINES)                  if (p_editor_data->display_line_total >= MAX_EDITOR_DATA_LINES)
281                  {                  {
282                          // log_error("Split line error, display_line_total(%ld) reach limit(%d)\n",  #ifdef _DEBUG
283                          //                p_editor_data->display_line_total, MAX_EDITOR_DATA_LINES);                          log_error("Split line error, display_line_total(%ld) reach limit(%d)\n",
284                                              p_editor_data->display_line_total, MAX_EDITOR_DATA_LINES);
285    #endif
286    
287                          return -2;                          return -2;
288                  }                  }
289    
# Line 371  int editor_data_insert(EDITOR_DATA *p_ed Line 372  int editor_data_insert(EDITOR_DATA *p_ed
372                          // Insert blank display line after last_display_line                          // Insert blank display line after last_display_line
373                          if (p_editor_data->display_line_total >= MAX_EDITOR_DATA_LINES)                          if (p_editor_data->display_line_total >= MAX_EDITOR_DATA_LINES)
374                          {                          {
375                                  // log_error("display_line_total over limit %d >= %d\n", p_editor_data->display_line_total, MAX_EDITOR_DATA_LINES);  #ifdef _DEBUG
376                                    log_error("display_line_total over limit %d >= %d\n", p_editor_data->display_line_total, MAX_EDITOR_DATA_LINES);
377    #endif
378    
379                                  // Terminate prior display line with \n, to avoid error on cleanup                                  // Terminate prior display line with \n, to avoid error on cleanup
380                                  if (display_line + i - 1 >= 0 && p_editor_data->display_line_lengths[display_line + i - 1] > 0)                                  if (display_line + i - 1 >= 0 && p_editor_data->display_line_lengths[display_line + i - 1] > 0)
381                                  {                                  {
# Line 609  static int editor_display_key_handler(in Line 613  static int editor_display_key_handler(in
613          {          {
614          case 0: // Set msg          case 0: // Set msg
615                  snprintf(p_ctx->msg, sizeof(p_ctx->msg),                  snprintf(p_ctx->msg, sizeof(p_ctx->msg),
616                                   "| Í˳ö[\033[32mCtrl-W\033[33m] | °ïÖú[\033[32mh\033[33m] |");                                   "| Í˳ö[\033[32mCtrl-W\033[33m] |");
617                  break;                  break;
618          case KEY_CSI:          case KEY_CSI:
619                  *p_key = KEY_ESC;                  *p_key = KEY_ESC;
# Line 683  int editor_display(EDITOR_DATA *p_editor Line 687  int editor_display(EDITOR_DATA *p_editor
687                          moveto((int)row_pos, (int)col_pos);                          moveto((int)row_pos, (int)col_pos);
688                          iflush();                          iflush();
689    
690                            str_len = 0;
691                          input_ok = 0;                          input_ok = 0;
692                            ch = igetch_t(MAX_DELAY_TIME);
693                          while (!SYS_server_exit && !input_ok)                          while (!SYS_server_exit && !input_ok)
694                          {                          {
                                 ch = igetch_t(MAX_DELAY_TIME);  
                                 input_ok = 1;  
   
695                                  // extended key handler                                  // extended key handler
696                                  if (editor_display_key_handler(&ch, &ctx) != 0)                                  if (editor_display_key_handler(&ch, &ctx) != 0)
697                                  {                                  {
# Line 709  int editor_display(EDITOR_DATA *p_editor Line 712  int editor_display(EDITOR_DATA *p_editor
712                                  if ((ch >= 32 && ch < 127) || (ch > 127 && ch <= 255 && str_len == 2) || // Printable character or GBK                                  if ((ch >= 32 && ch < 127) || (ch > 127 && ch <= 255 && str_len == 2) || // Printable character or GBK
713                                          ch == CR || ch == KEY_ESC)                                                                                       // Special character                                          ch == CR || ch == KEY_ESC)                                                                                       // Special character
714                                  {                                  {
715                                            BBS_last_access_tm = time(NULL);
716    
717                                          if (str_len == 0) // ch >= 32 && ch < 127                                          if (str_len == 0) // ch >= 32 && ch < 127
718                                          {                                          {
719                                                  input_str[0] = (char)ch;                                                  input_str[0] = (char)ch;
# Line 767  int editor_display(EDITOR_DATA *p_editor Line 772  int editor_display(EDITOR_DATA *p_editor
772                                                  col_pos = offset_out + 1; // Set col_pos to accurate pos                                                  col_pos = offset_out + 1; // Set col_pos to accurate pos
773                                          }                                          }
774    
775                                            if (display_line_out != display_line_in) // Output on line change
776                                            {
777                                                    break;
778                                            }
779    
780                                            ch = igetch(0);
781                                            if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Output if no futher input
782                                            {
783                                                    break;
784                                            }
785    
786                                          str_len = 0;                                          str_len = 0;
787                                          continue;                                          continue;
788                                  }                                  }
789                                  else if (ch == KEY_DEL || ch == BACKSPACE) // Del                                  else if (ch == KEY_DEL || ch == BACKSPACE) // Del
790                                  {                                  {
791                                            BBS_last_access_tm = time(NULL);
792    
793                                          if (ch == BACKSPACE)                                          if (ch == BACKSPACE)
794                                          {                                          {
795                                                  if (line_current - output_current_row + row_pos <= 0 && col_pos <= 1) // Forbidden                                                  if (line_current - output_current_row + row_pos <= 0 && col_pos <= 1) // Forbidden
796                                                  {                                                  {
797                                                          input_ok = 0;                                                          ch = igetch_t(MAX_DELAY_TIME);
798                                                          continue;                                                          continue;
799                                                  }                                                  }
800    
# Line 835  int editor_display(EDITOR_DATA *p_editor Line 853  int editor_display(EDITOR_DATA *p_editor
853                                                  clrline(output_current_row, output_end_row);                                                  clrline(output_current_row, output_end_row);
854                                          }                                          }
855    
856                                            if (display_line_out != display_line_in) // Output on line change
857                                            {
858                                                    break;
859                                            }
860    
861                                            ch = igetch(0);
862                                            if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Output if no futher input
863                                            {
864                                                    break;
865                                            }
866    
867                                          str_len = 0;                                          str_len = 0;
868                                          continue;                                          continue;
869                                  }                                  }
870    
871                                    input_ok = 1;
872                                  switch (ch)                                  switch (ch)
873                                  {                                  {
874                                  case KEY_NULL:                                  case KEY_NULL:
# Line 1035  int editor_display(EDITOR_DATA *p_editor Line 1065  int editor_display(EDITOR_DATA *p_editor
1065                                          break;                                          break;
1066                                  }                                  }
1067    
1068                                  BBS_last_access_tm = time(0);                                  BBS_last_access_tm = time(NULL);
1069    
1070                                  if (input_ok)                                  if (input_ok)
1071                                  {                                  {
1072                                          break;                                          break;
1073                                  }                                  }
1074    
1075                                    ch = igetch_t(MAX_DELAY_TIME);
1076                          }                          }
1077    
1078                          continue;                          continue;


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

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