/[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.40 by sysadm, Sun Jul 20 02:04:21 2025 UTC Revision 1.60 by sysadm, Tue Nov 11 00:28:05 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /* SPDX-License-Identifier: GPL-3.0-or-later */
2                                                     editor.h  -  description  /*
3                                                           -------------------   * editor
4          copyright            : (C) 2004-2025 by Leaflet   *   - user interactive full-screen text editor
5          email                : leaflet@leafok.com   *
6   ***************************************************************************/   * Copyright (C) 2004-2025  Leaflet <leaflet@leafok.com>
7     */
8  /***************************************************************************  
9   *                                                                         *  #ifdef HAVE_CONFIG_H
10   *   This program is free software; you can redistribute it and/or modify  *  #include "config.h"
11   *   it under the terms of the GNU General Public License as published by  *  #endif
  *   the Free Software Foundation; either version 3 of the License, or     *  
  *   (at your option) any later version.                                   *  
  *                                                                         *  
  ***************************************************************************/  
12    
13  #include "bbs.h"  #include "bbs.h"
14  #include "common.h"  #include "common.h"
15  #include "editor.h"  #include "editor.h"
16  #include "io.h"  #include "io.h"
17  #include "log.h"  #include "log.h"
18    #include "login.h"
19  #include "memory_pool.h"  #include "memory_pool.h"
20  #include "str_process.h"  #include "str_process.h"
21  #include <stdlib.h>  #include <stdlib.h>
22  #include <string.h>  #include <string.h>
23    #include <wchar.h>
24  #include <sys/param.h>  #include <sys/param.h>
25    
26  #define EDITOR_ESC_DISPLAY_STR "\033[32m*\033[m"  enum _editor_constant_t
27  #define EDITOR_MEM_POOL_LINE_PER_CHUNK 1000  {
28  #define EDITOR_MEM_POOL_CHUNK_LIMIT (MAX_EDITOR_DATA_LINES / EDITOR_MEM_POOL_LINE_PER_CHUNK + 1)          EDITOR_MEM_POOL_LINE_PER_CHUNK = 1000,
29            EDITOR_MEM_POOL_CHUNK_LIMIT = (MAX_EDITOR_DATA_LINES / EDITOR_MEM_POOL_LINE_PER_CHUNK + 1),
30    };
31    
32    static const char EDITOR_ESC_DISPLAY_STR[] = "\033[32m*\033[m";
33    
34  static MEMORY_POOL *p_mp_data_line;  static MEMORY_POOL *p_mp_data_line;
35  static MEMORY_POOL *p_mp_editor_data;  static MEMORY_POOL *p_mp_editor_data;
# Line 48  int editor_memory_pool_init(void) Line 50  int editor_memory_pool_init(void)
50          }          }
51    
52          p_mp_editor_data = memory_pool_init(sizeof(EDITOR_DATA), 1, 1);          p_mp_editor_data = memory_pool_init(sizeof(EDITOR_DATA), 1, 1);
53          if (p_mp_data_line == NULL)          if (p_mp_editor_data == NULL)
54          {          {
55                  log_error("Memory pool init error\n");                  log_error("Memory pool init error\n");
56                  return -3;                  return -3;
# Line 79  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          {          {
88                  log_error("editor_data_load() error: NULL pointer\n");                  log_error("NULL pointer error\n");
89                  return NULL;                  return NULL;
90          }          }
91    
# Line 125  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 149  long editor_data_save(const EDITOR_DATA Line 161  long editor_data_save(const EDITOR_DATA
161    
162          if (p_editor_data == NULL || p_data == NULL)          if (p_editor_data == NULL || p_data == NULL)
163          {          {
164                  log_error("editor_data_save() error: NULL pointer\n");                  log_error("NULL pointer error\n");
165                  return -1;                  return -1;
166          }          }
167    
# Line 223  int editor_data_insert(EDITOR_DATA *p_ed Line 235  int editor_data_insert(EDITOR_DATA *p_ed
235    
236          if (p_editor_data == NULL || p_last_updated_line == NULL)          if (p_editor_data == NULL || p_last_updated_line == NULL)
237          {          {
238                  log_error("editor_data_op() error: NULL pointer\n");                  log_error("NULL pointer error\n");
239                  return -1;                  return -1;
240          }          }
241    
# Line 444  int editor_data_insert(EDITOR_DATA *p_ed Line 456  int editor_data_insert(EDITOR_DATA *p_ed
456  }  }
457    
458  int editor_data_delete(EDITOR_DATA *p_editor_data, long *p_display_line, long *p_offset,  int editor_data_delete(EDITOR_DATA *p_editor_data, long *p_display_line, long *p_offset,
459                                             long *p_last_updated_line)                                             long *p_last_updated_line, int del_line)
460  {  {
461          long display_line = *p_display_line;          long display_line = *p_display_line;
462          long offset = *p_offset;          long offset = *p_offset;
# Line 461  int editor_data_delete(EDITOR_DATA *p_ed Line 473  int editor_data_delete(EDITOR_DATA *p_ed
473    
474          if (p_editor_data == NULL || p_last_updated_line == NULL)          if (p_editor_data == NULL || p_last_updated_line == NULL)
475          {          {
476                  log_error("editor_data_op() error: NULL pointer\n");                  log_error("NULL pointer error\n");
477                  return -1;                  return -1;
478          }          }
479    
# Line 499  int editor_data_delete(EDITOR_DATA *p_ed Line 511  int editor_data_delete(EDITOR_DATA *p_ed
511          }          }
512    
513          // Check str to be deleted          // Check str to be deleted
514          if (p_data_line[offset_data_line] > 0 && p_data_line[offset_data_line] < 127)          if (del_line)
515            {
516                    str_len = (int)(p_editor_data->display_line_lengths[display_line] - offset);
517            }
518            else if (p_data_line[offset_data_line] > 0 && p_data_line[offset_data_line] < 127)
519          {          {
520                  str_len = 1;                  str_len = 1;
521          }          }
522          else if (p_data_line[offset_data_line] & 0b10000000) // head of multi-byte character          else if (p_data_line[offset_data_line] & 0x80) // head of multi-byte character
523          {          {
524                  str_len = 1;                  str_len = 1;
525                  c = (p_data_line[offset_data_line] & 0b01110000) << 1;                  c = (p_data_line[offset_data_line] & 0x70) << 1;
526                  while (c & 0b10000000)                  while (c & 0x80)
527                  {                  {
528                          str_len++;                          str_len++;
529                          c = (c & 0b01111111) << 1;                          c = (c & 0x7f) << 1;
530                  }                  }
531          }          }
532          else          else
# Line 522  int editor_data_delete(EDITOR_DATA *p_ed Line 538  int editor_data_delete(EDITOR_DATA *p_ed
538    
539          // Current display line is (almost) empty          // Current display line is (almost) empty
540          if (offset_data_line + str_len > len_data_line ||          if (offset_data_line + str_len > len_data_line ||
541                  (offset_data_line + str_len == len_data_line && p_data_line[offset_data_line] == '\n'))                  (offset_data_line + str_len == len_data_line &&
542                     p_data_line[del_line ? len_data_line - 1 : offset_data_line] == '\n'))
543          {          {
544                  if (display_line + 1 >= p_editor_data->display_line_total) // No additional display line (data line)                  if (display_line + 1 >= p_editor_data->display_line_total) // No additional display line (data line)
545                  {                  {
# Line 626  static int editor_display_key_handler(in Line 643  static int editor_display_key_handler(in
643          {          {
644          case 0: // Set msg          case 0: // Set msg
645                  snprintf(p_ctx->msg, sizeof(p_ctx->msg),                  snprintf(p_ctx->msg, sizeof(p_ctx->msg),
646                                   "| 退出[\033[32mCtrl-W\033[33m] |");                                   "| 退出[\033[32mCtrl-W\033[33m] | [\033[32m%s\033[33m]",
647                                     (UTF8_fixed_width ? "定宽" : "变宽"));
648                  break;                  break;
649          case KEY_CSI:          case KEY_CSI:
650                  *p_key = KEY_ESC;                  *p_key = KEY_ESC;
# Line 642  int editor_display(EDITOR_DATA *p_editor Line 660  int editor_display(EDITOR_DATA *p_editor
660          char buffer[MAX_EDITOR_DATA_LINE_LENGTH];          char buffer[MAX_EDITOR_DATA_LINE_LENGTH];
661          EDITOR_CTX ctx;          EDITOR_CTX ctx;
662          int ch = 0;          int ch = 0;
663          char input_str[4];          char input_str[5];
         char c;  
664          int str_len = 0;          int str_len = 0;
665            wchar_t wcs[2];
666            int wc_len;
667            char c;
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 662  int editor_display(EDITOR_DATA *p_editor Line 682  int editor_display(EDITOR_DATA *p_editor
682          int key_insert = 1;          int key_insert = 1;
683          int i, j;          int i, j;
684          char *p_str;          char *p_str;
685            int del_line;
686            int tab_width = 0;
687    
688          clrline(output_current_row, SCREEN_ROWS);          clrline(output_current_row, SCREEN_ROWS);
689    
# Line 700  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(MAX_DELAY_TIME);                          ch = igetch_t(BBS_max_user_idle_time);
728                          while (!SYS_server_exit)                          while (!SYS_server_exit)
729                          {                          {
730                                    if (ch != KEY_NULL && ch != KEY_TIMEOUT)
731                                    {
732                                            BBS_last_access_tm = time(NULL);
733                                    }
734    
735                                  // extended key handler                                  // extended key handler
736                                  if (editor_display_key_handler(&ch, &ctx) != 0)                                  if (editor_display_key_handler(&ch, &ctx) != 0)
737                                  {                                  {
738                                          goto cleanup;                                          goto cleanup;
739                                  }                                  }
740    
741                                  if (ch < 256 && (ch & 0b10000000)) // head of multi-byte character                                  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
748                                  {                                  {
749                                          str_len = 0;                                          str_len = 0;
750                                          c = (char)(ch & 0b11110000);                                          c = (char)(ch & 0xf0);
751                                          while (c & 0b10000000)                                          while (c & 0x80)
752                                          {                                          {
753                                                  input_str[str_len] = (char)(ch - 256);                                                  input_str[str_len] = (char)(ch - 256);
754                                                  str_len++;                                                  str_len++;
755                                                  c = (c & 0b01111111) << 1;                                                  c = (c & 0x7f) << 1;
756    
757                                                  if ((c & 0b10000000) == 0) // Input completed                                                  if ((c & 0x80) == 0) // Input completed
758                                                  {                                                  {
759                                                          break;                                                          break;
760                                                  }                                                  }
# Line 736  int editor_display(EDITOR_DATA *p_editor Line 770  int editor_display(EDITOR_DATA *p_editor
770                                                          break;                                                          break;
771                                                  }                                                  }
772                                          }                                          }
773                                            input_str[str_len] = '\0';
774                                  }                                  }
775    
776                                  if ((ch >= 32 && ch < 127) || str_len >= 2 || // Printable character or multi-byte character                                  if ((ch >= 32 && ch < 127) || str_len >= 2 || // Printable character or multi-byte character
777                                          ch == CR || ch == KEY_ESC)                                // Special character                                          ch == CR || ch == KEY_ESC)                                // Special character
778                                  {                                  {
779                                          BBS_last_access_tm = time(NULL);                                          // Refresh current action while user input
780                                            if (user_online_update(NULL) < 0)
781                                            {
782                                                    log_error("user_online_update(NULL) error\n");
783                                            }
784    
785                                          if (str_len == 0) // ch >= 32 && ch < 127                                          if (str_len == 0) // ch >= 32 && ch < 127
786                                          {                                          {
# Line 759  int editor_display(EDITOR_DATA *p_editor Line 798  int editor_display(EDITOR_DATA *p_editor
798                                          if (!key_insert) // overwrite                                          if (!key_insert) // overwrite
799                                          {                                          {
800                                                  if (editor_data_delete(p_editor_data, &display_line_out, &offset_out,                                                  if (editor_data_delete(p_editor_data, &display_line_out, &offset_out,
801                                                                                             &last_updated_line) < 0)                                                                                             &last_updated_line, 0) < 0)
802                                                  {                                                  {
803                                                          log_error("editor_data_delete() error\n");                                                          log_error("editor_data_delete() error\n");
804                                                  }                                                  }
# Line 807  int editor_display(EDITOR_DATA *p_editor Line 846  int editor_display(EDITOR_DATA *p_editor
846                                                          {                                                          {
847                                                                  col_pos = 1;                                                                  col_pos = 1;
848                                                          }                                                          }
849                                                          if (ch != CR)                                                          if (offset_out > 0)
850                                                          {                                                          {
851                                                                  col_pos += (str_len == 1 ? 1 : 2);                                                                  if (mbstowcs(wcs, input_str, 1) == (size_t)-1)
852                                                                    {
853                                                                            log_error("mbstowcs() error\n");
854                                                                    }
855                                                                    col_pos += (str_len == 1 ? 1 : (UTF8_fixed_width ? 2 : wcwidth(wcs[0])));
856                                                          }                                                          }
857                                                  }                                                  }
858                                          }                                          }
# Line 819  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;
879                                          continue;                                          continue;
880                                  }                                  }
881                                  else if (ch == KEY_DEL || ch == BACKSPACE) // Del                                  else if (ch == KEY_DEL || ch == BACKSPACE || ch == Ctrl('K') || ch == Ctrl('Y')) // Del
882                                  {                                  {
883                                          BBS_last_access_tm = time(NULL);                                          // Refresh current action while user input
884                                            if (user_online_update(NULL) < 0)
885                                            {
886                                                    log_error("user_online_update(NULL) error\n");
887                                            }
888    
889                                            del_line = 0;
890    
891                                          if (ch == BACKSPACE)                                          if (ch == BACKSPACE)
892                                          {                                          {
# Line 841  int editor_display(EDITOR_DATA *p_editor Line 897  int editor_display(EDITOR_DATA *p_editor
897    
898                                                  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],
899                                                                                             (int)col_pos - 1, &eol, &display_len, 0);                                                                                             (int)col_pos - 1, &eol, &display_len, 0);
900                                                  if (offset_in >= 1 && p_editor_data->p_display_lines[line_current - output_current_row + row_pos][offset_in - 1] < 0) // UTF8                                                  col_pos = display_len;
                                                 {  
                                                         col_pos = display_len - 1;  
                                                 }  
                                                 else  
                                                 {  
                                                         col_pos = display_len;  
                                                 }  
   
901                                                  if (col_pos < 1 && line_current - output_current_row + row_pos >= 0)                                                  if (col_pos < 1 && line_current - output_current_row + row_pos >= 0)
902                                                  {                                                  {
903                                                          row_pos--;                                                          row_pos--;
904                                                          col_pos = MAX(1, p_editor_data->display_line_widths[line_current - output_current_row + row_pos]);                                                          col_pos = MAX(1, p_editor_data->display_line_widths[line_current - output_current_row + row_pos]);
905                                                  }                                                  }
906                                          }                                          }
907                                            else if (ch == Ctrl('K'))
908                                            {
909                                                    del_line = 1;
910                                            }
911                                            else if (ch == Ctrl('Y'))
912                                            {
913                                                    col_pos = 1;
914                                                    del_line = 1;
915                                            }
916    
917                                          display_line_in = line_current - output_current_row + row_pos;                                          display_line_in = line_current - output_current_row + row_pos;
918                                          offset_in = split_line(p_editor_data->p_display_lines[display_line_in], (int)col_pos - 1, &eol, &display_len, 0);                                          offset_in = split_line(p_editor_data->p_display_lines[display_line_in], (int)col_pos - 1, &eol, &display_len, 0);
# Line 863  int editor_display(EDITOR_DATA *p_editor Line 920  int editor_display(EDITOR_DATA *p_editor
920                                          offset_out = offset_in;                                          offset_out = offset_in;
921    
922                                          if ((str_len = editor_data_delete(p_editor_data, &display_line_out, &offset_out,                                          if ((str_len = editor_data_delete(p_editor_data, &display_line_out, &offset_out,
923                                                                                                            &last_updated_line)) < 0)                                                                                                            &last_updated_line, del_line)) < 0)
924                                          {                                          {
925                                                  log_error("editor_data_delete() error\n");                                                  log_error("editor_data_delete() error: %d\n", str_len);
926                                          }                                          }
927                                          else                                          else
928                                          {                                          {
# Line 917  int editor_display(EDITOR_DATA *p_editor Line 974  int editor_display(EDITOR_DATA *p_editor
974                                  switch (ch)                                  switch (ch)
975                                  {                                  {
976                                  case KEY_NULL:                                  case KEY_NULL:
977                                            log_error("KEY_NULL\n");
978                                            goto cleanup;
979                                  case KEY_TIMEOUT:                                  case KEY_TIMEOUT:
980                                            log_error("User input timeout\n");
981                                          goto cleanup;                                          goto cleanup;
982                                  case Ctrl('W'):                                  case Ctrl('W'):
983                                    case Ctrl('X'):
984                                          loop = 0;                                          loop = 0;
985                                          break;                                          break;
986                                  case Ctrl('S'): // Start of line                                  case Ctrl('S'): // Start of line
# Line 993  int editor_display(EDITOR_DATA *p_editor Line 1054  int editor_display(EDITOR_DATA *p_editor
1054                                  case KEY_LEFT:                                  case KEY_LEFT:
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                                          if (offset_in >= 1 && p_editor_data->p_display_lines[line_current - output_current_row + row_pos][offset_in - 1] < 0) // UTF8                                          col_pos = display_len;
1058                                          {                                          if (offset_in > 0)
                                                 col_pos = display_len - 1;  
                                         }  
                                         else  
1059                                          {                                          {
1060                                                  col_pos = display_len;                                                  str_len = 1;
1061                                                    offset_in--;
1062                                                    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                                                            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)
1091                                          {                                          {
# Line 1025  int editor_display(EDITOR_DATA *p_editor Line 1111  int editor_display(EDITOR_DATA *p_editor
1111                                          output_end_row = SCREEN_ROWS - 1; // Legacy Fterm only works with this line                                          output_end_row = SCREEN_ROWS - 1; // Legacy Fterm only works with this line
1112                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_widths[line_current - output_current_row + row_pos]));                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_widths[line_current - output_current_row + row_pos]));
1113                                          break;                                          break;
                                 case KEY_SPACE:  
                                         break;  
1114                                  case KEY_RIGHT:                                  case KEY_RIGHT:
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                                          if (offset_in < p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] &&                                          col_pos = display_len + 2;
1118                                                  p_editor_data->p_display_lines[line_current - output_current_row + row_pos][offset_in] < 0) // UTF8                                          if (offset_in < p_editor_data->display_line_lengths[line_current - output_current_row + row_pos])
                                         {  
                                                 col_pos = display_len + 3;  
                                         }  
                                         else  
1119                                          {                                          {
1120                                                  col_pos = display_len + 2;                                                  str_len = 0;
1121                                                    if ((p_editor_data->p_display_lines[line_current - output_current_row + row_pos][offset_in] & 0x80) ==
1122                                                            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                                                            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                                          {                                          {
# Line 1096  int editor_display(EDITOR_DATA *p_editor Line 1208  int editor_display(EDITOR_DATA *p_editor
1208                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_widths[line_current - output_current_row + row_pos]));                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_widths[line_current - output_current_row + row_pos]));
1209                                          clrline(output_current_row, SCREEN_ROWS);                                          clrline(output_current_row, SCREEN_ROWS);
1210                                          break;                                          break;
1211                                    case Ctrl('Q'):
1212                                  case KEY_F1:                                  case KEY_F1:
1213                                          if (!show_help) // Not reentrant                                          if (!show_help) // Not re-entrant
1214                                          {                                          {
1215                                                  break;                                                  break;
1216                                          }                                          }
1217                                          // Display help information                                          // Display help information
1218                                          show_help = 0;                                          show_help = 0;
1219                                          display_file(DATA_READ_HELP, 1);                                          display_file(DATA_EDITOR_HELP, 1);
1220                                          show_help = 1;                                          show_help = 1;
1221                                  case KEY_F5:                                  case KEY_F5:
1222                                          // Refresh after display help information                                          // Refresh after display help information
# Line 1119  int editor_display(EDITOR_DATA *p_editor Line 1232  int editor_display(EDITOR_DATA *p_editor
1232                                          break;                                          break;
1233                                  }                                  }
1234    
1235                                  BBS_last_access_tm = time(NULL);                                  // Refresh current action while user input
1236                                    if (user_online_update(NULL) < 0)
1237                                    {
1238                                            log_error("user_online_update(NULL) error\n");
1239                                    }
1240    
1241                                  if (input_ok)                                  if (input_ok)
1242                                  {                                  {
1243                                          break;                                          break;
1244                                  }                                  }
1245    
1246                                  ch = igetch_t(MAX_DELAY_TIME);                                  ch = igetch_t(BBS_max_user_idle_time);
1247                          }                          }
1248    
1249                          continue;                          continue;


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

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