/[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.1 by sysadm, Sun Jun 8 09:25:53 2025 UTC Revision 1.19 by sysadm, Fri Jun 13 13:39:46 2025 UTC
# Line 20  Line 20 
20  #include "log.h"  #include "log.h"
21  #include "common.h"  #include "common.h"
22  #include "str_process.h"  #include "str_process.h"
23    #include "memory_pool.h"
24  #include <stdlib.h>  #include <stdlib.h>
25  #include <sys/param.h>  #include <sys/param.h>
26    #include <strings.h>
27    
28  #define _POSIX_C_SOURCE 200809L  #define _POSIX_C_SOURCE 200809L
29  #include <string.h>  #include <string.h>
30    
31    #define EDITOR_ESC_DISPLAY_STR "\033[32m*\033[m"
32    #define EDITOR_MEM_POOL_LINE_PER_CHUNK 1000
33    #define EDITOR_MEM_POOL_CHUNK_LIMIT (MAX_EDITOR_DATA_LINES / EDITOR_MEM_POOL_LINE_PER_CHUNK + 1)
34    
35    static MEMORY_POOL *p_mp_data_line;
36    static MEMORY_POOL *p_mp_editor_data;
37    
38    int editor_memory_pool_init(void)
39    {
40            if (p_mp_data_line != NULL || p_mp_editor_data != NULL)
41            {
42                    log_error("Editor mem pool already initialized\n");
43                    return -1;
44            }
45    
46            p_mp_data_line = memory_pool_init(MAX_EDITOR_DATA_LINE_LENGTH, EDITOR_MEM_POOL_LINE_PER_CHUNK, EDITOR_MEM_POOL_CHUNK_LIMIT);
47            if (p_mp_data_line == NULL)
48            {
49                    log_error("Memory pool init error\n");
50                    return -2;
51            }
52    
53            p_mp_editor_data = memory_pool_init(sizeof(EDITOR_DATA), 1, 1);
54            if (p_mp_data_line == NULL)
55            {
56                    log_error("Memory pool init error\n");
57                    return -3;
58            }
59    
60            return 0;
61    }
62    
63    void editor_memory_pool_cleanup(void)
64    {
65            if (p_mp_data_line != NULL)
66            {
67                    memory_pool_cleanup(p_mp_data_line);
68                    p_mp_data_line = NULL;
69            }
70    
71            if (p_mp_editor_data != NULL)
72            {
73                    memory_pool_cleanup(p_mp_editor_data);
74                    p_mp_editor_data = NULL;
75            }
76    }
77    
78  EDITOR_DATA *editor_data_load(const char *p_data)  EDITOR_DATA *editor_data_load(const char *p_data)
79  {  {
80          EDITOR_DATA *p_editor_data;          EDITOR_DATA *p_editor_data;
81            char *p_data_line = NULL;
82          long line_offsets[MAX_EDITOR_DATA_LINES];          long line_offsets[MAX_EDITOR_DATA_LINES];
83          long current_data_line_length = 0;          long current_data_line_length = 0;
84          long i, j;          long i;
85    
86          if (p_data == NULL)          if (p_data == NULL)
87          {          {
# Line 39  EDITOR_DATA *editor_data_load(const char Line 89  EDITOR_DATA *editor_data_load(const char
89                  return NULL;                  return NULL;
90          }          }
91    
92          p_editor_data = malloc(sizeof(EDITOR_DATA));          p_editor_data = memory_pool_alloc(p_mp_editor_data);
93          if (p_editor_data == NULL)          if (p_editor_data == NULL)
94          {          {
95                  log_error("malloc(EDITOR_DATA) error: OOM\n");                  log_error("memory_pool_alloc() error\n");
96                  return NULL;                  return NULL;
97          }          }
98    
         p_editor_data->data_line_total = 0;  
99          p_editor_data->display_line_total = split_data_lines(p_data, SCREEN_COLS, line_offsets, MAX_EDITOR_DATA_LINES);          p_editor_data->display_line_total = split_data_lines(p_data, SCREEN_COLS, line_offsets, MAX_EDITOR_DATA_LINES);
100    
101          for (i = 0; i < p_editor_data->display_line_total; i++)          for (i = 0; i < p_editor_data->display_line_total; i++)
# Line 54  EDITOR_DATA *editor_data_load(const char Line 103  EDITOR_DATA *editor_data_load(const char
103                  p_editor_data->display_line_lengths[i] = line_offsets[i + 1] - line_offsets[i];                  p_editor_data->display_line_lengths[i] = line_offsets[i + 1] - line_offsets[i];
104    
105                  if (i == 0 ||                  if (i == 0 ||
106                          (current_data_line_length + p_editor_data->display_line_lengths[i] + 1) >= MAX_EDITOR_DATA_LINE_LENGTH ||                          current_data_line_length + p_editor_data->display_line_lengths[i] + 1 > MAX_EDITOR_DATA_LINE_LENGTH ||
107                          (p_editor_data->display_line_lengths[i - 1] > 0 && p_data[line_offsets[i - 1] + p_editor_data->display_line_lengths[i - 1] - 1] == '\n'))                          (p_editor_data->display_line_lengths[i - 1] > 0 && p_data[line_offsets[i - 1] + p_editor_data->display_line_lengths[i - 1] - 1] == '\n'))
108                  {                  {
109                          // Allocate new data line                          // Allocate new data line
110                          p_editor_data->p_data_lines[p_editor_data->data_line_total] = malloc(MAX_EDITOR_DATA_LINE_LENGTH);                          p_data_line = memory_pool_alloc(p_mp_data_line);
111                          if (p_editor_data->p_data_lines[p_editor_data->data_line_total] == NULL)                          if (p_data_line == NULL)
112                          {                          {
113                                  log_error("malloc(MAX_EDITOR_DATA_LINE_LENGTH * %d) error: OOM\n", i);                                  log_error("memory_pool_alloc() error: i = %d\n", i);
114                                  // Cleanup                                  // Cleanup
115                                  for (j = p_editor_data->data_line_total - 1; j >= 0; j--)                                  editor_data_cleanup(p_editor_data);
                                 {  
                                         free(p_editor_data->p_data_lines[j]);  
                                 }  
                                 free(p_editor_data);  
116                                  return NULL;                                  return NULL;
117                          }                          }
118    
119                          p_editor_data->p_display_lines[i] = p_editor_data->p_data_lines[p_editor_data->data_line_total];                          p_editor_data->p_display_lines[i] = p_data_line;
120                          (p_editor_data->data_line_total)++;                          current_data_line_length = 0;
121                  }                  }
122                  else                  else
123                  {                  {
124                          p_editor_data->p_display_lines[i] = p_editor_data->p_display_lines[i - 1] + p_editor_data->display_line_lengths[i - 1];                          p_editor_data->p_display_lines[i] = p_editor_data->p_display_lines[i - 1] + p_editor_data->display_line_lengths[i - 1];
                         current_data_line_length = 0;  
125                  }                  }
126    
127                  memcpy(p_editor_data->p_display_lines[i], p_data + line_offsets[i], (size_t)p_editor_data->display_line_lengths[i]);                  memcpy(p_editor_data->p_display_lines[i], p_data + line_offsets[i], (size_t)p_editor_data->display_line_lengths[i]);
                 p_editor_data->p_display_lines[i][p_editor_data->display_line_lengths[i]] = '\0';  
   
128                  current_data_line_length += p_editor_data->display_line_lengths[i];                  current_data_line_length += p_editor_data->display_line_lengths[i];
129    
130                    // Trim \n from last line
131                    if (i + 1 == p_editor_data->display_line_total &&
132                            p_editor_data->display_line_lengths[i] > 0 &&
133                            p_editor_data->p_display_lines[i][p_editor_data->display_line_lengths[i] - 1] == '\n')
134                    {
135                            p_editor_data->display_line_lengths[i]--;
136                            current_data_line_length--;
137                    }
138                    p_data_line[current_data_line_length] = '\0';
139          }          }
140    
141            bzero(p_editor_data->p_display_lines + p_editor_data->display_line_total, MAX_EDITOR_DATA_LINES - (size_t)p_editor_data->display_line_total);
142    
143          return p_editor_data;          return p_editor_data;
144  }  }
145    
# Line 120  long editor_data_save(const EDITOR_DATA Line 174  long editor_data_save(const EDITOR_DATA
174    
175  void editor_data_cleanup(EDITOR_DATA *p_editor_data)  void editor_data_cleanup(EDITOR_DATA *p_editor_data)
176  {  {
177            char *p_data_line = NULL;
178          long i;          long i;
179    
180          if (p_editor_data == NULL)          if (p_editor_data == NULL)
# Line 127  void editor_data_cleanup(EDITOR_DATA *p_ Line 182  void editor_data_cleanup(EDITOR_DATA *p_
182                  return;                  return;
183          }          }
184    
185          for (i = p_editor_data->data_line_total - 1; i >= 0; i--)          for (i = 0; i < p_editor_data->display_line_total; i++)
186            {
187                    if (p_data_line == NULL)
188                    {
189                            p_data_line = p_editor_data->p_display_lines[i];
190                    }
191    
192                    if (p_editor_data->display_line_lengths[i] > 0 &&
193                            p_editor_data->p_display_lines[i][p_editor_data->display_line_lengths[i] - 1] == '\n')
194                    {
195                            memory_pool_free(p_mp_data_line, p_data_line);
196                            p_data_line = NULL;
197                    }
198            }
199    
200            if (p_data_line != NULL)
201            {
202                    memory_pool_free(p_mp_data_line, p_data_line);
203            }
204    
205            memory_pool_free(p_mp_editor_data, p_editor_data);
206    }
207    
208    int editor_data_insert(EDITOR_DATA *p_editor_data, long *p_display_line, long *p_offset,
209                                               const char *str, int str_len, long *p_last_updated_line)
210    {
211            long display_line = *p_display_line;
212            long offset = *p_offset;
213            char *p_data_line = NULL;
214            long len_data_line;
215            long offset_data_line;
216            long last_display_line; // of data line
217            long line_offsets[MAX_EDITOR_DATA_LINE_LENGTH + 1];
218            long split_line_total;
219            long i, j;
220            int len;
221            int eol;
222            int display_len;
223    
224            if (p_editor_data == NULL || p_last_updated_line == NULL)
225            {
226                    log_error("editor_data_op() error: NULL pointer\n");
227                    return -1;
228            }
229    
230            // Get accurate offset of first character of CJK at offset position
231            for (i = 0; i < offset; i++)
232            {
233                    if (p_editor_data->p_display_lines[display_line][i] < 0 || p_editor_data->p_display_lines[display_line][i] > 127) // GBK
234                    {
235                            i++;
236                    }
237            }
238            if (i > offset) // offset was skipped
239            {
240                    offset--;
241            }
242    
243            // Get length of current data line
244            len_data_line = 0;
245            p_data_line = p_editor_data->p_display_lines[display_line];
246            for (i = display_line - 1; i >= 0; i--)
247            {
248                    if (p_editor_data->display_line_lengths[i] > 0 &&
249                            p_editor_data->p_display_lines[i][p_editor_data->display_line_lengths[i] - 1] == '\n') // reach end of prior data line
250                    {
251                            break;
252                    }
253    
254                    len_data_line += p_editor_data->display_line_lengths[i];
255                    p_data_line = p_editor_data->p_display_lines[i];
256            }
257            offset_data_line = len_data_line + offset;
258            last_display_line = p_editor_data->display_line_total - 1;
259            for (i = display_line; i < p_editor_data->display_line_total; i++)
260            {
261                    len_data_line += p_editor_data->display_line_lengths[i];
262    
263                    if (p_editor_data->display_line_lengths[i] > 0 &&
264                            p_editor_data->p_display_lines[i][p_editor_data->display_line_lengths[i] - 1] == '\n') // reach end of current data line
265                    {
266                            last_display_line = i;
267                            break;
268                    }
269            }
270    
271            // Split current data line if over-length
272            if (len_data_line + str_len + 1 > MAX_EDITOR_DATA_LINE_LENGTH || str[0] == CR)
273            {
274                    if (p_editor_data->display_line_total >= MAX_EDITOR_DATA_LINES)
275                    {
276                            // log_error("Split line error, display_line_total(%ld) reach limit(%d)\n",
277                            //                p_editor_data->display_line_total, MAX_EDITOR_DATA_LINES);
278                            return -2;
279                    }
280    
281                    // Allocate new data line
282                    p_data_line = memory_pool_alloc(p_mp_data_line);
283                    if (p_data_line == NULL)
284                    {
285                            log_error("memory_pool_alloc() error\n");
286                            return -2;
287                    }
288    
289                    if (offset_data_line + str_len + 1 >= MAX_EDITOR_DATA_LINE_LENGTH || str[0] == CR)
290                    {
291                            if (str[0] == CR)
292                            {
293                                    str_len = 0;
294                            }
295    
296                            // Copy str to new data line
297                            memcpy(p_data_line, str, (size_t)str_len);
298    
299                            // Copy rest part of current data line to new data line
300                            memcpy(p_data_line + str_len,
301                                       p_editor_data->p_display_lines[display_line] + offset,
302                                       (size_t)(len_data_line - offset_data_line));
303    
304                            p_data_line[str_len + len_data_line - offset_data_line] = '\0';
305    
306                            // Add line ending to current display line (data line)
307                            p_editor_data->p_display_lines[display_line][offset] = '\n';
308                            p_editor_data->p_display_lines[display_line][offset + 1] = '\0';
309                            p_editor_data->display_line_lengths[display_line] = offset + 1;
310    
311                            *p_display_line = display_line + 1;
312                            *p_offset = str_len;
313                    }
314                    else
315                    {
316                            // Copy rest part of current data line to new data line
317                            memcpy(p_data_line,
318                                       p_editor_data->p_display_lines[display_line] + offset,
319                                       (size_t)(len_data_line - offset_data_line));
320    
321                            p_data_line[len_data_line - offset_data_line] = '\0';
322    
323                            // Append str to current display line
324                            memcpy(p_editor_data->p_display_lines[display_line] + offset, str, (size_t)str_len);
325    
326                            // Add line ending to current display line (data line)
327                            p_editor_data->p_display_lines[display_line][offset + str_len] = '\n';
328                            p_editor_data->p_display_lines[display_line][offset + str_len + 1] = '\0';
329                            p_editor_data->display_line_lengths[display_line] = offset + str_len + 1;
330    
331                            *p_display_line = display_line;
332                            *p_offset = offset + str_len;
333                    }
334    
335                    split_line_total = last_display_line - display_line + 3;
336    
337                    // Set start display_line for spliting new data line
338                    display_line++;
339    
340                    *p_last_updated_line = p_editor_data->display_line_total;
341            }
342            else // insert str into current data line at offset_data_line
343            {
344                    memmove(p_data_line + offset_data_line + str_len, p_data_line + offset_data_line, (size_t)(len_data_line - offset_data_line));
345                    memcpy(p_data_line + offset_data_line, str, (size_t)str_len);
346                    p_data_line[len_data_line + str_len] = '\0';
347    
348                    // Set p_data_line to head of current display line
349                    p_data_line = p_editor_data->p_display_lines[display_line];
350                    split_line_total = last_display_line - display_line + 3;
351    
352                    *p_display_line = display_line;
353                    *p_offset = offset + str_len;
354            }
355    
356            // Split current data line since beginning of current display line
357            split_line_total = split_data_lines(p_data_line, SCREEN_COLS, line_offsets, split_line_total);
358    
359            for (i = 0; i < split_line_total; i++)
360            {
361                    if (display_line + i > last_display_line)
362                    {
363                            // Insert blank display line after last_display_line
364                            if (p_editor_data->display_line_total >= MAX_EDITOR_DATA_LINES)
365                            {
366                                    // log_error("display_line_total over limit %d >= %d\n", p_editor_data->display_line_total, MAX_EDITOR_DATA_LINES);
367                                    // Terminate prior display line with \n, to avoid error on cleanup
368                                    if (display_line + i - 1 >= 0 && p_editor_data->display_line_lengths[display_line + i - 1] > 0)
369                                    {
370                                            len = split_line(p_editor_data->p_display_lines[display_line + i - 1], SCREEN_COLS - 1, &eol, &display_len);
371                                            p_editor_data->p_display_lines[display_line + i - 1][len] = '\n';
372                                            p_editor_data->p_display_lines[display_line + i - 1][len + 1] = '\0';
373                                            p_editor_data->display_line_lengths[display_line + i - 1] = len + 1;
374                                    }
375                                    if (*p_offset >= p_editor_data->display_line_lengths[*p_display_line])
376                                    {
377                                            *p_offset = p_editor_data->display_line_lengths[*p_display_line] - 1;
378                                    }
379                                    break;
380                            }
381                            for (j = p_editor_data->display_line_total; j > last_display_line + 1; j--)
382                            {
383                                    p_editor_data->p_display_lines[j] = p_editor_data->p_display_lines[j - 1];
384                                    p_editor_data->display_line_lengths[j] = p_editor_data->display_line_lengths[j - 1];
385                            }
386                            last_display_line++;
387                            (p_editor_data->display_line_total)++;
388                    }
389    
390                    p_editor_data->display_line_lengths[display_line + i] = line_offsets[i + 1] - line_offsets[i];
391                    p_editor_data->p_display_lines[display_line + i] =
392                            (i == 0
393                                     ? p_data_line
394                                     : (p_editor_data->p_display_lines[display_line + i - 1] + p_editor_data->display_line_lengths[display_line + i - 1]));
395    
396                    if (p_editor_data->display_line_lengths[display_line + i] > 0 &&
397                            p_editor_data->p_display_lines[display_line + i][p_editor_data->display_line_lengths[display_line + i] - 1] == '\n')
398                    {
399                            break;
400                    }
401            }
402    
403            *p_last_updated_line = MAX(display_line + MIN(i, split_line_total - 1), *p_last_updated_line);
404    
405            if (*p_offset >= p_editor_data->display_line_lengths[*p_display_line])
406            {
407                    if (*p_display_line + 1 < p_editor_data->display_line_total)
408                    {
409                            *p_offset -= p_editor_data->display_line_lengths[*p_display_line];
410                            (*p_display_line)++;
411                    }
412            }
413    
414            return 0;
415    }
416    
417    int editor_data_delete(EDITOR_DATA *p_editor_data, long display_line, long offset,
418                                               long *p_last_updated_line)
419    {
420            char *p_data_line = NULL;
421            long len_data_line;
422            long offset_data_line;
423            long last_display_line; // of data line
424            long line_offsets[MAX_EDITOR_DATA_LINE_LENGTH + 1];
425            long split_line_total;
426            long i, j;
427            int str_len = 0;
428    
429            if (p_editor_data == NULL || p_last_updated_line == NULL)
430            {
431                    log_error("editor_data_op() error: NULL pointer\n");
432                    return -1;
433            }
434    
435            // Get accurate offset of first character of CJK at offset position
436            for (i = 0; i < offset; i++)
437            {
438                    if (p_editor_data->p_display_lines[display_line][i] < 0 || p_editor_data->p_display_lines[display_line][i] > 127) // GBK
439                    {
440                            i++;
441                    }
442            }
443            if (i > offset) // offset was skipped
444            {
445                    offset--;
446            }
447    
448            // Get length of current data line
449            len_data_line = 0;
450            p_data_line = p_editor_data->p_display_lines[display_line];
451            for (i = display_line - 1; i >= 0; i--)
452            {
453                    if (p_editor_data->display_line_lengths[i] > 0 &&
454                            p_editor_data->p_display_lines[i][p_editor_data->display_line_lengths[i] - 1] == '\n') // reach end of prior data line
455                    {
456                            break;
457                    }
458    
459                    len_data_line += p_editor_data->display_line_lengths[i];
460                    p_data_line = p_editor_data->p_display_lines[i];
461            }
462            offset_data_line = len_data_line + offset;
463            last_display_line = p_editor_data->display_line_total - 1;
464            for (i = display_line; i < p_editor_data->display_line_total; i++)
465            {
466                    len_data_line += p_editor_data->display_line_lengths[i];
467    
468                    if (p_editor_data->display_line_lengths[i] > 0 &&
469                            p_editor_data->p_display_lines[i][p_editor_data->display_line_lengths[i] - 1] == '\n') // reach end of current data line
470                    {
471                            last_display_line = i;
472                            break;
473                    }
474            }
475    
476            if (offset_data_line >= len_data_line) // end-of-line
477            {
478                    return 0;
479            }
480    
481            // Check str to be deleted
482            if (p_data_line[offset_data_line] > 0 && p_data_line[offset_data_line] < 127)
483            {
484                    str_len = 1;
485            }
486            else if (p_data_line[offset_data_line + 1] < 0 || p_data_line[offset_data_line] > 127) // GBK
487            {
488                    str_len = 2;
489            }
490            else
491            {
492                    log_error("Some strange character at display_line %ld, offset %ld: %d %d\n",
493                                      display_line, offset, p_data_line[offset_data_line], p_data_line[offset_data_line + 1]);
494                    str_len = 1;
495            }
496    
497            // Current display line is (almost) empty
498            if (offset_data_line + str_len > len_data_line ||
499                    (offset_data_line + str_len == len_data_line && p_data_line[offset_data_line] == '\n'))
500            {
501                    if (display_line + 1 >= p_editor_data->display_line_total) // No additional display line (data line)
502                    {
503                            return 0;
504                    }
505    
506                    len_data_line = 0; // Next data line
507                    last_display_line = p_editor_data->display_line_total - 1;
508                    for (i = display_line + 1; i < p_editor_data->display_line_total; i++)
509                    {
510                            len_data_line += p_editor_data->display_line_lengths[i];
511    
512                            if (p_editor_data->display_line_lengths[i] > 0 &&
513                                    p_editor_data->p_display_lines[i][p_editor_data->display_line_lengths[i] - 1] == '\n') // reach end of current data line
514                            {
515                                    last_display_line = i;
516                                    break;
517                            }
518                    }
519    
520                    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
521                    {
522                            return 0;
523                    }
524    
525                    // Append next data line to current one
526                    memcpy(p_data_line + offset_data_line, p_editor_data->p_display_lines[display_line + 1], (size_t)len_data_line);
527                    p_data_line[offset_data_line + len_data_line] = '\0';
528    
529                    // Recycle next data line
530                    memory_pool_free(p_mp_data_line, p_editor_data->p_display_lines[display_line + 1]);
531            }
532            else
533            {
534                    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));
535                    p_data_line[len_data_line - str_len] = '\0';
536                    len_data_line -= str_len;
537            }
538    
539            // Set p_data_line to head of current display line
540            p_data_line = p_editor_data->p_display_lines[display_line];
541            split_line_total = last_display_line - display_line + 2;
542    
543            // Split current data line since beginning of current display line
544            split_line_total = split_data_lines(p_data_line, SCREEN_COLS, line_offsets, split_line_total);
545    
546            for (i = 0; i < split_line_total; i++)
547          {          {
548                  free(p_editor_data->p_data_lines[i]);                  p_editor_data->display_line_lengths[display_line + i] = line_offsets[i + 1] - line_offsets[i];
549                    p_editor_data->p_display_lines[display_line + i] =
550                            (i == 0
551                                     ? p_data_line
552                                     : (p_editor_data->p_display_lines[display_line + i - 1] + p_editor_data->display_line_lengths[display_line + i - 1]));
553    
554                    if (p_editor_data->display_line_lengths[display_line + i] > 0 &&
555                            p_editor_data->p_display_lines[display_line + i][p_editor_data->display_line_lengths[display_line + i] - 1] == '\n')
556                    {
557                            break;
558                    }
559            }
560    
561            *p_last_updated_line = display_line + MIN(i, split_line_total - 1);
562    
563            if (*p_last_updated_line < last_display_line)
564            {
565                    // Remove redundant display line after last_display_line
566                    for (j = last_display_line + 1; j < p_editor_data->display_line_total; j++)
567                    {
568                            p_editor_data->p_display_lines[j - (last_display_line - *p_last_updated_line)] = p_editor_data->p_display_lines[j];
569                            p_editor_data->display_line_lengths[j - (last_display_line - *p_last_updated_line)] = p_editor_data->display_line_lengths[j];
570                    }
571    
572                    j = p_editor_data->display_line_total;
573                    (p_editor_data->display_line_total) -= (last_display_line - *p_last_updated_line);
574                    *p_last_updated_line = MAX(j - 1, *p_last_updated_line);
575          }          }
576    
577          free(p_editor_data);          return str_len;
578  }  }
579    
580  static int editor_display_key_handler(int *p_key, DISPLAY_CTX *p_ctx)  static int editor_display_key_handler(int *p_key, EDITOR_CTX *p_ctx)
581  {  {
582          switch (*p_key)          switch (*p_key)
583          {          {
584          case 0: // Set msg          case 0: // Set msg
585                  snprintf(p_ctx->msg, sizeof(p_ctx->msg),                  snprintf(p_ctx->msg, sizeof(p_ctx->msg),
586                                   "| ·µ»Ø[\033[32m¡û\033[33m,\033[32mESC\033[33m] | "                                   "| Í˳ö[\033[32mCtrl-W\033[33m] | °ïÖú[\033[32mh\033[33m] |");
                                  "ÒÆ¶¯[\033[32m¡ü\033[33m/\033[32m¡ý\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] | "  
                                  "°ïÖú[\033[32mh\033[33m] |");  
587                  break;                  break;
588          }          }
589    
# Line 154  int editor_display(EDITOR_DATA *p_editor Line 594  int editor_display(EDITOR_DATA *p_editor
594  {  {
595          static int show_help = 1;          static int show_help = 1;
596          char buffer[MAX_EDITOR_DATA_LINE_LENGTH];          char buffer[MAX_EDITOR_DATA_LINE_LENGTH];
597          DISPLAY_CTX ctx;          EDITOR_CTX ctx;
598          int ch = 0;          int ch = 0;
599          int input_ok, screen_current_line;          char input_str[4];
600          const int screen_begin_line = 1;          int str_len = 0;
601          int screen_end_line = SCREEN_ROWS - 1;          int input_ok;
602          const int screen_line_total = screen_end_line - screen_begin_line + 1;          const int screen_begin_row = 1;
603            const int screen_row_total = SCREEN_ROWS - screen_begin_row;
604            int output_current_row = screen_begin_row;
605            int output_end_row = SCREEN_ROWS - 1;
606          long int line_current = 0;          long int line_current = 0;
607          long int len;          long int len;
         long int percentile;  
608          int loop;          int loop;
609          int eol, display_len;          int eol, display_len;
610          long row_pos = 1, col_pos = 1;          long row_pos = 1, col_pos = 1;
611            long display_line_in, offset_in;
612            long display_line_out, offset_out;
613            int scroll_rows;
614            long last_updated_line = 0;
615            int key_insert = 1;
616            int i, j;
617            char *p_str;
618    
619          screen_current_line = screen_begin_line;          clrline(output_current_row, SCREEN_ROWS);
         clrline(screen_begin_line, SCREEN_ROWS);  
620    
621          // update msg_ext with extended key handler          // update msg_ext with extended key handler
622          if (editor_display_key_handler(&ch, &ctx) != 0)          if (editor_display_key_handler(&ch, &ctx) != 0)
# Line 179  int editor_display(EDITOR_DATA *p_editor Line 627  int editor_display(EDITOR_DATA *p_editor
627          loop = 1;          loop = 1;
628          while (!SYS_server_exit && loop)          while (!SYS_server_exit && loop)
629          {          {
630                  if (line_current >= p_editor_data->display_line_total || screen_current_line > screen_end_line)                  if (line_current >= p_editor_data->display_line_total || output_current_row > output_end_row)
631                  {                  {
632                          ctx.reach_begin = (line_current < screen_current_line ? 1 : 0);                          ctx.line_cursor = line_current - output_current_row + row_pos + 1;
   
                         if (line_current - (screen_current_line - screen_begin_line) + screen_line_total < p_editor_data->display_line_total)  
                         {  
                                 percentile = (line_current - (screen_current_line - screen_begin_line) + screen_line_total) * 100 / p_editor_data->display_line_total;  
                                 ctx.reach_end = 0;  
                         }  
                         else  
                         {  
                                 percentile = 100;  
                                 ctx.reach_end = 1;  
                         }  
   
                         ctx.line_top = line_current - (screen_current_line - screen_begin_line) + 1;  
                         ctx.line_bottom = MIN(line_current - (screen_current_line - screen_begin_line) + screen_line_total, p_editor_data->display_line_total);  
633    
634                          snprintf(buffer, sizeof(buffer),                          snprintf(buffer, sizeof(buffer),
635                                           "\033[1;44;33mµÚ\033[32m%ld\033[33m-\033[32m%ld\033[33mÐÐ (\033[32m%ld%%\033[33m) %s",                                           "\033[1;44;33m[\033[32m%ld\033[33m;\033[32m%ld\033[33m] "
636                                           ctx.line_top,                                           "µÚ\033[32m%ld\033[33m/\033[32m%ld\033[33mÐÐ [\033[32m%s\033[33m] "
637                                           ctx.line_bottom,                                           "%s",
638                                           percentile,                                           row_pos, col_pos,
639                                             ctx.line_cursor, p_editor_data->display_line_total,
640                                             key_insert ? "²åÈë" : "¸Äд",
641                                           ctx.msg);                                           ctx.msg);
642    
643                          len = split_line(buffer, SCREEN_COLS, &eol, &display_len);                          len = split_line(buffer, SCREEN_COLS, &eol, &display_len);
# Line 230  int editor_display(EDITOR_DATA *p_editor Line 666  int editor_display(EDITOR_DATA *p_editor
666                                          goto cleanup;                                          goto cleanup;
667                                  }                                  }
668    
669                                    if (ch > 127 && ch <= 255) // GBK
670                                    {
671                                            input_str[str_len] = (char)(ch - 256);
672                                            str_len++;
673                                    }
674                                    else
675                                    {
676                                            str_len = 0;
677                                    }
678    
679                                    if ((ch >= 32 && ch < 127) || (ch > 127 && ch <= 255 && str_len == 2) || // Printable character or GBK
680                                            ch == CR || ch == KEY_ESC)                                                                                       // Special character
681                                    {
682                                            if (str_len == 0)
683                                            {
684                                                    input_str[0] = (char)ch;
685                                                    str_len = 1;
686                                            }
687    
688                                            last_updated_line = line_current;
689                                            display_line_in = line_current - output_current_row + row_pos;
690                                            offset_in = col_pos - 1;
691                                            display_line_out = display_line_in;
692                                            offset_out = offset_in;
693    
694                                            if (!key_insert) // overwrite
695                                            {
696                                                    if (editor_data_delete(p_editor_data, display_line_in, offset_in,
697                                                                                               &last_updated_line) < 0)
698                                                    {
699                                                            log_error("editor_data_delete() error\n");
700                                                    }
701                                            }
702    
703                                            if (editor_data_insert(p_editor_data, &display_line_out, &offset_out,
704                                                                                       input_str, str_len, &last_updated_line) < 0)
705                                            {
706                                                    log_error("editor_data_insert(str_len=%d) error\n", str_len);
707                                                    str_len = 0;
708                                            }
709                                            else
710                                            {
711                                                    str_len = 0;
712    
713                                                    output_end_row = MIN(SCREEN_ROWS - 1, output_current_row + (int)(last_updated_line - line_current));
714                                                    line_current -= (output_current_row - row_pos);
715                                                    output_current_row = (int)row_pos;
716    
717                                                    scroll_rows = MAX(0, (int)(display_line_out - display_line_in) - (output_end_row - output_current_row));
718    
719                                                    if (scroll_rows > 0)
720                                                    {
721                                                            moveto(SCREEN_ROWS, 0);
722                                                            clrtoeol();
723                                                            for (i = 0; i < scroll_rows; i++)
724                                                            {
725                                                                    prints("\033[S"); // Scroll up 1 line
726                                                            }
727    
728                                                            output_current_row -= scroll_rows;
729                                                            if (output_current_row < screen_begin_row)
730                                                            {
731                                                                    line_current += (screen_begin_row - output_current_row);
732                                                                    output_current_row = screen_begin_row;
733                                                            }
734                                                            row_pos = output_end_row;
735                                                    }
736                                                    else // if (scroll_lines == 0)
737                                                    {
738                                                            row_pos += (display_line_out - display_line_in);
739                                                    }
740                                                    col_pos = offset_out + 1;
741                                            }
742    
743                                            continue;
744                                    }
745                                    else if (ch == KEY_DEL || ch == BACKSPACE) // Del
746                                    {
747                                            if (ch == BACKSPACE)
748                                            {
749                                                    if (line_current - output_current_row + row_pos <= 0 && col_pos <= 1) // Forbidden
750                                                    {
751                                                            input_ok = 0;
752                                                            continue;
753                                                    }
754    
755                                                    col_pos--;
756                                                    if (col_pos < 1 && line_current - output_current_row + row_pos >= 0)
757                                                    {
758                                                            row_pos--;
759                                                            col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]);
760                                                    }
761                                            }
762    
763                                            if ((str_len = editor_data_delete(p_editor_data, line_current - output_current_row + row_pos, col_pos - 1,
764                                                                                                              &last_updated_line)) < 0)
765                                            {
766                                                    log_error("editor_data_delete() error\n");
767                                            }
768                                            else
769                                            {
770                                                    if (ch == BACKSPACE)
771                                                    {
772                                                            for (i = 1; i < str_len; i++)
773                                                            {
774                                                                    col_pos--;
775                                                                    if (col_pos < 1 && line_current - output_current_row + row_pos >= 0)
776                                                                    {
777                                                                            row_pos--;
778                                                                            col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]);
779                                                                    }
780                                                            }
781                                                    }
782    
783                                                    output_end_row = MIN(SCREEN_ROWS - 1, output_current_row + (int)(last_updated_line - line_current));
784                                                    line_current -= (output_current_row - row_pos);
785                                                    output_current_row = (int)row_pos;
786    
787                                                    if (output_current_row < screen_begin_row) // row_pos <= 0
788                                                    {
789                                                            output_current_row = screen_begin_row;
790                                                            row_pos = screen_begin_row;
791                                                            output_end_row = SCREEN_ROWS - 1;
792                                                    }
793    
794                                                    // Exceed end
795                                                    if (line_current + (screen_row_total - output_current_row) >= p_editor_data->display_line_total &&
796                                                            p_editor_data->display_line_total > screen_row_total)
797                                                    {
798                                                            scroll_rows = (int)((line_current - (output_current_row - screen_begin_row)) -
799                                                                                                    (p_editor_data->display_line_total - screen_row_total));
800    
801                                                            line_current = p_editor_data->display_line_total - screen_row_total;
802                                                            row_pos += scroll_rows;
803                                                            output_current_row = screen_begin_row;
804                                                            output_end_row = SCREEN_ROWS - 1;
805                                                    }
806    
807                                                    clrline(output_current_row, output_end_row);
808                                            }
809    
810                                            continue;
811                                    }
812    
813                                  switch (ch)                                  switch (ch)
814                                  {                                  {
815                                  case KEY_NULL:                                  case KEY_NULL:
816                                  case KEY_TIMEOUT:                                  case KEY_TIMEOUT:
817                                          goto cleanup;                                          goto cleanup;
818                                  case Ctrl('C'):                                  case Ctrl('W'):
819                                          loop = 0;                                          loop = 0;
820                                          break;                                          break;
821                                  case Ctrl('H'):                                  case Ctrl('S'): // Start of line
822                                    case KEY_CTRL_LEFT:
823                                          col_pos = 1;                                          col_pos = 1;
824                                          break;                                          break;
825                                  case Ctrl('E'):                                  case Ctrl('E'): // End of line
826                                          col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]);                                  case KEY_CTRL_RIGHT:
827                                            col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]);
828                                            break;
829                                    case Ctrl('T'): // Top of screen
830                                    case KEY_CTRL_UP:
831                                            row_pos = screen_begin_row;
832                                            col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]));
833                                            break;
834                                    case Ctrl('B'): // Bottom of screen
835                                    case KEY_CTRL_DOWN:
836                                            if (p_editor_data->display_line_total < screen_row_total)
837                                            {
838                                                    row_pos = p_editor_data->display_line_total;
839                                            }
840                                            else
841                                            {
842                                                    row_pos = SCREEN_ROWS - 1;
843                                            }
844                                            if (line_current + (screen_row_total - (output_current_row - screen_begin_row)) >= p_editor_data->display_line_total) // Reach end
845                                            {
846                                                    // last display line does NOT have \n in the end
847                                                    col_pos = MIN(col_pos, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] + 1);
848                                            }
849                                            else
850                                            {
851                                                    col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]));
852                                            }
853                                            break;
854                                    case KEY_INS:
855                                            key_insert = !key_insert;
856                                          break;                                          break;
857                                  case KEY_HOME:                                  case KEY_HOME:
858                                          row_pos = 1;                                          row_pos = 1;
859                                          col_pos = 1;                                          col_pos = 1;
860                                          if (line_current - screen_current_line < 0) // Reach begin                                          if (line_current - output_current_row < 0) // Reach begin
861                                          {                                          {
862                                                  break;                                                  break;
863                                          }                                          }
864                                          line_current = 0;                                          line_current = 0;
865                                          screen_current_line = screen_begin_line;                                          output_current_row = screen_begin_row;
866                                          screen_end_line = SCREEN_ROWS - 1;                                          output_end_row = SCREEN_ROWS - 1;
867                                          clrline(screen_begin_line, SCREEN_ROWS);                                          clrline(output_current_row, SCREEN_ROWS);
868                                          break;                                          break;
869                                  case KEY_END:                                  case KEY_END:
870                                          if (p_editor_data->display_line_total < screen_line_total)                                          if (p_editor_data->display_line_total < screen_row_total)
871                                          {                                          {
872                                                  row_pos = p_editor_data->display_line_total;                                                  row_pos = p_editor_data->display_line_total;
873                                                  col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]);                                                  col_pos = p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] + 1;
874                                                  break;                                                  break;
875                                          }                                          }
876                                          line_current = p_editor_data->display_line_total - screen_line_total;                                          line_current = p_editor_data->display_line_total - screen_row_total;
877                                          screen_current_line = screen_begin_line;                                          output_current_row = screen_begin_row;
878                                          screen_end_line = SCREEN_ROWS - 1;                                          output_end_row = SCREEN_ROWS - 1;
879                                          row_pos = screen_line_total;                                          row_pos = SCREEN_ROWS - 1;
880                                          col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]);                                          col_pos = p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] + 1;
881                                          clrline(screen_begin_line, SCREEN_ROWS);                                          clrline(output_current_row, SCREEN_ROWS);
882                                          break;                                          break;
883                                  case KEY_LEFT:                                  case KEY_LEFT:
884                                          if (col_pos > 1)                                          if (col_pos > 1)
# Line 278  int editor_display(EDITOR_DATA *p_editor Line 888  int editor_display(EDITOR_DATA *p_editor
888                                          }                                          }
889                                          col_pos = SCREEN_COLS; // continue to KEY_UP                                          col_pos = SCREEN_COLS; // continue to KEY_UP
890                                  case KEY_UP:                                  case KEY_UP:
891                                          if (row_pos > screen_begin_line)                                          if (row_pos > screen_begin_row)
892                                          {                                          {
893                                                  row_pos--;                                                  row_pos--;
894                                                  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 - output_current_row + row_pos]));
895                                                  break;                                                  break;
896                                          }                                          }
897                                          if (line_current - screen_current_line < 0) // Reach begin                                          if (line_current - output_current_row < 0) // Reach begin
898                                          {                                          {
899                                                  col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]);                                                  col_pos = 1;
900                                                  break;                                                  break;
901                                          }                                          }
902                                          line_current -= screen_current_line;                                          line_current -= output_current_row;
903                                          screen_current_line = screen_begin_line;                                          output_current_row = screen_begin_row;
904                                          // screen_end_line = begin_line;                                          // screen_end_line = begin_line;
905                                          // prints("\033[T"); // Scroll down 1 line                                          // prints("\033[T"); // Scroll down 1 line
906                                          screen_end_line = SCREEN_ROWS - 1; // Legacy Fterm only works with this line                                          output_end_row = SCREEN_ROWS - 1; // Legacy Fterm only works with this line
907                                          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 - output_current_row + row_pos]));
                                         break;  
                                 case CR:  
