/[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.60 by sysadm, Tue Nov 11 00:28:05 2025 UTC
# Line 6  Line 6 
6   * Copyright (C) 2004-2025  Leaflet <leaflet@leafok.com>   * Copyright (C) 2004-2025  Leaflet <leaflet@leafok.com>
7   */   */
8    
9    #ifdef HAVE_CONFIG_H
10    #include "config.h"
11    #endif
12    
13  #include "bbs.h"  #include "bbs.h"
14  #include "common.h"  #include "common.h"
15  #include "editor.h"  #include "editor.h"
# Line 77  EDITOR_DATA *editor_data_load(const char Line 81  EDITOR_DATA *editor_data_load(const char
81          long line_offsets[MAX_EDITOR_DATA_LINES + 1];          long line_offsets[MAX_EDITOR_DATA_LINES + 1];
82          long current_data_line_length = 0;          long current_data_line_length = 0;
83          long i;          long i;
84            int j;
85    
86          if (p_data == NULL)          if (p_data == NULL)
87          {          {
# Line 123  EDITOR_DATA *editor_data_load(const char Line 128  EDITOR_DATA *editor_data_load(const char
128                  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]);
129                  current_data_line_length += p_editor_data->display_line_lengths[i];                  current_data_line_length += p_editor_data->display_line_lengths[i];
130    
131                    // Convert \t to single space
132                    for (j = 0; j < p_editor_data->display_line_lengths[i]; j++)
133                    {
134                            if (p_editor_data->p_display_lines[i][j] == '\t')
135                            {
136                                    p_editor_data->p_display_lines[i][j] = ' ';
137                            }
138                    }
139    
140                  // Trim \n from last line                  // Trim \n from last line
141                  if (i + 1 == p_editor_data->display_line_total &&                  if (i + 1 == p_editor_data->display_line_total &&
142                          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 661  int editor_display(EDITOR_DATA *p_editor
661          EDITOR_CTX ctx;          EDITOR_CTX ctx;
662          int ch = 0;          int ch = 0;
663          char input_str[5];          char input_str[5];
664            int str_len = 0;
665          wchar_t wcs[2];          wchar_t wcs[2];
666            int wc_len;
667          char c;          char c;
         int str_len = 0;  
668          int input_ok;          int input_ok;
669          const int screen_begin_row = 1;          const int screen_begin_row = 1;
670          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 683  int editor_display(EDITOR_DATA *p_editor
683          int i, j;          int i, j;
684          char *p_str;          char *p_str;
685          int del_line;          int del_line;
686            int tab_width = 0;
687    
688          clrline(output_current_row, SCREEN_ROWS);          clrline(output_current_row, SCREEN_ROWS);
689    
# Line 706  int editor_display(EDITOR_DATA *p_editor Line 722  int editor_display(EDITOR_DATA *p_editor
722                          moveto((int)row_pos, (int)col_pos);                          moveto((int)row_pos, (int)col_pos);
723                          iflush();                          iflush();
724    
725                            tab_width = 0;
726                          str_len = 0;                          str_len = 0;
727                          ch = igetch_t(BBS_max_user_idle_time);                          ch = igetch_t(BBS_max_user_idle_time);
728                          while (!SYS_server_exit)                          while (!SYS_server_exit)
# Line 721  int editor_display(EDITOR_DATA *p_editor Line 738  int editor_display(EDITOR_DATA *p_editor
738                                          goto cleanup;                                          goto cleanup;
739                                  }                                  }
740    
741                                    if (ch == '\t')
742                                    {
743                                            ch = ' ';
744                                            tab_width = TAB_SIZE - ((int)(col_pos - 1) % TAB_SIZE) - 1;
745                                    }
746    
747                                  if (ch < 256 && (ch & 0x80)) // head of multi-byte character                                  if (ch < 256 && (ch & 0x80)) // head of multi-byte character
748                                  {                                  {
749                                          str_len = 0;                                          str_len = 0;
# Line 839  int editor_display(EDITOR_DATA *p_editor Line 862  int editor_display(EDITOR_DATA *p_editor
862                                                  break;                                                  break;
863                                          }                                          }
864    
865                                          ch = igetch(0);                                          if (ch == ' ' && tab_width > 0)
                                         if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Output if no futher input  
866                                          {                                          {
867                                                  break;                                                  tab_width--;
868                                            }
869                                            else
870                                            {
871                                                    ch = igetch(0);
872                                                    if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Output if no futher input
873                                                    {
874                                                            break;
875                                                    }
876                                          }                                          }
877    
878                                          str_len = 0;                                          str_len = 0;
# Line 1025  int editor_display(EDITOR_DATA *p_editor Line 1055  int editor_display(EDITOR_DATA *p_editor
1055                                          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],
1056                                                                                     (int)col_pos - 1, &eol, &display_len, 0);                                                                                     (int)col_pos - 1, &eol, &display_len, 0);
1057                                          col_pos = display_len;                                          col_pos = display_len;
1058                                          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)
1059                                          {                                          {
1060                                                  split_line(p_editor_data->p_display_lines[line_current - output_current_row + row_pos],                                                  str_len = 1;
1061                                                                     (int)col_pos - 1, &eol, &display_len, 0);                                                  offset_in--;
1062                                                  if (display_len == col_pos - 2)                                                  if (p_editor_data->p_display_lines[line_current - output_current_row + row_pos][offset_in] < 0 ||
1063                                                            p_editor_data->p_display_lines[line_current - output_current_row + row_pos][offset_in] > 127) // UTF8
1064                                                  {                                                  {
1065                                                          col_pos--;                                                          while (offset_in > 0 &&
1066                                                                       (p_editor_data->p_display_lines[line_current - output_current_row + row_pos][offset_in] & 0xc0) != 0xc0)
1067                                                            {
1068                                                                    str_len++;
1069                                                                    offset_in--;
1070                                                            }
1071    
1072                                                            if (str_len > 4)
1073                                                            {
1074                                                                    log_error("Invalid UTF-8 data detected: str_len > 4\n");
1075                                                            }
1076    
1077                                                            if (mbstowcs(wcs, p_editor_data->p_display_lines[line_current - output_current_row + row_pos] + offset_in, 1) ==
1078                                                                    (size_t)-1)
1079                                                            {
1080                                                                    log_error("mbstowcs() error\n");
1081                                                            }
1082                                                            wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0]));
1083    
1084                                                            if (wc_len == 2)
1085                                                            {
1086                                                                    col_pos--;
1087                                                            }
1088                                                  }                                                  }
1089                                          }                                          }
1090                                          if (col_pos >= 1)                                          if (col_pos >= 1)
# Line 1062  int editor_display(EDITOR_DATA *p_editor Line 1115  int editor_display(EDITOR_DATA *p_editor
1115                                          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],
1116                                                                                     (int)col_pos - 1, &eol, &display_len, 0);                                                                                     (int)col_pos - 1, &eol, &display_len, 0);
1117                                          col_pos = display_len + 2;                                          col_pos = display_len + 2;
1118                                          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  
1119                                          {                                          {
1120                                                  split_line(p_editor_data->p_display_lines[line_current - output_current_row + row_pos] + offset_in,                                                  str_len = 0;
1121                                                                     1, &eol, &display_len, 0);                                                  if ((p_editor_data->p_display_lines[line_current - output_current_row + row_pos][offset_in] & 0x80) ==
1122                                                  if (display_len == 0)                                                          0x80) // head of multi-byte character
1123                                                    {
1124                                                            c = (char)(p_editor_data->p_display_lines[line_current - output_current_row + row_pos][offset_in] & 0xf0);
1125                                                            while (c & 0x80)
1126                                                            {
1127                                                                    str_len++;
1128                                                                    c = (c & 0x7f) << 1;
1129                                                            }
1130    
1131                                                            if (str_len > 4)
1132                                                            {
1133                                                                    log_error("Invalid UTF-8 data detected: str_len > 4\n");
1134                                                            }
1135    
1136                                                            if (mbstowcs(wcs, p_editor_data->p_display_lines[line_current - output_current_row + row_pos] + offset_in, 1) ==
1137                                                                    (size_t)-1)
1138                                                            {
1139                                                                    log_error("mbstowcs() error\n");
1140                                                            }
1141                                                            wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0]));
1142    
1143                                                            if (wc_len == 2)
1144                                                            {
1145                                                                    col_pos++;
1146                                                            }
1147                                                    }
1148                                                    else
1149                                                  {                                                  {
1150                                                          col_pos++;                                                          str_len = 1;
1151                                                  }                                                  }
1152                                                    offset_in += str_len;
1153                                          }                                          }
1154                                          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])
1155                                          {                                          {


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

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