| 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" |
| 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; |
|
|
} |
|
|
|
|
|
strncat(s, weekday[local_tm.tm_wday], len - 1 - j); |
|
| 49 |
|
|
| 50 |
return s; |
return j; |
| 51 |
} |
} |
| 52 |
|
|
| 53 |
void moveto(int row, int col) |
void moveto(int row, int col) |
| 88 |
void clearscr() |
void clearscr() |
| 89 |
{ |
{ |
| 90 |
prints("\033[2J"); |
prints("\033[2J"); |
| 91 |
moveto(0, 0); |
moveto(1, 1); |
| 92 |
} |
} |
| 93 |
|
|
| 94 |
inline int press_any_key() |
inline int press_any_key() |
| 95 |
{ |
{ |
| 96 |
return press_any_key_ex(" \033[1;33m按任意键继续...\033[m"); |
return press_any_key_ex(" \033[1;33m按任意键继续...\033[m", 60); |
| 97 |
} |
} |
| 98 |
|
|
| 99 |
int press_any_key_ex(const char *msg) |
int press_any_key_ex(const char *msg, int sec) |
| 100 |
{ |
{ |
|
int ch = 0; |
|
|
int wait_seconds = 60; |
|
|
int duration = 0; |
|
|
time_t t_begin = time(NULL); |
|
|
|
|
| 101 |
moveto(SCREEN_ROWS, 0); |
moveto(SCREEN_ROWS, 0); |
| 102 |
clrtoeol(); |
clrtoeol(); |
| 103 |
|
|
| 104 |
prints(msg); |
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 |
|
|
| 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'; |
| 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 |
{ |
{ |
| 170 |
{ |
{ |
| 171 |
continue; |
continue; |
| 172 |
} |
} |
| 173 |
else if (ch == BACKSPACE) |
else if (ch == BACKSPACE || ch == KEY_DEL) |
| 174 |
{ |
{ |
| 175 |
if (offset > 0) |
if (offset > 0) |
| 176 |
{ |
{ |
| 177 |
offset--; |
offset--; |
| 178 |
if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8 |
if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8 |
| 179 |
{ |
{ |
| 180 |
while (offset > 0 && (buffer[offset] & 0b11000000) != 0b11000000) |
while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0) |
| 181 |
{ |
{ |
| 182 |
offset--; |
offset--; |
| 183 |
} |
} |
| 198 |
else if ((ch & 0xff80) == 0x80) // head of multi-byte character |
else if ((ch & 0xff80) == 0x80) // head of multi-byte character |
| 199 |
{ |
{ |
| 200 |
str_len = 0; |
str_len = 0; |
| 201 |
c = (char)(ch & 0b11110000); |
c = (char)(ch & 0xf0); |
| 202 |
while (c & 0b10000000) |
while (c & 0x80) |
| 203 |
{ |
{ |
| 204 |
input_str[str_len] = (char)(ch - 256); |
input_str[str_len] = (char)(ch - 256); |
| 205 |
str_len++; |
str_len++; |
| 206 |
c = (c & 0b01111111) << 1; |
c = (c & 0x7f) << 1; |
| 207 |
|
|
| 208 |
if ((c & 0b10000000) == 0) // Input completed |
if ((c & 0x80) == 0) // Input completed |
| 209 |
{ |
{ |
| 210 |
break; |
break; |
| 211 |
} |
} |
| 214 |
ch = igetch(100); // 0.1 second |
ch = igetch(100); // 0.1 second |
| 215 |
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 |
| 216 |
{ |
{ |
| 217 |
#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 |
|
| 218 |
str_len = 0; |
str_len = 0; |
| 219 |
break; |
break; |
| 220 |
} |
} |
| 221 |
} |
} |
| 222 |
|
input_str[str_len] = '\0'; |
| 223 |
|
|
| 224 |
if (str_len == 0) // Incomplete input |
if (str_len == 0) // Incomplete input |
| 225 |
{ |
{ |
| 226 |
continue; |
continue; |
| 227 |
} |
} |
| 228 |
|
|
| 229 |
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) |
| 230 |
|
{ |
| 231 |
|
log_error("mbstowcs() error"); |
| 232 |
|
} |
| 233 |
|
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 |
| 234 |
{ |
{ |
| 235 |
outc('\a'); |
outc('\a'); |
| 236 |
iflush(); |
iflush(); |
| 286 |
return offset; |
return offset; |
| 287 |
} |
} |
| 288 |
|
|
| 289 |
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) |
| 290 |
{ |
{ |
| 291 |
int len; |
int len; |
| 292 |
|
|
| 298 |
iflush(); |
iflush(); |
| 299 |
|
|
| 300 |
return len; |
return len; |
| 301 |
}; |
} |
| 302 |
|
|
| 303 |
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) |
| 304 |
{ |
{ |
| 308 |
int offset = 0; |
int offset = 0; |
| 309 |
int eol; |
int eol; |
| 310 |
int display_len; |
int display_len; |
| 311 |
char input_str[4]; |
char input_str[5]; |
| 312 |
int str_len = 0; |
int str_len = 0; |
| 313 |
|
wchar_t wcs[2]; |
| 314 |
|
int wc_len; |
| 315 |
char c; |
char c; |
| 316 |
|
|
| 317 |
buffer[buf_size - 1] = '\0'; |
buffer[buf_size - 1] = '\0'; |
| 331 |
|
|
| 332 |
while (!SYS_server_exit) |
while (!SYS_server_exit) |
| 333 |
{ |
{ |
| 334 |
ch = igetch_t(MIN(MAX_DELAY_TIME, 60)); |
ch = igetch_t(MIN(BBS_max_user_idle_time, 60)); |
| 335 |
|
|
| 336 |
if (ch == CR) |
if (ch == CR) |
| 337 |
{ |
{ |
| 353 |
offset--; |
offset--; |
| 354 |
if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8 |
if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8 |
| 355 |
{ |
{ |
| 356 |
while (offset > 0 && (buffer[offset] & 0b11000000) != 0b11000000) |
while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0) |
| 357 |
{ |
{ |
| 358 |
str_len++; |
str_len++; |
| 359 |
offset--; |
offset--; |
| 360 |
} |
} |
| 361 |
display_len--; |
|
| 362 |
col_cur--; |
if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1) |
| 363 |
|
{ |
| 364 |
|
log_error("mbstowcs() error"); |
| 365 |
|
} |
| 366 |
|
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
| 367 |
|
|
| 368 |
|
if (wc_len == 2) |
| 369 |
|
{ |
| 370 |
|
display_len--; |
| 371 |
|
col_cur--; |
| 372 |
|
} |
| 373 |
} |
} |
| 374 |
|
|
| 375 |
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)); |
| 393 |
if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character |
if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character |
| 394 |
{ |
{ |
| 395 |
str_len = 0; |
str_len = 0; |
| 396 |
c = (char)(buffer[offset] & 0b11110000); |
c = (char)(buffer[offset] & 0xf0); |
| 397 |
while (c & 0b10000000) |
while (c & 0x80) |
| 398 |
{ |
{ |
| 399 |
str_len++; |
str_len++; |
| 400 |
c = (c & 0b01111111) << 1; |
c = (c & 0x7f) << 1; |
| 401 |
} |
} |
| 402 |
display_len--; |
display_len--; |
| 403 |
} |
} |
| 427 |
offset--; |
offset--; |
| 428 |
if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8 |
if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8 |
| 429 |
{ |
{ |
| 430 |
while (offset > 0 && (buffer[offset] & 0b11000000) != 0b11000000) |
while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0) |
| 431 |
{ |
{ |
| 432 |
str_len++; |
str_len++; |
| 433 |
offset--; |
offset--; |
| 434 |
} |
} |
| 435 |
col_cur--; |
|
| 436 |
|
if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1) |
| 437 |
|
{ |
| 438 |
|
log_error("mbstowcs() error"); |
| 439 |
|
} |
| 440 |
|
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
| 441 |
|
|
| 442 |
|
if (wc_len == 2) |
| 443 |
|
{ |
| 444 |
|
col_cur--; |
| 445 |
|
} |
| 446 |
} |
} |
| 447 |
col_cur--; |
col_cur--; |
| 448 |
|
|
| 458 |
str_len = 0; |
str_len = 0; |
| 459 |
if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character |
if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character |
| 460 |
{ |
{ |
| 461 |
c = (char)(buffer[offset] & 0b11110000); |
c = (char)(buffer[offset] & 0xf0); |
| 462 |
while (c & 0b10000000) |
while (c & 0x80) |
| 463 |
{ |
{ |
| 464 |
str_len++; |
str_len++; |
| 465 |
c = (c & 0b01111111) << 1; |
c = (c & 0x7f) << 1; |
| 466 |
|
} |
| 467 |
|
|
| 468 |
|
if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1) |
| 469 |
|
{ |
| 470 |
|
log_error("mbstowcs() error"); |
| 471 |
|
} |
| 472 |
|
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
| 473 |
|
|
| 474 |
|
if (wc_len == 2) |
| 475 |
|
{ |
| 476 |
|
col_cur++; |
| 477 |
} |
} |
|
col_cur++; |
|
| 478 |
} |
} |
| 479 |
else |
else |
| 480 |
{ |
{ |
| 520 |
else if ((ch & 0xff80) == 0x80) // head of multi-byte character |
else if ((ch & 0xff80) == 0x80) // head of multi-byte character |
| 521 |
{ |
{ |
| 522 |
str_len = 0; |
str_len = 0; |
| 523 |
c = (char)(ch & 0b11110000); |
c = (char)(ch & 0xf0); |
| 524 |
while (c & 0b10000000) |
while (c & 0x80) |
| 525 |
{ |
{ |
| 526 |
input_str[str_len] = (char)(ch - 256); |
input_str[str_len] = (char)(ch - 256); |
| 527 |
str_len++; |
str_len++; |
| 528 |
c = (c & 0b01111111) << 1; |
c = (c & 0x7f) << 1; |
| 529 |
|
|
| 530 |
if ((c & 0b10000000) == 0) // Input completed |
if ((c & 0x80) == 0) // Input completed |
| 531 |
{ |
{ |
| 532 |
break; |
break; |
| 533 |
} |
} |
| 536 |
ch = igetch(100); // 0.1 second |
ch = igetch(100); // 0.1 second |
| 537 |
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 |
| 538 |
{ |
{ |
| 539 |
#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 |
|
| 540 |
str_len = 0; |
str_len = 0; |
| 541 |
break; |
break; |
| 542 |
} |
} |
| 543 |
} |
} |
| 544 |
|
input_str[str_len] = '\0'; |
| 545 |
|
|
| 546 |
if (str_len == 0) // Incomplete input |
if (str_len == 0) // Incomplete input |
| 547 |
{ |
{ |
| 548 |
continue; |
continue; |
| 549 |
} |
} |
| 550 |
|
|
| 551 |
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) |
| 552 |
|
{ |
| 553 |
|
log_error("mbstowcs() error"); |
| 554 |
|
} |
| 555 |
|
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
| 556 |
|
|
| 557 |
|
if (len + str_len > buf_size - 1 || |
| 558 |
|
display_len + wc_len > max_display_len) // No enough space for Chinese character |
| 559 |
{ |
{ |
| 560 |
outc('\a'); |
outc('\a'); |
| 561 |
iflush(); |
iflush(); |
| 566 |
memcpy(buffer + offset, input_str, (size_t)str_len); |
memcpy(buffer + offset, input_str, (size_t)str_len); |
| 567 |
len += str_len; |
len += str_len; |
| 568 |
buffer[len] = '\0'; |
buffer[len] = '\0'; |
| 569 |
display_len += 2; |
display_len += wc_len; |
| 570 |
|
|
| 571 |
moveto(row, col_cur); |
moveto(row, col_cur); |
| 572 |
prints("%s", buffer + offset); |
prints("%s", buffer + offset); |
| 573 |
prints("%*s", max_display_len - display_len, ""); |
prints("%*s", max_display_len - display_len, ""); |
| 574 |
|
|
| 575 |
col_cur += 2; |
col_cur += wc_len; |
| 576 |
|
|
| 577 |
moveto(row, col_cur); |
moveto(row, col_cur); |
| 578 |
iflush(); |
iflush(); |
| 643 |
loop = 1; |
loop = 1; |
| 644 |
while (!SYS_server_exit && loop) |
while (!SYS_server_exit && loop) |
| 645 |
{ |
{ |
| 646 |
if (eof_exit > 0 && line_current >= display_line_total && display_line_total <= screen_row_total) |
if (eof_exit > 0 && line_current >= display_line_total) |
| 647 |
{ |
{ |
| 648 |
if (eof_exit == 1) |
if (eof_exit == 1) |
| 649 |
{ |
{ |
| 698 |
input_ok = 0; |
input_ok = 0; |
| 699 |
while (!SYS_server_exit && !input_ok) |
while (!SYS_server_exit && !input_ok) |
| 700 |
{ |
{ |
| 701 |
ch = igetch_t(MAX_DELAY_TIME); |
ch = igetch_t(BBS_max_user_idle_time); |
| 702 |
input_ok = 1; |
input_ok = 1; |
| 703 |
|
|
| 704 |
if (ch != KEY_NULL && ch != KEY_TIMEOUT) |
if (ch != KEY_NULL && ch != KEY_TIMEOUT) |
| 705 |
{ |
{ |
| 706 |
BBS_last_access_tm = time(NULL); |
BBS_last_access_tm = time(NULL); |
| 707 |
|
|
| 708 |
|
// Refresh current action |
| 709 |
|
if (user_online_update(NULL) < 0) |
| 710 |
|
{ |
| 711 |
|
log_error("user_online_update(NULL) error"); |
| 712 |
|
} |
| 713 |
} |
} |
| 714 |
|
|
| 715 |
// extended key handler |
// extended key handler |
| 721 |
switch (ch) |
switch (ch) |
| 722 |
{ |
{ |
| 723 |
case KEY_NULL: |
case KEY_NULL: |
| 724 |
log_error("KEY_NULL\n"); |
log_debug("KEY_NULL"); |
| 725 |
goto cleanup; |
goto cleanup; |
| 726 |
case KEY_TIMEOUT: |
case KEY_TIMEOUT: |
| 727 |
log_error("User input timeout\n"); |
log_debug("User input timeout"); |
| 728 |
goto cleanup; |
goto cleanup; |
| 729 |
case KEY_HOME: |
case KEY_HOME: |
| 730 |
if (line_current - output_current_row < 0) // Reach begin |
if (line_current - output_current_row < 0) // Reach begin |
| 758 |
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 |
| 759 |
break; |
break; |
| 760 |
case CR: |
case CR: |
|
case KEY_SPACE: |
|
| 761 |
case KEY_DOWN: |
case KEY_DOWN: |
| 762 |
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 |
| 763 |
{ |
{ |
| 785 |
output_end_row = SCREEN_ROWS - 1; |
output_end_row = SCREEN_ROWS - 1; |
| 786 |
clrline(output_current_row, SCREEN_ROWS); |
clrline(output_current_row, SCREEN_ROWS); |
| 787 |
break; |
break; |
| 788 |
|
case KEY_SPACE: |
| 789 |
case KEY_PGDN: |
case KEY_PGDN: |
| 790 |
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 |
| 791 |
{ |
{ |
| 834 |
len = p_line_offsets[line_current + 1] - p_line_offsets[line_current]; |
len = p_line_offsets[line_current + 1] - p_line_offsets[line_current]; |
| 835 |
if (len >= sizeof(buffer)) |
if (len >= sizeof(buffer)) |
| 836 |
{ |
{ |
| 837 |
log_error("Buffer overflow: len=%ld(%ld - %ld) line=%ld \n", |
log_error("Buffer overflow: len=%ld(%ld - %ld) line=%ld ", |
| 838 |
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); |
| 839 |
len = sizeof(buffer) - 1; |
len = sizeof(buffer) - 1; |
| 840 |
} |
} |
| 841 |
else if (len < 0) |
else if (len < 0) |
| 842 |
{ |
{ |
| 843 |
log_error("Incorrect line offsets: len=%ld(%ld - %ld) line=%ld \n", |
log_error("Incorrect line offsets: len=%ld(%ld - %ld) line=%ld ", |
| 844 |
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); |
| 845 |
len = 0; |
len = 0; |
| 846 |
} |
} |
| 859 |
return ch; |
return ch; |
| 860 |
} |
} |
| 861 |
|
|
| 862 |
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) |
| 863 |
{ |
{ |
| 864 |
switch (*p_key) |
switch (*p_key) |
| 865 |
{ |
{ |
| 877 |
int display_file(const char *filename, int eof_exit) |
int display_file(const char *filename, int eof_exit) |
| 878 |
{ |
{ |
| 879 |
int ret; |
int ret; |
| 880 |
const void *p_shm; |
void *p_shm; |
| 881 |
size_t data_len; |
size_t data_len; |
| 882 |
long line_total; |
long line_total; |
| 883 |
const void *p_data; |
const void *p_data; |
| 885 |
|
|
| 886 |
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) |
| 887 |
{ |
{ |
| 888 |
log_error("get_file_shm(%s) error\n", filename); |
log_error("get_file_shm(%s) error", filename); |
| 889 |
return KEY_NULL; |
return KEY_NULL; |
| 890 |
} |
} |
| 891 |
|
|
| 892 |
if (user_online_update("VIEW_FILE") < 0) |
if (user_online_update("VIEW_FILE") < 0) |
| 893 |
{ |
{ |
| 894 |
log_error("user_online_update(VIEW_FILE) error\n"); |
log_error("user_online_update(VIEW_FILE) error"); |
| 895 |
} |
} |
| 896 |
|
|
| 897 |
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); |
| 898 |
|
|
| 899 |
if (detach_file_shm(p_shm) < 0) |
if (detach_file_shm(p_shm) < 0) |
| 900 |
{ |
{ |
| 901 |
log_error("detach_file_shm(%s) error\n", filename); |
log_error("detach_file_shm(%s) error", filename); |
| 902 |
} |
} |
| 903 |
|
|
| 904 |
return ret; |
return ret; |
| 942 |
int show_bottom(const char *msg) |
int show_bottom(const char *msg) |
| 943 |
{ |
{ |
| 944 |
char str_time[LINE_BUFFER_LEN]; |
char str_time[LINE_BUFFER_LEN]; |
| 945 |
|
int len_str_time; |
| 946 |
time_t time_online; |
time_t time_online; |
| 947 |
struct tm *tm_online; |
struct tm *tm_online; |
| 948 |
char msg_f[LINE_BUFFER_LEN]; |
char msg_f[LINE_BUFFER_LEN]; |
| 949 |
int eol; |
int eol; |
| 950 |
int msg_len; |
int len_msg; |
| 951 |
int len; |
int len; |
| 952 |
int len_username; |
int len_username; |
| 953 |
char str_tm_online[LINE_BUFFER_LEN]; |
char str_tm_online[LINE_BUFFER_LEN]; |
| 954 |
|
int len_str_tm_online; |
| 955 |
|
|
| 956 |
get_time_str(str_time, sizeof(str_time)); |
len_str_time = (int)get_time_str(str_time, sizeof(str_time)); |
| 957 |
|
|
| 958 |
msg_f[0] = '\0'; |
msg_f[0] = '\0'; |
| 959 |
msg_len = 0; |
len_msg = 0; |
| 960 |
if (msg != NULL) |
if (msg != NULL) |
| 961 |
{ |
{ |
| 962 |
strncpy(msg_f, msg, sizeof(msg_f) - 1); |
strncpy(msg_f, msg, sizeof(msg_f) - 1); |
| 963 |
msg_f[sizeof(msg_f) - 1] = '\0'; |
msg_f[sizeof(msg_f) - 1] = '\0'; |
| 964 |
len = split_line(msg_f, 23, &eol, &msg_len, 1); |
len = split_line(msg_f, 23, &eol, &len_msg, 1); |
| 965 |
msg_f[len] = '\0'; |
msg_f[len] = '\0'; |
| 966 |
} |
} |
| 967 |
|
|
| 972 |
if (tm_online->tm_mday > 1) |
if (tm_online->tm_mday > 1) |
| 973 |
{ |
{ |
| 974 |
snprintf(str_tm_online, sizeof(str_tm_online), |
snprintf(str_tm_online, sizeof(str_tm_online), |
| 975 |
"\033[36m%2d\033[33m天\033[36m%2d\033[33m时", |
"\033[36m%d\033[33md \033[36m%d\033[33m:\033[36m%.2d", |
| 976 |
tm_online->tm_mday - 1, tm_online->tm_hour); |
tm_online->tm_mday - 1, tm_online->tm_hour, tm_online->tm_min); |
| 977 |
} |
} |
| 978 |
else |
else |
| 979 |
{ |
{ |
| 980 |
snprintf(str_tm_online, sizeof(str_tm_online), |
snprintf(str_tm_online, sizeof(str_tm_online), |
| 981 |
"\033[36m%2d\033[33m时\033[36m%2d\033[33m分", |
"\033[36m%d\033[33m:\033[36m%.2d", |
| 982 |
tm_online->tm_hour, tm_online->tm_min); |
tm_online->tm_hour, tm_online->tm_min); |
| 983 |
} |
} |
| 984 |
|
len_str_tm_online = str_length(str_tm_online, 1); |
| 985 |
|
|
| 986 |
moveto(SCREEN_ROWS, 0); |
moveto(SCREEN_ROWS, 0); |
| 987 |
clrtoeol(); |
clrtoeol(); |
| 988 |
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", |
| 989 |
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, |
| 990 |
|
"", BBS_username, str_tm_online); |
| 991 |
|
|
| 992 |
return 0; |
return 0; |
| 993 |
} |
} |
| 1011 |
{ |
{ |
| 1012 |
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) |
| 1013 |
{ |
{ |
| 1014 |
log_error("get_file_shm(%s) error\n", DATA_ACTIVE_BOARD); |
log_error("get_file_shm(%s) error", DATA_ACTIVE_BOARD); |
| 1015 |
return KEY_NULL; |
return KEY_NULL; |
| 1016 |
} |
} |
| 1017 |
} |
} |
| 1033 |
len = p_line_offsets[line_current + 1] - p_line_offsets[line_current]; |
len = p_line_offsets[line_current + 1] - p_line_offsets[line_current]; |
| 1034 |
if (len >= LINE_BUFFER_LEN) |
if (len >= LINE_BUFFER_LEN) |
| 1035 |
{ |
{ |
| 1036 |
log_error("buffer overflow: len=%ld(%ld - %ld) line=%ld \n", |
log_error("buffer overflow: len=%ld(%ld - %ld) line=%ld ", |
| 1037 |
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); |
| 1038 |
len = LINE_BUFFER_LEN - 1; |
len = LINE_BUFFER_LEN - 1; |
| 1039 |
} |
} |