908                                          break;                                          break;
909                                  case KEY_SPACE:                                  case KEY_SPACE:
910                                          break;                                          break;
911                                  case KEY_RIGHT:                                  case KEY_RIGHT:
912                                          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 - output_current_row + row_pos])
913                                          {                                          {
914                                                  col_pos++;                                                  col_pos++;
915                                                  break;                                                  break;
916                                          }                                          }
917                                          col_pos = 1; // continue to KEY_DOWN                                          col_pos = 1; // continue to KEY_DOWN
918                                  case KEY_DOWN:                                  case KEY_DOWN:
919                                          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))
920                                          {                                          {
921                                                  row_pos++;                                                  row_pos++;
922                                                  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 - output_current_row + row_pos]));
923                                                  break;                                                  break;
924                                          }                                          }
925                                          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 - (output_current_row - screen_begin_row)) >= p_editor_data->display_line_total) // Reach end
926                                          {                                          {
927                                                  col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_line + row_pos]);                                                  // last display line does NOT have \n in the end
928                                                    col_pos = p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] + 1;
929                                                  break;                                                  break;
930                                          }                                          }
931                                          line_current += (screen_line_total - (screen_current_line - screen_begin_line));                                          line_current += (screen_row_total - (output_current_row - screen_begin_row));
932                                          screen_current_line = screen_line_total;                                          output_current_row = screen_row_total;
933                                          screen_end_line = SCREEN_ROWS - 1;                                          output_end_row = SCREEN_ROWS - 1;
934                                          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 - output_current_row + row_pos]));
935                                          moveto(SCREEN_ROWS, 0);                                          moveto(SCREEN_ROWS, 0);
936                                          clrtoeol();                                          clrtoeol();
937                                          prints("\033[S"); // Scroll up 1 line                                          prints("\033[S"); // Scroll up 1 line
938                                          break;                                          break;
939                                  case KEY_PGUP:                                  case KEY_PGUP:
940                                          if (line_current - screen_current_line < 0) // Reach begin                                          if (line_current - output_current_row < 0) // Reach begin
941                                          {                                          {
942                                                  break;                                                  break;
943                                          }                                          }
944                                          line_current -= ((screen_line_total - 1) + (screen_current_line - screen_begin_line));                                          line_current -= ((screen_row_total - 1) + (output_current_row - screen_begin_row));
945                                          if (line_current < 0)                                          if (line_current < 0)
946                                          {                                          {
947                                                  line_current = 0;                                                  line_current = 0;
948                                          }                                          }
949                                          screen_current_line = screen_begin_line;                                          output_current_row = screen_begin_row;
950                                          screen_end_line = SCREEN_ROWS - 1;                                          output_end_row = SCREEN_ROWS - 1;
951                                          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 - output_current_row + row_pos]));
952                                          clrline(screen_begin_line, SCREEN_ROWS);                                          clrline(output_current_row, SCREEN_ROWS);
953                                          break;                                          break;
954                                  case KEY_PGDN:                                  case KEY_PGDN:
955                                          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 - (output_current_row - screen_begin_row) >= p_editor_data->display_line_total) // Reach end
956                                          {                                          {
957                                                  break;                                                  break;
958                                          }                                          }
959                                          line_current += (screen_line_total - 1) - (screen_current_line - screen_begin_line);                                          line_current += (screen_row_total - 1) - (output_current_row - screen_begin_row);
960                                          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
961                                          {                                          {
962                                                  line_current = p_editor_data->display_line_total - screen_line_total;                                                  line_current = p_editor_data->display_line_total - screen_row_total;
963                                          }                                          }
964                                          screen_current_line = screen_begin_line;                                          output_current_row = screen_begin_row;
965                                          screen_end_line = SCREEN_ROWS - 1;                                          output_end_row = SCREEN_ROWS - 1;
966                                          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 - output_current_row + row_pos]));
967                                          clrline(screen_begin_line, SCREEN_ROWS);                                          clrline(output_current_row, SCREEN_ROWS);
                                         break;  
                                 case KEY_ESC:  
