/[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.2 by sysadm, Mon Jun 9 15:41:09 2025 UTC Revision 1.11 by sysadm, Wed Jun 11 11:55:50 2025 UTC
# Line 22  Line 22 
22  #include "str_process.h"  #include "str_process.h"
23  #include <stdlib.h>  #include <stdlib.h>
24  #include <sys/param.h>  #include <sys/param.h>
25    #include <strings.h>
26    
27  #define _POSIX_C_SOURCE 200809L  #define _POSIX_C_SOURCE 200809L
28  #include <string.h>  #include <string.h>
# Line 29  Line 30 
30  EDITOR_DATA *editor_data_load(const char *p_data)  EDITOR_DATA *editor_data_load(const char *p_data)
31  {  {
32          EDITOR_DATA *p_editor_data;          EDITOR_DATA *p_editor_data;
33            char *p_data_line = NULL;
34          long line_offsets[MAX_EDITOR_DATA_LINES];          long line_offsets[MAX_EDITOR_DATA_LINES];
35          long current_data_line_length = 0;          long current_data_line_length = 0;
36          long i, j;          long i, j;
# Line 64  EDITOR_DATA *editor_data_load(const char Line 66  EDITOR_DATA *editor_data_load(const char
66                          }                          }
67    
68                          // Allocate new data line                          // Allocate new data line
69                          p_editor_data->p_data_lines[p_editor_data->data_line_total] = malloc(MAX_EDITOR_DATA_LINE_LENGTH);                          p_data_line = malloc(MAX_EDITOR_DATA_LINE_LENGTH);
70                          if (p_editor_data->p_data_lines[p_editor_data->data_line_total] == NULL)                          if (p_data_line == NULL)
71                          {                          {
72                                  log_error("malloc(MAX_EDITOR_DATA_LINE_LENGTH * %d) error: OOM\n", i);                                  log_error("malloc(MAX_EDITOR_DATA_LINE_LENGTH * %d) error: OOM\n", i);
73                                  // Cleanup                                  // Cleanup
# Line 76  EDITOR_DATA *editor_data_load(const char Line 78  EDITOR_DATA *editor_data_load(const char
78                                  free(p_editor_data);                                  free(p_editor_data);
79                                  return NULL;                                  return NULL;
80                          }                          }
81                            p_editor_data->p_data_lines[p_editor_data->data_line_total] = p_data_line;
                         p_editor_data->p_display_lines[i] = p_editor_data->p_data_lines[p_editor_data->data_line_total];  
82                          (p_editor_data->data_line_total)++;                          (p_editor_data->data_line_total)++;
83    
84                            p_editor_data->p_display_lines[i] = p_data_line;
85                          current_data_line_length = 0;                          current_data_line_length = 0;
86                  }                  }
87                  else                  else
# Line 88  EDITOR_DATA *editor_data_load(const char Line 91  EDITOR_DATA *editor_data_load(const char
91    
92                  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]);
93                  current_data_line_length += p_editor_data->display_line_lengths[i];                  current_data_line_length += p_editor_data->display_line_lengths[i];
94                  p_editor_data->p_data_lines[p_editor_data->data_line_total - 1][current_data_line_length] = '\0';                  p_data_line[current_data_line_length] = '\0';
95          }          }
96    
97            bzero(p_editor_data->p_data_lines + p_editor_data->data_line_total, MAX_EDITOR_DATA_LINES - (size_t)p_editor_data->data_line_total);
98            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);
99    
100          return p_editor_data;          return p_editor_data;
101  }  }
102    
# Line 141  void editor_data_cleanup(EDITOR_DATA *p_ Line 147  void editor_data_cleanup(EDITOR_DATA *p_
147          free(p_editor_data);          free(p_editor_data);
148  }  }
149    
150  int editor_data_insert(EDITOR_DATA *p_editor_data, long display_line, long offset,  int editor_data_insert(EDITOR_DATA *p_editor_data, long *p_display_line, long *p_offset,
151                                             const char *str, int str_len, long *p_last_updated_line)                                             const char *str, int str_len, long *p_last_updated_line)
152  {  {
153          int len;          long display_line = *p_display_line;
154          int display_len;          long offset = *p_offset;
155          int eol;          char *p_data_line = NULL;
         char *p_data_line;  
156          long len_data_line;          long len_data_line;
157          long offset_data_line;          long offset_data_line;
158          long last_display_line; // of data line          long last_display_line; // of data line
159          char buf_insert[MAX_EDITOR_DATA_LINE_LENGTH];          long line_offsets[MAX_EDITOR_DATA_LINE_LENGTH + 1];
160          long len_insert;          long split_line_total;
161          int display_len_insert;          long i, j;
         char buf_catenate[MAX_EDITOR_DATA_LINE_LENGTH];  
         long len_catenate;  
         long i;  
162    
163          if (p_editor_data == NULL || p_last_updated_line == NULL)          if (p_editor_data == NULL || p_last_updated_line == NULL)
164          {          {
# Line 164  int editor_data_insert(EDITOR_DATA *p_ed Line 166  int editor_data_insert(EDITOR_DATA *p_ed
166                  return -1;                  return -1;
167          }          }
168    
         memcpy(buf_insert, str, (size_t)str_len);  
         buf_insert[str_len] = '\0';  
         len_insert = str_len;  
   
169          // Get accurate offset of first character of CJK at offset position          // Get accurate offset of first character of CJK at offset position
170          for (i = 0; i < offset; i++)          for (i = 0; i < offset; i++)
171          {          {
172                  if (p_editor_data->p_display_lines[display_line][i] < 0) // GBK                  if (p_editor_data->p_display_lines[display_line][i] < 0 || p_editor_data->p_display_lines[display_line][i] > 127) // GBK
173                  {                  {
174                          i++;                          i++;
175                  }                  }
# Line 210  int editor_data_insert(EDITOR_DATA *p_ed Line 208  int editor_data_insert(EDITOR_DATA *p_ed
208          }          }
209    
210          // Split current data line if over-length          // Split current data line if over-length
211          if (len_data_line + str_len + 1 > MAX_EDITOR_DATA_LINE_LENGTH)          if (len_data_line + str_len + 1 > MAX_EDITOR_DATA_LINE_LENGTH || str[0] == CR)
212          {          {
213                  if (p_editor_data->display_line_total >= MAX_EDITOR_DATA_LINES || p_editor_data->data_line_total >= MAX_EDITOR_DATA_LINES)                  if (p_editor_data->display_line_total >= MAX_EDITOR_DATA_LINES || p_editor_data->data_line_total >= MAX_EDITOR_DATA_LINES)
214                  {                  {
# Line 220  int editor_data_insert(EDITOR_DATA *p_ed Line 218  int editor_data_insert(EDITOR_DATA *p_ed
218                  }                  }
219    
220                  // Allocate new data line                  // Allocate new data line
221                  p_editor_data->p_data_lines[p_editor_data->data_line_total] = malloc(MAX_EDITOR_DATA_LINE_LENGTH);                  p_data_line = malloc(MAX_EDITOR_DATA_LINE_LENGTH);
222                  if (p_editor_data->p_data_lines[p_editor_data->data_line_total] == NULL)                  if (p_data_line == NULL)
223                  {                  {
224                          log_error("malloc(MAX_EDITOR_DATA_LINE_LENGTH) error: OOM\n");                          log_error("malloc(MAX_EDITOR_DATA_LINE_LENGTH) error: OOM\n");
225                          return -2;                          return -2;
226                  }                  }
227                    p_editor_data->p_data_lines[p_editor_data->data_line_total] = p_data_line;
228                    (p_editor_data->data_line_total)++;
229    
230                  // Copy rest part of current data line since next display line to new data line                  if (offset_data_line + str_len + 1 >= MAX_EDITOR_DATA_LINE_LENGTH || str[0] == CR)
                 memcpy(p_editor_data->p_data_lines[p_editor_data->data_line_total],  
                            p_editor_data->p_display_lines[display_line + 1],  
                            (size_t)(len_data_line - (p_editor_data->p_display_lines[display_line + 1] - p_data_line)));  
                 p_editor_data->p_data_lines[p_editor_data->data_line_total]  
                                                                    [len_data_line - (p_editor_data->p_display_lines[display_line + 1] - p_data_line)] = '\0';  
   
                 p_data_line = p_editor_data->p_display_lines[display_line + 1];  
                 for (i = display_line + 1; i <= last_display_line; i++)  
231                  {                  {
232                          p_editor_data->p_display_lines[i] +=                          if (str[0] == CR)
233                                  (p_editor_data->p_data_lines[p_editor_data->data_line_total] - p_data_line);                          {
234                  }                                  str_len = 0;
235                            }
236    
237                  // Copy rest part of current display line to buffer                          // Copy str to new data line
238                  if (offset_data_line >= MAX_EDITOR_DATA_LINE_LENGTH / 2)                          memcpy(p_data_line, str, (size_t)str_len);
239                  {  
240                          memcpy(buf_insert + len_insert,                          // Copy rest part of current data line to new data line
241                                     p_editor_data->p_display_lines[display_line] + offset,                          memcpy(p_data_line + str_len,
                                    (size_t)(p_editor_data->display_line_lengths[display_line] - offset));  
                         len_insert += (p_editor_data->display_line_lengths[display_line] - offset);  
                 }  
                 else  
                 {  
                         memcpy(buf_insert,  
242                                     p_editor_data->p_display_lines[display_line] + offset,                                     p_editor_data->p_display_lines[display_line] + offset,
243                                     (size_t)(p_editor_data->display_line_lengths[display_line] - offset));                                     (size_t)(len_data_line - offset_data_line));
244                          len_insert = (p_editor_data->display_line_lengths[display_line] - offset);  
245                  }                          p_data_line[str_len + len_data_line - offset_data_line] = '\0';
                 buf_insert[len_insert] = '\0';  
246    
                 if (offset_data_line >= MAX_EDITOR_DATA_LINE_LENGTH / 2)  
                 {  
247                          // Add line ending to current display line (data line)                          // Add line ending to current display line (data line)
248                          p_editor_data->p_display_lines[display_line][offset] = '\n';                          p_editor_data->p_display_lines[display_line][offset] = '\n';
249                          p_editor_data->p_display_lines[display_line][offset + 1] = '\0';                          p_editor_data->p_display_lines[display_line][offset + 1] = '\0';
250                          p_editor_data->display_line_lengths[display_line] = offset + 1;                          p_editor_data->display_line_lengths[display_line] = offset + 1;
251    
252                            *p_display_line = display_line + 1;
253                            *p_offset = str_len;
254                  }                  }
255                  else                  else
256                  {                  {
257                            // Copy rest part of current data line to new data line
258                            memcpy(p_data_line,
259                                       p_editor_data->p_display_lines[display_line] + offset,
260                                       (size_t)(len_data_line - offset_data_line));
261    
262                            p_data_line[len_data_line - offset_data_line] = '\0';
263    
264                            // Append str to current display line
265                          memcpy(p_editor_data->p_display_lines[display_line] + offset, str, (size_t)str_len);                          memcpy(p_editor_data->p_display_lines[display_line] + offset, str, (size_t)str_len);
266    
267                          // Add line ending to current display line (data line)                          // Add line ending to current display line (data line)
268                          p_editor_data->p_display_lines[display_line][offset + str_len] = '\n';                          p_editor_data->p_display_lines[display_line][offset + str_len] = '\n';
269                          p_editor_data->p_display_lines[display_line][offset + str_len + 1] = '\0';                          p_editor_data->p_display_lines[display_line][offset + str_len + 1] = '\0';
270                          p_editor_data->display_line_lengths[display_line] = offset + str_len + 1;                          p_editor_data->display_line_lengths[display_line] = offset + str_len + 1;
271    
272                            *p_display_line = display_line;
273                            *p_offset = offset + str_len;
274                  }                  }
275    
276                    split_line_total = last_display_line - display_line + 3;
277    
278                    // Set start display_line for spliting new data line
279                  display_line++;                  display_line++;
                 offset = 0;  
280    
281                  *p_last_updated_line = p_editor_data->display_line_total;                  *p_last_updated_line = p_editor_data->display_line_total;
282            }
283            else // insert str into current data line at offset_data_line
284            {
285                    memmove(p_data_line + offset_data_line + str_len, p_data_line + offset_data_line, (size_t)(len_data_line - offset_data_line));
286                    memcpy(p_data_line + offset_data_line, str, (size_t)str_len);
287                    p_data_line[len_data_line + str_len] = '\0';
288    
289                  last_display_line++;                  // Set p_data_line to head of current display line
290                  (p_editor_data->display_line_total)++;                  p_data_line = p_editor_data->p_display_lines[display_line];
291                  (p_editor_data->data_line_total)++;                  split_line_total = last_display_line - display_line + 3;
292    
293                    *p_display_line = display_line;
294                    *p_offset = offset + str_len;
295          }          }
296    
297          for (i = display_line; len_insert > 0 && i <= last_display_line; i++)          // Split current data line since beginning of current display line
298            split_line_total = split_data_lines(p_data_line, SCREEN_COLS, line_offsets, split_line_total);
299    
300            for (i = 0; i < split_line_total; i++)
301          {          {
302                  len = split_line(buf_insert, SCREEN_COLS, &eol, &display_len_insert);                  if (display_line + i > last_display_line)
                 if (len != len_insert)  
303                  {                  {
304                          log_error("buf_insert is truncated at display_line(%ld): len(%d) != len_insert(%d), buf_insert: %s\n",                          // Insert blank display line after last_display_line
305                                            i, len, len_insert, buf_insert);                          if (p_editor_data->display_line_total >= MAX_EDITOR_DATA_LINES)
306                          return -3;                          {
307                                    log_error("display_line_total over limit %d >= %d\n", p_editor_data->display_line_total, MAX_EDITOR_DATA_LINES);
308                                    return -3;
309                            }
310                            for (j = p_editor_data->display_line_total; j > last_display_line + 1; j--)
311                            {
312                                    p_editor_data->p_display_lines[j] = p_editor_data->p_display_lines[j - 1];
313                                    p_editor_data->display_line_lengths[j] = p_editor_data->display_line_lengths[j - 1];
314                            }
315                            last_display_line++;
316                            (p_editor_data->display_line_total)++;
317                  }                  }
318    
319                  memcpy(buf_catenate, p_editor_data->p_display_lines[i], (size_t)p_editor_data->display_line_lengths[i]);                  p_editor_data->display_line_lengths[display_line + i] = line_offsets[i + 1] - line_offsets[i];
320                  buf_catenate[p_editor_data->display_line_lengths[i]] = '\0';                  p_editor_data->p_display_lines[display_line + i] =
321                            (i == 0
322                                     ? p_data_line
323                                     : (p_editor_data->p_display_lines[display_line + i - 1] + p_editor_data->display_line_lengths[display_line + i - 1]));
324    
325                  len = split_line(buf_catenate, SCREEN_COLS - display_len_insert, &eol, &display_len);                  if (p_editor_data->display_line_lengths[display_line + i] > 0 &&
326                  if (len < offset) // have no space to insert                          p_editor_data->p_display_lines[display_line + i][p_editor_data->display_line_lengths[display_line + i] - 1] == '\n')
327                  {                  {
328                          offset = 0;                          break;
                         continue; // retry at next display line  
329                  }                  }
330            }
331    
332            *p_last_updated_line = MAX(display_line + MIN(i, split_line_total - 1), *p_last_updated_line);
333    
334                  // move \n to next display line if current line is full          if (*p_offset > p_editor_data->display_line_lengths[*p_display_line] ||
335                  if (len > 0 && buf_catenate[len - 1] == '\n' && display_len + display_len_insert >= SCREEN_COLS)                  (*p_offset > 0 && *p_offset == p_editor_data->display_line_lengths[*p_display_line] &&
336                     p_editor_data->p_display_lines[*p_display_line][*p_offset - 1] == '\n'))
337            {
338                    *p_offset -= p_editor_data->display_line_lengths[*p_display_line];
339                    (*p_display_line)++;
340    
341                    if (*p_display_line >= p_editor_data->display_line_total)
342                  {                  {
343                          len--;                          log_error("*p_display_line(%d) >= display_line_total(%d)\n", *p_display_line, p_editor_data->display_line_total);
344                  }                  }
345            }
346    
347                  memcpy(buf_catenate, p_editor_data->p_display_lines[i], (size_t)offset);          return 0;
348                  memcpy(buf_catenate + offset, buf_insert, (size_t)len_insert);  }
                 memcpy(buf_catenate + offset + len_insert, p_editor_data->p_display_lines[i] + offset, (size_t)(len - offset));  
                 len_catenate = len_insert + len;  
                 buf_catenate[len_catenate] = '\0';  
349    
350                  offset = 0;  int editor_data_delete(EDITOR_DATA *p_editor_data, long display_line, long offset,
351                  len_insert = p_editor_data->display_line_lengths[i] - len;                                             long *p_last_updated_line)
352                  if (len_insert > 0)  {
353            char *p_data_line = NULL;
354            long len_data_line;
355            long offset_data_line;
356            long last_display_line; // of data line
357            long line_offsets[MAX_EDITOR_DATA_LINE_LENGTH + 1];
358            long split_line_total;
359            long i, j;
360            int str_len = 0;
361    
362            if (p_editor_data == NULL || p_last_updated_line == NULL)
363            {
364                    log_error("editor_data_op() error: NULL pointer\n");
365                    return -1;
366            }
367    
368            // Get accurate offset of first character of CJK at offset position
369            for (i = 0; i < offset; i++)
370            {
371                    if (p_editor_data->p_display_lines[display_line][i] < 0 || p_editor_data->p_display_lines[display_line][i] > 127) // GBK
372                  {                  {
373                          memcpy(buf_insert, p_editor_data->p_display_lines[i] + len, (size_t)len_insert);                          i++;
                         buf_insert[len_insert] = '\0';  
374                  }                  }
375            }
376            if (i > offset) // offset was skipped
377            {
378                    offset--;
379            }
380    
381                  memcpy(p_editor_data->p_display_lines[i], buf_catenate, (size_t)len_catenate);          // Get length of current data line
382                  p_editor_data->display_line_lengths[i] = len_catenate;          len_data_line = 0;
383            p_data_line = p_editor_data->p_display_lines[display_line];
384            for (i = display_line - 1; i >= 0; i--)
385            {
386                    if (p_editor_data->display_line_lengths[i] > 0 &&
387                            p_editor_data->p_display_lines[i][p_editor_data->display_line_lengths[i] - 1] == '\n') // reach end of prior data line
388                    {
389                            break;
390                    }
391    
392                    len_data_line += p_editor_data->display_line_lengths[i];
393                    p_data_line = p_editor_data->p_display_lines[i];
394          }          }
395            offset_data_line = len_data_line + offset;
396            last_display_line = p_editor_data->display_line_total - 1;
397            for (i = display_line; i < p_editor_data->display_line_total; i++)
398            {
399                    len_data_line += p_editor_data->display_line_lengths[i];
400    
401          *p_last_updated_line = MAX(i, *p_last_updated_line);                  if (p_editor_data->display_line_lengths[i] > 0 &&
402                            p_editor_data->p_display_lines[i][p_editor_data->display_line_lengths[i] - 1] == '\n') // reach end of current data line
403                    {
404                            last_display_line = i;
405                            break;
406                    }
407            }
408    
409          if (len_insert > 0)          // Check str to be deleted
410            if (p_data_line[offset_data_line] > 0 && p_data_line[offset_data_line] < 127)
411          {          {
412                  if (p_editor_data->display_line_total >= MAX_EDITOR_DATA_LINES)                  str_len = 1;
413            }
414            else if (p_data_line[offset_data_line + 1] < 0 || p_data_line[offset_data_line] > 127) // GBK
415            {
416                    str_len = 2;
417            }
418            else
419            {
420                    log_error("Some strange character at display_line %ld, offset %ld: %d %d %d %d\n",
421                                      display_line, offset, p_data_line[offset_data_line], p_data_line[offset_data_line + 1],
422                                      p_data_line[offset_data_line + 2], p_data_line[offset_data_line + 3]);
423                    str_len = 1;
424            }
425    
426            // Current display line is (almost) empty
427            if (offset_data_line + str_len > len_data_line ||
428                    (offset_data_line + str_len == len_data_line && p_data_line[offset_data_line] == '\n'))
429            {
430                    if (display_line + 1 >= p_editor_data->display_line_total) // No additional display line (data line)
431                  {                  {
432                          log_error("Append line error, display_line_total(%ld) reach limit(%d)\n",                          log_common("Debug: No additional display line: %ld + 1 >= %ld\n", display_line, p_editor_data->display_line_total);
433                                            p_editor_data->display_line_total, MAX_EDITOR_DATA_LINES);                          return 0;
                         return -2;  
434                  }                  }
435    
436                  // Prepare one blank display line after last_display_line                  len_data_line = 0; // Next data line
437                  for (i = p_editor_data->display_line_total; i > last_display_line + 1; i--)                  last_display_line = p_editor_data->display_line_total - 1;
438                    for (i = display_line + 1; i < p_editor_data->display_line_total; i++)
439                  {                  {
440                          p_editor_data->p_display_lines[i] = p_editor_data->p_display_lines[i - 1];                          len_data_line += p_editor_data->display_line_lengths[i];
441                          p_editor_data->display_line_lengths[i] = p_editor_data->display_line_lengths[i - 1];  
442                            if (p_editor_data->display_line_lengths[i] > 0 &&
443                                    p_editor_data->p_display_lines[i][p_editor_data->display_line_lengths[i] - 1] == '\n') // reach end of current data line
444                            {
445                                    last_display_line = i;
446                                    break;
447                            }
448                  }                  }
                 p_editor_data->p_display_lines[last_display_line + 1] =  
                         p_editor_data->p_display_lines[last_display_line] + p_editor_data->display_line_lengths[last_display_line];  
                 p_editor_data->display_line_lengths[last_display_line + 1] = 0;  
449    
450                  (p_editor_data->display_line_total)++;                  if (offset_data_line + len_data_line + 1 > MAX_EDITOR_DATA_LINE_LENGTH) // No enough buffer to merge current data line with next data line
451                  last_display_line++;                  {
452                            log_common("Debug: No enough buffer to merge with next data line: %ld > %ld\n",
453                                               offset_data_line + len_data_line + 1, MAX_EDITOR_DATA_LINE_LENGTH);
454                            return 0;
455                    }
456    
457                  // Fill data into blank display line                  // Append next data line to current one
458                  memcpy(p_editor_data->p_display_lines[last_display_line], buf_insert, (size_t)len_insert);                  memcpy(p_data_line + offset_data_line, p_editor_data->p_display_lines[display_line + 1], (size_t)len_data_line);
459                  p_editor_data->p_display_lines[last_display_line][len_insert] = '\0';                  p_data_line[offset_data_line + len_data_line] = '\0';
                 p_editor_data->display_line_lengths[last_display_line] = len_insert;  
460    
461                  *p_last_updated_line = MAX(last_display_line, *p_last_updated_line);                  // Recycle next data line
462                    // TODO: free(p_editor_data->p_display_lines[display_line + 1]);
463            }
464            else
465            {
466                    memmove(p_data_line + offset_data_line, p_data_line + offset_data_line + str_len, (size_t)(len_data_line - offset_data_line - str_len));
467                    p_data_line[len_data_line - str_len] = '\0';
468                    len_data_line -= str_len;
469          }          }
470    
471          return 0;          // Set p_data_line to head of current display line
472  }          p_data_line = p_editor_data->p_display_lines[display_line];
473            split_line_total = last_display_line - display_line + 2;
474    
475  int editor_data_delete(EDITOR_DATA *p_editor_data, long display_line, long offset,          // Split current data line since beginning of current display line
476                                             long *p_last_updated_line)          split_line_total = split_data_lines(p_data_line, SCREEN_COLS, line_offsets, split_line_total);
477  {  
478          return 0;          for (i = 0; i < split_line_total; i++)
479            {
480                    p_editor_data->display_line_lengths[display_line + i] = line_offsets[i + 1] - line_offsets[i];
481                    p_editor_data->p_display_lines[display_line + i] =
482                            (i == 0
483                                     ? p_data_line
484                                     : (p_editor_data->p_display_lines[display_line + i - 1] + p_editor_data->display_line_lengths[display_line + i - 1]));
485    
486                    if (p_editor_data->display_line_lengths[display_line + i] > 0 &&
487                            p_editor_data->p_display_lines[display_line + i][p_editor_data->display_line_lengths[display_line + i] - 1] == '\n')
488                    {
489                            break;
490                    }
491            }
492    
493            *p_last_updated_line = display_line + MIN(i, split_line_total - 1);
494    
495            if (display_line + i < last_display_line)
496            {
497                    // Remove redundant display line after last_display_line
498                    for (j = last_display_line + 1; j < p_editor_data->display_line_total; j++)
499                    {
500                            p_editor_data->p_display_lines[j - (last_display_line - (display_line + i))] = p_editor_data->p_display_lines[j];
501                            p_editor_data->display_line_lengths[j - (last_display_line - (display_line + i))] = p_editor_data->display_line_lengths[j];
502                    }
503    
504                    (p_editor_data->display_line_total) -= (last_display_line - (display_line + i));
505                    last_display_line = display_line + i;
506    
507                    *p_last_updated_line = p_editor_data->display_line_total - 1;
508            }
509    
510            return str_len;
511  }  }
512    
513  static int editor_display_key_handler(int *p_key, EDITOR_CTX *p_ctx)  static int editor_display_key_handler(int *p_key, EDITOR_CTX *p_ctx)
# Line 389  int editor_display(EDITOR_DATA *p_editor Line 529  int editor_display(EDITOR_DATA *p_editor
529          char buffer[MAX_EDITOR_DATA_LINE_LENGTH];          char buffer[MAX_EDITOR_DATA_LINE_LENGTH];
530          EDITOR_CTX ctx;          EDITOR_CTX ctx;
531          int ch = 0;          int ch = 0;
532          char hz_ch[4];          char input_str[4];
533          int hz_len;          int str_len = 0;
534          int input_ok, screen_current_line;          int input_ok;
535          const int screen_begin_line = 1;          int screen_current_row;
536          int screen_end_line = SCREEN_ROWS - 1;          const int screen_begin_row = 1;
537          const int screen_line_total = screen_end_line - screen_begin_line + 1;          int screen_end_row = SCREEN_ROWS - 1;
538            const int screen_row_total = screen_end_row - screen_begin_row + 1;
539          long int line_current = 0;          long int line_current = 0;
540          long int len;          long int len;
541          int loop;          int loop;
542          int eol, display_len;          int eol, display_len;
543          long row_pos = 1, col_pos = 1;          long row_pos = 1, col_pos = 1;
544            long display_line_in, offset_in;
545            long display_line_out, offset_out;
546            int scroll_rows;
547          long last_updated_line = 0;          long last_updated_line = 0;
548          int insert = 1;          int key_insert = 1;
549            int i;
550    
551          screen_current_line = screen_begin_line;          screen_current_row = screen_begin_row;
552          clrline(screen_begin_line, SCREEN_ROWS);          clrline(screen_begin_row, SCREEN_ROWS);
553    
554          // update msg_ext with extended key handler          // update msg_ext with extended key handler
555          if (editor_display_key_handler(&ch, &ctx) != 0)          if (editor_display_key_handler(&ch, &ctx) != 0)
# Line 415  int editor_display(EDITOR_DATA *p_editor Line 560  int editor_display(EDITOR_DATA *p_editor
560          loop = 1;          loop = 1;
561          while (!SYS_server_exit && loop)          while (!SYS_server_exit && loop)
562          {          {
563                  if (line_current >= p_editor_data->display_line_total || screen_current_line > screen_end_line)                  if (line_current >= p_editor_data->display_line_total || screen_current_row > screen_end_row)
564                  {                  {
565                          ctx.line_cursor = line_current - screen_current_line + row_pos + 1;                          ctx.line_cursor = line_current - screen_current_row + row_pos + 1;
566    
567                          snprintf(buffer, sizeof(buffer),                          snprintf(buffer, sizeof(buffer),
568                                           "\033[1;44;33m[\033[32m%ld\033[33m;\033[32m%ld\033[33m] "                                           "\033[1;44;33m[\033[32m%ld\033[33m;\033[32m%ld\033[33m] "
569                                           "µÚ\033[32m%ld\033[33m/\033[32m%ld\033[33mÐÐ "                                           "µÚ\033[32m%ld\033[33m/\033[32m%ld\033[33mÐÐ [\033[32m%s\033[33m] "
570                                           "%s",                                           "%s",
571                                           row_pos, col_pos,                                           row_pos, col_pos,
572                                           ctx.line_cursor, p_editor_data->display_line_total,                                           ctx.line_cursor, p_editor_data->display_line_total,
573                                             key_insert ? "²åÈë" : "¸Äд",
574                                           ctx.msg);                                           ctx.msg);
575    
576                          len = split_line(buffer, SCREEN_COLS, &eol, &display_len);                          len = split_line(buffer, SCREEN_COLS, &eol, &display_len);
# Line 442  int editor_display(EDITOR_DATA *p_editor Line 588  int editor_display(EDITOR_DATA *p_editor
588                          iflush();                          iflush();
589    
590                          input_ok = 0;                          input_ok = 0;
591                            ch = igetch_t(MAX_DELAY_TIME);
592                          while (!SYS_server_exit && !input_ok)                          while (!SYS_server_exit && !input_ok)
593                          {                          {
                                 ch = igetch_t(MAX_DELAY_TIME);  
                                 input_ok = 1;  
   
594                                  // extended key handler                                  // extended key handler
595                                  if (editor_display_key_handler(&ch, &ctx) != 0)                                  if (editor_display_key_handler(&ch, &ctx) != 0)
596                                  {                                  {
597                                          goto cleanup;                                          goto cleanup;
598                                  }                                  }
599    
600                                  if (ch >= 32 && ch < 127) // printable character                                  if (ch > 127 && ch <= 255) // GBK
601                                  {                                  {
602                                          last_updated_line = line_current;                                          input_str[str_len] = (char)(ch - 256);
603                                            str_len++;
604                                    }
605                                    else
606                                    {
607                                            str_len = 0;
608                                    }
609    
610                                          if (editor_data_insert(p_editor_data, line_current - screen_current_line + row_pos, col_pos - 1,                                  if ((ch >= 32 && ch < 127) || (ch > 127 && ch <= 255 && str_len == 2) || ch == CR) // printable character or GBK
611                                                                                     (const char *)&ch, 1, &last_updated_line) < 0)                                  {
612                                            if (str_len == 0)
613                                          {                                          {
614                                                  log_error("editor_data_op(INSERT ch) error\n");                                                  input_str[0] = (char)ch;
615                                                    str_len = 1;
616                                          }                                          }
                                         else  
                                         {  
                                                 screen_end_line = MIN(SCREEN_ROWS - 1, screen_current_line + (int)(last_updated_line - line_current));  
                                                 line_current -= (screen_current_line - row_pos);  
                                                 screen_current_line = (int)row_pos;  
617    
618                                                  col_pos++;                                          last_updated_line = line_current;
619                                                  if (col_pos <= p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos])                                          display_line_in = line_current - screen_current_row + row_pos;
620                                            offset_in = col_pos - 1;
621                                            display_line_out = display_line_in;
622                                            offset_out = offset_in;
623    
624                                            if (!key_insert) // overwrite
625                                            {
626                                                    if (editor_data_delete(p_editor_data, display_line_in, offset_in,
627                                                                                               &last_updated_line) < 0)
628                                                  {                                                  {
629                                                          continue;                                                          log_error("editor_data_delete() error\n");
630                                                  }                                                  }
                                                 col_pos = 1;  
                                                 ch = KEY_DOWN;  
631                                          }                                          }
                                 }  
                                 else if (ch > 127 && ch <= 255) // CJK character  
                                 {  
                                         hz_ch[hz_len] = (char)(ch - 256);  
                                         hz_len++;  
632    
633                                          if (hz_len == 2) // GBK                                          if (editor_data_insert(p_editor_data, &display_line_out, &offset_out,
634                                                                                       input_str, str_len, &last_updated_line) < 0)
635                                            {
636                                                    log_error("editor_data_insert(%s) error\n", input_str);
637                                                    str_len = 0;
638                                            }
639                                            else
640                                          {                                          {
641                                                  hz_len = 0;                                                  str_len = 0;
                                                 last_updated_line = line_current;  
642    
643                                                  if (editor_data_insert(p_editor_data, line_current - screen_current_line + row_pos, col_pos - 1,                                                  screen_end_row = MIN(SCREEN_ROWS - 1, screen_current_row + (int)(last_updated_line - line_current));
644                                                                                             hz_ch, 2, &last_updated_line) < 0)                                                  line_current -= (screen_current_row - row_pos);
645                                                  {                                                  screen_current_row = (int)row_pos;
646                                                          log_error("editor_data_op(INSERT hz) error\n");  
647                                                  }                                                  scroll_rows = MAX(0, (int)(display_line_out - display_line_in) - (screen_end_row - screen_current_row));
648                                                  else  
649                                                    if (scroll_rows > 0)
650                                                  {                                                  {
651                                                          screen_end_line = MIN(SCREEN_ROWS - 1, screen_current_line + (int)(last_updated_line - line_current));                                                          moveto(SCREEN_ROWS, 0);
652                                                          line_current -= (screen_current_line - row_pos);                                                          clrtoeol();
653                                                          screen_current_line = (int)row_pos;                                                          for (i = 0; i < scroll_rows; i++)
654                                                            {
655                                                                    prints("\033[S"); // Scroll up 1 line
656                                                            }
657    
658                                                          col_pos += 2;                                                          screen_current_row -= scroll_rows;
659                                                          if (col_pos <= p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos])                                                          if (screen_current_row < screen_begin_row)
660                                                          {                                                          {
661                                                                  continue;                                                                  line_current += (screen_begin_row - screen_current_row);
662                                                                    screen_current_row = screen_begin_row;
663                                                          }                                                          }
664                                                          col_pos = 1;                                                          row_pos = screen_end_row;
                                                         ch = KEY_DOWN;  
665                                                  }                                                  }
666                                                    else // if (scroll_lines == 0)
667                                                    {
668                                                            row_pos += (display_line_out - display_line_in);
669                                                    }
670                                                    col_pos = offset_out + 1;
671                                            }
672    
673                                            // Check whether there is additional input
674                                            ch = igetch(0);
675                                            if (ch == KEY_TIMEOUT)
676                                            {
677                                                    input_ok = 1;
678                                          }                                          }
679                                            continue;
680                                  }                                  }
681                                  else if (ch == KEY_DEL) // Del                                  else if (ch == KEY_DEL || ch == BACKSPACE) // Del
682                                  {                                  {
683                                          last_updated_line = line_current;                                          if (ch == BACKSPACE)
684                                            {
685                                                    col_pos--;
686                                                    if (col_pos < 1 && line_current - screen_current_row + row_pos >= 0)
687                                                    {
688                                                            row_pos--;
689                                                            col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos]);
690                                                    }
691                                            }
692    
693                                          if (editor_data_delete(p_editor_data, line_current - screen_current_line + row_pos, col_pos - 1,                                          if ((str_len = editor_data_delete(p_editor_data, line_current - screen_current_row + row_pos, col_pos - 1,
694                                                                                     &last_updated_line) < 0)                                                                                                            &last_updated_line)) < 0)
695                                          {                                          {
696                                                  log_error("editor_data_op(DELETE) error\n");                                                  log_error("editor_data_delete() error\n");
697                                          }                                          }
698                                          else                                          else
699                                          {                                          {
700                                                  screen_end_line = MIN(SCREEN_ROWS - 1, screen_current_line + (int)(last_updated_line - line_current));                                                  if (ch == BACKSPACE)
701                                                    {
702                                                            for (i = 1; i < str_len; i++)
703                                                            {
704                                                                    col_pos--;
705                                                                    if (col_pos < 1 && line_current - screen_current_row + row_pos >= 0)
706                                                                    {
707                                                                            row_pos--;
708                                                                            col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos]);
709                                                                    }
710                                                            }
711                                                    }
712    
713                                                    screen_end_row = MIN(SCREEN_ROWS - 1, screen_current_row + (int)(last_updated_line - line_current));
714                                                    line_current -= (screen_current_row - row_pos);
715                                                    screen_current_row = (int)row_pos;
716    
717                                                    if (screen_current_row < screen_begin_row) // row_pos <= 0
718                                                    {
719                                                            screen_current_row = screen_begin_row;
720                                                            row_pos = screen_begin_row;
721                                                            screen_end_row = SCREEN_ROWS - 1;
722                                                    }
723                                          }                                          }
724    
725                                            // Check whether there is additional input
726                                            ch = igetch(0);
727                                            if (ch == KEY_TIMEOUT)
728                                            {
729                                                    input_ok = 1;
730                                            }
731                                          continue;                                          continue;
732                                  }                                  }
733    
734                                  hz_len = 0;                                  input_ok = 1;
   
