/[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.20 by sysadm, Fri Jun 13 15:50:21 2025 UTC Revision 1.22 by sysadm, Sun Jun 15 04:43:33 2025 UTC
# Line 79  EDITOR_DATA *editor_data_load(const char Line 79  EDITOR_DATA *editor_data_load(const char
79  {  {
80          EDITOR_DATA *p_editor_data;          EDITOR_DATA *p_editor_data;
81          char *p_data_line = NULL;          char *p_data_line = NULL;
82          long line_offsets[MAX_EDITOR_DATA_LINES];          long line_offsets[MAX_EDITOR_DATA_LINES + 1];
83          long current_data_line_length = 0;          long current_data_line_length = 0;
84          long i;          long i;
85    
# Line 96  EDITOR_DATA *editor_data_load(const char Line 96  EDITOR_DATA *editor_data_load(const char
96                  return NULL;                  return NULL;
97          }          }
98    
99          p_editor_data->display_line_total = split_data_lines(p_data, SCREEN_COLS, line_offsets, MAX_EDITOR_DATA_LINES);          p_editor_data->display_line_total = split_data_lines(p_data, SCREEN_COLS, line_offsets, MAX_EDITOR_DATA_LINES + 1);
100    
101          for (i = 0; i < p_editor_data->display_line_total; i++)          for (i = 0; i < p_editor_data->display_line_total; i++)
102          {          {
# Line 227  int editor_data_insert(EDITOR_DATA *p_ed Line 227  int editor_data_insert(EDITOR_DATA *p_ed
227                  return -1;                  return -1;
228          }          }
229    
230            // Validate str
231            if ((str_len == 1 && str[0] <= 0) ||
232                    (str_len == 2 && (str[0] >= 0 || str[1] >= 0)))
233            {
234                    log_error("Invalid input str, len=%d\n", str_len);
235                    return -2;
236            }
237    
238          // Get accurate offset of first character of CJK at offset position          // Get accurate offset of first character of CJK at offset position
239          for (i = 0; i < offset; i++)          for (i = 0; i < offset; i++)
240          {          {
# Line 409  int editor_data_insert(EDITOR_DATA *p_ed Line 417  int editor_data_insert(EDITOR_DATA *p_ed
417                          *p_offset -= p_editor_data->display_line_lengths[*p_display_line];                          *p_offset -= p_editor_data->display_line_lengths[*p_display_line];
418                          (*p_display_line)++;                          (*p_display_line)++;
419                  }                  }
420                  else if (*p_display_line + 1 >= MAX_EDITOR_DATA_LINES)          }
421    
422            // Prevent the last display line from being over-length
423            if (p_editor_data->display_line_total == MAX_EDITOR_DATA_LINES)
424            {
425                    len = split_line(p_editor_data->p_display_lines[p_editor_data->display_line_total - 1], SCREEN_COLS - 1, &eol, &display_len);
426                    p_editor_data->p_display_lines[p_editor_data->display_line_total - 1][len] = '\0';
427                    p_editor_data->display_line_lengths[p_editor_data->display_line_total - 1] = len;
428                    if (*p_display_line + 1 >= p_editor_data->display_line_total)
429                  {                  {
430                          len = split_line(p_editor_data->p_display_lines[*p_display_line], SCREEN_COLS - 1, &eol, &display_len);                          *p_offset = MIN(*p_offset, len);
431                          p_editor_data->p_display_lines[*p_display_line][len] = '\0';                          *p_display_line = p_editor_data->display_line_total - 1;
                         p_editor_data->display_line_lengths[*p_display_line] = len;  
                         *p_offset = len;  
432                  }                  }
433          }          }
434    
# Line 678  int editor_display(EDITOR_DATA *p_editor Line 692  int editor_display(EDITOR_DATA *p_editor
692                                          input_str[str_len] = (char)(ch - 256);                                          input_str[str_len] = (char)(ch - 256);
693                                          str_len++;                                          str_len++;
694                                  }                                  }
695                                  else                                  else if (str_len > 0)
696                                  {                                  {
697                                            log_error("Received %d character over 127 followed by character less than 127\n", str_len);
698                                          str_len = 0;                                          str_len = 0;
699                                  }                                  }
700    
701                                  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
702                                          ch == CR || ch == KEY_ESC)                                                                                       // Special character                                          ch == CR || ch == KEY_ESC)                                                                                       // Special character
703                                  {                                  {
704                                          if (str_len == 0)                                          if (str_len == 0) // ch >= 32 && ch < 127
705                                          {                                          {
706                                                  input_str[0] = (char)ch;                                                  input_str[0] = (char)ch;
707                                                  str_len = 1;                                                  str_len = 1;
# Line 711  int editor_display(EDITOR_DATA *p_editor Line 726  int editor_display(EDITOR_DATA *p_editor
726                                                                                     input_str, str_len, &last_updated_line) < 0)                                                                                     input_str, str_len, &last_updated_line) < 0)
727                                          {                                          {
728                                                  log_error("editor_data_insert(str_len=%d) error\n", str_len);                                                  log_error("editor_data_insert(str_len=%d) error\n", str_len);
                                                 str_len = 0;  
729                                          }                                          }
730                                          else                                          else
731                                          {                                          {
                                                 str_len = 0;  
   
732                                                  output_end_row = MIN(SCREEN_ROWS - 1, output_current_row + (int)(last_updated_line - line_current));                                                  output_end_row = MIN(SCREEN_ROWS - 1, output_current_row + (int)(last_updated_line - line_current));
733                                                  line_current -= (output_current_row - row_pos);                                                  line_current -= (output_current_row - row_pos);
734                                                  output_current_row = (int)row_pos;                                                  output_current_row = (int)row_pos;
# Line 747  int editor_display(EDITOR_DATA *p_editor Line 759  int editor_display(EDITOR_DATA *p_editor
759                                                  col_pos = offset_out + 1;                                                  col_pos = offset_out + 1;
760                                          }                                          }
761    
762                                            str_len = 0;
763                                          continue;                                          continue;
764                                  }                                  }
765                                  else if (ch == KEY_DEL || ch == BACKSPACE) // Del                                  else if (ch == KEY_DEL || ch == BACKSPACE) // Del
# Line 814  int editor_display(EDITOR_DATA *p_editor Line 827  int editor_display(EDITOR_DATA *p_editor
827                                                  clrline(output_current_row, output_end_row);                                                  clrline(output_current_row, output_end_row);
828                                          }                                          }
829    
830                                            str_len = 0;
831                                          continue;                                          continue;
832                                  }                                  }
833    
# Line 831  int editor_display(EDITOR_DATA *p_editor Line 845  int editor_display(EDITOR_DATA *p_editor
845                                          break;                                          break;
846                                  case Ctrl('E'): // End of line                                  case Ctrl('E'): // End of line
847                                  case KEY_CTRL_RIGHT:                                  case KEY_CTRL_RIGHT:
848                                            if (line_current + (screen_row_total - (output_current_row - screen_begin_row)) >= p_editor_data->display_line_total) // Reach end
849                                            {
850                                                    // last display line does NOT have \n in the end
851                                                    col_pos = p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] + 1;
852                                                    break;
853                                            }
854                                          col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]);                                          col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]);
855                                          break;                                          break;
856                                  case Ctrl('T'): // Top of screen                                  case Ctrl('T'): // Top of screen


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

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