/[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.55 by sysadm, Sat Nov 8 08:21:31 2025 UTC Revision 1.58 by sysadm, Mon Nov 10 07:23:16 2025 UTC
# Line 23  enum _editor_constant_t Line 23  enum _editor_constant_t
23  {  {
24          EDITOR_MEM_POOL_LINE_PER_CHUNK = 1000,          EDITOR_MEM_POOL_LINE_PER_CHUNK = 1000,
25          EDITOR_MEM_POOL_CHUNK_LIMIT = (MAX_EDITOR_DATA_LINES / EDITOR_MEM_POOL_LINE_PER_CHUNK + 1),          EDITOR_MEM_POOL_CHUNK_LIMIT = (MAX_EDITOR_DATA_LINES / EDITOR_MEM_POOL_LINE_PER_CHUNK + 1),
26            TAB_SIZE = 4,
27  };  };
28    
29  static const char EDITOR_ESC_DISPLAY_STR[] = "\033[32m*\033[m";  static const char EDITOR_ESC_DISPLAY_STR[] = "\033[32m*\033[m";
# Line 77  EDITOR_DATA *editor_data_load(const char Line 78  EDITOR_DATA *editor_data_load(const char
78          long line_offsets[MAX_EDITOR_DATA_LINES + 1];          long line_offsets[MAX_EDITOR_DATA_LINES + 1];
79          long current_data_line_length = 0;          long current_data_line_length = 0;
80          long i;          long i;
81            int j;
82    
83          if (p_data == NULL)          if (p_data == NULL)
84          {          {
# Line 123  EDITOR_DATA *editor_data_load(const char Line 125  EDITOR_DATA *editor_data_load(const char
125                  memcpy(p_editor_data->p_display_lines[i], p_data + line_offsets[i], (size_t)p_editor_data->display_line_lengths[i]);                  memcpy(p_editor_data->p_display_lines[i], p_data + line_offsets[i], (size_t)p_editor_data->display_line_lengths[i]);
126                  current_data_line_length += p_editor_data->display_line_lengths[i];                  current_data_line_length += p_editor_data->display_line_lengths[i];
127    
128                    // Convert \t to single space
129                    for (j = 0; j < p_editor_data->display_line_lengths[i]; j++)
130                    {
131                            if (p_editor_data->p_display_lines[i][j] == '\t')
132                            {
133                                    p_editor_data->p_display_lines[i][j] = ' ';
134                            }
135                    }
136    
137                  // Trim \n from last line                  // Trim \n from last line
138                  if (i + 1 == p_editor_data->display_line_total &&                  if (i + 1 == p_editor_data->display_line_total &&
139                          p_editor_data->display_line_lengths[i] > 0 &&                          p_editor_data->display_line_lengths[i] > 0 &&
# Line 647  int editor_display(EDITOR_DATA *p_editor Line 658  int editor_display(EDITOR_DATA *p_editor
658          EDITOR_CTX ctx;          EDITOR_CTX ctx;
659          int ch = 0;          int ch = 0;
660          char input_str[5];          char input_str[5];
661            int str_len = 0;
662          wchar_t wcs[2];          wchar_t wcs[2];
663            int wc_len;
664          char c;          char c;
         int str_len = 0;  
665          int input_ok;          int input_ok;
666          const int screen_begin_row = 1;          const int screen_begin_row = 1;
667          const int screen_row_total = SCREEN_ROWS - screen_begin_row;          const int screen_row_total = SCREEN_ROWS - screen_begin_row;
# Line 668  int editor_display(EDITOR_DATA *p_editor Line 680  int editor_display(EDITOR_DATA *p_editor
680          int i, j;          int i, j;
681          char *p_str;          char *p_str;
682          int del_line;          int del_line;
683            int tab_width = 0;
684    
685          clrline(output_current_row, SCREEN_ROWS);          clrline(output_current_row, SCREEN_ROWS);
686    
# Line 706  int editor_display(EDITOR_DATA *p_editor Line 719  int editor_display(EDITOR_DATA *p_editor
719                          moveto((int)row_pos, (int)col_pos);                          moveto((int)row_pos, (int)col_pos);
720                          iflush();                          iflush();
721    
722                            tab_width = 0;
723                          str_len = 0;                          str_len = 0;
724                          ch = igetch_t(BBS_max_user_idle_time);                          ch = igetch_t(BBS_max_user_idle_time);
725                          while (!SYS_server_exit)                          while (!SYS_server_exit)
# Line 721  int editor_display(EDITOR_DATA *p_editor Line 735  int editor_display(EDITOR_DATA *p_editor
735                                          goto cleanup;                                          goto cleanup;
736                                  }                                  }
737    
738                                    if (ch == '\t')
739                                    {
740                                            ch = ' ';
741                                            tab_width = TAB_SIZE - ((int)(col_pos - 1) % TAB_SIZE) - 1;
742                                    }
743    
744                                  if (ch < 256 && (ch & 0x80)) // head of multi-byte character                                  if (ch < 256 && (ch & 0x80)) // head of multi-byte character
745                                  {                                  {
746                                          str_len = 0;                                          str_len = 0;
# Line 839  int editor_display(EDITOR_DATA *p_editor Line 859  int editor_display(EDITOR_DATA *p_editor
859                                                  break;                                                  break;
860                                          }                                          }
861    
862                                          ch = igetch(0);                                          if (ch == ' ' && tab_width > 0)
                                         if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Output if no futher input  
863                                          {                                          {
864                                                  break;                                                  tab_width--;
865                                            }
866                                            else
867                                            {
868                                                    ch = igetch(0);
869                                                    if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Output if no futher input
870                                                    {
871                                                            break;
872                                                    }
873                                          }                                          }
874    
875                                          str_len = 0;                                          str_len = 0;
# Line 1025  int editor_display(EDITOR_DATA *p_editor Line 1052  int editor_display(EDITOR_DATA *p_editor
1052                                          offset_in = split_line(p_editor_data->p_display_lines[line_current - output_current_row + row_pos],                                          offset_in = split_line(p_editor_data->p_display_lines[line_current - output_current_row + row_pos],
1053                                                                                     (int)col_pos - 1, &eol, &display_len, 0);                                                                                     (int)col_pos - 1, &eol, &display_len, 0);
1054                                          col_pos = display_len;                                          col_pos = display_len;
1055                                          if (offset_in >= 1 && p_editor_data->p_display_lines[line_current - output_current_row + row_pos][offset_in - 1] < 0) // UTF8                                          if (offset_in > 0)
1056                                          {                                          {
1057                                                  split_line(p_editor_data->p_display_lines[line_current - output_current_row + row_pos],                                                  str_len = 1;
1058                                                                     (int)col_pos - 1, &eol, &display_len, 0);                                                  offset_in--;
1059                                                  if (display_len == col_pos - 2)                                                  if (p_editor_data->p_display_lines[line_current - output_current_row + row_pos][offset_in] < 0 ||
1060                                                            p_editor_data->p_display_lines[line_current - output_current_row + row_pos][offset_in] > 127) // UTF8
1061                                                  {                                                  {
1062                                                          col_pos--;                                                          while (offset_in > 0 &&
1063                                                                       (p_editor_data->p_display_lines[line_current - output_current_row + row_pos][offset_in] & 0xc0) != 0xc0)
1064                                                            {
1065                                                                    str_len++;
1066                                                                    offset_in--;
1067                                                            }
1068    
1069                                                            if (str_len > 4)
1070                                                            {
1071                                                                    log_error("Invalid UTF-8 data detected: str_len > 4\n");
1072                                                            }
1073    
1074                                                            if (mbstowcs(wcs, p_editor_data->p_display_lines[line_current - output_current_row + row_pos] + offset_in, 1) ==
1075                                                                    (size_t)-1)
1076                                                            {
1077                                                                    log_error("mbstowcs() error\n");
1078                                                            }
1079                                                            wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0]));
1080    
1081                                                            if (wc_len == 2)
1082                                                            {
1083                                                                    col_pos--;
1084                                                            }
1085                                                  }                                                  }
1086                                          }                                          }
1087                                          if (col_pos >= 1)                                          if (col_pos >= 1)
# Line 1062  int editor_display(EDITOR_DATA *p_editor Line 1112  int editor_display(EDITOR_DATA *p_editor
1112                                          offset_in = split_line(p_editor_data->p_display_lines[line_current - output_current_row + row_pos],                                          offset_in = split_line(p_editor_data->p_display_lines[line_current - output_current_row + row_pos],
1113                                                                                     (int)col_pos - 1, &eol, &display_len, 0);                                                                                     (int)col_pos - 1, &eol, &display_len, 0);
1114                                          col_pos = display_len + 2;                                          col_pos = display_len + 2;
1115                                          if (offset_in < p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] &&                                          if (offset_in < p_editor_data->display_line_lengths[line_current - output_current_row + row_pos])
                                                 p_editor_data->p_display_lines[line_current - output_current_row + row_pos][offset_in] < 0) // UTF8  