735                                  switch (ch)                                  switch (ch)
736                                  {                                  {
737                                  case KEY_NULL:                                  case KEY_NULL:
# Line 539  int editor_display(EDITOR_DATA *p_editor Line 744  int editor_display(EDITOR_DATA *p_editor
744                                          col_pos = 1;                                          col_pos = 1;
745                                          break;                                          break;
746                                  case KEY_CTRL_RIGHT:                                  case KEY_CTRL_RIGHT:
747                                          col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]);                                          col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos]);
748                                          break;                                          break;
749                                  case KEY_CTRL_UP:                                  case KEY_CTRL_UP:
750                                          row_pos = screen_begin_line;                                          row_pos = screen_begin_row;
751                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]));                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos]));
752                                          break;                                          break;
753                                  case KEY_CTRL_DOWN:                                  case KEY_CTRL_DOWN:
754                                          row_pos = SCREEN_ROWS - 1;                                          row_pos = SCREEN_ROWS - 1;
755                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]));                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos]));
756                                          break;                                          break;
757                                  case KEY_INS:                                  case KEY_INS:
758                                          insert = !insert;                                          key_insert = !key_insert;
759                                          break;                                          break;
760                                  case KEY_HOME:                                  case KEY_HOME:
761                                          row_pos = 1;                                          row_pos = 1;
762                                          col_pos = 1;                                          col_pos = 1;
763                                          if (line_current - screen_current_line < 0) // Reach begin                                          if (line_current - screen_current_row < 0) // Reach begin
764                                          {                                          {
765                                                  break;                                                  break;
766                                          }                                          }
767                                          line_current = 0;                                          line_current = 0;
768                                          screen_current_line = screen_begin_line;                                          screen_current_row = screen_begin_row;
769                                          screen_end_line = SCREEN_ROWS - 1;                                          screen_end_row = SCREEN_ROWS - 1;
770                                          clrline(screen_begin_line, SCREEN_ROWS);                                          clrline(screen_begin_row, SCREEN_ROWS);
771                                          break;                                          break;
772                                  case KEY_END:                                  case KEY_END:
773                                          if (p_editor_data->display_line_total < screen_line_total)                                          if (p_editor_data->display_line_total < screen_row_total)
774                                          {                                          {
775                                                  row_pos = p_editor_data->display_line_total;                                                  row_pos = p_editor_data->display_line_total;
776                                                  col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]);                                                  col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos]);
777                                                  break;                                                  break;
778                                          }                                          }
779                                          line_current = p_editor_data->display_line_total - screen_line_total;                                          line_current = p_editor_data->display_line_total - screen_row_total;
780                                          screen_current_line = screen_begin_line;                                          screen_current_row = screen_begin_row;
781                                          screen_end_line = SCREEN_ROWS - 1;                                          screen_end_row = SCREEN_ROWS - 1;
782                                          row_pos = screen_line_total;                                          row_pos = screen_row_total;
783                                          col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]);                                          col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos]);
784                                          clrline(screen_begin_line, SCREEN_ROWS);                                          clrline(screen_begin_row, SCREEN_ROWS);
785                                          break;                                          break;
786                                  case KEY_LEFT:                                  case KEY_LEFT:
787                                          if (col_pos > 1)                                          if (col_pos > 1)
# Line 586  int editor_display(EDITOR_DATA *p_editor Line 791  int editor_display(EDITOR_DATA *p_editor
791                                          }                                          }
792                                          col_pos = SCREEN_COLS; // continue to KEY_UP                                          col_pos = SCREEN_COLS; // continue to KEY_UP
793                                  case KEY_UP:                                  case KEY_UP:
794                                          if (row_pos > screen_begin_line)                                          if (row_pos > screen_begin_row)
795                                          {                                          {
796                                                  row_pos--;                                                  row_pos--;
797                                                  col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]));                                                  col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos]));
798                                                  break;                                                  break;
799                                          }                                          }
800                                          if (line_current - screen_current_line < 0) // Reach begin                                          if (line_current - screen_current_row < 0) // Reach begin
801                                          {                                          {
802                                                  col_pos = 1;                                                  col_pos = 1;
803                                                  break;                                                  break;
804                                          }                                          }
805                                          line_current -= screen_current_line;                                          line_current -= screen_current_row;
806                                          screen_current_line = screen_begin_line;                                          screen_current_row = screen_begin_row;
807                                          // screen_end_line = begin_line;                                          // screen_end_line = begin_line;
808                                          // prints("\033[T"); // Scroll down 1 line                                          // prints("\033[T"); // Scroll down 1 line
809                                          screen_end_line = SCREEN_ROWS - 1; // Legacy Fterm only works with this line                                          screen_end_row = SCREEN_ROWS - 1; // Legacy Fterm only works with this line
810                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]));                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos]));
                                         break;  
                                 case CR:  
