/[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.16 by sysadm, Thu Jun 12 10:34:21 2025 UTC Revision 1.20 by sysadm, Fri Jun 13 15:50:21 2025 UTC
# Line 126  EDITOR_DATA *editor_data_load(const char Line 126  EDITOR_DATA *editor_data_load(const char
126    
127                  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]);
128                  current_data_line_length += p_editor_data->display_line_lengths[i];                  current_data_line_length += p_editor_data->display_line_lengths[i];
129    
130                    // Trim \n from last line
131                    if (i + 1 == p_editor_data->display_line_total &&
132                            p_editor_data->display_line_lengths[i] > 0 &&
133                            p_editor_data->p_display_lines[i][p_editor_data->display_line_lengths[i] - 1] == '\n')
134                    {
135                            p_editor_data->display_line_lengths[i]--;
136                            current_data_line_length--;
137                    }
138                  p_data_line[current_data_line_length] = '\0';                  p_data_line[current_data_line_length] = '\0';
139          }          }
140    
# Line 395  int editor_data_insert(EDITOR_DATA *p_ed Line 404  int editor_data_insert(EDITOR_DATA *p_ed
404    
405          if (*p_offset >= p_editor_data->display_line_lengths[*p_display_line])          if (*p_offset >= p_editor_data->display_line_lengths[*p_display_line])
406          {          {
407                  *p_offset -= p_editor_data->display_line_lengths[*p_display_line];                  if (*p_display_line + 1 < p_editor_data->display_line_total)
   
                 if (*p_display_line + 1 >= p_editor_data->display_line_total)  
408                  {                  {
409                          log_error("*p_display_line(%d) >= display_line_total(%d)\n", *p_display_line, p_editor_data->display_line_total);                          *p_offset -= p_editor_data->display_line_lengths[*p_display_line];
410                            (*p_display_line)++;
411                  }                  }
412                  else                  else if (*p_display_line + 1 >= MAX_EDITOR_DATA_LINES)
413                  {                  {
414                          (*p_display_line)++;                          len = split_line(p_editor_data->p_display_lines[*p_display_line], SCREEN_COLS - 1, &eol, &display_len);
415                            p_editor_data->p_display_lines[*p_display_line][len] = '\0';
416                            p_editor_data->display_line_lengths[*p_display_line] = len;
417                            *p_offset = len;
418                  }                  }
419          }          }
420    
# Line 469  int editor_data_delete(EDITOR_DATA *p_ed Line 480  int editor_data_delete(EDITOR_DATA *p_ed
480                  }                  }
481          }          }
482    
483            if (offset_data_line >= len_data_line) // end-of-line
484            {
485                    return 0;
486            }
487    
488          // Check str to be deleted          // Check str to be deleted
489          if (p_data_line[offset_data_line] > 0 && p_data_line[offset_data_line] < 127)          if (p_data_line[offset_data_line] > 0 && p_data_line[offset_data_line] < 127)
490          {          {
# Line 480  int editor_data_delete(EDITOR_DATA *p_ed Line 496  int editor_data_delete(EDITOR_DATA *p_ed
496          }          }
497          else          else
498          {          {
499                  log_error("Some strange character at display_line %ld, offset %ld: %d %d %d %d\n",                  log_error("Some strange character at display_line %ld, offset %ld: %d %d\n",
500                                    display_line, offset, p_data_line[offset_data_line], p_data_line[offset_data_line + 1],                                    display_line, offset, p_data_line[offset_data_line], p_data_line[offset_data_line + 1]);
                                   p_data_line[offset_data_line + 2], p_data_line[offset_data_line + 3]);  
501                  str_len = 1;                  str_len = 1;
502          }          }
503    
# Line 552  int editor_data_delete(EDITOR_DATA *p_ed Line 567  int editor_data_delete(EDITOR_DATA *p_ed
567    
568          *p_last_updated_line = display_line + MIN(i, split_line_total - 1);          *p_last_updated_line = display_line + MIN(i, split_line_total - 1);
569    
570          if (display_line + i < last_display_line)          if (*p_last_updated_line < last_display_line)
571          {          {
572                  // Remove redundant display line after last_display_line                  // Remove redundant display line after last_display_line
573                  for (j = last_display_line + 1; j < p_editor_data->display_line_total; j++)                  for (j = last_display_line + 1; j < p_editor_data->display_line_total; j++)
574                  {                  {
575                          p_editor_data->p_display_lines[j - (last_display_line - (display_line + i))] = p_editor_data->p_display_lines[j];                          p_editor_data->p_display_lines[j - (last_display_line - *p_last_updated_line)] = p_editor_data->p_display_lines[j];
576                          p_editor_data->display_line_lengths[j - (last_display_line - (display_line + i))] = p_editor_data->display_line_lengths[j];                          p_editor_data->display_line_lengths[j - (last_display_line - *p_last_updated_line)] = p_editor_data->display_line_lengths[j];
577                  }                  }
578    
579                  (p_editor_data->display_line_total) -= (last_display_line - (display_line + i));                  j = p_editor_data->display_line_total;
580                  last_display_line = display_line + i;                  (p_editor_data->display_line_total) -= (last_display_line - *p_last_updated_line);
581                    *p_last_updated_line = MAX(j - 1, *p_last_updated_line);
                 *p_last_updated_line = p_editor_data->display_line_total - 1;  
582          }          }
583    
584          return str_len;          return str_len;
# Line 576  static int editor_display_key_handler(in Line 590  static int editor_display_key_handler(in
590          {          {
591          case 0: // Set msg          case 0: // Set msg
592                  snprintf(p_ctx->msg, sizeof(p_ctx->msg),                  snprintf(p_ctx->msg, sizeof(p_ctx->msg),
593                                   "| Í˳ö[\033[32mCtrl-C\033[33m] | °ïÖú[\033[32mh\033[33m] |");                                   "| Í˳ö[\033[32mCtrl-W\033[33m] | °ïÖú[\033[32mh\033[33m] |");
594                  break;                  break;
595          }          }
596    
# Line 739  int editor_display(EDITOR_DATA *p_editor Line 753  int editor_display(EDITOR_DATA *p_editor
753                                  {                                  {
754                                          if (ch == BACKSPACE)                                          if (ch == BACKSPACE)
755                                          {                                          {
756                                                    if (line_current - output_current_row + row_pos <= 0 && col_pos <= 1) // Forbidden
757                                                    {
758                                                            input_ok = 0;
759                                                            continue;
760                                                    }
761    
762                                                  col_pos--;                                                  col_pos--;
763                                                  if (col_pos < 1 && line_current - output_current_row + row_pos >= 0)                                                  if (col_pos < 1 && line_current - output_current_row + row_pos >= 0)
764                                                  {                                                  {
# Line 789  int editor_display(EDITOR_DATA *p_editor Line 809  int editor_display(EDITOR_DATA *p_editor
809                                                          row_pos += scroll_rows;                                                          row_pos += scroll_rows;
810                                                          output_current_row = screen_begin_row;                                                          output_current_row = screen_begin_row;
811                                                          output_end_row = SCREEN_ROWS - 1;                                                          output_end_row = SCREEN_ROWS - 1;
                                                         clrline(output_current_row, SCREEN_ROWS);  
812                                                  }                                                  }
813    
814                                                    clrline(output_current_row, output_end_row);
815                                          }                                          }
816    
817                                          continue;                                          continue;
# Line 801  int editor_display(EDITOR_DATA *p_editor Line 822  int editor_display(EDITOR_DATA *p_editor
822                                  case KEY_NULL:                                  case KEY_NULL:
823                                  case KEY_TIMEOUT:                                  case KEY_TIMEOUT:
824                                          goto cleanup;                                          goto cleanup;
825                                  case Ctrl('C'):                                  case Ctrl('W'):
826                                          loop = 0;                                          loop = 0;
827                                          break;                                          break;
828                                  case Ctrl('S'): // Start of line                                  case Ctrl('S'): // Start of line
# Line 819  int editor_display(EDITOR_DATA *p_editor Line 840  int editor_display(EDITOR_DATA *p_editor
840                                          break;                                          break;
841                                  case Ctrl('B'): // Bottom of screen                                  case Ctrl('B'): // Bottom of screen
842                                  case KEY_CTRL_DOWN:                                  case KEY_CTRL_DOWN:
843                                          row_pos = SCREEN_ROWS - 1;                                          if (p_editor_data->display_line_total < screen_row_total)
844                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]));                                          {
845                                                    row_pos = p_editor_data->display_line_total;
846                                            }
847                                            else
848                                            {
849                                                    row_pos = SCREEN_ROWS - 1;
850                                            }
851                                            if (line_current + (screen_row_total - (output_current_row - screen_begin_row)) >= p_editor_data->display_line_total) // Reach end
852                                            {
853                                                    // last display line does NOT have \n in the end
854                                                    col_pos = MIN(col_pos, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] + 1);
855                                            }
856                                            else
857                                            {
858                                                    col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]));
859                                            }
860                                          break;                                          break;
861                                  case KEY_INS:                                  case KEY_INS:
862                                          key_insert = !key_insert;                                          key_insert = !key_insert;
# Line 841  int editor_display(EDITOR_DATA *p_editor Line 877  int editor_display(EDITOR_DATA *p_editor
877                                          if (p_editor_data->display_line_total < screen_row_total)                                          if (p_editor_data->display_line_total < screen_row_total)
878                                          {                                          {
879                                                  row_pos = p_editor_data->display_line_total;                                                  row_pos = p_editor_data->display_line_total;
880                                                  col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]);                                                  col_pos = p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] + 1;
881                                                  break;                                                  break;
882                                          }                                          }
883                                          line_current = p_editor_data->display_line_total - screen_row_total;                                          line_current = p_editor_data->display_line_total - screen_row_total;
884                                          output_current_row = screen_begin_row;                                          output_current_row = screen_begin_row;
885                                          output_end_row = SCREEN_ROWS - 1;                                          output_end_row = SCREEN_ROWS - 1;
886                                          row_pos = SCREEN_ROWS - 1;                                          row_pos = SCREEN_ROWS - 1;
887                                          col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]);                                          col_pos = p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] + 1;
888                                          clrline(output_current_row, SCREEN_ROWS);                                          clrline(output_current_row, SCREEN_ROWS);
889                                          break;                                          break;
890                                  case KEY_LEFT:                                  case KEY_LEFT:
# Line 895  int editor_display(EDITOR_DATA *p_editor Line 931  int editor_display(EDITOR_DATA *p_editor
931                                          }                                          }
932                                          if (line_current + (screen_row_total - (output_current_row - screen_begin_row)) >= p_editor_data->display_line_total) // Reach end                                          if (line_current + (screen_row_total - (output_current_row - screen_begin_row)) >= p_editor_data->display_line_total) // Reach end
933                                          {                                          {
934                                                  col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]);                                                  // last display line does NOT have \n in the end
935                                                    col_pos = p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] + 1;
936                                                  break;                                                  break;
937                                          }                                          }
938                                          line_current += (screen_row_total - (output_current_row - screen_begin_row));                                          line_current += (screen_row_total - (output_current_row - screen_begin_row));


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

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