1116                                          {                                          {
1117                                                  split_line(p_editor_data->p_display_lines[line_current - output_current_row + row_pos] + offset_in,                                                  str_len = 0;
1118                                                                     1, &eol, &display_len, 0);                                                  if ((p_editor_data->p_display_lines[line_current - output_current_row + row_pos][offset_in] & 0x80) ==
1119                                                  if (display_len == 0)                                                          0x80) // head of multi-byte character
1120                                                    {
1121                                                            c = (char)(p_editor_data->p_display_lines[line_current - output_current_row + row_pos][offset_in] & 0xf0);
1122                                                            while (c & 0x80)
1123                                                            {
1124                                                                    str_len++;
1125                                                                    c = (c & 0x7f) << 1;
1126                                                            }
1127    
1128                                                            if (str_len > 4)
1129                                                            {
1130                                                                    log_error("Invalid UTF-8 data detected: str_len > 4\n");
1131                                                            }
1132    
1133                                                            if (mbstowcs(wcs, p_editor_data->p_display_lines[line_current - output_current_row + row_pos] + offset_in, 1) ==
1134                                                                    (size_t)-1)
1135                                                            {
1136                                                                    log_error("mbstowcs() error\n");
1137                                                            }
1138                                                            wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0]));
1139    
1140                                                            if (wc_len == 2)
1141                                                            {
1142                                                                    col_pos++;
1143                                                            }
1144                                                    }
1145                                                    else
1146                                                  {                                                  {
1147                                                          col_pos++;                                                          str_len = 1;
1148                                                  }                                                  }
1149                                                    offset_in += str_len;
1150                                          }                                          }
1151                                          if (col_pos <= p_editor_data->display_line_widths[line_current - output_current_row + row_pos])                                          if (col_pos <= p_editor_data->display_line_widths[line_current - output_current_row + row_pos])
1152                                          {                                          {


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

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