/[LeafOK_CVS]/lbbs/src/screen.c
ViewVC logotype

Diff of /lbbs/src/screen.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.95 by sysadm, Thu Jun 12 03:14:23 2025 UTC Revision 1.124 by sysadm, Wed Nov 5 02:33:30 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /* SPDX-License-Identifier: GPL-3.0-or-later */
2                                                    screen.c  -  description  /*
3                                                           -------------------   * screen
4          Copyright            : (C) 2004-2025 by Leaflet   *   - advanced telnet-based user interactive input / output features
5          Email                : leaflet@leafok.com   *
6   ***************************************************************************/   * Copyright (C) 2004-2025  Leaflet <leaflet@leafok.com>
7     */
 /***************************************************************************  
  *                                                                         *  
  *   This program is free software; you can redistribute it and/or modify  *  
  *   it under the terms of the GNU General Public License as published by  *  
  *   the Free Software Foundation; either version 3 of the License, or     *  
  *   (at your option) any later version.                                   *  
  *                                                                         *  
  ***************************************************************************/  
8    
 #include "screen.h"  
9  #include "bbs.h"  #include "bbs.h"
10  #include "common.h"  #include "common.h"
 #include "str_process.h"  
 #include "log.h"  
 #include "io.h"  
11  #include "editor.h"  #include "editor.h"
12  #include "file_loader.h"  #include "file_loader.h"
13  #include <fcntl.h>  #include "io.h"
14    #include "log.h"
15    #include "login.h"
16    #include "screen.h"
17    #include "str_process.h"
18  #include <ctype.h>  #include <ctype.h>
 #include <unistd.h>  
 #include <stdlib.h>  
