/[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.27 by sysadm, Tue Jun 17 02:06:48 2025 UTC
# Line 14  Line 14 
14   *                                                                         *   *                                                                         *
15   ***************************************************************************/   ***************************************************************************/
16    
17    #define _POSIX_C_SOURCE 200809L
18    
19  #include "editor.h"  #include "editor.h"
20  #include "bbs.h"  #include "bbs.h"
21  #include "io.h"  #include "io.h"
# Line 24  Line 26 
26  #include <stdlib.h>  #include <stdlib.h>
27  #include <sys/param.h>  #include <sys/param.h>
28  #include <strings.h>  #include <strings.h>
   
 #define _POSIX_C_SOURCE 200809L  
29  #include <string.h>  #include <string.h>
30    
31  #define EDITOR_ESC_DISPLAY_STR "\033[32m*\033[m"  #define EDITOR_ESC_DISPLAY_STR "\033[32m*\033[m"
# 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, 0);
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 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    
141          bzero(p_editor_data->p_display_lines + p_editor_data->display_line_total, MAX_EDITOR_DATA_LINES - (size_t)p_editor_data->display_line_total);          memset(p_editor_data->p_display_lines + p_editor_data->display_line_total, 0, MAX_EDITOR_DATA_LINES - (size_t)p_editor_data->display_line_total);
142    
143          return p_editor_data;          return p_editor_data;
144  }  }
# Line 218  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          {          {
241                  if (p_editor_data->p_display_lines[display_line][i] < 0 || p_editor_data->p_display_lines[display_line][i] > 127) // GBK                  if (p_editor_data->p_display_lines[display_line][i] < 0) // GBK
242                  {                  {
243                          i++;                          i++;
244                  }                  }
# Line 345  int editor_data_insert(EDITOR_DATA *p_ed Line 362  int editor_data_insert(EDITOR_DATA *p_ed
362          }          }
363    
364          // Split current data line since beginning of current display line          // Split current data line since beginning of current display line
365          split_line_total = split_data_lines(p_data_line, SCREEN_COLS, line_offsets, split_line_total);          split_line_total = split_data_lines(p_data_line, SCREEN_COLS, line_offsets, split_line_total, 0);
366    
367          for (i = 0; i < split_line_total; i++)          for (i = 0; i < split_line_total; i++)
368          {          {
# Line 358  int editor_data_insert(EDITOR_DATA *p_ed Line 375  int editor_data_insert(EDITOR_DATA *p_ed
375                                  // Terminate prior display line with \n, to avoid error on cleanup                                  // Terminate prior display line with \n, to avoid error on cleanup
376                                  if (display_line + i - 1 >= 0 && p_editor_data->display_line_lengths[display_line + i - 1] > 0)                                  if (display_line + i - 1 >= 0 && p_editor_data->display_line_lengths[display_line + i - 1] > 0)
377                                  {                                  {
378                                          len = split_line(p_editor_data->p_display_lines[display_line + i - 1], SCREEN_COLS - 1, &eol, &display_len);                                          len = split_line(p_editor_data->p_display_lines[display_line + i - 1], SCREEN_COLS - 1, &eol, &display_len, 0);
379                                          p_editor_data->p_display_lines[display_line + i - 1][len] = '\n';                                          p_editor_data->p_display_lines[display_line + i - 1][len] = '\n';
380                                          p_editor_data->p_display_lines[display_line + i - 1][len + 1] = '\0';                                          p_editor_data->p_display_lines[display_line + i - 1][len + 1] = '\0';
381                                          p_editor_data->display_line_lengths[display_line + i - 1] = len + 1;                                          p_editor_data->display_line_lengths[display_line + i - 1] = len + 1;
# Line 395  int editor_data_insert(EDITOR_DATA *p_ed Line 412  int editor_data_insert(EDITOR_DATA *p_ed
412    
413          if (*p_offset >= p_editor_data->display_line_lengths[*p_display_line])          if (*p_offset >= p_editor_data->display_line_lengths[*p_display_line])
414          {          {
415                  *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)  
416                  {                  {
417                          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];
418                            (*p_display_line)++;
419                  }                  }
420                  else          }
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, 0);
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                          (*p_display_line)++;                          *p_offset = MIN(*p_offset, len);
431                            *p_display_line = p_editor_data->display_line_total - 1;
432                  }                  }
433          }          }
434    
435          return 0;          return 0;
436  }  }
437    
438  int editor_data_delete(EDITOR_DATA *p_editor_data, long display_line, long offset,  int editor_data_delete(EDITOR_DATA *p_editor_data, long *p_display_line, long *p_offset,
439                                             long *p_last_updated_line)                                             long *p_last_updated_line)
440  {  {
441            long display_line = *p_display_line;
442            long offset = *p_offset;
443          char *p_data_line = NULL;          char *p_data_line = NULL;
444          long len_data_line;          long len_data_line;
445          long offset_data_line;          long offset_data_line;
# Line 431  int editor_data_delete(EDITOR_DATA *p_ed Line 458  int editor_data_delete(EDITOR_DATA *p_ed
458          // Get accurate offset of first character of CJK at offset position          // Get accurate offset of first character of CJK at offset position
459          for (i = 0; i < offset; i++)          for (i = 0; i < offset; i++)
460          {          {
461                  if (p_editor_data->p_display_lines[display_line][i] < 0 || p_editor_data->p_display_lines[display_line][i] > 127) // GBK                  if (p_editor_data->p_display_lines[display_line][i] < 0) // GBK
462                  {                  {
463                          i++;                          i++;
464                  }                  }
# Line 469  int editor_data_delete(EDITOR_DATA *p_ed Line 496  int editor_data_delete(EDITOR_DATA *p_ed
496                  }                  }
497          }          }
498    
499            if (offset_data_line >= len_data_line) // end-of-line
500            {
501                    return 0;
502            }
503    
504          // Check str to be deleted          // Check str to be deleted
505          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)
506          {          {
507                  str_len = 1;                  str_len = 1;
508          }          }
509          else if (p_data_line[offset_data_line + 1] < 0 || p_data_line[offset_data_line] > 127) // GBK          else if (p_data_line[offset_data_line + 1] < 0) // GBK
510          {          {
511                  str_len = 2;                  str_len = 2;
512          }          }
513          else          else
514          {          {
515                  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",
516                                    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]);  
517                  str_len = 1;                  str_len = 1;
518          }          }
519    
# Line 533  int editor_data_delete(EDITOR_DATA *p_ed Line 564  int editor_data_delete(EDITOR_DATA *p_ed
564          split_line_total = last_display_line - display_line + 2;          split_line_total = last_display_line - display_line + 2;
565    
566          // Split current data line since beginning of current display line          // Split current data line since beginning of current display line
567          split_line_total = split_data_lines(p_data_line, SCREEN_COLS, line_offsets, split_line_total);          split_line_total = split_data_lines(p_data_line, SCREEN_COLS, line_offsets, split_line_total, 0);
568    
569          for (i = 0; i < split_line_total; i++)          for (i = 0; i < split_line_total; i++)
570          {          {
# Line 552  int editor_data_delete(EDITOR_DATA *p_ed Line 583  int editor_data_delete(EDITOR_DATA *p_ed
583    
584          *p_last_updated_line = display_line + MIN(i, split_line_total - 1);          *p_last_updated_line = display_line + MIN(i, split_line_total - 1);
585    
586          if (display_line + i < last_display_line)          if (*p_last_updated_line < last_display_line)
587          {          {
588                  // Remove redundant display line after last_display_line                  // Remove redundant display line after last_display_line
589                  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++)
590                  {                  {
591                          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];
592                          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];
593                  }                  }
594    
595                  (p_editor_data->display_line_total) -= (last_display_line - (display_line + i));                  j = p_editor_data->display_line_total;
596                  last_display_line = display_line + i;                  (p_editor_data->display_line_total) -= (last_display_line - *p_last_updated_line);
597                    *p_last_updated_line = MAX(j - 1, *p_last_updated_line);
                 *p_last_updated_line = p_editor_data->display_line_total - 1;  
598          }          }
599    
600            // Return real offset
601            *p_offset = offset;
602    
603          return str_len;          return str_len;
604  }  }
605    
# Line 576  static int editor_display_key_handler(in Line 609  static int editor_display_key_handler(in
609          {          {
610          case 0: // Set msg          case 0: // Set msg
611                  snprintf(p_ctx->msg, sizeof(p_ctx->msg),                  snprintf(p_ctx->msg, sizeof(p_ctx->msg),
612                                   "| Í˳ö[\033[32mCtrl-C\033[33m] | °ïÖú[\033[32mh\033[33m] |");                                   "| Í˳ö[\033[32mCtrl-W\033[33m] |");
613                    break;
614            case KEY_CSI:
615                    *p_key = KEY_ESC;
616                  break;                  break;
617          }          }
618    
# Line 630  int editor_display(EDITOR_DATA *p_editor Line 666  int editor_display(EDITOR_DATA *p_editor
666                                           "%s",                                           "%s",
667                                           row_pos, col_pos,                                           row_pos, col_pos,
668                                           ctx.line_cursor, p_editor_data->display_line_total,                                           ctx.line_cursor, p_editor_data->display_line_total,
669                                           key_insert ? "²åÈë" : "¸Äд",                                           key_insert ? "²åÈë" : "Ìæ»»",
670                                           ctx.msg);                                           ctx.msg);
671    
672                          len = split_line(buffer, SCREEN_COLS, &eol, &display_len);                          len = split_line(buffer, SCREEN_COLS, &eol, &display_len, 1);
673                          for (; display_len < SCREEN_COLS; display_len++)                          for (; display_len < SCREEN_COLS; display_len++)
674                          {                          {
675                                  buffer[len++] = ' ';                                  buffer[len++] = ' ';
# Line 647  int editor_display(EDITOR_DATA *p_editor Line 683  int editor_display(EDITOR_DATA *p_editor
683                          moveto((int)row_pos, (int)col_pos);                          moveto((int)row_pos, (int)col_pos);
684                          iflush();                          iflush();
685    
686                            str_len = 0;
687                          input_ok = 0;                          input_ok = 0;
688                            ch = igetch_t(MAX_DELAY_TIME);
689                          while (!SYS_server_exit && !input_ok)                          while (!SYS_server_exit && !input_ok)
690                          {                          {
                                 ch = igetch_t(MAX_DELAY_TIME);  
                                 input_ok = 1;  
   
691                                  // extended key handler                                  // extended key handler
692                                  if (editor_display_key_handler(&ch, &ctx) != 0)                                  if (editor_display_key_handler(&ch, &ctx) != 0)
693                                  {                                  {
# Line 664  int editor_display(EDITOR_DATA *p_editor Line 699  int editor_display(EDITOR_DATA *p_editor
699                                          input_str[str_len] = (char)(ch - 256);                                          input_str[str_len] = (char)(ch - 256);
700                                          str_len++;                                          str_len++;
701                                  }                                  }
702                                  else                                  else if (str_len > 0)
703                                  {                                  {
704                                            log_error("Received %d character over 127 followed by character less than 127\n", str_len);
705                                          str_len = 0;                                          str_len = 0;
706                                  }                                  }
707    
708                                  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
709                                          ch == CR || ch == KEY_ESC)                                                                                       // Special character                                          ch == CR || ch == KEY_ESC)                                                                                       // Special character
710                                  {                                  {
711                                          if (str_len == 0)                                          BBS_last_access_tm = time(NULL);
712    
713                                            if (str_len == 0) // ch >= 32 && ch < 127
714                                          {                                          {
715                                                  input_str[0] = (char)ch;                                                  input_str[0] = (char)ch;
716                                                  str_len = 1;                                                  str_len = 1;
# Line 686  int editor_display(EDITOR_DATA *p_editor Line 724  int editor_display(EDITOR_DATA *p_editor
724    
725                                          if (!key_insert) // overwrite                                          if (!key_insert) // overwrite
726                                          {                                          {
727                                                  if (editor_data_delete(p_editor_data, display_line_in, offset_in,                                                  if (editor_data_delete(p_editor_data, &display_line_out, &offset_out,
728                                                                                             &last_updated_line) < 0)                                                                                             &last_updated_line) < 0)
729                                                  {                                                  {
730                                                          log_error("editor_data_delete() error\n");                                                          log_error("editor_data_delete() error\n");
# Line 697  int editor_display(EDITOR_DATA *p_editor Line 735  int editor_display(EDITOR_DATA *p_editor
735                                                                                     input_str, str_len, &last_updated_line) < 0)                                                                                     input_str, str_len, &last_updated_line) < 0)
736                                          {                                          {
737                                                  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;  
738                                          }                                          }
739                                          else                                          else
740                                          {                                          {
                                                 str_len = 0;  
   
741                                                  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));
742                                                  line_current -= (output_current_row - row_pos);                                                  line_current -= (output_current_row - row_pos);
743                                                  output_current_row = (int)row_pos;                                                  output_current_row = (int)row_pos;
# Line 730  int editor_display(EDITOR_DATA *p_editor Line 765  int editor_display(EDITOR_DATA *p_editor
765                                                  {                                                  {
766                                                          row_pos += (display_line_out - display_line_in);                                                          row_pos += (display_line_out - display_line_in);
767                                                  }                                                  }
768                                                  col_pos = offset_out + 1;                                                  col_pos = offset_out + 1; // Set col_pos to accurate pos
769                                            }
770    
771                                            if (display_line_out != display_line_in) // Output on line change
772                                            {
773                                                    break;
774                                            }
775    
776                                            ch = igetch(0);
777                                            if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Output if no futher input
778                                            {
779                                                    break;
780                                          }                                          }
781    
782                                            str_len = 0;
783                                          continue;                                          continue;
784                                  }                                  }
785                                  else if (ch == KEY_DEL || ch == BACKSPACE) // Del                                  else if (ch == KEY_DEL || ch == BACKSPACE) // Del
786                                  {                                  {
787                                            BBS_last_access_tm = time(NULL);
788    
789                                          if (ch == BACKSPACE)                                          if (ch == BACKSPACE)
790                                          {                                          {
791                                                    if (line_current - output_current_row + row_pos <= 0 && col_pos <= 1) // Forbidden
792                                                    {
793                                                            ch = igetch_t(MAX_DELAY_TIME);
794                                                            continue;
795                                                    }
796    
797                                                  col_pos--;                                                  col_pos--;
798                                                    if (col_pos > 1 &&
799                                                            p_editor_data->p_display_lines[line_current - output_current_row + row_pos][col_pos - 1] < 0) // GBK
800                                                    {
801                                                            col_pos--;
802                                                    }
803    
804                                                  if (col_pos < 1 && line_current - output_current_row + row_pos >= 0)                                                  if (col_pos < 1 && line_current - output_current_row + row_pos >= 0)
805                                                  {                                                  {
806                                                          row_pos--;                                                          row_pos--;
# Line 747  int editor_display(EDITOR_DATA *p_editor Line 808  int editor_display(EDITOR_DATA *p_editor
808                                                  }                                                  }
809                                          }                                          }
810    
811                                          if ((str_len = editor_data_delete(p_editor_data, line_current - output_current_row + row_pos, col_pos - 1,                                          display_line_in = line_current - output_current_row + row_pos;
812                                            offset_in = col_pos - 1;
813                                            display_line_out = display_line_in;
814                                            offset_out = offset_in;
815    
816                                            if ((str_len = editor_data_delete(p_editor_data, &display_line_out, &offset_out,
817                                                                                                            &last_updated_line)) < 0)                                                                                                            &last_updated_line)) < 0)
818                                          {                                          {
819                                                  log_error("editor_data_delete() error\n");                                                  log_error("editor_data_delete() error\n");
820                                          }                                          }
821                                          else                                          else
822                                          {                                          {
823                                                  if (ch == BACKSPACE)                                                  col_pos = offset_out + 1; // Set col_pos to accurate pos
                                                 {  
                                                         for (i = 1; i < str_len; i++)  
                                                         {  
                                                                 col_pos--;  
                                                                 if (col_pos < 1 && line_current - output_current_row + row_pos >= 0)  
                                                                 {  
                                                                         row_pos--;  
                                                                         col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]);  
                                                                 }  
                                                         }  
                                                 }  
824    
825                                                  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));
826                                                  line_current -= (output_current_row - row_pos);                                                  line_current -= (output_current_row - row_pos);
# Line 789  int editor_display(EDITOR_DATA *p_editor Line 844  int editor_display(EDITOR_DATA *p_editor
844                                                          row_pos += scroll_rows;                                                          row_pos += scroll_rows;
845                                                          output_current_row = screen_begin_row;                                                          output_current_row = screen_begin_row;
846                                                          output_end_row = SCREEN_ROWS - 1;                                                          output_end_row = SCREEN_ROWS - 1;
                                                         clrline(output_current_row, SCREEN_ROWS);  
847                                                  }                                                  }
848    
849                                                    clrline(output_current_row, output_end_row);
850                                            }
851    
852                                            if (display_line_out != display_line_in) // Output on line change
853                                            {
854                                                    break;
855                                            }
856    
857                                            ch = igetch(0);
858                                            if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Output if no futher input
859                                            {
860                                                    break;
861                                          }                                          }
862    
863                                            str_len = 0;
864                                          continue;                                          continue;
865                                  }                                  }
866    
867                                    input_ok = 1;
868                                  switch (ch)                                  switch (ch)
869                                  {                                  {
870                                  case KEY_NULL:                                  case KEY_NULL:
871                                  case KEY_TIMEOUT:                                  case KEY_TIMEOUT:
872                                          goto cleanup;                                          goto cleanup;
873                                  case Ctrl('C'):                                  case Ctrl('W'):
874                                          loop = 0;                                          loop = 0;
875                                          break;                                          break;
876                                  case Ctrl('S'): // Start of line                                  case Ctrl('S'): // Start of line
# Line 810  int editor_display(EDITOR_DATA *p_editor Line 879  int editor_display(EDITOR_DATA *p_editor
879                                          break;                                          break;
880                                  case Ctrl('E'): // End of line                                  case Ctrl('E'): // End of line
881                                  case KEY_CTRL_RIGHT:                                  case KEY_CTRL_RIGHT:
882                                            if (line_current - output_current_row + row_pos == p_editor_data->display_line_total - 1) // row_pos at end line
883                                            {
884                                                    // last display line does NOT have \n in the end
885                                                    col_pos = p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] + 1;
886                                                    break;
887                                            }
888                                          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]);
889                                          break;                                          break;
890                                  case Ctrl('T'): // Top of screen                                  case Ctrl('T'): // Top of screen
# Line 819  int editor_display(EDITOR_DATA *p_editor Line 894  int editor_display(EDITOR_DATA *p_editor
894                                          break;                                          break;
895                                  case Ctrl('B'): // Bottom of screen                                  case Ctrl('B'): // Bottom of screen
896                                  case KEY_CTRL_DOWN:                                  case KEY_CTRL_DOWN:
897                                          row_pos = SCREEN_ROWS - 1;                                          if (p_editor_data->display_line_total < screen_row_total)
898                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]));                                          {
899                                                    row_pos = p_editor_data->display_line_total;
900                                            }
901                                            else
902                                            {
903                                                    row_pos = SCREEN_ROWS - 1;
904                                            }
905                                            if (line_current + (screen_row_total - (output_current_row - screen_begin_row)) >= p_editor_data->display_line_total) // Reach end
906                                            {
907                                                    // last display line does NOT have \n in the end
908                                                    col_pos = MIN(col_pos, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] + 1);
909                                            }
910                                            else
911                                            {
912                                                    col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]));
913                                            }
914                                          break;                                          break;
915                                  case KEY_INS:                                  case KEY_INS:
916                                          key_insert = !key_insert;                                          key_insert = !key_insert;
# Line 841  int editor_display(EDITOR_DATA *p_editor Line 931  int editor_display(EDITOR_DATA *p_editor
931                                          if (p_editor_data->display_line_total < screen_row_total)                                          if (p_editor_data->display_line_total < screen_row_total)
932                                          {                                          {
933                                                  row_pos = p_editor_data->display_line_total;                                                  row_pos = p_editor_data->display_line_total;
934                                                  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;
935                                                  break;                                                  break;
936                                          }                                          }
937                                          line_current = p_editor_data->display_line_total - screen_row_total;                                          line_current = p_editor_data->display_line_total - screen_row_total;
938                                          output_current_row = screen_begin_row;                                          output_current_row = screen_begin_row;
939                                          output_end_row = SCREEN_ROWS - 1;                                          output_end_row = SCREEN_ROWS - 1;
940                                          row_pos = SCREEN_ROWS - 1;                                          row_pos = SCREEN_ROWS - 1;
941                                          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;
942                                          clrline(output_current_row, SCREEN_ROWS);                                          clrline(output_current_row, SCREEN_ROWS);
943                                          break;                                          break;
944                                  case KEY_LEFT:                                  case KEY_LEFT:
945                                          if (col_pos > 1)                                          if (col_pos > 1)
946                                          {                                          {
947                                                  col_pos--;                                                  col_pos--;
948                                                    if (col_pos > 1 &&
949                                                            p_editor_data->p_display_lines[line_current - output_current_row + row_pos][col_pos - 1] < 0 &&
950                                                            p_editor_data->p_display_lines[line_current - output_current_row + row_pos][col_pos - 2] < 0) // GBK
951                                                    {
952                                                            col_pos--;
953                                                    }
954                                                  break;                                                  break;
955                                          }                                          }
956                                          col_pos = SCREEN_COLS; // continue to KEY_UP                                          col_pos = SCREEN_COLS; // continue to KEY_UP
# Line 882  int editor_display(EDITOR_DATA *p_editor Line 978  int editor_display(EDITOR_DATA *p_editor
978                                  case KEY_RIGHT:                                  case KEY_RIGHT:
979                                          if (col_pos < p_editor_data->display_line_lengths[line_current - output_current_row + row_pos])                                          if (col_pos < p_editor_data->display_line_lengths[line_current - output_current_row + row_pos])
980                                          {                                          {
981                                                    if (p_editor_data->p_display_lines[line_current - output_current_row + row_pos][col_pos - 1] < 0 &&
982                                                            p_editor_data->p_display_lines[line_current - output_current_row + row_pos][col_pos] < 0) // GBK
983                                                    {
984                                                            col_pos++;
985                                                    }
986                                                  col_pos++;                                                  col_pos++;
987                                                  break;                                                  break;
988                                          }                                          }
# Line 893  int editor_display(EDITOR_DATA *p_editor Line 994  int editor_display(EDITOR_DATA *p_editor
994                                                  col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]));                                                  col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]));
995                                                  break;                                                  break;
996                                          }                                          }
997                                          if (line_current + (screen_row_total - (output_current_row - screen_begin_row)) >= p_editor_data->display_line_total) // Reach end                                          if (line_current - output_current_row + row_pos == p_editor_data->display_line_total - 1) // row_pos at end line
998                                          {                                          {
999                                                  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
1000                                                    col_pos = p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] + 1;
1001                                                  break;                                                  break;
1002                                          }                                          }
1003                                          line_current += (screen_row_total - (output_current_row - screen_begin_row));                                          line_current += (screen_row_total - (output_current_row - screen_begin_row));
# Line 959  int editor_display(EDITOR_DATA *p_editor Line 1061  int editor_display(EDITOR_DATA *p_editor
1061                                          break;                                          break;
1062                                  }                                  }
1063    
1064                                  BBS_last_access_tm = time(0);                                  BBS_last_access_tm = time(NULL);
1065    
1066                                  if (input_ok)                                  if (input_ok)
1067                                  {                                  {
1068                                          break;                                          break;
1069                                  }                                  }
1070    
1071                                    ch = igetch_t(MAX_DELAY_TIME);
1072                          }                          }
1073    
1074                          continue;                          continue;


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

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