/[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.104 by sysadm, Wed Jul 2 04:17:33 2025 UTC Revision 1.131 by sysadm, Thu Nov 20 09:02:46 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     */
8  /***************************************************************************  
9   *                                                                         *  #ifdef HAVE_CONFIG_H
10   *   This program is free software; you can redistribute it and/or modify  *  #include "config.h"
11   *   it under the terms of the GNU General Public License as published by  *  #endif
  *   the Free Software Foundation; either version 3 of the License, or     *  
  *   (at your option) any later version.                                   *  
  *                                                                         *  
  ***************************************************************************/  
12    
13  #include "bbs.h"  #include "bbs.h"
14  #include "common.h"  #include "common.h"
# Line 29  Line 25 
25  #include <string.h>  #include <string.h>
26  #include <stdlib.h>  #include <stdlib.h>
27  #include <unistd.h>  #include <unistd.h>
28    #include <wchar.h>
29  #include <sys/param.h>  #include <sys/param.h>
30  #include <sys/stat.h>  #include <sys/stat.h>
 #include <sys/shm.h>  
31  #include <sys/types.h>  #include <sys/types.h>
32    
33  #define ACTIVE_BOARD_HEIGHT 8  const char CTRL_SEQ_CLR_LINE[] = "\033[K";
34    
35  #define STR_TOP_LEFT_MAX_LEN 40  static const int ACTIVE_BOARD_HEIGHT = 8;
36  #define STR_TOP_MIDDLE_MAX_LEN 20  
37  #define STR_TOP_RIGHT_MAX_LEN 20  static const int STR_TOP_LEFT_MAX_LEN = 80;
38    static const int STR_TOP_MIDDLE_MAX_LEN = 40;
39    static const int STR_TOP_RIGHT_MAX_LEN = 80;
40    
41    static size_t get_time_str(char *s, size_t len)
42    {
43            time_t curtime;
44            struct tm local_tm;
45    
46            time(&curtime);
47            localtime_r(&curtime, &local_tm);
48            size_t j = strftime(s, len, "%m/%d %H:%M %Z", &local_tm);
49    
50            return j;
51    }
52    
53  void moveto(int row, int col)  void moveto(int row, int col)
54  {  {
# Line 81  void clearscr() Line 91  void clearscr()
91          moveto(0, 0);          moveto(0, 0);
92  }  }
93    
94  int press_any_key()  inline int press_any_key()
95    {
96            return press_any_key_ex("                           \033[1;33m按任意键继续...\033[m", 60);
97    }
98    
99    int press_any_key_ex(const char *msg, int sec)
100  {  {
101            int ch = 0;
102            int duration = 0;
103            time_t t_begin = time(NULL);
104    
105          moveto(SCREEN_ROWS, 0);          moveto(SCREEN_ROWS, 0);
106          clrtoeol();          clrtoeol();
107    
108          prints("                           \033[1;33m按任意键继续...\033[0;37m");          prints(msg);
109          iflush();          iflush();
110    
111          return igetch_t(MIN(MAX_DELAY_TIME, 60));          igetch_reset();
112    
113            do
114            {
115                    ch = igetch_t(sec - duration);
116                    duration = (int)(time(NULL) - t_begin);
117            } while (!SYS_server_exit && ch == 0 && duration < 60);
118    
119            return ch;
120  }  }
121    
122  void set_input_echo(int echo)  void set_input_echo(int echo)
# Line 97  void set_input_echo(int echo) Line 124  void set_input_echo(int echo)
124          if (echo)          if (echo)
125          {          {
126                  outc('\x83'); // ASCII code 131                  outc('\x83'); // ASCII code 131
                 iflush();  
127          }          }
128          else          else
129          {          {
130                  //    outc ('\x85'); // ASCII code 133                  // outc ('\x85'); // ASCII code 133
131                  prints("\xff\xfb\x01\xff\xfb\x03");                  prints("\xff\xfb\x01\xff\xfb\x03");
                 iflush();  
                 igetch(0);  
                 igetch_reset();  
132          }          }
133            iflush();
134  }  }
135    
136  static int _str_input(char *buffer, int buf_size, int max_display_len, int echo_mode)  static int _str_input(char *buffer, int buf_size, int max_display_len, enum io_echo_t echo_mode)
137  {  {
138          int ch;          int ch;
139          int offset = 0;          int offset = 0;
140          int eol;          int eol;
141          int display_len;          int display_len;
142          char input_str[4];          char input_str[5];
143          int str_len = 0;          int str_len = 0;
144            wchar_t wcs[2];
145          char c;          char c;
146    
147          buffer[buf_size - 1] = '\0';          buffer[buf_size - 1] = '\0';
# Line 126  static int _str_input(char *buffer, int Line 151  static int _str_input(char *buffer, int
151    
152          while (!SYS_server_exit)          while (!SYS_server_exit)
153          {          {
154                  ch = igetch_t(MIN(MAX_DELAY_TIME, 60));                  ch = igetch_t(MIN(BBS_max_user_idle_time, 60));
155    
156                  if (ch == CR)                  if (ch == CR)
157                  {                  {
                         igetch_reset();  
158                          break;                          break;
159                  }                  }
160                  else if (ch == KEY_TIMEOUT || ch == KEY_NULL) // timeout or broken pipe                  else if (ch == KEY_TIMEOUT || ch == KEY_NULL) // timeout or broken pipe
# Line 148  static int _str_input(char *buffer, int Line 172  static int _str_input(char *buffer, int
172                                  offset--;                                  offset--;
173                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8
174                                  {                                  {
175                                          while (offset > 0 && (buffer[offset] & 0b11000000) != 0b11000000)                                          while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0)
176                                          {                                          {
177                                                  offset--;                                                  offset--;
178                                          }                                          }
# Line 169  static int _str_input(char *buffer, int Line 193  static int _str_input(char *buffer, int
193                  else if ((ch & 0xff80) == 0x80) // head of multi-byte character                  else if ((ch & 0xff80) == 0x80) // head of multi-byte character
194                  {                  {
195                          str_len = 0;                          str_len = 0;
196                          c = (char)(ch & 0b11110000);                          c = (char)(ch & 0xf0);
197                          while (c & 0b10000000)                          while (c & 0x80)
198                          {                          {
199                                  input_str[str_len] = (char)(ch - 256);                                  input_str[str_len] = (char)(ch - 256);
200                                  str_len++;                                  str_len++;
201                                  c = (c & 0b01111111) << 1;                                  c = (c & 0x7f) << 1;
202    
203                                  if ((c & 0b10000000) == 0) // Input completed                                  if ((c & 0x80) == 0) // Input completed
204                                  {                                  {
205                                          break;                                          break;
206                                  }                                  }
# Line 185  static int _str_input(char *buffer, int Line 209  static int _str_input(char *buffer, int
209                                  ch = igetch(100);                                                // 0.1 second                                  ch = igetch(100);                                                // 0.1 second
210                                  if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Ignore received bytes if no futher input                                  if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Ignore received bytes if no futher input
211                                  {                                  {
212    #ifdef _DEBUG
213                                          log_error("Ignore %d bytes of incomplete UTF8 character\n", str_len);                                          log_error("Ignore %d bytes of incomplete UTF8 character\n", str_len);
214    #endif
215                                          str_len = 0;                                          str_len = 0;
216                                          break;                                          break;
217                                  }                                  }
218                          }                          }
219                            input_str[str_len] = '\0';
220    
221                          if (str_len == 0) // Incomplete input                          if (str_len == 0) // Incomplete input
222                          {                          {
223                                  continue;                                  continue;
224                          }                          }
225    
226                          if (offset + str_len > buf_size - 1 || display_len + 2 > max_display_len) // No enough space for Chinese character                          if (mbstowcs(wcs, input_str, 1) == (size_t)-1)
227                            {
228                                    log_error("mbstowcs() error\n");
229                            }
230                            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
231                          {                          {
232                                  outc('\a');                                  outc('\a');
233                                  iflush();                                  iflush();
# Line 252  static int _str_input(char *buffer, int Line 283  static int _str_input(char *buffer, int
283          return offset;          return offset;
284  }  }
285    
286  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)
287  {  {
288          int len;          int len;
289    
# Line 264  int str_input(char *buffer, int buf_size Line 295  int str_input(char *buffer, int buf_size
295          iflush();          iflush();
296    
297          return len;          return len;
298  };  }
299    
300  int get_data(int row, int col, char *prompt, char *buffer, int buf_size, int max_display_len, int echo_mode)  int get_data(int row, int col, char *prompt, char *buffer, int buf_size, int max_display_len)
301  {  {
302          int len;          int len = 0;
303            int col_cur = 0;
304            int ch;
305            int offset = 0;
306            int eol;
307            int display_len;
308            char input_str[5];
309            int str_len = 0;
310            wchar_t wcs[2];
311            int wc_len;
312            char c;
313    
314            buffer[buf_size - 1] = '\0';
315            offset = split_line(buffer, max_display_len, &eol, &display_len, 0);
316            buffer[offset] = '\0';
317            len = offset;
318            col_cur = col + str_length(prompt, 1) + display_len;
319    
320          moveto(row, col);          moveto(row, col);
321          prints("%s", prompt);          prints("%s", prompt);
322          prints("%s", buffer);          prints("%s", buffer);
323            prints("%*s", max_display_len - display_len, "");
324            moveto(row, col_cur);
325          iflush();          iflush();
326    
327          len = _str_input(buffer, buf_size, max_display_len, echo_mode);          igetch_reset();
328    
329            while (!SYS_server_exit)
330            {
331                    ch = igetch_t(MIN(BBS_max_user_idle_time, 60));
332    
333                    if (ch == CR)
334                    {
335                            break;
336                    }
337                    else if (ch == KEY_TIMEOUT || ch == KEY_NULL) // timeout or broken pipe
338                    {
339                            return -1;
340                    }
341                    else if (ch == LF || ch == '\0')
342                    {
343                            continue;
344                    }
345                    else if (ch == BACKSPACE)
346                    {
347                            if (offset > 0)
348                            {
349                                    str_len = 1;
350                                    offset--;
351                                    if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8
352                                    {
353                                            while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0)
354                                            {
355                                                    str_len++;
356                                                    offset--;
357                                            }
358    
359                                            if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1)
360                                            {
361                                                    log_error("mbstowcs() error\n");
362                                            }
363                                            wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0]));
364    
365                                            if (wc_len == 2)
366                                            {
367                                                    display_len--;
368                                                    col_cur--;
369                                            }
370                                    }
371    
372                                    memmove(buffer + offset, buffer + offset + str_len, (size_t)(len - offset - str_len));
373                                    len -= str_len;
374                                    buffer[len] = '\0';
375                                    display_len--;
376                                    col_cur--;
377    
378                                    moveto(row, col_cur);
379                                    prints("%s", buffer + offset);
380                                    prints("%*s", max_display_len - display_len, "");
381                                    moveto(row, col_cur);
382                                    iflush();
383                            }
384                            continue;
385                    }
386                    else if (ch == KEY_DEL)
387                    {
388                            if (offset < len)
389                            {
390                                    if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character
391                                    {
392                                            str_len = 0;
393                                            c = (char)(buffer[offset] & 0xf0);
394                                            while (c & 0x80)
395                                            {
396                                                    str_len++;
397                                                    c = (c & 0x7f) << 1;
398                                            }
399                                            display_len--;
400                                    }
401                                    else
402                                    {
403                                            str_len = 1;
404                                    }
405    
406                                    memmove(buffer + offset, buffer + offset + str_len, (size_t)(len - offset - str_len));
407                                    len -= str_len;
408                                    buffer[len] = '\0';
409                                    display_len--;
410    
411                                    moveto(row, col_cur);
412                                    prints("%s", buffer + offset);
413                                    prints("%*s", max_display_len - display_len, "");
414                                    moveto(row, col_cur);
415                                    iflush();
416                            }
417                            continue;
418                    }
419                    else if (ch == KEY_LEFT)
420                    {
421                            if (offset > 0)
422                            {
423                                    str_len = 1;
424                                    offset--;
425                                    if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8
426                                    {
427                                            while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0)
428                                            {
429                                                    str_len++;
430                                                    offset--;
431                                            }
432    
433                                            if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1)
434                                            {
435                                                    log_error("mbstowcs() error\n");
436                                            }
437                                            wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0]));
438    
439                                            if (wc_len == 2)
440                                            {
441                                                    col_cur--;
442                                            }
443                                    }
444                                    col_cur--;
445    
446                                    moveto(row, col_cur);
447                                    iflush();
448                            }
449                            continue;
450                    }
451                    else if (ch == KEY_RIGHT)
452                    {
453                            if (offset < len)
454                            {
455                                    str_len = 0;
456                                    if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character
457                                    {
458                                            c = (char)(buffer[offset] & 0xf0);
459                                            while (c & 0x80)
460                                            {
461                                                    str_len++;
462                                                    c = (c & 0x7f) << 1;
463                                            }
464    
465                                            if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1)
466                                            {
467                                                    log_error("mbstowcs() error\n");
468                                            }
469                                            wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0]));
470    
471                                            if (wc_len == 2)
472                                            {
473                                                    col_cur++;
474                                            }
475                                    }
476                                    else
477                                    {
478                                            str_len = 1;
479                                    }
480    
481                                    col_cur++;
482                                    offset += str_len;
483    
484                                    moveto(row, col_cur);
485                                    iflush();
486                            }
487                            continue;
488                    }
489                    else if (ch == KEY_HOME || ch == KEY_UP)
490                    {
491                            if (offset > 0)
492                            {
493                                    offset = 0;
494                                    col_cur = col + str_length(prompt, 1);
495    
496                                    moveto(row, col_cur);
497                                    iflush();
498                            }
499                            continue;
500                    }
501                    else if (ch == KEY_END || ch == KEY_DOWN)
502                    {
503                            if (offset < len)
504                            {
505                                    offset = len;
506                                    col_cur = col + str_length(prompt, 1) + display_len;
507    
508                                    moveto(row, col_cur);
509                                    iflush();
510                            }
511                            continue;
512                    }
513                    else if (ch > 255 || iscntrl(ch))
514                    {
515                            continue;
516                    }
517                    else if ((ch & 0xff80) == 0x80) // head of multi-byte character
518                    {
519                            str_len = 0;
520                            c = (char)(ch & 0xf0);
521                            while (c & 0x80)
522                            {
523                                    input_str[str_len] = (char)(ch - 256);
524                                    str_len++;
525                                    c = (c & 0x7f) << 1;
526    
527                                    if ((c & 0x80) == 0) // Input completed
528                                    {
529                                            break;
530                                    }
531    
532                                    // Expect additional bytes of input
533                                    ch = igetch(100);                                                // 0.1 second
534                                    if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Ignore received bytes if no futher input
535                                    {
536    #ifdef _DEBUG
537                                            log_error("Ignore %d bytes of incomplete UTF8 character\n", str_len);
538    #endif
539                                            str_len = 0;
540                                            break;
541                                    }
542                            }
543                            input_str[str_len] = '\0';
544    
545                            if (str_len == 0) // Incomplete input
546                            {
547                                    continue;
548                            }
549    
550                            if (mbstowcs(wcs, input_str, 1) == (size_t)-1)
551                            {
552                                    log_error("mbstowcs() error\n");
553                            }
554                            wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0]));
555    
556                            if (len + str_len > buf_size - 1 ||
557                                    display_len + wc_len > max_display_len) // No enough space for Chinese character
558                            {
559                                    outc('\a');
560                                    iflush();
561                                    continue;
562                            }
563    
564                            memmove(buffer + offset + str_len, buffer + offset, (size_t)(len - offset));
565                            memcpy(buffer + offset, input_str, (size_t)str_len);
566                            len += str_len;
567                            buffer[len] = '\0';
568                            display_len += wc_len;
569    
570                            moveto(row, col_cur);
571                            prints("%s", buffer + offset);
572                            prints("%*s", max_display_len - display_len, "");
573    
574                            col_cur += wc_len;
575    
576                            moveto(row, col_cur);
577                            iflush();
578    
579                            offset += str_len;
580                    }
581                    else if (ch >= 32 && ch < 127) // Printable character
582                    {
583                            if (len + 1 > buf_size - 1 || display_len + 1 > max_display_len)
584                            {
585                                    outc('\a');
586                                    iflush();
587                                    continue;
588                            }
589    
590                            memmove(buffer + offset + 1, buffer + offset, (size_t)(len - offset));
591                            buffer[offset] = (char)ch;
592                            len++;
593                            buffer[len] = '\0';
594                            display_len++;
595    
596                            moveto(row, col_cur);
597                            prints("%s", buffer + offset);
598                            prints("%*s", max_display_len - display_len, "");
599    
600                            col_cur++;
601    
602                            moveto(row, col_cur);
603                            iflush();
604    
605                            offset++;
606                    }
607                    else // Invalid character
608                    {
609                            continue;
610                    }
611            }
612    
613          return len;          return len;
614  }  }
# Line 309  int display_data(const void *p_data, lon Line 642  int display_data(const void *p_data, lon
642          loop = 1;          loop = 1;
643          while (!SYS_server_exit && loop)          while (!SYS_server_exit && loop)
644          {          {
645                  if (eof_exit > 0 && line_current >= display_line_total && display_line_total <= screen_row_total)                  if (eof_exit > 0 && line_current >= display_line_total)
646                  {                  {
647                          if (eof_exit == 1)                          if (eof_exit == 1)
648                          {                          {
# Line 364  int display_data(const void *p_data, lon Line 697  int display_data(const void *p_data, lon
697                          input_ok = 0;                          input_ok = 0;
698                          while (!SYS_server_exit && !input_ok)                          while (!SYS_server_exit && !input_ok)
699                          {                          {
700                                  ch = igetch_t(MAX_DELAY_TIME);                                  ch = igetch_t(BBS_max_user_idle_time);
701                                  input_ok = 1;                                  input_ok = 1;
702    
703                                    if (ch != KEY_NULL && ch != KEY_TIMEOUT)
704                                    {
705                                            BBS_last_access_tm = time(NULL);
706                                    }
707    
708                                  // extended key handler                                  // extended key handler
709                                  if (key_handler(&ch, &ctx) != 0)                                  if (key_handler(&ch, &ctx) != 0)
710                                  {                                  {
# Line 376  int display_data(const void *p_data, lon Line 714  int display_data(const void *p_data, lon
714                                  switch (ch)                                  switch (ch)
715                                  {                                  {
716                                  case KEY_NULL:                                  case KEY_NULL:
717                                            log_error("KEY_NULL\n");
718                                            goto cleanup;
719                                  case KEY_TIMEOUT:                                  case KEY_TIMEOUT:
720                                            log_error("User input timeout\n");
721                                          goto cleanup;                                          goto cleanup;
722                                  case KEY_HOME:                                  case KEY_HOME:
723                                          if (line_current - output_current_row < 0) // Reach begin                                          if (line_current - output_current_row < 0) // Reach begin
# Line 410  int display_data(const void *p_data, lon Line 751  int display_data(const void *p_data, lon
751                                          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
752                                          break;                                          break;
753                                  case CR:                                  case CR:
                                         igetch_reset();  
                                 case KEY_SPACE:  
754                                  case KEY_DOWN:                                  case KEY_DOWN:
755                                          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
756                                          {                                          {
# Line 439  int display_data(const void *p_data, lon Line 778  int display_data(const void *p_data, lon
778                                          output_end_row = SCREEN_ROWS - 1;                                          output_end_row = SCREEN_ROWS - 1;
779                                          clrline(output_current_row, SCREEN_ROWS);                                          clrline(output_current_row, SCREEN_ROWS);
780                                          break;                                          break;
781                                    case KEY_SPACE:
782                                  case KEY_PGDN:                                  case KEY_PGDN:
783                                          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
784                                          {                                          {
# Line 479  int display_data(const void *p_data, lon Line 819  int display_data(const void *p_data, lon
819                                          input_ok = 0;                                          input_ok = 0;
820                                          break;                                          break;
821                                  }                                  }
   
                                 BBS_last_access_tm = time(NULL);  
822                          }                          }
823    
824                          continue;                          continue;
# Line 514  cleanup: Line 852  cleanup:
852          return ch;          return ch;
853  }  }
854    
855  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)
856  {  {
857          switch (*p_key)          switch (*p_key)
858          {          {
# Line 532  static int display_file_key_handler(int Line 870  static int display_file_key_handler(int
870  int display_file(const char *filename, int eof_exit)  int display_file(const char *filename, int eof_exit)
871  {  {
872          int ret;          int ret;
873          const void *p_shm;          void *p_shm;
874          size_t data_len;          size_t data_len;
875          long line_total;          long line_total;
876          const void *p_data;          const void *p_data;
# Line 572  int show_top(const char *str_left, const Line 910  int show_top(const char *str_left, const
910    
911          strncpy(str_left_f, str_left, sizeof(str_left_f) - 1);          strncpy(str_left_f, str_left, sizeof(str_left_f) - 1);
912          str_left_f[sizeof(str_left_f) - 1] = '\0';          str_left_f[sizeof(str_left_f) - 1] = '\0';
913          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);
914          str_left_f[len] = '\0';          str_left_f[len] = '\0';
915    
916          strncpy(str_middle_f, str_middle, sizeof(str_middle_f) - 1);          strncpy(str_middle_f, str_middle, sizeof(str_middle_f) - 1);
917          str_middle_f[sizeof(str_middle_f) - 1] = '\0';          str_middle_f[sizeof(str_middle_f) - 1] = '\0';
918          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);
919          str_middle_f[len] = '\0';          str_middle_f[len] = '\0';
920    
921          strncpy(str_right_f, str_right, sizeof(str_right_f) - 1);          strncpy(str_right_f, str_right, sizeof(str_right_f) - 1);
922          str_right_f[sizeof(str_right_f) - 1] = '\0';          str_right_f[sizeof(str_right_f) - 1] = '\0';
923          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);
924          str_right_f[len] = '\0';          str_right_f[len] = '\0';
925    
926          moveto(1, 0);          moveto(1, 0);
927          clrtoeol();          clrtoeol();
928          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",
929                     str_left_f, 44 - str_left_len, str_middle_f, 36, str_right_f);                     str_left_f, 44 - str_left_len - str_middle_len, "",
930                       str_middle_f, 36 - str_right_len, "", str_right_f);
931    
932          return 0;          return 0;
933  }  }
# Line 596  int show_top(const char *str_left, const Line 935  int show_top(const char *str_left, const
935  int show_bottom(const char *msg)  int show_bottom(const char *msg)
936  {  {
937          char str_time[LINE_BUFFER_LEN];          char str_time[LINE_BUFFER_LEN];
938            int len_str_time;
939          time_t time_online;          time_t time_online;
940          struct tm *tm_online;          struct tm *tm_online;
941          char msg_f[LINE_BUFFER_LEN];          char msg_f[LINE_BUFFER_LEN];
942          int eol;          int eol;
943          int msg_len;          int len_msg;
944          int len;          int len;
945          int len_username;          int len_username;
946          char str_tm_online[LINE_BUFFER_LEN];          char str_tm_online[LINE_BUFFER_LEN];
947            int len_str_tm_online;
948    
949          get_time_str(str_time, sizeof(str_time));          len_str_time = (int)get_time_str(str_time, sizeof(str_time));
950    
951          msg_f[0] = '\0';          msg_f[0] = '\0';
952          msg_len = 0;          len_msg = 0;
953          if (msg != NULL)          if (msg != NULL)
954          {          {
955                  strncpy(msg_f, msg, sizeof(msg_f) - 1);                  strncpy(msg_f, msg, sizeof(msg_f) - 1);
956                  msg_f[sizeof(msg_f) - 1] = '\0';                  msg_f[sizeof(msg_f) - 1] = '\0';
957                  len = split_line(msg_f, 23, &eol, &msg_len, 1);                  len = split_line(msg_f, 23, &eol, &len_msg, 1);
958                  msg_f[len] = '\0';                  msg_f[len] = '\0';
959          }          }
960    
# Line 624  int show_bottom(const char *msg) Line 965  int show_bottom(const char *msg)
965          if (tm_online->tm_mday > 1)          if (tm_online->tm_mday > 1)
966          {          {
967                  snprintf(str_tm_online, sizeof(str_tm_online),                  snprintf(str_tm_online, sizeof(str_tm_online),
968                                   "\033[36m%2d\033[33m天\033[36m%2d\033[33m时",                                   "\033[36m%d\033[33md \033[36m%d\033[33m:\033[36m%.2d",
969                                   tm_online->tm_mday - 1, tm_online->tm_hour);                                   tm_online->tm_mday - 1, tm_online->tm_hour, tm_online->tm_min);
970          }          }
971          else          else
972          {          {
973                  snprintf(str_tm_online, sizeof(str_tm_online),                  snprintf(str_tm_online, sizeof(str_tm_online),
974                                   "\033[36m%2d\033[33m时\033[36m%2d\033[33m分",                                   "\033[36m%d\033[33m:\033[36m%.2d",
975                                   tm_online->tm_hour, tm_online->tm_min);                                   tm_online->tm_hour, tm_online->tm_min);
976          }          }
977            len_str_tm_online = str_length(str_tm_online, 1);
978    
979          moveto(SCREEN_ROWS, 0);          moveto(SCREEN_ROWS, 0);
980          clrtoeol();          clrtoeol();
981          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",
982                     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,
983                       "", BBS_username, str_tm_online);
984    
985          return 0;          return 0;
986  }  }


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

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