19  #include <errno.h>  #include <errno.h>
20  #include <sys/types.h>  #include <fcntl.h>
21  #include <sys/stat.h>  #include <string.h>
22    #include <stdlib.h>
23    #include <unistd.h>
24  #include <sys/param.h>  #include <sys/param.h>
25    #include <sys/stat.h>
26  #include <sys/shm.h>  #include <sys/shm.h>
27    #include <sys/types.h>
28    
29  #define _POSIX_C_SOURCE 200809L  const char CTRL_SEQ_CLR_LINE[] = "\033[K";
30  #include <string.h>  
31    static const int ACTIVE_BOARD_HEIGHT = 8;
32    
33  #define ACTIVE_BOARD_HEIGHT 8  static const int STR_TOP_LEFT_MAX_LEN = 80;
34    static const int STR_TOP_MIDDLE_MAX_LEN = 40;
35    static const int STR_TOP_RIGHT_MAX_LEN = 80;
36    
37    static size_t get_time_str(char *s, size_t len)
38    {
39            time_t curtime;
40            struct tm local_tm;
41    
42  #define STR_TOP_LEFT_MAX_LEN 40          time(&curtime);
43  #define STR_TOP_MIDDLE_MAX_LEN 20          localtime_r(&curtime, &local_tm);
44  #define STR_TOP_RIGHT_MAX_LEN 20          size_t j = strftime(s, len, "%m/%d %H:%M %Z", &local_tm);
45    
46            return j;
47    }
48    
49  void moveto(int row, int col)  void moveto(int row, int col)
50  {  {
# Line 82  void clearscr() Line 87  void clearscr()
87          moveto(0, 0);          moveto(0, 0);
88  }  }
89    
90  int press_any_key()  inline int press_any_key()
91  {  {
92            return press_any_key_ex("                           \033[1;33m按任意键继续...\033[m", 60);
93    }
94    
95    int press_any_key_ex(const char *msg, int sec)
96    {
97            int ch = 0;
98            int duration = 0;
99            time_t t_begin = time(NULL);
100    
101          moveto(SCREEN_ROWS, 0);          moveto(SCREEN_ROWS, 0);
102          clrtoeol();          clrtoeol();
103    
104          prints("                           \033[1;33m...\033[0;37m");          prints(msg);
105          iflush();          iflush();
106    
107          return igetch_t(MIN(MAX_DELAY_TIME, 60));          igetch_reset();
108    
109            do
110            {
111                    ch = igetch_t(sec - duration);
112                    duration = (int)(time(NULL) - t_begin);
113            } while (!SYS_server_exit && ch == 0 && duration < 60);
114    
115            return ch;
116  }  }
117    
118  void set_input_echo(int echo)  void set_input_echo(int echo)
# Line 98  void set_input_echo(int echo) Line 120  void set_input_echo(int echo)
120          if (echo)          if (echo)
121          {          {
122                  outc('\x83'); // ASCII code 131                  outc('\x83'); // ASCII code 131
                 iflush();  
123          }          }
124          else          else
125          {          {
126                  //    outc ('\x85'); // ASCII code 133                  // outc ('\x85'); // ASCII code 133
127                  prints("\xff\xfb\x01\xff\xfb\x03");                  prints("\xff\xfb\x01\xff\xfb\x03");
                 iflush();  
                 igetch(0);  
                 igetch_reset();  
128          }          }
129            iflush();
130  }  }
131    
132  static int _str_input(char *buffer, int buf_size, int echo_mode)  static int _str_input(char *buffer, int buf_size, int max_display_len, enum io_echo_t echo_mode)
133  {  {
134          int c;          int ch;
135          int offset = 0;          int offset = 0;
136          int hz = 0;          int eol;
137            int display_len;
138            char input_str[4];
139            int str_len = 0;
140            char c;
141    
142          buffer[buf_size - 1] = '\0';          buffer[buf_size - 1] = '\0';
143          for (offset = 0; offset < buf_size - 1 && buffer[offset] != '\0'; offset++)          offset = split_line(buffer, max_display_len, &eol, &display_len, 0);
                 ;  
144    
145          igetch_reset();          igetch_reset();
146    
147          while (!SYS_server_exit)          while (!SYS_server_exit)
148          {          {
149                  c = igetch_t(MIN(MAX_DELAY_TIME, 60));                  ch = igetch_t(MIN(BBS_max_user_idle_time, 60));
150    
151                  if (c == CR)                  if (ch == CR)
152                  {                  {
                         igetch_reset();  
153                          break;                          break;
154                  }                  }
155                  else if (c == KEY_TIMEOUT || c == KEY_NULL) // timeout or broken pipe                  else if (ch == KEY_TIMEOUT || ch == KEY_NULL) // timeout or broken pipe
156                  {                  {
157                          return -1;                          return -1;
158                  }                  }
159                  else if (c == LF || c == '\0')                  else if (ch == LF || ch == '\0')
160                  {                  {
161                          continue;                          continue;
162                  }                  }
163                  else if (c == BACKSPACE)                  else if (ch == BACKSPACE)
164                  {                  {
165                          if (offset > 0)                          if (offset > 0)
166                          {                          {
167                                  offset--;                                  offset--;
168                                  if (buffer[offset] < 0 || buffer[offset] > 127)                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8
169                                  {                                  {
170                                          prints("\033[D \033[D");                                          while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0)
                                         offset--;  
                                         if (offset < 0) // should not happen  
171                                          {                                          {
172                                                  log_error("Offset of buffer is negative\n");                                                  offset--;
                                                 offset = 0;  
173                                          }                                          }
174                                            display_len--;
175                                            prints("\033[D \033[D");
176                                  }                                  }
177                                  buffer[offset] = '\0';                                  buffer[offset] = '\0';
178                                    display_len--;
179                                  prints("\033[D \033[D");                                  prints("\033[D \033[D");
180                                  iflush();                                  iflush();
181                          }                          }
182                          continue;                          continue;
183                  }                  }
184                  else if (c > 255 || iscntrl(c))                  else if (ch > 255 || iscntrl(ch))
185                  {                  {
186                          continue;                          continue;
187                  }                  }
188                  else if (c > 127 && c <= 255)                  else if ((ch & 0xff80) == 0x80) // head of multi-byte character
189                  {                  {
190                          if (!hz && offset + 2 > buf_size - 1) // No enough space for Chinese character                          str_len = 0;
191                            c = (char)(ch & 0xf0);
192                            while (c & 0x80)
193                            {
194                                    input_str[str_len] = (char)(ch - 256);
195                                    str_len++;
196                                    c = (c & 0x7f) << 1;
197    
198                                    if ((c & 0x80) == 0) // Input completed
199                                    {
200                                            break;
201                                    }
202    
203                                    // Expect additional bytes of input
204                                    ch = igetch(100);                                                // 0.1 second
205                                    if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Ignore received bytes if no futher input
206                                    {
207    #ifdef _DEBUG
208                                            log_error("Ignore %d bytes of incomplete UTF8 character\n", str_len);
209    #endif
210                                            str_len = 0;
211                                            break;
212                                    }
213                            }
214    
215                            if (str_len == 0) // Incomplete input
216                            {
217                                    continue;
218                            }
219    
220                            if (offset + str_len > buf_size - 1 || display_len + 2 > max_display_len) // No enough space for Chinese character
221                          {                          {
                                 igetch(0); // Ignore 1 character  
222                                  outc('\a');                                  outc('\a');
223                                  iflush();                                  iflush();
224                                  continue;                                  continue;
225                          }                          }
                         hz = (!hz);  
                 }  
226    
227                  if (offset + 1 > buf_size - 1)                          memcpy(buffer + offset, input_str, (size_t)str_len);
228                  {                          offset += str_len;
229                          outc('\a');                          buffer[offset] = '\0';
230                          iflush();                          display_len += 2;
231                          continue;  
232                            switch (echo_mode)
233                            {
234                            case DOECHO:
235                                    prints(input_str);
236                                    break;
237                            case NOECHO:
238                                    prints("**");
239                                    break;
240                            }
241                  }                  }
242                    else if (ch >= 32 && ch < 127) // Printable character
243                    {
244                            if (offset + 1 > buf_size - 1 || display_len + 1 > max_display_len)
245                            {
246                                    outc('\a');
247                                    iflush();
248                                    continue;
249                            }
250    
251                  buffer[offset++] = (char)c;                          buffer[offset++] = (char)ch;
252                  buffer[offset] = '\0';                          buffer[offset] = '\0';
253                            display_len++;
254    
255                  switch (echo_mode)                          switch (echo_mode)
256                  {                          {
257                  case DOECHO:                          case DOECHO:
258                          outc((char)c);                                  outc((char)ch);
259                          break;                                  break;
260                  case NOECHO:                          case NOECHO:
261                          outc('*');                                  outc('*');
262                          break;                                  break;
263                            }
264                  }                  }
265                  if (!hz)                  else // Invalid character
266                  {                  {
267                          iflush();                          continue;
268                  }                  }
269    
270                    iflush();
271          }          }
272    
273          return offset;          return offset;
274  }  }
275    
276  int str_input(char *buffer, int buf_size, int echo_mode)  int str_input(char *buffer, int buf_size, enum io_echo_t echo_mode)
277  {  {
278          int len;          int len;
279    
280          buffer[0] = '\0';          buffer[0] = '\0';
281    
282          len = _str_input(buffer, buf_size, echo_mode);          len = _str_input(buffer, buf_size, buf_size, echo_mode);
283    
284          prints("\r\n");          prints("\r\n");
285          iflush();          iflush();
286    
287          return len;          return len;
288  };  }
289    
290  int get_data(int row, int col, char *prompt, char *buffer, int buf_size, int echo_mode)  int get_data(int row, int col, char *prompt, char *buffer, int buf_size, int max_display_len)
291  {  {
292          int len;          int len = 0;
293            int col_cur = 0;
294            int ch;
295            int offset = 0;
296            int eol;
297            int display_len;
298            char input_str[4];
299            int str_len = 0;
300            char c;
301    
302            buffer[buf_size - 1] = '\0';
303            offset = split_line(buffer, max_display_len, &eol, &display_len, 0);
304            buffer[offset] = '\0';
305            len = offset;
306            col_cur = col + str_length(prompt, 1) + display_len;
307    
308          moveto(row, col);          moveto(row, col);
309          prints("%s", prompt);          prints("%s", prompt);
310          prints("%s", buffer);          prints("%s", buffer);
311            prints("%*s", max_display_len - display_len, "");
312            moveto(row, col_cur);
313          iflush();          iflush();
314    
315          len = _str_input(buffer, buf_size, echo_mode);          igetch_reset();
316    
317            while (!SYS_server_exit)
318            {
319                    ch = igetch_t(MIN(BBS_max_user_idle_time, 60));
320    
321                    if (ch == CR)
322                    {
323                            break;
324                    }
325                    else if (ch == KEY_TIMEOUT || ch == KEY_NULL) // timeout or broken pipe
326                    {
327                            return -1;
328                    }
329                    else if (ch == LF || ch == '\0')
330                    {
331                            continue;
332                    }
333                    else if (ch == BACKSPACE)
334                    {
335                            if (offset > 0)
336                            {
337                                    str_len = 1;
338                                    offset--;
339                                    if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8
340                                    {
341                                            while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0)
342                                            {
343                                                    str_len++;
344                                                    offset--;
345                                            }
346                                            display_len--;
347                                            col_cur--;
348                                    }
349    
350                                    memmove(buffer + offset, buffer + offset + str_len, (size_t)(len - offset - str_len));
351                                    len -= str_len;
352                                    buffer[len] = '\0';
353                                    display_len--;
354                                    col_cur--;
355    
356                                    moveto(row, col_cur);
357                                    prints("%s", buffer + offset);
358                                    prints("%*s", max_display_len - display_len, "");
359                                    moveto(row, col_cur);
360                                    iflush();
361                            }
362                            continue;
363                    }
364                    else if (ch == KEY_DEL)
365                    {
366                            if (offset < len)
367                            {
368                                    if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character
369                                    {
370                                            str_len = 0;
371                                            c = (char)(buffer[offset] & 0xf0);
372                                            while (c & 0x80)
373                                            {
374                                                    str_len++;
375                                                    c = (c & 0x7f) << 1;
376                                            }
377                                            display_len--;
378                                    }
379                                    else
380                                    {
381                                            str_len = 1;
382                                    }
383    
384                                    memmove(buffer + offset, buffer + offset + str_len, (size_t)(len - offset - str_len));
385                                    len -= str_len;
386                                    buffer[len] = '\0';
387                                    display_len--;
388    
389                                    moveto(row, col_cur);
390                                    prints("%s", buffer + offset);
391                                    prints("%*s", max_display_len - display_len, "");
392                                    moveto(row, col_cur);
393                                    iflush();
394                            }
395                            continue;
396                    }
397                    else if (ch == KEY_LEFT)
398                    {
399                            if (offset > 0)
400                            {
401                                    str_len = 1;
402                                    offset--;
403                                    if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8
404                                    {
405                                            while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0)
406                                            {
407                                                    str_len++;
408                                                    offset--;
409                                            }
410                                            col_cur--;
411                                    }
412                                    col_cur--;
413    
414                                    moveto(row, col_cur);
415                                    iflush();
416                            }
417                            continue;
418                    }
419                    else if (ch == KEY_RIGHT)
420                    {
421                            if (offset < len)
422                            {
423                                    str_len = 0;
424                                    if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character
425                                    {
426                                            c = (char)(buffer[offset] & 0xf0);
427                                            while (c & 0x80)
428                                            {
429                                                    str_len++;
430                                                    c = (c & 0x7f) << 1;
431                                            }
432                                            col_cur++;
433                                    }
434                                    else
435                                    {
436                                            str_len = 1;
437                                    }
438    
439                                    col_cur++;
440                                    offset += str_len;
441    
442                                    moveto(row, col_cur);
443                                    iflush();
444                            }
445                            continue;
446                    }
447                    else if (ch == KEY_HOME || ch == KEY_UP)
448                    {
449                            if (offset > 0)
450                            {
451                                    offset = 0;
452                                    col_cur = col + str_length(prompt, 1);
453    
454                                    moveto(row, col_cur);
455                                    iflush();
456                            }
457                            continue;
458                    }
459                    else if (ch == KEY_END || ch == KEY_DOWN)
460                    {
461                            if (offset < len)
462                            {
463                                    offset = len;
464                                    col_cur = col + str_length(prompt, 1) + display_len;
465    
466                                    moveto(row, col_cur);
467                                    iflush();
468                            }
469                            continue;
470                    }
471                    else if (ch > 255 || iscntrl(ch))
472                    {
473                            continue;
474                    }
475                    else if ((ch & 0xff80) == 0x80) // head of multi-byte character
476                    {
477                            str_len = 0;
478                            c = (char)(ch & 0xf0);
479                            while (c & 0x80)
480                            {
481                                    input_str[str_len] = (char)(ch - 256);
482                                    str_len++;
483                                    c = (c & 0x7f) << 1;
484    
485                                    if ((c & 0x80) == 0) // Input completed
486                                    {
487                                            break;
488                                    }
489    
490                                    // Expect additional bytes of input
491                                    ch = igetch(100);                                                // 0.1 second
492                                    if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Ignore received bytes if no futher input
493                                    {
494    #ifdef _DEBUG
495                                            log_error("Ignore %d bytes of incomplete UTF8 character\n", str_len);
496    #endif
497                                            str_len = 0;
498                                            break;
499                                    }
500                            }
501    
502                            if (str_len == 0) // Incomplete input
503                            {
504                                    continue;
505                            }
506    
507                            if (len + str_len > buf_size - 1 || display_len + 2 > max_display_len) // No enough space for Chinese character
508                            {
509                                    outc('\a');
510                                    iflush();
511                                    continue;
512                            }
513    
514                            memmove(buffer + offset + str_len, buffer + offset, (size_t)(len - offset));
515                            memcpy(buffer + offset, input_str, (size_t)str_len);
516                            len += str_len;
517                            buffer[len] = '\0';
518                            display_len += 2;
519    
520                            moveto(row, col_cur);
521                            prints("%s", buffer + offset);
522                            prints("%*s", max_display_len - display_len, "");
523    
524                            col_cur += 2;
525    
526                            moveto(row, col_cur);
527                            iflush();
528    
529                            offset += str_len;
530                    }
531                    else if (ch >= 32 && ch < 127) // Printable character
532                    {
533                            if (len + 1 > buf_size - 1 || display_len + 1 > max_display_len)
534                            {
535                                    outc('\a');
536                                    iflush();
537                                    continue;
538                            }
539    
540                            memmove(buffer + offset + 1, buffer + offset, (size_t)(len - offset));
541                            buffer[offset] = (char)ch;
542                            len++;
543                            buffer[len] = '\0';
544                            display_len++;
545    
546                            moveto(row, col_cur);
547                            prints("%s", buffer + offset);
548                            prints("%*s", max_display_len - display_len, "");
549    
550                            col_cur++;
551    
552                            moveto(row, col_cur);
553                            iflush();
554    
555                            offset++;
556                    }
557                    else // Invalid character
558                    {
559                            continue;
560                    }
561            }
562    
563          return len;          return len;
564  }  }
# Line 295  int display_data(const void *p_data, lon Line 626  int display_data(const void *p_data, lon
626                          ctx.line_bottom = MIN(line_current - (output_current_row - screen_begin_row) + screen_row_total, display_line_total);                          ctx.line_bottom = MIN(line_current - (output_current_row - screen_begin_row) + screen_row_total, display_line_total);
627    
628                          snprintf(buffer, sizeof(buffer),                          snprintf(buffer, sizeof(buffer),
629                                           "\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行 (\033[32m%ld%%\033[33m) %s",
630                                           ctx.line_top,                                           ctx.line_top,
631                                           ctx.line_bottom,                                           ctx.line_bottom,
632                                           percentile,                                           percentile,
633                                           ctx.msg);                                           ctx.msg);
634    
635                          len = split_line(buffer, SCREEN_COLS, &eol, &display_len);                          len = split_line(buffer, SCREEN_COLS, &eol, &display_len, 1);
636                          for (; display_len < SCREEN_COLS; display_len++)                          for (; display_len < SCREEN_COLS; display_len++)
637                          {                          {
638                                  buffer[len++] = ' ';                                  buffer[len++] = ' ';
# Line 316  int display_data(const void *p_data, lon Line 647  int display_data(const void *p_data, lon
647                          input_ok = 0;                          input_ok = 0;
648                          while (!SYS_server_exit && !input_ok)                          while (!SYS_server_exit && !input_ok)
649                          {                          {
650                                  ch = igetch_t(MAX_DELAY_TIME);                                  ch = igetch_t(BBS_max_user_idle_time);
651                                  input_ok = 1;                                  input_ok = 1;
652    
653                                    if (ch != KEY_NULL && ch != KEY_TIMEOUT)
654                                    {
655                                            BBS_last_access_tm = time(NULL);
656                                    }
657    
658                                  // extended key handler                                  // extended key handler
659                                  if (key_handler(&ch, &ctx) != 0)                                  if (key_handler(&ch, &ctx) != 0)
660                                  {                                  {
# Line 328  int display_data(const void *p_data, lon Line 664  int display_data(const void *p_data, lon
664                                  switch (ch)                                  switch (ch)
665                                  {                                  {
666                                  case KEY_NULL:                                  case KEY_NULL:
667                                            log_error("KEY_NULL\n");
668                                            goto cleanup;
669                                  case KEY_TIMEOUT:                                  case KEY_TIMEOUT:
670                                            log_error("User input timeout\n");
671                                          goto cleanup;                                          goto cleanup;
672                                  case KEY_HOME:                                  case KEY_HOME:
673                                          if (line_current - output_current_row < 0) // Reach begin                                          if (line_current - output_current_row < 0) // Reach begin
# Line 362  int display_data(const void *p_data, lon Line 701  int display_data(const void *p_data, lon
701                                          output_end_row = SCREEN_ROWS - 1; // Legacy Fterm only works with this line                                          output_end_row = SCREEN_ROWS - 1; // Legacy Fterm only works with this line
702                                          break;                                          break;
703                                  case CR:                                  case CR:
                                         igetch_reset();  
                                 case KEY_SPACE:  
704                                  case KEY_DOWN:                                  case KEY_DOWN:
705                                          if (line_current + (screen_row_total - (output_current_row - screen_begin_row)) >= display_line_total) // Reach end                                          if (line_current + (screen_row_total - (output_current_row - screen_begin_row)) >= display_line_total) // Reach end
706                                          {                                          {
# Line 374  int display_data(const void *p_data, lon Line 711  int display_data(const void *p_data, lon
711                                          output_end_row = SCREEN_ROWS - 1;                                          output_end_row = SCREEN_ROWS - 1;
712                                          moveto(SCREEN_ROWS, 0);                                          moveto(SCREEN_ROWS, 0);
713                                          clrtoeol();                                          clrtoeol();
714                                          prints("\033[S"); // Scroll up 1 line                                          // prints("\033[S"); // Scroll up 1 line
715                                            prints("\n"); // Legacy Cterm only works with this line
716                                          break;                                          break;
717                                  case KEY_PGUP:                                  case KEY_PGUP:
718                                          if (line_current - output_current_row < 0) // Reach begin                                          if (line_current - output_current_row < 0) // Reach begin
# Line 390  int display_data(const void *p_data, lon Line 728  int display_data(const void *p_data, lon
728                                          output_end_row = SCREEN_ROWS - 1;                                          output_end_row = SCREEN_ROWS - 1;
729                                          clrline(output_current_row, SCREEN_ROWS);                                          clrline(output_current_row, SCREEN_ROWS);
730                                          break;                                          break;
731                                    case KEY_SPACE:
732                                  case KEY_PGDN:                                  case KEY_PGDN:
733                                          if (line_current + screen_row_total - (output_current_row - screen_begin_row) >= display_line_total) // Reach end                                          if (line_current + screen_row_total - (output_current_row - screen_begin_row) >= display_line_total) // Reach end
734                                          {                                          {
# Line 424  int display_data(const void *p_data, lon Line 763  int display_data(const void *p_data, lon
763                                          output_end_row = SCREEN_ROWS - 1;                                          output_end_row = SCREEN_ROWS - 1;
764                                          clrline(output_current_row, SCREEN_ROWS);                                          clrline(output_current_row, SCREEN_ROWS);
765                                          break;                                          break;
                                 case KEY_F2: // For test only  
                                         EDITOR_DATA *p_editor_data;  
                                         size_t data_new_len = strlen(p_data) + LINE_BUFFER_LEN;  
   
                                         char *p_data_new = malloc(data_new_len);  
                                         if (p_data_new == NULL)  
                                         {  
                                                 break;  
                                         }  
                                         p_editor_data = editor_data_load(p_data);  
                                         if (p_editor_data == NULL)  
                                         {  
                                                 free(p_data_new);  
                                                 break;  
                                         }  
   
                                         editor_display(p_editor_data);  
                                         editor_data_save(p_editor_data, p_data_new, data_new_len);  
                                         editor_data_cleanup(p_editor_data);  
                                         p_editor_data = NULL;  
                                         free(p_data_new);  
                                         p_data_new = NULL;  
   
                                         // Refresh after display editor  
                                         line_current -= (output_current_row - screen_begin_row);  
                                         output_current_row = screen_begin_row;  
                                         output_end_row = SCREEN_ROWS - 1;  
                                         clrline(output_current_row, SCREEN_ROWS);  
                                         break;  
766                                  case 0: // Refresh bottom line                                  case 0: // Refresh bottom line
767                                          break;                                          break;
768                                  default:                                  default:
769                                          input_ok = 0;                                          input_ok = 0;
770                                          break;                                          break;
771                                  }                                  }
   
                                 BBS_last_access_tm = time(0);  
772                          }                          }
773    
774                          continue;                          continue;
# Line 500  static int display_file_key_handler(int Line 808  static int display_file_key_handler(int
808          {          {
809          case 0: // Set msg          case 0: // Set msg
810                  snprintf(p_ctx->msg, sizeof(p_ctx->msg),                  snprintf(p_ctx->msg, sizeof(p_ctx->msg),
811                                   "| [\033[32m\033[33m,\033[32mESC\033[33m] | "                                   "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] | "
812                                   "ƶ[\033[32m\033[33m/\033[32m\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] | "                                   "移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] | "
813                                   "[\033[32mh\033[33m] |");                                   "帮助[\033[32mh\033[33m] |");
814                  break;                  break;
815          }          }
816    
# Line 524  int display_file(const char *filename, i Line 832  int display_file(const char *filename, i
832                  return KEY_NULL;                  return KEY_NULL;
833          }          }
834    
835            if (user_online_update("VIEW_FILE") < 0)
836            {
837                    log_error("user_online_update(VIEW_FILE) error\n");
838            }
839    
840          ret = display_data(p_data, line_total, p_line_offsets, eof_exit, display_file_key_handler, DATA_READ_HELP);          ret = display_data(p_data, line_total, p_line_offsets, eof_exit, display_file_key_handler, DATA_READ_HELP);
841    
842          if (detach_file_shm(p_shm) < 0)          if (detach_file_shm(p_shm) < 0)
# Line 547  int show_top(const char *str_left, const Line 860  int show_top(const char *str_left, const
860    
861          strncpy(str_left_f, str_left, sizeof(str_left_f) - 1);          strncpy(str_left_f, str_left, sizeof(str_left_f) - 1);
862          str_left_f[sizeof(str_left_f) - 1] = '\0';          str_left_f[sizeof(str_left_f) - 1] = '\0';
863          len = split_line(str_left_f, STR_TOP_LEFT_MAX_LEN, &eol, &str_left_len);          len = split_line(str_left_f, STR_TOP_LEFT_MAX_LEN / 2, &eol, &str_left_len, 1);
864          str_left_f[len] = '\0';          str_left_f[len] = '\0';
865    
866          strncpy(str_middle_f, str_middle, sizeof(str_middle_f) - 1);          strncpy(str_middle_f, str_middle, sizeof(str_middle_f) - 1);
867          str_middle_f[sizeof(str_middle_f) - 1] = '\0';          str_middle_f[sizeof(str_middle_f) - 1] = '\0';
868          len = split_line(str_middle, STR_TOP_MIDDLE_MAX_LEN, &eol, &str_middle_len);          len = split_line(str_middle, STR_TOP_MIDDLE_MAX_LEN / 2, &eol, &str_middle_len, 1);
869          str_middle_f[len] = '\0';          str_middle_f[len] = '\0';
870    
871          strncpy(str_right_f, str_right, sizeof(str_right_f) - 1);          strncpy(str_right_f, str_right, sizeof(str_right_f) - 1);
872          str_right_f[sizeof(str_right_f) - 1] = '\0';          str_right_f[sizeof(str_right_f) - 1] = '\0';
873          len = split_line(str_right, STR_TOP_RIGHT_MAX_LEN, &eol, &str_right_len);          len = split_line(str_right, STR_TOP_RIGHT_MAX_LEN / 2, &eol, &str_right_len, 1);
874          str_right_f[len] = '\0';          str_right_f[len] = '\0';
875    
876          moveto(1, 0);          moveto(1, 0);
877          clrtoeol();          clrtoeol();
878          prints("\033[1;44;33m%s\033[37m%*s\033[33m%*s\033[m",          prints("\033[1;44;33m%s\033[37m%*s%s\033[33m%*s%s\033[m",
879                     str_left_f, 44 - str_left_len, str_middle_f, 36, str_right_f);                     str_left_f, 44 - str_left_len - str_middle_len, "",
880                       str_middle_f, 36 - str_right_len, "", str_right_f);
881    
882          return 0;          return 0;
883  }  }
# Line 571  int show_top(const char *str_left, const Line 885  int show_top(const char *str_left, const
885  int show_bottom(const char *msg)  int show_bottom(const char *msg)
886  {  {
887          char str_time[LINE_BUFFER_LEN];          char str_time[LINE_BUFFER_LEN];
888            int len_str_time;
889          time_t time_online;          time_t time_online;
890          struct tm *tm_online;          struct tm *tm_online;
891          char msg_f[LINE_BUFFER_LEN];          char msg_f[LINE_BUFFER_LEN];
892          int eol;          int eol;
893          int msg_len;          int len_msg;
894          int len;          int len;
895          int len_username;          int len_username;
896          char str_tm_online[LINE_BUFFER_LEN];          char str_tm_online[LINE_BUFFER_LEN];
897    
898          get_time_str(str_time, sizeof(str_time));          len_str_time = (int)get_time_str(str_time, sizeof(str_time));
899    
900          msg_f[0] = '\0';          msg_f[0] = '\0';
901          msg_len = 0;          len_msg = 0;
902          if (msg != NULL)          if (msg != NULL)
903          {          {
904                  strncpy(msg_f, msg, sizeof(msg_f) - 1);                  strncpy(msg_f, msg, sizeof(msg_f) - 1);
905                  msg_f[sizeof(msg_f) - 1] = '\0';                  msg_f[sizeof(msg_f) - 1] = '\0';
906                  len = split_line(msg_f, 23, &eol, &msg_len);                  len = split_line(msg_f, 23, &eol, &len_msg, 1);
907                  msg_f[len] = '\0';                  msg_f[len] = '\0';
908          }          }
909    
910          len_username = (int)strnlen(BBS_username, sizeof(BBS_username));          len_username = (int)strnlen(BBS_username, sizeof(BBS_username));
911    
912          time_online = time(0) - BBS_login_tm;          time_online = time(NULL) - BBS_login_tm;
913          tm_online = gmtime(&time_online);          tm_online = gmtime(&time_online);
914          if (tm_online->tm_mday > 1)          if (tm_online->tm_mday > 1)
915          {          {
916                  snprintf(str_tm_online, sizeof(str_tm_online),                  snprintf(str_tm_online, sizeof(str_tm_online),
917                                   "\033[36m%2d\033[33m\033[36m%2d\033[33mʱ",                                   "\033[36m%d\033[33md \033[36m%d\033[33m:\033[36m%.2d",
918                                   tm_online->tm_mday - 1, tm_online->tm_hour);                                   tm_online->tm_mday - 1, tm_online->tm_hour, tm_online->tm_min);
919          }          }
920          else          else
921          {          {
922                  snprintf(str_tm_online, sizeof(str_tm_online),                  snprintf(str_tm_online, sizeof(str_tm_online),
923                                   "\033[36m%2d\033[33mʱ\033[36m%2d\033[33m",                                   "\033[36m%d\033[33m:\033[36m%.2d",
924                                   tm_online->tm_hour, tm_online->tm_min);                                   tm_online->tm_hour, tm_online->tm_min);
925          }          }
926    
927          moveto(SCREEN_ROWS, 0);          moveto(SCREEN_ROWS, 0);
928          clrtoeol();          clrtoeol();
929          prints("\033[1;44;33mʱ[\033[36m%s\033[33m]%s%*s \033[33mʺ[\033[36m%s\033[33m][%s\033[33m]\033[m",          prints("\033[1;44;33m时间[\033[36m%s\033[33m]%s%*s \033[33m用户[\033[36m%s\033[33m][%s\033[33m]\033[m",
930                     str_time, msg_f, 38 - msg_len - len_username, "", BBS_username, str_tm_online);                     str_time, msg_f, 61 - len_str_time - len_msg - len_username, "", BBS_username, str_tm_online);
931    
932          return 0;          return 0;
933  }  }
# Line 641  int show_active_board() Line 956  int show_active_board()
956                  }                  }
957          }          }
958    
959          if (time(0) - t_last_show >= 10)          if (time(NULL) - t_last_show >= 10)
960          {          {
961                  line_last = line_current;                  line_last = line_current;
962                  t_last_show = time(0);                  t_last_show = time(NULL);
963          }          }
964          else          else
965          {          {


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

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