/[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.41 by sysadm, Sun Sep 28 11:18:28 2025 UTC Revision 1.48 by sysadm, Sat Oct 18 12:06:10 2025 UTC
# Line 19  Line 19 
19  #include "editor.h"  #include "editor.h"
20  #include "io.h"  #include "io.h"
21  #include "log.h"  #include "log.h"
22    #include "login.h"
23  #include "memory_pool.h"  #include "memory_pool.h"
24  #include "str_process.h"  #include "str_process.h"
25  #include <stdlib.h>  #include <stdlib.h>
# Line 48  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 82  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 149  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 223  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 461  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 503  int editor_data_delete(EDITOR_DATA *p_ed Line 504  int editor_data_delete(EDITOR_DATA *p_ed
504          {          {
505                  str_len = 1;                  str_len = 1;
506          }          }
507          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
508          {          {
509                  str_len = 1;                  str_len = 1;
510                  c = (p_data_line[offset_data_line] & 0b01110000) << 1;                  c = (p_data_line[offset_data_line] & 0x70) << 1;
511                  while (c & 0b10000000)                  while (c & 0x80)
512                  {                  {
513                          str_len++;                          str_len++;
514                          c = (c & 0b01111111) << 1;                          c = (c & 0x7f) << 1;
515                  }                  }
516          }          }
517          else          else
# Line 704  int editor_display(EDITOR_DATA *p_editor Line 705  int editor_display(EDITOR_DATA *p_editor
705                          ch = igetch_t(MAX_DELAY_TIME);                          ch = igetch_t(MAX_DELAY_TIME);
706                          while (!SYS_server_exit)                          while (!SYS_server_exit)
707                          {                          {
708                                    if (ch != KEY_NULL && ch != KEY_TIMEOUT)
709                                    {
710                                            BBS_last_access_tm = time(NULL);
711                                    }
712    
713                                  // extended key handler                                  // extended key handler
714                                  if (editor_display_key_handler(&ch, &ctx) != 0)                                  if (editor_display_key_handler(&ch, &ctx) != 0)
715                                  {                                  {
716                                          goto cleanup;                                          goto cleanup;
717                                  }                                  }
718    
719                                  if (ch < 256 && (ch & 0b10000000)) // head of multi-byte character                                  if (ch < 256 && (ch & 0x80)) // head of multi-byte character
720                                  {                                  {
721                                          str_len = 0;                                          str_len = 0;
722                                          c = (char)(ch & 0b11110000);                                          c = (char)(ch & 0xf0);
723                                          while (c & 0b10000000)                                          while (c & 0x80)
724                                          {                                          {
725                                                  input_str[str_len] = (char)(ch - 256);                                                  input_str[str_len] = (char)(ch - 256);
726                                                  str_len++;                                                  str_len++;
727                                                  c = (c & 0b01111111) << 1;                                                  c = (c & 0x7f) << 1;
728    
729                                                  if ((c & 0b10000000) == 0) // Input completed                                                  if ((c & 0x80) == 0) // Input completed
730                                                  {                                                  {
731                                                          break;                                                          break;
732                                                  }                                                  }
# Line 741  int editor_display(EDITOR_DATA *p_editor Line 747  int editor_display(EDITOR_DATA *p_editor
747                                  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
748                                          ch == CR || ch == KEY_ESC)                                // Special character                                          ch == CR || ch == KEY_ESC)                                // Special character
749                                  {                                  {
750                                          BBS_last_access_tm = time(NULL);                                          // Refresh current action while user input
751                                            if (user_online_update(NULL) < 0)
752                                            {
753                                                    log_error("user_online_update(NULL) error\n");
754                                            }
755    
756                                          if (str_len == 0) // ch >= 32 && ch < 127                                          if (str_len == 0) // ch >= 32 && ch < 127
757                                          {                                          {
# Line 807  int editor_display(EDITOR_DATA *p_editor Line 817  int editor_display(EDITOR_DATA *p_editor
817                                                          {                                                          {
818                                                                  col_pos = 1;                                                                  col_pos = 1;
819                                                          }                                                          }
820                                                          if (ch != CR)                                                          if (offset_out > 0)
821                                                          {                                                          {
822                                                                  col_pos += (str_len == 1 ? 1 : 2);                                                                  col_pos += (str_len == 1 ? 1 : 2);
823                                                          }                                                          }
# Line 830  int editor_display(EDITOR_DATA *p_editor Line 840  int editor_display(EDITOR_DATA *p_editor
840                                  }                                  }
841                                  else if (ch == KEY_DEL || ch == BACKSPACE) // Del                                  else if (ch == KEY_DEL || ch == BACKSPACE) // Del
842                                  {                                  {
843                                          BBS_last_access_tm = time(NULL);                                          // Refresh current action while user input
844                                            if (user_online_update(NULL) < 0)
845                                            {
846                                                    log_error("user_online_update(NULL) error\n");
847                                            }
848    
849                                          if (ch == BACKSPACE)                                          if (ch == BACKSPACE)
850                                          {                                          {
# Line 917  int editor_display(EDITOR_DATA *p_editor Line 931  int editor_display(EDITOR_DATA *p_editor
931                                  switch (ch)                                  switch (ch)
932                                  {                                  {
933                                  case KEY_NULL:                                  case KEY_NULL:
934                                            log_error("KEY_NULL\n");
935                                            goto cleanup;
936                                  case KEY_TIMEOUT:                                  case KEY_TIMEOUT:
937                                            log_error("User input timeout\n");
938                                          goto cleanup;                                          goto cleanup;
939                                  case Ctrl('W'):                                  case Ctrl('W'):
940                                  case Ctrl('X'):                                  case Ctrl('X'):
# Line 1097  int editor_display(EDITOR_DATA *p_editor Line 1114  int editor_display(EDITOR_DATA *p_editor
1114                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_widths[line_current - output_current_row + row_pos]));                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_widths[line_current - output_current_row + row_pos]));
1115                                          clrline(output_current_row, SCREEN_ROWS);                                          clrline(output_current_row, SCREEN_ROWS);
1116                                          break;                                          break;
1117                                    case Ctrl('Q'):
1118                                  case KEY_F1:                                  case KEY_F1:
1119                                          if (!show_help) // Not reentrant                                          if (!show_help) // Not reentrant
1120                                          {                                          {
# Line 1120  int editor_display(EDITOR_DATA *p_editor Line 1138  int editor_display(EDITOR_DATA *p_editor
1138                                          break;                                          break;
1139                                  }                                  }
1140    
1141                                  BBS_last_access_tm = time(NULL);                                  // Refresh current action while user input
1142                                    if (user_online_update(NULL) < 0)
1143                                    {
1144                                            log_error("user_online_update(NULL) error\n");
1145                                    }
1146    
1147                                  if (input_ok)                                  if (input_ok)
1148                                  {                                  {


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

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