/[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.102 by sysadm, Sat Jun 21 02:15:18 2025 UTC Revision 1.127 by sysadm, Sat Nov 8 08:21:31 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    
9  #include "bbs.h"  #include "bbs.h"
10  #include "common.h"  #include "common.h"
# Line 29  Line 21 
21  #include <string.h>  #include <string.h>
22  #include <stdlib.h>  #include <stdlib.h>
23  #include <unistd.h>  #include <unistd.h>
24    #include <wchar.h>
25  #include <sys/param.h>  #include <sys/param.h>
26  #include <sys/stat.h>  #include <sys/stat.h>
27  #include <sys/shm.h>  #include <sys/shm.h>
28  #include <sys/types.h>  #include <sys/types.h>
29    
30  #define ACTIVE_BOARD_HEIGHT 8  const char CTRL_SEQ_CLR_LINE[] = "\033[K";
31    
32  #define STR_TOP_LEFT_MAX_LEN 40  static const int ACTIVE_BOARD_HEIGHT = 8;
33  #define STR_TOP_MIDDLE_MAX_LEN 20  
34  #define STR_TOP_RIGHT_MAX_LEN 20  static const int STR_TOP_LEFT_MAX_LEN = 80;
35    static const int STR_TOP_MIDDLE_MAX_LEN = 40;
36    static const int STR_TOP_RIGHT_MAX_LEN = 80;
37    
38    static size_t get_time_str(char *s, size_t len)
39    {
40            time_t curtime;
41            struct tm local_tm;
42    
43            time(&curtime);
44            localtime_r(&curtime, &local_tm);
45            size_t j = strftime(s, len, "%m/%d %H:%M %Z", &local_tm);
46    
47            return j;
48    }
49    
50  void moveto(int row, int col)  void moveto(int row, int col)
51  {  {
# Line 81  void clearscr() Line 88  void clearscr()
88          moveto(0, 0);          moveto(0, 0);
89  }  }
90    
91  int press_any_key()  inline int press_any_key()
92  {  {
93            return press_any_key_ex("                           \033[1;33m按任意键继续...\033[m", 60);
94    }
95    
96    int press_any_key_ex(const char *msg, int sec)
97    {
98            int ch = 0;
99            int duration = 0;
100            time_t t_begin = time(NULL);
101    
102          moveto(SCREEN_ROWS, 0);          moveto(SCREEN_ROWS, 0);
103          clrtoeol();          clrtoeol();
104    
105          prints("                           \033[1;33m...\033[0;37m");          prints(msg);
106          iflush();          iflush();
107    
108          return igetch_t(MIN(MAX_DELAY_TIME, 60));          igetch_reset();
109    
110            do
111            {
112                    ch = igetch_t(sec - duration);
113                    duration = (int)(time(NULL) - t_begin);
114            } while (!SYS_server_exit && ch == 0 && duration < 60);
115    
116            return ch;
117  }  }
118    
119  void set_input_echo(int echo)  void set_input_echo(int echo)
# Line 97  void set_input_echo(int echo) Line 121  void set_input_echo(int echo)
121          if (echo)          if (echo)
122          {          {
123                  outc('\x83'); // ASCII code 131                  outc('\x83'); // ASCII code 131
                 iflush();  
124          }          }
125          else          else
126          {          {
127                  //    outc ('\x85'); // ASCII code 133                  // outc ('\x85'); // ASCII code 133
128                  prints("\xff\xfb\x01\xff\xfb\x03");                  prints("\xff\xfb\x01\xff\xfb\x03");
                 iflush();  
                 igetch(0);  
                 igetch_reset();  
129          }          }
130            iflush();
131  }  }
132    
133  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)
134  {  {
135          int c;          int ch;
136          int offset = 0;          int offset = 0;
137          int hz = 0;          int eol;
138            int display_len;
139            char input_str[5];
140            int str_len = 0;
141            wchar_t wcs[2];
142            char c;
143    
144          buffer[buf_size - 1] = '\0';          buffer[buf_size - 1] = '\0';
145          for (offset = 0; offset < buf_size - 1 && buffer[offset] != '\0'; offset++)          offset = split_line(buffer, max_display_len, &eol, &display_len, 0);
                 ;  
146    
147          igetch_reset();          igetch_reset();
148    
149          while (!SYS_server_exit)          while (!SYS_server_exit)
150          {          {
151                  c = igetch_t(MIN(MAX_DELAY_TIME, 60));                  ch = igetch_t(MIN(BBS_max_user_idle_time, 60));
152    
153                  if (c == CR)                  if (ch == CR)
154                  {                  {
                         igetch_reset();  
155                          break;                          break;
156                  }                  }
157                  else if (c == KEY_TIMEOUT || c == KEY_NULL) // timeout or broken pipe                  else if (ch == KEY_TIMEOUT || ch == KEY_NULL) // timeout or broken pipe
158                  {                  {
159                          return -1;                          return -1;
160                  }                  }
161                  else if (c == LF || c == '\0')                  else if (ch == LF || ch == '\0')
162                  {                  {
163                          continue;                          continue;
164                  }                  }
165                  else if (c == BACKSPACE)                  else if (ch == BACKSPACE)
166                  {                  {
167                          if (offset > 0)                          if (offset > 0)
168                          {                          {
169                                  offset--;                                  offset--;
170                                  if (buffer[offset] < 0 || buffer[offset] > 127)                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8
171                                  {                                  {
172                                          prints("\033[D \033[D");                                          while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0)
                                         offset--;  
                                         if (offset < 0) // should not happen  
173                                          {                                          {
174                                                  log_error("Offset of buffer is negative\n");                                                  offset--;
                                                 offset = 0;  
175                                          }                                          }
176                                            display_len--;
177                                            prints("\033[D \033[D");
178                                  }                                  }
179                                  buffer[offset] = '\0';                                  buffer[offset] = '\0';
180                                    display_len--;
181                                  prints("\033[D \033[D");                                  prints("\033[D \033[D");
182                                  iflush();                                  iflush();
183                          }                          }
184                          continue;                          continue;
185                  }                  }
186                  else if (c > 255 || iscntrl(c))                  else if (ch > 255 || iscntrl(ch))
187                  {                  {
188                          continue;                          continue;
189                  }                  }
190                  else if (c > 127 && c <= 255)                  else if ((ch & 0xff80) == 0x80) // head of multi-byte character
191                  {                  {
192                          if (!hz && offset + 2 > buf_size - 1) // No enough space for Chinese character                          str_len = 0;
193                            c = (char)(ch & 0xf0);
194                            while (c & 0x80)
195                            {
196                                    input_str[str_len] = (char)(ch - 256);
197                                    str_len++;
198                                    c = (c & 0x7f) << 1;
199    
200                                    if ((c & 0x80) == 0) // Input completed
201                                    {
202                                            break;
203                                    }
204    
205                                    // Expect additional bytes of input
206                                    ch = igetch(100);                                                // 0.1 second
207                                    if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Ignore received bytes if no futher input
208                                    {
209    #ifdef _DEBUG
210                                            log_error("Ignore %d bytes of incomplete UTF8 character\n", str_len);
211    #endif
212                                            str_len = 0;
213                                            break;
214                                    }
215                            }
216                            input_str[str_len] = '\0';
217    
218                            if (str_len == 0) // Incomplete input
219                            {
220                                    continue;
221                            }
222    
223                            if (mbstowcs(wcs, input_str, 1) == (size_t)-1)
224                            {
225                                    log_error("mbstowcs() error\n");
226                            }
227                            if (offset + str_len > buf_size - 1 || display_len + (UTF8_fixed_width ? 2 : wcwidth(wcs[0])) > max_display_len) // No enough space for Chinese character
228                          {                          {
                                 igetch(0); // Ignore 1 character  
229                                  outc('\a');                                  outc('\a');
230                                  iflush();                                  iflush();
231                                  continue;                                  continue;
232                          }                          }
                         hz = (!hz);  
                 }  
233    
234                  if (offset + 1 > buf_size - 1)                          memcpy(buffer + offset, input_str, (size_t)str_len);
235                  {                          offset += str_len;
236                          outc('\a');                          buffer[offset] = '\0';
237                          iflush();                          display_len += 2;
238                          continue;  
239                            switch (echo_mode)
240                            {
241                            case DOECHO:
242                                    prints(input_str);
243                                    break;
244                            case NOECHO:
245                                    prints("**");
246                                    break;
247                            }
248                  }                  }
249                    else if (ch >= 32 && ch < 127) // Printable character
250                    {
251                            if (offset + 1 > buf_size - 1 || display_len + 1 > max_display_len)
252                            {
253                                    outc('\a');
254                                    iflush();
255                                    continue;
256                            }
257    
258                  buffer[offset++] = (char)c;                          buffer[offset++] = (char)ch;
259                  buffer[offset] = '\0';                          buffer[offset] = '\0';
260                            display_len++;
261    
262                  switch (echo_mode)                          switch (echo_mode)
263                  {                          {
264                  case DOECHO:                          case DOECHO:
265                          outc((char)c);                                  outc((char)ch);
266                          break;                                  break;
267                  case NOECHO:                          case NOECHO:
268                          outc('*');                                  outc('*');
269                          break;                                  break;
270                            }
271                  }                  }
272                  if (!hz)                  else // Invalid character
273                  {                  {
274                          iflush();                          continue;
275                  }                  }
276    
277                    iflush();
278          }          }
279    
280          return offset;          return offset;
281  }  }
282    
283  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)
284  {  {
285          int len;          int len;
286    
287          buffer[0] = '\0';          buffer[0] = '\0';
288    
289          len = _str_input(buffer, buf_size, echo_mode);          len = _str_input(buffer, buf_size, buf_size, echo_mode);
290    
291          prints("\r\n");          prints("\r\n");
292          iflush();          iflush();
293    
294          return len;          return len;
295  };  }
296    
297  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)
298  {  {
299          int len;          int len = 0;
300            int col_cur = 0;
301            int ch;
302            int offset = 0;
303            int eol;
304            int display_len;
305            char input_str[5];
306            wchar_t wcs[2];
307            int str_len = 0;
308            char c;
309    
310            buffer[buf_size - 1] = '\0';
311            offset = split_line(buffer, max_display_len, &eol, &display_len, 0);
312            buffer[offset] = '\0';
313            len = offset;
314            col_cur = col + str_length(prompt, 1) + display_len;
315    
316          moveto(row, col);          moveto(row, col);
317          prints("%s", prompt);          prints("%s", prompt);
318          prints("%s", buffer);          prints("%s", buffer);
319            prints("%*s", max_display_len - display_len, "");
320            moveto(row, col_cur);
321          iflush();          iflush();
322    
323          len = _str_input(buffer, buf_size, echo_mode);          igetch_reset();
324    
325            while (!SYS_server_exit)
326            {
327                    ch = igetch_t(MIN(BBS_max_user_idle_time, 60));
328    
329                    if (ch == CR)
330                    {
331                            break;
332                    }
333                    else if (ch == KEY_TIMEOUT || ch == KEY_NULL) // timeout or broken pipe
334                    {
335                            return -1;
336                    }
337                    else if (ch == LF || ch == '\0')
338                    {
339                            continue;
340                    }
341                    else if (ch == BACKSPACE)
342                    {
343                            if (offset > 0)
344                            {
345                                    str_len = 1;
346                                    offset--;
347                                    if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8
348                                    {
349                                            while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0)
350                                            {
351                                                    str_len++;
352                                                    offset--;
353                                            }
354                                            display_len--;
355                                            col_cur--;
356                                    }
357    
358                                    memmove(buffer + offset, buffer + offset + str_len, (size_t)(len - offset - str_len));
359                                    len -= str_len;
360                                    buffer[len] = '\0';
361                                    display_len--;
362                                    col_cur--;
363    
364                                    moveto(row, col_cur);
365                                    prints("%s", buffer + offset);
366                                    prints("%*s", max_display_len - display_len, "");
367                                    moveto(row, col_cur);
368                                    iflush();
369                            }
370                            continue;
371                    }
372                    else if (ch == KEY_DEL)
373                    {
374                            if (offset < len)
375                            {
376                                    if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character
377                                    {
378                                            str_len = 0;
379                                            c = (char)(buffer[offset] & 0xf0);
380                                            while (c & 0x80)
381                                            {
382                                                    str_len++;
383                                                    c = (c & 0x7f) << 1;
384                                            }
385                                            display_len--;
386                                    }
387                                    else
388                                    {
389                                            str_len = 1;
390                                    }
391    
392                                    memmove(buffer + offset, buffer + offset + str_len, (size_t)(len - offset - str_len));
393                                    len -= str_len;
394                                    buffer[len] = '\0';
395                                    display_len--;
396    
397                                    moveto(row, col_cur);
398                                    prints("%s", buffer + offset);
399                                    prints("%*s", max_display_len - display_len, "");
400                                    moveto(row, col_cur);
401                                    iflush();
402                            }
403                            continue;
404                    }
405                    else if (ch == KEY_LEFT)
406                    {
407                            if (offset > 0)
408                            {
409                                    str_len = 1;
410                                    offset--;
411                                    if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8
412                                    {
413                                            while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0)
414                                            {
415                                                    str_len++;
416                                                    offset--;
417                                            }
418                                            col_cur--;
419                                    }
420                                    col_cur--;
421    
422                                    moveto(row, col_cur);
423                                    iflush();
424                            }
425                            continue;
426                    }
427                    else if (ch == KEY_RIGHT)
428                    {
429                            if (offset < len)
430                            {
431                                    str_len = 0;
432                                    if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character
433                                    {
434                                            c = (char)(buffer[offset] & 0xf0);
435                                            while (c & 0x80)
436                                            {
437                                                    str_len++;
438                                                    c = (c & 0x7f) << 1;
439                                            }
440                                            col_cur++;
441                                    }
442                                    else
443                                    {
444                                            str_len = 1;
445                                    }
446    
447                                    col_cur++;
448                                    offset += str_len;
449    
450                                    moveto(row, col_cur);
451                                    iflush();
452                            }
453                            continue;
454                    }
455                    else if (ch == KEY_HOME || ch == KEY_UP)
456                    {
457                            if (offset > 0)
458                            {
459                                    offset = 0;
460                                    col_cur = col + str_length(prompt, 1);
461    
462                                    moveto(row, col_cur);
463                                    iflush();
464                            }
465                            continue;
466                    }
467                    else if (ch == KEY_END || ch == KEY_DOWN)
468                    {
469                            if (offset < len)
470                            {
471                                    offset = len;
472                                    col_cur = col + str_length(prompt, 1) + display_len;
473    
474                                    moveto(row, col_cur);
475                                    iflush();
476                            }
477                            continue;
478                    }
479                    else if (ch > 255 || iscntrl(ch))
480                    {
481                            continue;
482                    }
483                    else if ((ch & 0xff80) == 0x80) // head of multi-byte character
484                    {
485                            str_len = 0;
486                            c = (char)(ch & 0xf0);
487                            while (c & 0x80)
488                            {
489                                    input_str[str_len] = (char)(ch - 256);
490                                    str_len++;
491                                    c = (c & 0x7f) << 1;
492    
493                                    if ((c & 0x80) == 0) // Input completed
494                                    {
495                                            break;
496                                    }
497    
498                                    // Expect additional bytes of input
499                                    ch = igetch(100);                                                // 0.1 second
500                                    if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Ignore received bytes if no futher input
501                                    {
502    #ifdef _DEBUG
503                                            log_error("Ignore %d bytes of incomplete UTF8 character\n", str_len);
504    #endif
505                                            str_len = 0;
506                                            break;
507                                    }
508                            }
509                            input_str[str_len] = '\0';
510    
511                            if (str_len == 0) // Incomplete input
512                            {
513                                    continue;
514                            }
515    
516                            if (mbstowcs(wcs, input_str, 1) == (size_t)-1)
517                            {
518                                    log_error("mbstowcs() error\n");
519                            }
520                            if (len + str_len > buf_size - 1 || display_len + (UTF8_fixed_width ? 2 : wcwidth(wcs[0])) > max_display_len) // No enough space for Chinese character
521                            {
522                                    outc('\a');
523                                    iflush();
524                                    continue;
525                            }
526    
527                            memmove(buffer + offset + str_len, buffer + offset, (size_t)(len - offset));
528                            memcpy(buffer + offset, input_str, (size_t)str_len);
529                            len += str_len;
530                            buffer[len] = '\0';
531                            display_len += 2;
532    
533                            moveto(row, col_cur);
534                            prints("%s", buffer + offset);
535                            prints("%*s", max_display_len - display_len, "");
536    
537                            col_cur += 2;
538    
539                            moveto(row, col_cur);
540                            iflush();
541    
542                            offset += str_len;
543                    }
544                    else if (ch >= 32 && ch < 127) // Printable character
545                    {
546                            if (len + 1 > buf_size - 1 || display_len + 1 > max_display_len)
547                            {
548                                    outc('\a');
549                                    iflush();
550                                    continue;
551                            }
552    
553                            memmove(buffer + offset + 1, buffer + offset, (size_t)(len - offset));
554                            buffer[offset] = (char)ch;
555                            len++;
556                            buffer[len] = '\0';
557                            display_len++;
558    
559                            moveto(row, col_cur);
560                            prints("%s", buffer + offset);
561                            prints("%*s", max_display_len - display_len, "");
562    
563                            col_cur++;
564    
565                            moveto(row, col_cur);
566                            iflush();
567    
568                            offset++;
569                    }
570                    else // Invalid character
571                    {
572                            continue;
573                    }
574            }
575    
576          return len;          return len;
577  }  }
# Line 260  int display_data(const void *p_data, lon Line 605  int display_data(const void *p_data, lon
605          loop = 1;          loop = 1;
606          while (!SYS_server_exit && loop)          while (!SYS_server_exit && loop)
607          {          {
608                  if (eof_exit > 0 && line_current >= display_line_total && display_line_total <= screen_row_total)                  if (eof_exit > 0 && line_current >= display_line_total)
609                  {                  {
610                          if (eof_exit == 1)                          if (eof_exit == 1)
611                          {                          {
# Line 294  int display_data(const void *p_data, lon Line 639  int display_data(const void *p_data, lon
639                          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);
640    
641                          snprintf(buffer, sizeof(buffer),                          snprintf(buffer, sizeof(buffer),
642                                           "\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",
643                                           ctx.line_top,                                           ctx.line_top,
644                                           ctx.line_bottom,                                           ctx.line_bottom,
645                                           percentile,                                           percentile,
# Line 315  int display_data(const void *p_data, lon Line 660  int display_data(const void *p_data, lon
660                          input_ok = 0;                          input_ok = 0;
661                          while (!SYS_server_exit && !input_ok)                          while (!SYS_server_exit && !input_ok)
662                          {                          {
663                                  ch = igetch_t(MAX_DELAY_TIME);                                  ch = igetch_t(BBS_max_user_idle_time);
664                                  input_ok = 1;                                  input_ok = 1;
665    
666                                    if (ch != KEY_NULL && ch != KEY_TIMEOUT)
667                                    {
668                                            BBS_last_access_tm = time(NULL);
669                                    }
670    
671                                  // extended key handler                                  // extended key handler
672                                  if (key_handler(&ch, &ctx) != 0)                                  if (key_handler(&ch, &ctx) != 0)
673                                  {                                  {
# Line 327  int display_data(const void *p_data, lon Line 677  int display_data(const void *p_data, lon
677                                  switch (ch)                                  switch (ch)
678                                  {                                  {
679                                  case KEY_NULL:                                  case KEY_NULL:
680                                            log_error("KEY_NULL\n");
681                                            goto cleanup;
682                                  case KEY_TIMEOUT:                                  case KEY_TIMEOUT:
683                                            log_error("User input timeout\n");
684                                          goto cleanup;                                          goto cleanup;
685                                  case KEY_HOME:                                  case KEY_HOME:
686                                          if (line_current - output_current_row < 0) // Reach begin                                          if (line_current - output_current_row < 0) // Reach begin
# Line 361  int display_data(const void *p_data, lon Line 714  int display_data(const void *p_data, lon
714                                          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
715                                          break;                                          break;
716                                  case CR:                                  case CR:
                                         igetch_reset();  
                                 case KEY_SPACE:  
717                                  case KEY_DOWN:                                  case KEY_DOWN:
718                                          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
719                                          {                                          {
# Line 373  int display_data(const void *p_data, lon Line 724  int display_data(const void *p_data, lon
724                                          output_end_row = SCREEN_ROWS - 1;                                          output_end_row = SCREEN_ROWS - 1;
725                                          moveto(SCREEN_ROWS, 0);                                          moveto(SCREEN_ROWS, 0);
726                                          clrtoeol();                                          clrtoeol();
727                                          prints("\033[S"); // Scroll up 1 line                                          // prints("\033[S"); // Scroll up 1 line
728                                            prints("\n"); // Legacy Cterm only works with this line
729                                          break;                                          break;
730                                  case KEY_PGUP:                                  case KEY_PGUP:
731                                          if (line_current - output_current_row < 0) // Reach begin                                          if (line_current - output_current_row < 0) // Reach begin
# Line 389  int display_data(const void *p_data, lon Line 741  int display_data(const void *p_data, lon
741                                          output_end_row = SCREEN_ROWS - 1;                                          output_end_row = SCREEN_ROWS - 1;
742                                          clrline(output_current_row, SCREEN_ROWS);                                          clrline(output_current_row, SCREEN_ROWS);
743                                          break;                                          break;
744                                    case KEY_SPACE:
745                                  case KEY_PGDN:                                  case KEY_PGDN:
746                                          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
747                                          {                                          {
# Line 429  int display_data(const void *p_data, lon Line 782  int display_data(const void *p_data, lon
782                                          input_ok = 0;                                          input_ok = 0;
783                                          break;                                          break;
784                                  }                                  }
   
                                 BBS_last_access_tm = time(NULL);  
785                          }                          }
786    
787                          continue;                          continue;
# Line 464  cleanup: Line 815  cleanup:
815          return ch;          return ch;
816  }  }
817    
818  static int display_file_key_handler(int *p_key, DISPLAY_CTX *p_ctx)  int display_file_key_handler(int *p_key, DISPLAY_CTX *p_ctx)
819  {  {
820          switch (*p_key)          switch (*p_key)
821          {          {
822          case 0: // Set msg          case 0: // Set msg
823                  snprintf(p_ctx->msg, sizeof(p_ctx->msg),                  snprintf(p_ctx->msg, sizeof(p_ctx->msg),
824                                   "| [\033[32m\033[33m,\033[32mESC\033[33m] | "                                   "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] | "
825                                   "ƶ[\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] | "
826                                   "[\033[32mh\033[33m] |");                                   "帮助[\033[32mh\033[33m] |");
827                  break;                  break;
828          }          }
829    
# Line 522  int show_top(const char *str_left, const Line 873  int show_top(const char *str_left, const
873    
874          strncpy(str_left_f, str_left, sizeof(str_left_f) - 1);          strncpy(str_left_f, str_left, sizeof(str_left_f) - 1);
875          str_left_f[sizeof(str_left_f) - 1] = '\0';          str_left_f[sizeof(str_left_f) - 1] = '\0';
876          len = split_line(str_left_f, STR_TOP_LEFT_MAX_LEN, &eol, &str_left_len, 1);          len = split_line(str_left_f, STR_TOP_LEFT_MAX_LEN / 2, &eol, &str_left_len, 1);
877          str_left_f[len] = '\0';          str_left_f[len] = '\0';
878    
879          strncpy(str_middle_f, str_middle, sizeof(str_middle_f) - 1);          strncpy(str_middle_f, str_middle, sizeof(str_middle_f) - 1);
880          str_middle_f[sizeof(str_middle_f) - 1] = '\0';          str_middle_f[sizeof(str_middle_f) - 1] = '\0';
881          len = split_line(str_middle, STR_TOP_MIDDLE_MAX_LEN, &eol, &str_middle_len, 1);          len = split_line(str_middle, STR_TOP_MIDDLE_MAX_LEN / 2, &eol, &str_middle_len, 1);
882          str_middle_f[len] = '\0';          str_middle_f[len] = '\0';
883    
884          strncpy(str_right_f, str_right, sizeof(str_right_f) - 1);          strncpy(str_right_f, str_right, sizeof(str_right_f) - 1);
885          str_right_f[sizeof(str_right_f) - 1] = '\0';          str_right_f[sizeof(str_right_f) - 1] = '\0';
886          len = split_line(str_right, STR_TOP_RIGHT_MAX_LEN, &eol, &str_right_len, 1);          len = split_line(str_right, STR_TOP_RIGHT_MAX_LEN / 2, &eol, &str_right_len, 1);
887          str_right_f[len] = '\0';          str_right_f[len] = '\0';
888    
889          moveto(1, 0);          moveto(1, 0);
890          clrtoeol();          clrtoeol();
891          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",
892                     str_left_f, 44 - str_left_len, str_middle_f, 36, str_right_f);                     str_left_f, 44 - str_left_len - str_middle_len, "",
893                       str_middle_f, 36 - str_right_len, "", str_right_f);
894    
895          return 0;          return 0;
896  }  }
# Line 546  int show_top(const char *str_left, const Line 898  int show_top(const char *str_left, const
898  int show_bottom(const char *msg)  int show_bottom(const char *msg)
899  {  {
900          char str_time[LINE_BUFFER_LEN];          char str_time[LINE_BUFFER_LEN];
901            int len_str_time;
902          time_t time_online;          time_t time_online;
903          struct tm *tm_online;          struct tm *tm_online;
904          char msg_f[LINE_BUFFER_LEN];          char msg_f[LINE_BUFFER_LEN];
905          int eol;          int eol;
906          int msg_len;          int len_msg;
907          int len;          int len;
908          int len_username;          int len_username;
909          char str_tm_online[LINE_BUFFER_LEN];          char str_tm_online[LINE_BUFFER_LEN];
910            int len_str_tm_online;
911    
912          get_time_str(str_time, sizeof(str_time));          len_str_time = (int)get_time_str(str_time, sizeof(str_time));
913    
914          msg_f[0] = '\0';          msg_f[0] = '\0';
915          msg_len = 0;          len_msg = 0;
916          if (msg != NULL)          if (msg != NULL)
917          {          {
918                  strncpy(msg_f, msg, sizeof(msg_f) - 1);                  strncpy(msg_f, msg, sizeof(msg_f) - 1);
919                  msg_f[sizeof(msg_f) - 1] = '\0';                  msg_f[sizeof(msg_f) - 1] = '\0';
920                  len = split_line(msg_f, 23, &eol, &msg_len, 1);                  len = split_line(msg_f, 23, &eol, &len_msg, 1);
921                  msg_f[len] = '\0';                  msg_f[len] = '\0';
922          }          }
923    
# Line 574  int show_bottom(const char *msg) Line 928  int show_bottom(const char *msg)
928          if (tm_online->tm_mday > 1)          if (tm_online->tm_mday > 1)
929          {          {
930                  snprintf(str_tm_online, sizeof(str_tm_online),                  snprintf(str_tm_online, sizeof(str_tm_online),
931                                   "\033[36m%2d\033[33m\033[36m%2d\033[33mʱ",                                   "\033[36m%d\033[33md \033[36m%d\033[33m:\033[36m%.2d",
932                                   tm_online->tm_mday - 1, tm_online->tm_hour);                                   tm_online->tm_mday - 1, tm_online->tm_hour, tm_online->tm_min);
933          }          }
934          else          else
935          {          {
936                  snprintf(str_tm_online, sizeof(str_tm_online),                  snprintf(str_tm_online, sizeof(str_tm_online),
937                                   "\033[36m%2d\033[33mʱ\033[36m%2d\033[33m",                                   "\033[36m%d\033[33m:\033[36m%.2d",
938                                   tm_online->tm_hour, tm_online->tm_min);                                   tm_online->tm_hour, tm_online->tm_min);
939          }          }
940            len_str_tm_online = str_length(str_tm_online, 1);
941    
942          moveto(SCREEN_ROWS, 0);          moveto(SCREEN_ROWS, 0);
943          clrtoeol();          clrtoeol();
944          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",
945                     str_time, msg_f, 38 - msg_len - len_username, "", BBS_username, str_tm_online);                     str_time, msg_f, 65 - len_str_time - len_msg - len_username - len_str_tm_online,
946                       "", BBS_username, str_tm_online);
947    
948          return 0;          return 0;
949  }  }


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

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