968                                          break;                                          break;
969                                  case KEY_F1:                                  case KEY_F1:
970                                          if (!show_help) // Not reentrant                                          if (!show_help) // Not reentrant
# Line 370  int editor_display(EDITOR_DATA *p_editor Line 977  int editor_display(EDITOR_DATA *p_editor
977                                          show_help = 1;                                          show_help = 1;
978                                  case KEY_F5:                                  case KEY_F5:
979                                          // Refresh after display help information                                          // Refresh after display help information
980                                          line_current -= (screen_current_line - screen_begin_line);                                          line_current -= (output_current_row - screen_begin_row);
981                                          screen_current_line = screen_begin_line;                                          output_current_row = screen_begin_row;
982                                          screen_end_line = SCREEN_ROWS - 1;                                          output_end_row = SCREEN_ROWS - 1;
983                                          clrline(screen_begin_line, SCREEN_ROWS);                                          clrline(output_current_row, SCREEN_ROWS);
984                                          break;                                          break;
985                                  case 0: // Refresh bottom line                                  case 0: // Refresh bottom line
986                                          break;                                          break;
# Line 383  int editor_display(EDITOR_DATA *p_editor Line 990  int editor_display(EDITOR_DATA *p_editor
990                                  }                                  }
991    
992                                  BBS_last_access_tm = time(0);                                  BBS_last_access_tm = time(0);
993    
994                                    if (input_ok)
995                                    {
996                                            break;
997                                    }
998                          }                          }
999    
1000                          continue;                          continue;
# Line 400  int editor_display(EDITOR_DATA *p_editor Line 1012  int editor_display(EDITOR_DATA *p_editor
1012                          len = 0;                          len = 0;
1013                  }                  }
1014    
1015                  memcpy(buffer, (const char *)p_editor_data->p_display_lines[line_current], (size_t)len);                  // memcpy(buffer, p_editor_data->p_display_lines[line_current], (size_t)len);
1016                  buffer[len] = '\0';                  // Replace '\033' with '*'
1017                    p_str = p_editor_data->p_display_lines[line_current];
1018                    for (i = 0, j = 0; i < len; i++)
1019                    {
1020                            if (p_str[i] == '\033')
1021                            {
1022                                    memcpy(buffer + j, EDITOR_ESC_DISPLAY_STR, sizeof(EDITOR_ESC_DISPLAY_STR) - 1);
1023                                    j += (int)(sizeof(EDITOR_ESC_DISPLAY_STR) - 1);
1024                            }
1025                            else
1026                            {
1027                                    buffer[j] = p_str[i];
1028                                    j++;
1029                            }
1030                    }
1031                    buffer[j] = '\0';
1032    
1033                  moveto(screen_current_line, 0);                  moveto(output_current_row, 0);
1034                  clrtoeol();                  clrtoeol();
1035                  prints("%s", buffer);                  prints("%s", buffer);
1036                  line_current++;                  line_current++;
1037                  screen_current_line++;                  output_current_row++;
1038          }          }
1039    
1040  cleanup:  cleanup:


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

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