/[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.112 by sysadm, Fri Oct 17 10:57:43 2025 UTC Revision 1.141 by sysadm, Sun Feb 8 15:43:19 2026 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-2026  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 80  static const int ACTIVE_BOARD_HEIGHT = 8;
 #define STR_TOP_MIDDLE_MAX_LEN 40  
 #define STR_TOP_RIGHT_MAX_LEN 80  
36    
37  static const char *get_time_str(char *s, size_t len)  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  {  {
         static const char *weekday[] = {  
                 "天", "一", "二", "三", "四", "五", "六"};  
43          time_t curtime;          time_t curtime;
44          struct tm local_tm;          struct tm local_tm;
45    
46          time(&curtime);          time(&curtime);
47          localtime_r(&curtime, &local_tm);          localtime_r(&curtime, &local_tm);
48          size_t j = strftime(s, len, "%b %d %H:%M 星期", &local_tm);          size_t j = strftime(s, len, "%m/%d %H:%M %Z", &local_tm);
   
         if (j == 0 || j + strlen(weekday[local_tm.tm_wday]) + 1 > len)  
         {  
                 return NULL;  
         }  
49    
50          strncat(s, weekday[local_tm.tm_wday], len - 1 - j);          return j;
   
         return s;  
51  }  }
52    
53  void moveto(int row, int col)  void moveto(int row, int col)
# Line 99  void clrtobot(int line_begin) Line 88  void clrtobot(int line_begin)
88  void clearscr()  void clearscr()
89  {  {
90          prints("\033[2J");          prints("\033[2J");
91          moveto(0, 0);          moveto(1, 1);
92  }  }
93    
94  int press_any_key()  inline int press_any_key()
95  {  {
96          int ch = 0;          return press_any_key_ex("                           \033[1;33m按任意键继续...\033[m", 60);
97          int wait_seconds = 60;  }
         int duration = 0;  
         time_t t_begin = time(NULL);  
98    
99    int press_any_key_ex(const char *msg, int sec)
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 press_any_key_no_prompt(sec);
108    }
109    
110    inline int press_any_key_no_prompt(int sec)
111    {
112            int ch = 0;
113            int duration = 0;
114            time_t t_begin = time(NULL);
115    
116            igetch_reset();
117    
118          do          do
119          {          {
120                  ch = igetch_t(wait_seconds - duration);                  ch = igetch_t(sec - duration);
121                  duration = (int)(time(NULL) - t_begin);                  duration = (int)(time(NULL) - t_begin);
122          } while (!SYS_server_exit && ch == 0 && duration < 60);          } while (!SYS_server_exit && ch == 0 && duration < 60);
123    
# Line 138  void set_input_echo(int echo) Line 138  void set_input_echo(int echo)
138          iflush();          iflush();
139  }  }
140    
141  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)
142  {  {
143          int ch;          int ch;
144          int offset = 0;          int offset = 0;
145          int eol;          int eol;
146          int display_len;          int display_len;
147          char input_str[4];          char input_str[5];
148          int str_len = 0;          int str_len = 0;
149            wchar_t wcs[2];
150          char c;          char c;
151    
152          buffer[buf_size - 1] = '\0';          buffer[buf_size - 1] = '\0';
# Line 155  static int _str_input(char *buffer, int Line 156  static int _str_input(char *buffer, int
156    
157          while (!SYS_server_exit)          while (!SYS_server_exit)
158          {          {
159                  ch = igetch_t(MIN(MAX_DELAY_TIME, 60));                  ch = igetch_t(MIN(BBS_max_user_idle_time, 60));
160    
161                  if (ch == CR)                  if (ch == CR)
162                  {                  {
# Line 169  static int _str_input(char *buffer, int Line 170  static int _str_input(char *buffer, int
170                  {                  {
171                          continue;                          continue;
172                  }                  }
173                  else if (ch == BACKSPACE)                  else if (ch == KEY_ESC)
174                    {
175                            buffer[0] = '\0';
176                            offset = 0;
177                            break;
178                    }
179                    else if (ch == BACKSPACE || ch == KEY_DEL)
180                  {                  {
181                          if (offset > 0)                          if (offset > 0)
182                          {                          {
183                                  offset--;                                  offset--;
184                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8
185                                  {                                  {
186                                          while (offset > 0 && (buffer[offset] & 0b11000000) != 0b11000000)                                          while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0)
187                                          {                                          {
188                                                  offset--;                                                  offset--;
189                                          }                                          }
# Line 197  static int _str_input(char *buffer, int Line 204  static int _str_input(char *buffer, int
204                  else if ((ch & 0xff80) == 0x80) // head of multi-byte character                  else if ((ch & 0xff80) == 0x80) // head of multi-byte character
205                  {                  {
206                          str_len = 0;                          str_len = 0;
207                          c = (char)(ch & 0b11110000);                          c = (char)(ch & 0xf0);
208                          while (c & 0b10000000)                          while (c & 0x80)
209                          {                          {
210                                  input_str[str_len] = (char)(ch - 256);                                  input_str[str_len] = (char)(ch - 256);
211                                  str_len++;                                  str_len++;
212                                  c = (c & 0b01111111) << 1;                                  c = (c & 0x7f) << 1;
213    
214                                  if ((c & 0b10000000) == 0) // Input completed                                  if ((c & 0x80) == 0) // Input completed
215                                  {                                  {
216                                          break;                                          break;
217                                  }                                  }
# Line 213  static int _str_input(char *buffer, int Line 220  static int _str_input(char *buffer, int
220                                  ch = igetch(100);                                                // 0.1 second                                  ch = igetch(100);                                                // 0.1 second
221                                  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
222                                  {                                  {
223  #ifdef _DEBUG                                          log_debug("Ignore %d bytes of incomplete UTF8 character", str_len);
                                         log_error("Ignore %d bytes of incomplete UTF8 character\n", str_len);  
 #endif  
224                                          str_len = 0;                                          str_len = 0;
225                                          break;                                          break;
226                                  }                                  }
227                          }                          }
228                            input_str[str_len] = '\0';
229    
230                          if (str_len == 0) // Incomplete input                          if (str_len == 0) // Incomplete input
231                          {                          {
232                                  continue;                                  continue;
233                          }                          }
234    
235                          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)
236                            {
237                                    log_error("mbstowcs() error");
238                            }
239                            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
240                          {                          {
241                                  outc('\a');                                  outc('\a');
242                                  iflush();                                  iflush();
# Line 282  static int _str_input(char *buffer, int Line 292  static int _str_input(char *buffer, int
292          return offset;          return offset;
293  }  }
294    
295  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)
296  {  {
297          int len;          int len;
298    
# Line 294  int str_input(char *buffer, int buf_size Line 304  int str_input(char *buffer, int buf_size
304          iflush();          iflush();
305    
306          return len;          return len;
307  };  }
308    
309  int get_data(int row, int col, char *prompt, char *buffer, int buf_size, int max_display_len)  int get_data(int row, int col, char *prompt, char *buffer, int buf_size, int max_display_len)
310  {  {
# Line 304  int get_data(int row, int col, char *pro Line 314  int get_data(int row, int col, char *pro
314          int offset = 0;          int offset = 0;
315          int eol;          int eol;
316          int display_len;          int display_len;
317          char input_str[4];          char input_str[5];
318          int str_len = 0;          int str_len = 0;
319            wchar_t wcs[2];
320            int wc_len;
321          char c;          char c;
322    
323          buffer[buf_size - 1] = '\0';          buffer[buf_size - 1] = '\0';
# Line 325  int get_data(int row, int col, char *pro Line 337  int get_data(int row, int col, char *pro
337    
338          while (!SYS_server_exit)          while (!SYS_server_exit)
339          {          {
340                  ch = igetch_t(MIN(MAX_DELAY_TIME, 60));                  ch = igetch_t(MIN(BBS_max_user_idle_time, 60));
341    
342                  if (ch == CR)                  if (ch == CR)
343                  {                  {
# Line 339  int get_data(int row, int col, char *pro Line 351  int get_data(int row, int col, char *pro
351                  {                  {
352                          continue;                          continue;
353                  }                  }
354                    else if (ch == KEY_ESC)
355                    {
356                            buffer[0] = '\0';
357                            len = 0;
358                            break;
359                    }
360                  else if (ch == BACKSPACE)                  else if (ch == BACKSPACE)
361                  {                  {
362                          if (offset > 0)                          if (offset > 0)
# Line 347  int get_data(int row, int col, char *pro Line 365  int get_data(int row, int col, char *pro
365                                  offset--;                                  offset--;
366                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8
367                                  {                                  {
368                                          while (offset > 0 && (buffer[offset] & 0b11000000) != 0b11000000)                                          while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0)
369                                          {                                          {
370                                                  str_len++;                                                  str_len++;
371                                                  offset--;                                                  offset--;
372                                          }                                          }
373                                          display_len--;  
374                                          col_cur--;                                          if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1)
375                                            {
376                                                    log_error("mbstowcs() error");
377                                            }
378                                            wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0]));
379    
380                                            if (wc_len == 2)
381                                            {
382                                                    display_len--;
383                                                    col_cur--;
384                                            }
385                                  }                                  }
386    
387                                  memmove(buffer + offset, buffer + offset + str_len, (size_t)(len - offset - str_len));                                  memmove(buffer + offset, buffer + offset + str_len, (size_t)(len - offset - str_len));
# Line 377  int get_data(int row, int col, char *pro Line 405  int get_data(int row, int col, char *pro
405                                  if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character                                  if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character
406                                  {                                  {
407                                          str_len = 0;                                          str_len = 0;
408                                          c = (char)(buffer[offset] & 0b11110000);                                          c = (char)(buffer[offset] & 0xf0);
409                                          while (c & 0b10000000)                                          while (c & 0x80)
410                                          {                                          {
411                                                  str_len++;                                                  str_len++;
412                                                  c = (c & 0b01111111) << 1;                                                  c = (c & 0x7f) << 1;
413                                          }                                          }
414                                          display_len--;                                          display_len--;
415                                  }                                  }
# Line 411  int get_data(int row, int col, char *pro Line 439  int get_data(int row, int col, char *pro
439                                  offset--;                                  offset--;
440                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8                                  if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8
441                                  {                                  {
442                                          while (offset > 0 && (buffer[offset] & 0b11000000) != 0b11000000)                                          while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0)
443                                          {                                          {
444                                                  str_len++;                                                  str_len++;
445                                                  offset--;                                                  offset--;
446                                          }                                          }
447                                          col_cur--;  
448                                            if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1)
449                                            {
450                                                    log_error("mbstowcs() error");
451                                            }
452                                            wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0]));
453    
454                                            if (wc_len == 2)
455                                            {
456                                                    col_cur--;
457                                            }
458                                  }                                  }
459                                  col_cur--;                                  col_cur--;
460    
# Line 432  int get_data(int row, int col, char *pro Line 470  int get_data(int row, int col, char *pro
470                                  str_len = 0;                                  str_len = 0;
471                                  if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character                                  if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character
472                                  {                                  {
473                                          c = (char)(buffer[offset] & 0b11110000);                                          c = (char)(buffer[offset] & 0xf0);
474                                          while (c & 0b10000000)                                          while (c & 0x80)
475                                          {                                          {
476                                                  str_len++;                                                  str_len++;
477                                                  c = (c & 0b01111111) << 1;                                                  c = (c & 0x7f) << 1;
478                                            }
479    
480                                            if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1)
481                                            {
482                                                    log_error("mbstowcs() error");
483                                            }
484                                            wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0]));
485    
486                                            if (wc_len == 2)
487                                            {
488                                                    col_cur++;
489                                          }                                          }
                                         col_cur++;  
490                                  }                                  }
491                                  else                                  else
492                                  {                                  {
# Line 484  int get_data(int row, int col, char *pro Line 532  int get_data(int row, int col, char *pro
532                  else if ((ch & 0xff80) == 0x80) // head of multi-byte character                  else if ((ch & 0xff80) == 0x80) // head of multi-byte character
533                  {                  {
534                          str_len = 0;                          str_len = 0;
535                          c = (char)(ch & 0b11110000);                          c = (char)(ch & 0xf0);
536                          while (c & 0b10000000)                          while (c & 0x80)
537                          {                          {
538                                  input_str[str_len] = (char)(ch - 256);                                  input_str[str_len] = (char)(ch - 256);
539                                  str_len++;                                  str_len++;
540                                  c = (c & 0b01111111) << 1;                                  c = (c & 0x7f) << 1;
541    
542                                  if ((c & 0b10000000) == 0) // Input completed                                  if ((c & 0x80) == 0) // Input completed
543                                  {                                  {
544                                          break;                                          break;
545                                  }                                  }
# Line 500  int get_data(int row, int col, char *pro Line 548  int get_data(int row, int col, char *pro
548                                  ch = igetch(100);                                                // 0.1 second                                  ch = igetch(100);                                                // 0.1 second
549                                  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
550                                  {                                  {
551  #ifdef _DEBUG                                          log_debug("Ignore %d bytes of incomplete UTF8 character", str_len);
                                         log_error("Ignore %d bytes of incomplete UTF8 character\n", str_len);  
 #endif  
552                                          str_len = 0;                                          str_len = 0;
553                                          break;                                          break;
554                                  }                                  }
555                          }                          }
556                            input_str[str_len] = '\0';
557    
558                          if (str_len == 0) // Incomplete input                          if (str_len == 0) // Incomplete input
559                          {                          {
560                                  continue;                                  continue;
561                          }                          }
562    
563                          if (len + 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)
564                            {
565                                    log_error("mbstowcs() error");
566                            }
567                            wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0]));
568    
569                            if (len + str_len > buf_size - 1 ||
570                                    display_len + wc_len > max_display_len) // No enough space for Chinese character
571                          {                          {
572                                  outc('\a');                                  outc('\a');
573                                  iflush();                                  iflush();
# Line 524  int get_data(int row, int col, char *pro Line 578  int get_data(int row, int col, char *pro
578                          memcpy(buffer + offset, input_str, (size_t)str_len);                          memcpy(buffer + offset, input_str, (size_t)str_len);
579                          len += str_len;                          len += str_len;
580                          buffer[len] = '\0';                          buffer[len] = '\0';
581                          display_len += 2;                          display_len += wc_len;
582    
583                          moveto(row, col_cur);                          moveto(row, col_cur);
584                          prints("%s", buffer + offset);                          prints("%s", buffer + offset);
585                          prints("%*s", max_display_len - display_len, "");                          prints("%*s", max_display_len - display_len, "");
586    
587                          col_cur += 2;                          col_cur += wc_len;
588    
589                          moveto(row, col_cur);                          moveto(row, col_cur);
590                          iflush();                          iflush();
# Line 601  int display_data(const void *p_data, lon Line 655  int display_data(const void *p_data, lon
655          loop = 1;          loop = 1;
656          while (!SYS_server_exit && loop)          while (!SYS_server_exit && loop)
657          {          {
658                  if (eof_exit > 0 && line_current >= display_line_total && display_line_total <= screen_row_total)                  if (eof_exit > 0 && line_current >= display_line_total)
659                  {                  {
660                          if (eof_exit == 1)                          if (eof_exit == 1)
661                          {                          {
# Line 656  int display_data(const void *p_data, lon Line 710  int display_data(const void *p_data, lon
710                          input_ok = 0;                          input_ok = 0;
711                          while (!SYS_server_exit && !input_ok)                          while (!SYS_server_exit && !input_ok)
712                          {                          {
713                                  ch = igetch_t(MAX_DELAY_TIME);                                  ch = igetch_t(BBS_max_user_idle_time);
714                                  input_ok = 1;                                  input_ok = 1;
715    
716                                  if (ch != KEY_NULL && ch != KEY_TIMEOUT)                                  if (ch != KEY_NULL && ch != KEY_TIMEOUT)
717                                  {                                  {
718                                          BBS_last_access_tm = time(NULL);                                          BBS_last_access_tm = time(NULL);
719    
720                                            // Refresh current action
721                                            if (user_online_update(NULL) < 0)
722                                            {
723                                                    log_error("user_online_update(NULL) error");
724                                            }
725                                  }                                  }
726    
727                                  // extended key handler                                  // extended key handler
# Line 673  int display_data(const void *p_data, lon Line 733  int display_data(const void *p_data, lon
733                                  switch (ch)                                  switch (ch)
734                                  {                                  {
735                                  case KEY_NULL:                                  case KEY_NULL:
736                                          log_error("KEY_NULL\n");                                          log_debug("KEY_NULL");
737                                          goto cleanup;                                          goto cleanup;
738                                  case KEY_TIMEOUT:                                  case KEY_TIMEOUT:
739                                          log_error("User input timeout\n");                                          log_debug("User input timeout");
740                                          goto cleanup;                                          goto cleanup;
741                                  case KEY_HOME:                                  case KEY_HOME:
742                                          if (line_current - output_current_row < 0) // Reach begin                                          if (line_current - output_current_row < 0) // Reach begin
# Line 710  int display_data(const void *p_data, lon Line 770  int display_data(const void *p_data, lon
770                                          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
771                                          break;                                          break;
772                                  case CR:                                  case CR:
                                 case KEY_SPACE:  
773                                  case KEY_DOWN:                                  case KEY_DOWN:
774                                          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
775                                          {                                          {
# Line 738  int display_data(const void *p_data, lon Line 797  int display_data(const void *p_data, lon
797                                          output_end_row = SCREEN_ROWS - 1;                                          output_end_row = SCREEN_ROWS - 1;
798                                          clrline(output_current_row, SCREEN_ROWS);                                          clrline(output_current_row, SCREEN_ROWS);
799                                          break;                                          break;
800                                    case KEY_SPACE:
801                                  case KEY_PGDN:                                  case KEY_PGDN:
802                                          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
803                                          {                                          {
# Line 786  int display_data(const void *p_data, lon Line 846  int display_data(const void *p_data, lon
846                  len = p_line_offsets[line_current + 1] - p_line_offsets[line_current];                  len = p_line_offsets[line_current + 1] - p_line_offsets[line_current];
847                  if (len >= sizeof(buffer))                  if (len >= sizeof(buffer))
848                  {                  {
849                          log_error("Buffer overflow: len=%ld(%ld - %ld) line=%ld \n",                          log_error("Buffer overflow: len=%ld(%ld - %ld) line=%ld ",
850                                            len, p_line_offsets[line_current + 1], p_line_offsets[line_current], line_current);                                            len, p_line_offsets[line_current + 1], p_line_offsets[line_current], line_current);
851                          len = sizeof(buffer) - 1;                          len = sizeof(buffer) - 1;
852                  }                  }
853                  else if (len < 0)                  else if (len < 0)
854                  {                  {
855                          log_error("Incorrect line offsets: len=%ld(%ld - %ld) line=%ld \n",                          log_error("Incorrect line offsets: len=%ld(%ld - %ld) line=%ld ",
856                                            len, p_line_offsets[line_current + 1], p_line_offsets[line_current], line_current);                                            len, p_line_offsets[line_current + 1], p_line_offsets[line_current], line_current);
857                          len = 0;                          len = 0;
858                  }                  }
# Line 811  cleanup: Line 871  cleanup:
871          return ch;          return ch;
872  }  }
873    
874  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)
875  {  {
876          switch (*p_key)          switch (*p_key)
877          {          {
# Line 829  static int display_file_key_handler(int Line 889  static int display_file_key_handler(int
889  int display_file(const char *filename, int eof_exit)  int display_file(const char *filename, int eof_exit)
890  {  {
891          int ret;          int ret;
892          const void *p_shm;          void *p_shm;
893          size_t data_len;          size_t data_len;
894          long line_total;          long line_total;
895          const void *p_data;          const void *p_data;
# Line 837  int display_file(const char *filename, i Line 897  int display_file(const char *filename, i
897    
898          if ((p_shm = get_file_shm_readonly(filename, &data_len, &line_total, &p_data, &p_line_offsets)) == NULL)          if ((p_shm = get_file_shm_readonly(filename, &data_len, &line_total, &p_data, &p_line_offsets)) == NULL)
899          {          {
900                  log_error("get_file_shm(%s) error\n", filename);                  log_error("get_file_shm(%s) error", filename);
901                  return KEY_NULL;                  return KEY_NULL;
902          }          }
903    
904          if (user_online_update("VIEW_FILE") < 0)          if (user_online_update("VIEW_FILE") < 0)
905          {          {
906                  log_error("user_online_update(VIEW_FILE) error\n");                  log_error("user_online_update(VIEW_FILE) error");
907          }          }
908    
909          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);
910    
911          if (detach_file_shm(p_shm) < 0)          if (detach_file_shm(p_shm) < 0)
912          {          {
913                  log_error("detach_file_shm(%s) error\n", filename);                  log_error("detach_file_shm(%s) error", filename);
914          }          }
915    
916          return ret;          return ret;
# Line 894  int show_top(const char *str_left, const Line 954  int show_top(const char *str_left, const
954  int show_bottom(const char *msg)  int show_bottom(const char *msg)
955  {  {
956          char str_time[LINE_BUFFER_LEN];          char str_time[LINE_BUFFER_LEN];
957            int len_str_time;
958          time_t time_online;          time_t time_online;
959          struct tm *tm_online;          struct tm *tm_online;
960          char msg_f[LINE_BUFFER_LEN];          char msg_f[LINE_BUFFER_LEN];
961          int eol;          int eol;
962          int msg_len;          int len_msg;
963          int len;          int len;
964          int len_username;          int len_username;
965          char str_tm_online[LINE_BUFFER_LEN];          char str_tm_online[LINE_BUFFER_LEN];
966            int len_str_tm_online;
967    
968          get_time_str(str_time, sizeof(str_time));          len_str_time = (int)get_time_str(str_time, sizeof(str_time));
969    
970          msg_f[0] = '\0';          msg_f[0] = '\0';
971          msg_len = 0;          len_msg = 0;
972          if (msg != NULL)          if (msg != NULL)
973          {          {
974                  strncpy(msg_f, msg, sizeof(msg_f) - 1);                  strncpy(msg_f, msg, sizeof(msg_f) - 1);
975                  msg_f[sizeof(msg_f) - 1] = '\0';                  msg_f[sizeof(msg_f) - 1] = '\0';
976                  len = split_line(msg_f, 23, &eol, &msg_len, 1);                  len = split_line(msg_f, 23, &eol, &len_msg, 1);
977                  msg_f[len] = '\0';                  msg_f[len] = '\0';
978          }          }
979    
# Line 922  int show_bottom(const char *msg) Line 984  int show_bottom(const char *msg)
984          if (tm_online->tm_mday > 1)          if (tm_online->tm_mday > 1)
985          {          {
986                  snprintf(str_tm_online, sizeof(str_tm_online),                  snprintf(str_tm_online, sizeof(str_tm_online),
987                                   "\033[36m%2d\033[33m天\033[36m%2d\033[33m时",                                   "\033[36m%d\033[33md \033[36m%d\033[33m:\033[36m%.2d",
988                                   tm_online->tm_mday - 1, tm_online->tm_hour);                                   tm_online->tm_mday - 1, tm_online->tm_hour, tm_online->tm_min);
989          }          }
990          else          else
991          {          {
992                  snprintf(str_tm_online, sizeof(str_tm_online),                  snprintf(str_tm_online, sizeof(str_tm_online),
993                                   "\033[36m%2d\033[33m时\033[36m%2d\033[33m分",                                   "\033[36m%d\033[33m:\033[36m%.2d",
994                                   tm_online->tm_hour, tm_online->tm_min);                                   tm_online->tm_hour, tm_online->tm_min);
995          }          }
996            len_str_tm_online = str_length(str_tm_online, 1);
997    
998          moveto(SCREEN_ROWS, 0);          moveto(SCREEN_ROWS, 0);
999          clrtoeol();          clrtoeol();
1000          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",
1001                     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,
1002                       "", BBS_username, str_tm_online);
1003    
1004          return 0;          return 0;
1005  }  }
# Line 959  int show_active_board() Line 1023  int show_active_board()
1023          {          {
1024                  if ((p_shm = get_file_shm_readonly(DATA_ACTIVE_BOARD, &data_len, &line_total, &p_data, &p_line_offsets)) == NULL)                  if ((p_shm = get_file_shm_readonly(DATA_ACTIVE_BOARD, &data_len, &line_total, &p_data, &p_line_offsets)) == NULL)
1025                  {                  {
1026                          log_error("get_file_shm(%s) error\n", DATA_ACTIVE_BOARD);                          log_error("get_file_shm(%s) error", DATA_ACTIVE_BOARD);
1027                          return KEY_NULL;                          return KEY_NULL;
1028                  }                  }
1029          }          }
# Line 981  int show_active_board() Line 1045  int show_active_board()
1045                  len = p_line_offsets[line_current + 1] - p_line_offsets[line_current];                  len = p_line_offsets[line_current + 1] - p_line_offsets[line_current];
1046                  if (len >= LINE_BUFFER_LEN)                  if (len >= LINE_BUFFER_LEN)
1047                  {                  {
1048                          log_error("buffer overflow: len=%ld(%ld - %ld) line=%ld \n",                          log_error("buffer overflow: len=%ld(%ld - %ld) line=%ld ",
1049                                            len, p_line_offsets[line_current + 1], p_line_offsets[line_current], line_current);                                            len, p_line_offsets[line_current + 1], p_line_offsets[line_current], line_current);
1050                          len = LINE_BUFFER_LEN - 1;                          len = LINE_BUFFER_LEN - 1;
1051                  }                  }


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

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