811                                          break;                                          break;
812                                  case KEY_SPACE:                                  case KEY_SPACE:
813                                          break;                                          break;
814                                  case KEY_RIGHT:                                  case KEY_RIGHT:
815                                          if (col_pos < p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos])                                          if (col_pos < p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos])
816                                          {                                          {
817                                                  col_pos++;                                                  col_pos++;
818                                                  break;                                                  break;
819                                          }                                          }
820                                          col_pos = 1; // continue to KEY_DOWN                                          col_pos = 1; // continue to KEY_DOWN
821                                  case KEY_DOWN:                                  case KEY_DOWN:
822                                          if (row_pos < MIN(screen_line_total, p_editor_data->display_line_total))                                          if (row_pos < MIN(screen_row_total, p_editor_data->display_line_total))
823                                          {                                          {
824                                                  row_pos++;                                                  row_pos++;
825                                                  col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]));                                                  col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos]));
826                                                  break;                                                  break;
827                                          }                                          }
828                                          if (line_current + (screen_line_total - (screen_current_line - screen_begin_line)) >= p_editor_data->display_line_total) // Reach end                                          if (line_current + (screen_row_total - (screen_current_row - screen_begin_row)) >= p_editor_data->display_line_total) // Reach end
829                                          {                                          {
830                                                  col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]);                                                  col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos]);
831                                                  break;                                                  break;
832                                          }                                          }
833                                          screen_current_line--;                                          line_current += (screen_row_total - (screen_current_row - screen_begin_row));
834                                          screen_end_line = SCREEN_ROWS - 1;                                          screen_current_row = screen_row_total;
835                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]));                                          screen_end_row = SCREEN_ROWS - 1;
836                                            col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos]));
837                                          moveto(SCREEN_ROWS, 0);                                          moveto(SCREEN_ROWS, 0);
838                                          clrtoeol();                                          clrtoeol();
839                                          prints("\033[S"); // Scroll up 1 line                                          prints("\033[S"); // Scroll up 1 line
840                                          break;                                          break;
841                                  case KEY_PGUP:                                  case KEY_PGUP:
842                                          if (line_current - screen_current_line < 0) // Reach begin                                          if (line_current - screen_current_row < 0) // Reach begin
843                                          {                                          {
844                                                  break;                                                  break;
845                                          }                                          }
846                                          line_current -= ((screen_line_total - 1) + (screen_current_line - screen_begin_line));                                          line_current -= ((screen_row_total - 1) + (screen_current_row - screen_begin_row));
847                                          if (line_current < 0)                                          if (line_current < 0)
848                                          {                                          {
849                                                  line_current = 0;                                                  line_current = 0;
850                                          }                                          }
851                                          screen_current_line = screen_begin_line;                                          screen_current_row = screen_begin_row;
852                                          screen_end_line = SCREEN_ROWS - 1;                                          screen_end_row = SCREEN_ROWS - 1;
853                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]));                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos]));
854                                          clrline(screen_begin_line, SCREEN_ROWS);                                          clrline(screen_begin_row, SCREEN_ROWS);
855                                          break;                                          break;
856                                  case KEY_PGDN:                                  case KEY_PGDN:
857                                          if (line_current + screen_line_total - (screen_current_line - screen_begin_line) >= p_editor_data->display_line_total) // Reach end                                          if (line_current + screen_row_total - (screen_current_row - screen_begin_row) >= p_editor_data->display_line_total) // Reach end
858                                          {                                          {
859                                                  break;                                                  break;
860                                          }                                          }
861                                          line_current += (screen_line_total - 1) - (screen_current_line - screen_begin_line);                                          line_current += (screen_row_total - 1) - (screen_current_row - screen_begin_row);
862                                          if (line_current + screen_line_total > p_editor_data->display_line_total) // No enough lines to display                                          if (line_current + screen_row_total > p_editor_data->display_line_total) // No enough lines to display
863                                          {                                          {
864                                                  line_current = p_editor_data->display_line_total - screen_line_total;                                                  line_current = p_editor_data->display_line_total - screen_row_total;
865                                          }                                          }
866                                          screen_current_line = screen_begin_line;                                          screen_current_row = screen_begin_row;
867                                          screen_end_line = SCREEN_ROWS - 1;                                          screen_end_row = SCREEN_ROWS - 1;
868                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]));                                          col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos]));
869                                          clrline(screen_begin_line, SCREEN_ROWS);                                          clrline(screen_begin_row, SCREEN_ROWS);
870                                          break;                                          break;
871                                  case KEY_ESC:                                  case KEY_ESC:
872                                          break;                                          break;
# Line 677  int editor_display(EDITOR_DATA *p_editor Line 881  int editor_display(EDITOR_DATA *p_editor
881                                          show_help = 1;                                          show_help = 1;
882                                  case KEY_F5:                                  case KEY_F5:
883                                          // Refresh after display help information                                          // Refresh after display help information
884                                          line_current -= (screen_current_line - screen_begin_line);                                          line_current -= (screen_current_row - screen_begin_row);
885                                          screen_current_line = screen_begin_line;                                          screen_current_row = screen_begin_row;
886                                          screen_end_line = SCREEN_ROWS - 1;                                          screen_end_row = SCREEN_ROWS - 1;
887                                          clrline(screen_begin_line, SCREEN_ROWS);                                          clrline(screen_begin_row, SCREEN_ROWS);
888                                          break;                                          break;
889                                  case 0: // Refresh bottom line                                  case 0: // Refresh bottom line
890                                          break;                                          break;
# Line 690  int editor_display(EDITOR_DATA *p_editor Line 894  int editor_display(EDITOR_DATA *p_editor
894                                  }                                  }
895    
896                                  BBS_last_access_tm = time(0);                                  BBS_last_access_tm = time(0);
897                                    if (!input_ok)
898                                    {
899                                            ch = igetch_t(MAX_DELAY_TIME);
900                                    }
901                          }                          }
902    
903                          continue;                          continue;
# Line 710  int editor_display(EDITOR_DATA *p_editor Line 918  int editor_display(EDITOR_DATA *p_editor
918                  memcpy(buffer, (const char *)p_editor_data->p_display_lines[line_current], (size_t)len);                  memcpy(buffer, (const char *)p_editor_data->p_display_lines[line_current], (size_t)len);
919                  buffer[len] = '\0';                  buffer[len] = '\0';
920    
921                  moveto(screen_current_line, 0);                  moveto(screen_current_row, 0);
922                  clrtoeol();                  clrtoeol();
923                  prints("%s", buffer);                  prints("%s", buffer);
924                  line_current++;                  line_current++;
925                  screen_current_line++;                  screen_current_row++;
926          }          }
927    
928  cleanup:  cleanup:


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

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