/[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.44 by sysadm, Wed Oct 1 11:32:50 2025 UTC Revision 1.49 by sysadm, Sun Oct 19 07:08:29 2025 UTC
# Line 49  int editor_memory_pool_init(void) Line 49  int editor_memory_pool_init(void)
49          }          }
50    
51          p_mp_editor_data = memory_pool_init(sizeof(EDITOR_DATA), 1, 1);          p_mp_editor_data = memory_pool_init(sizeof(EDITOR_DATA), 1, 1);
52          if (p_mp_data_line == NULL)          if (p_mp_editor_data == NULL)
53          {          {
54                  log_error("Memory pool init error\n");                  log_error("Memory pool init error\n");
55                  return -3;                  return -3;
# Line 83  EDITOR_DATA *editor_data_load(const char Line 83  EDITOR_DATA *editor_data_load(const char
83    
84          if (p_data == NULL)          if (p_data == NULL)
85          {          {
86                  log_error("editor_data_load() error: NULL pointer\n");                  log_error("NULL pointer error\n");
87                  return NULL;                  return NULL;
88          }          }
89    
# Line 150  long editor_data_save(const EDITOR_DATA Line 150  long editor_data_save(const EDITOR_DATA
150    
151          if (p_editor_data == NULL || p_data == NULL)          if (p_editor_data == NULL || p_data == NULL)
152          {          {
153                  log_error("editor_data_save() error: NULL pointer\n");                  log_error("NULL pointer error\n");
154                  return -1;                  return -1;
155          }          }
156    
# Line 224  int editor_data_insert(EDITOR_DATA *p_ed Line 224  int editor_data_insert(EDITOR_DATA *p_ed
224    
225          if (p_editor_data == NULL || p_last_updated_line == NULL)          if (p_editor_data == NULL || p_last_updated_line == NULL)
226          {          {
227                  log_error("editor_data_op() error: NULL pointer\n");                  log_error("NULL pointer error\n");
228                  return -1;                  return -1;
229          }          }
230    
# Line 445  int editor_data_insert(EDITOR_DATA *p_ed Line 445  int editor_data_insert(EDITOR_DATA *p_ed
445  }  }
446    
447  int editor_data_delete(EDITOR_DATA *p_editor_data, long *p_display_line, long *p_offset,  int editor_data_delete(EDITOR_DATA *p_editor_data, long *p_display_line, long *p_offset,
448                                             long *p_last_updated_line)                                             long *p_last_updated_line, int del_line)
449  {  {
450          long display_line = *p_display_line;          long display_line = *p_display_line;
451          long offset = *p_offset;          long offset = *p_offset;
# Line 462  int editor_data_delete(EDITOR_DATA *p_ed Line 462  int editor_data_delete(EDITOR_DATA *p_ed
462    
463          if (p_editor_data == NULL || p_last_updated_line == NULL)          if (p_editor_data == NULL || p_last_updated_line == NULL)
464          {          {
465                  log_error("editor_data_op() error: NULL pointer\n");                  log_error("NULL pointer error\n");
466                  return -1;                  return -1;
467          }          }
468    
# Line 500  int editor_data_delete(EDITOR_DATA *p_ed Line 500  int editor_data_delete(EDITOR_DATA *p_ed
500          }          }
501    
502          // Check str to be deleted          // Check str to be deleted
503          if (p_data_line[offset_data_line] > 0 && p_data_line[offset_data_line] < 127)          if (del_line)
504            {
505                    str_len = (int)(p_editor_data->display_line_lengths[display_line] - offset);
506            }
507            else if (p_data_line[offset_data_line] > 0 && p_data_line[offset_data_line] < 127)
508          {          {
509                  str_len = 1;                  str_len = 1;
510          }          }
511          else if (p_data_line[offset_data_line] & 0b10000000) // head of multi-byte character          else if (p_data_line[offset_data_line] & 0x80) // head of multi-byte character
512          {          {
513                  str_len = 1;                  str_len = 1;
514                  c = (p_data_line[offset_data_line] & 0b01110000) << 1;                  c = (p_data_line[offset_data_line] & 0x70) << 1;
515                  while (c & 0b10000000)                  while (c & 0x80)
516                  {                  {
517                          str_len++;                          str_len++;
518                          c = (c & 0b01111111) << 1;                          c = (c & 0x7f) << 1;
519                  }                  }
520          }          }
521          else          else
# Line 523  int editor_data_delete(EDITOR_DATA *p_ed Line 527  int editor_data_delete(EDITOR_DATA *p_ed
527    
528          // Current display line is (almost) empty          // Current display line is (almost) empty
529          if (offset_data_line + str_len > len_data_line ||          if (offset_data_line + str_len > len_data_line ||
530                  (offset_data_line + str_len == len_data_line && p_data_line[offset_data_line] == '\n'))                  (offset_data_line + str_len == len_data_line &&
531                     p_data_line[del_line ? len_data_line - 1 : offset_data_line] == '\n'))
532          {          {
533                  if (display_line + 1 >= p_editor_data->display_line_total) // No additional display line (data line)                  if (display_line + 1 >= p_editor_data->display_line_total) // No additional display line (data line)
534                  {                  {
# Line 663  int editor_display(EDITOR_DATA *p_editor Line 668  int editor_display(EDITOR_DATA *p_editor
668          int key_insert = 1;          int key_insert = 1;
669          int i, j;          int i, j;
670          char *p_str;          char *p_str;
671            int del_line;
672    
673          clrline(output_current_row, SCREEN_ROWS);          clrline(output_current_row, SCREEN_ROWS);
674    
# Line 705  int editor_display(EDITOR_DATA *p_editor Line 711  int editor_display(EDITOR_DATA *p_editor
711                          ch = igetch_t(MAX_DELAY_TIME);                          ch = igetch_t(MAX_DELAY_TIME);
712                          while (!SYS_server_exit)                          while (!SYS_server_exit)
713                          {                          {
714                                    if (ch != KEY_NULL && ch != KEY_TIMEOUT)
715                                    {
716                                            BBS_last_access_tm = time(NULL);
717                                    }
718    
719                                  // extended key handler                                  // extended key handler
720                                  if (editor_display_key_handler(&ch, &ctx) != 0)                                  if (editor_display_key_handler(&ch, &ctx) != 0)
721                                  {                                  {
722                                          goto cleanup;                                          goto cleanup;
723                                  }                                  }
724    
725                                  if (ch < 256 && (ch & 0b10000000)) // head of multi-byte character                                  if (ch < 256 && (ch & 0x80)) // head of multi-byte character
726                                  {                                  {
727                                          str_len = 0;                                          str_len = 0;
728                                          c = (char)(ch & 0b11110000);                                          c = (char)(ch & 0xf0);
729                                          while (c & 0b10000000)                                          while (c & 0x80)
730                                          {                                          {
731                                                  input_str[str_len] = (char)(ch - 256);                                                  input_str[str_len] = (char)(ch - 256);
732                                                  str_len++;                                                  str_len++;
733                                                  c = (c & 0b01111111) << 1;                                                  c = (c & 0x7f) << 1;
734    
735                                                  if ((c & 0b10000000) == 0) // Input completed                                                  if ((c & 0x80) == 0) // Input completed
736                                                  {                                                  {
737                                                          break;                                                          break;
738                                                  }                                                  }
# Line 742  int editor_display(EDITOR_DATA *p_editor Line 753  int editor_display(EDITOR_DATA *p_editor
753                                  if ((ch >= 32 && ch < 127) || str_len >= 2 || // Printable character or multi-byte character                                  if ((ch >= 32 && ch < 127) || str_len >= 2 || // Printable character or multi-byte character
754                                          ch == CR || ch == KEY_ESC)                                // Special character                                          ch == CR || ch == KEY_ESC)                                // Special character
755                                  {                                  {
                                         BBS_last_access_tm = time(NULL);  
   
756                                          // Refresh current action while user input                                          // Refresh current action while user input
757                                          if (user_online_update(NULL) < 0)                                          if (user_online_update(NULL) < 0)
758                                          {                                          {
# Line 766  int editor_display(EDITOR_DATA *p_editor Line 775  int editor_display(EDITOR_DATA *p_editor
775                                          if (!key_insert) // overwrite                                          if (!key_insert) // overwrite
776                                          {                                          {
777                                                  if (editor_data_delete(p_editor_data, &display_line_out, &offset_out,                                                  if (editor_data_delete(p_editor_data, &display_line_out, &offset_out,
778                                                                                             &last_updated_line) < 0)                                                                                             &last_updated_line, 0) < 0)
779                                                  {                                                  {
780                                                          log_error("editor_data_delete() error\n");                                                          log_error("editor_data_delete() error\n");
781                                                  }                                                  }
# Line 835  int editor_display(EDITOR_DATA *p_editor Line 844  int editor_display(EDITOR_DATA *p_editor
844                                          str_len = 0;                                          str_len = 0;
845                                          continue;                                          continue;
846                                  }                                  }
847                                  else if (ch == KEY_DEL || ch == BACKSPACE) // Del                                  else if (ch == KEY_DEL || ch == BACKSPACE || ch == Ctrl('K') || ch == Ctrl('Y')) // Del
848                                  {                                  {
                                         BBS_last_access_tm = time(NULL);  
   
849                                          // Refresh current action while user input                                          // Refresh current action while user input
850                                          if (user_online_update(NULL) < 0)                                          if (user_online_update(NULL) < 0)
851                                          {                                          {
852                                                  log_error("user_online_update(NULL) error\n");                                                  log_error("user_online_update(NULL) error\n");
853                                          }                                          }
854    
855                                            del_line = 0;
856    
857                                          if (ch == BACKSPACE)                                          if (ch == BACKSPACE)
858                                          {                                          {
859                                                  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
# Line 869  int editor_display(EDITOR_DATA *p_editor Line 878  int editor_display(EDITOR_DATA *p_editor
878                                                          col_pos = MAX(1, p_editor_data->display_line_widths[line_current - output_current_row + row_pos]);                                                          col_pos = MAX(1, p_editor_data->display_line_widths[line_current - output_current_row + row_pos]);
879                                                  }                                                  }
880                                          }                                          }
881                                            else if (ch == Ctrl('K'))
882                                            {
883                                                    del_line = 1;
884                                            }
885                                            else if (ch == Ctrl('Y'))
886                                            {
887                                                    col_pos = 1;
888                                                    del_line = 1;
889                                            }
890    
891                                          display_line_in = line_current - output_current_row + row_pos;                                          display_line_in = line_current - output_current_row + row_pos;
892                                          offset_in = split_line(p_editor_data->p_display_lines[display_line_in], (int)col_pos - 1, &eol, &display_len, 0);                                          offset_in = split_line(p_editor_data->p_display_lines[display_line_in], (int)col_pos - 1, &eol, &display_len, 0);
# Line 876  int editor_display(EDITOR_DATA *p_editor Line 894  int editor_display(EDITOR_DATA *p_editor
894                                          offset_out = offset_in;                                          offset_out = offset_in;
895    
896                                          if ((str_len = editor_data_delete(p_editor_data, &display_line_out, &offset_out,                                          if ((str_len = editor_data_delete(p_editor_data, &display_line_out, &offset_out,
897                                                                                                            &last_updated_line)) < 0)                                                                                                            &last_updated_line, del_line)) < 0)
898                                          {                                          {
899                                                  log_error("editor_data_delete() error\n");                                                  log_error("editor_data_delete() error: %d\n", str_len);
900                                          }                                          }
901                                          else                                          else
902                                          {                                          {
# Line 930  int editor_display(EDITOR_DATA *p_editor Line 948  int editor_display(EDITOR_DATA *p_editor
948                                  switch (ch)                                  switch (ch)
949                                  {                                  {
950                                  case KEY_NULL:                                  case KEY_NULL:
951                                            log_error("KEY_NULL\n");
952                                            goto cleanup;
953                                  case KEY_TIMEOUT:                                  case KEY_TIMEOUT:
954                                            log_error("User input timeout\n");
955                                          goto cleanup;                                          goto cleanup;
956                                  case Ctrl('W'):                                  case Ctrl('W'):
957                                  case Ctrl('X'):                                  case Ctrl('X'):
# Line 1134  int editor_display(EDITOR_DATA *p_editor Line 1155  int editor_display(EDITOR_DATA *p_editor
1155                                          break;                                          break;
1156                                  }                                  }
1157    
                                 BBS_last_access_tm = time(NULL);  
   
1158                                  // Refresh current action while user input                                  // Refresh current action while user input
1159                                  if (user_online_update(NULL) < 0)                                  if (user_online_update(NULL) < 0)
1160                                  {                                  {


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

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