| 1 |
/*************************************************************************** |
/*************************************************************************** |
| 2 |
screen.c - description |
screen.c - description |
| 3 |
------------------- |
------------------- |
| 4 |
begin : Mon Oct 18 2004 |
Copyright : (C) 2004-2025 by Leaflet |
| 5 |
copyright : (C) 2004 by Leaflet |
Email : leaflet@leafok.com |
|
email : leaflet@leafok.com |
|
| 6 |
***************************************************************************/ |
***************************************************************************/ |
| 7 |
|
|
| 8 |
/*************************************************************************** |
/*************************************************************************** |
| 9 |
* * |
* * |
| 10 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
| 11 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
| 12 |
* the Free Software Foundation; either version 2 of the License, or * |
* the Free Software Foundation; either version 3 of the License, or * |
| 13 |
* (at your option) any later version. * |
* (at your option) any later version. * |
| 14 |
* * |
* * |
| 15 |
***************************************************************************/ |
***************************************************************************/ |
| 125 |
{ |
{ |
| 126 |
if (offset > 0) |
if (offset > 0) |
| 127 |
{ |
{ |
| 128 |
buffer[--offset] = '\0'; |
offset--; |
| 129 |
prints("\b \b"); |
if (buffer[offset] < 0 || buffer[offset] > 127) |
| 130 |
// clrtoeol (); |
{ |
| 131 |
|
prints("\033[D \033[D"); |
| 132 |
|
offset--; |
| 133 |
|
if (offset < 0) // should not happen |
| 134 |
|
{ |
| 135 |
|
log_error("Offset of buffer is negative\n"); |
| 136 |
|
offset = 0; |
| 137 |
|
} |
| 138 |
|
} |
| 139 |
|
buffer[offset] = '\0'; |
| 140 |
|
prints("\033[D \033[D"); |
| 141 |
iflush(); |
iflush(); |
| 142 |
} |
} |
| 143 |
continue; |
continue; |
| 148 |
} |
} |
| 149 |
if (c > 127 && c <= 255) |
if (c > 127 && c <= 255) |
| 150 |
{ |
{ |
| 151 |
|
if (!hz && offset + 2 > buffer_length) // No enough space for Chinese character |
| 152 |
|
{ |
| 153 |
|
igetch(1); // Cleanup remaining input |
| 154 |
|
outc('\a'); |
| 155 |
|
iflush(); |
| 156 |
|
continue; |
| 157 |
|
} |
| 158 |
hz = (!hz); |
hz = (!hz); |
| 159 |
} |
} |
| 160 |
if (offset >= buffer_length) |
if (offset >= buffer_length) |
| 161 |
{ |
{ |
| 162 |
outc('\a'); |
outc('\a'); |
| 163 |
|
iflush(); |
| 164 |
continue; |
continue; |
| 165 |
} |
} |
| 166 |
buffer[offset++] = (char)c; |
buffer[offset++] = (char)c; |
| 180 |
} |
} |
| 181 |
} |
} |
| 182 |
|
|
|
prints("\r\n"); |
|
|
iflush(); |
|
|
|
|
| 183 |
return offset; |
return offset; |
| 184 |
} |
} |
| 185 |
|
|
| 186 |
int str_input(char *buffer, int buffer_length, int echo_mode) |
int str_input(char *buffer, int buffer_length, int echo_mode) |
| 187 |
{ |
{ |
| 188 |
int offset; |
int len; |
| 189 |
|
|
| 190 |
|
buffer[0] = '\0'; |
| 191 |
|
|
| 192 |
memset(buffer, '\0', buffer_length); |
len = _str_input(buffer, buffer_length, echo_mode); |
| 193 |
|
|
| 194 |
offset = _str_input(buffer, buffer_length, echo_mode); |
prints("\r\n"); |
| 195 |
|
iflush(); |
| 196 |
|
|
| 197 |
return offset; |
return len; |
| 198 |
}; |
}; |
| 199 |
|
|
| 200 |
int get_data(int row, int col, char *prompt, char *buffer, int buffer_length, int echo_mode) |
int get_data(int row, int col, char *prompt, char *buffer, int buffer_length, int echo_mode) |
| 201 |
{ |
{ |
| 202 |
int len; |
int len; |
| 203 |
|
|
| 204 |
|
igetch(1); // Cleanup input buffer |
| 205 |
|
|
| 206 |
moveto(row, col); |
moveto(row, col); |
| 207 |
prints(prompt); |
prints(prompt); |
| 208 |
prints(buffer); |
prints(buffer); |
| 217 |
{ |
{ |
| 218 |
char buffer[LINE_BUFFER_LEN]; |
char buffer[LINE_BUFFER_LEN]; |
| 219 |
FILE *fin; |
FILE *fin; |
| 220 |
int i; |
size_t i; |
| 221 |
|
|
| 222 |
if ((fin = fopen(filename, "r")) == NULL) |
if ((fin = fopen(filename, "r")) == NULL) |
| 223 |
{ |
{ |
| 243 |
|
|
| 244 |
int display_file_ex(const char *filename, int begin_line, int wait) |
int display_file_ex(const char *filename, int begin_line, int wait) |
| 245 |
{ |
{ |
| 246 |
|
static int show_help = 1; |
| 247 |
char buffer[LINE_BUFFER_LEN]; |
char buffer[LINE_BUFFER_LEN]; |
| 248 |
int ch = 0; |
int ch = 0; |
| 249 |
int input_ok, line, max_lines; |
int input_ok, line, max_lines; |
| 250 |
long int c_line_current = 0, c_line_total = 0; |
long int c_line_current = 0; |
| 251 |
|
long int c_line_total = 0; |
| 252 |
FILE *fin; |
FILE *fin; |
| 253 |
long *p_line_offsets; |
long *p_line_offsets; |
| 254 |
int len; |
long int len; |
| 255 |
int percentile; |
long int percentile; |
| 256 |
int loop = 1; |
int loop = 1; |
| 257 |
|
|
| 258 |
if ((fin = fopen(filename, "r")) == NULL) |
if ((fin = fopen(filename, "r")) == NULL) |
| 376 |
case '?': |
case '?': |
| 377 |
case 'h': |
case 'h': |
| 378 |
case 'H': |
case 'H': |
| 379 |
|
if (!show_help) |
| 380 |
|
{ |
| 381 |
|
break; |
| 382 |
|
} |
| 383 |
|
|
| 384 |
// Display help information |
// Display help information |
| 385 |
|
show_help = 0; |
| 386 |
display_file_ex(DATA_READ_HELP, begin_line, 1); |
display_file_ex(DATA_READ_HELP, begin_line, 1); |
| 387 |
|
show_help = 1; |
| 388 |
|
|
| 389 |
// Refresh after display help information |
// Refresh after display help information |
| 390 |
c_line_current -= (line - 1); |
c_line_current -= (line - 1); |
| 408 |
log_error("Error length exceeds buffer size: %d\n", len); |
log_error("Error length exceeds buffer size: %d\n", len); |
| 409 |
len = LINE_BUFFER_LEN - 1; |
len = LINE_BUFFER_LEN - 1; |
| 410 |
} |
} |
| 411 |
if (fgets(buffer, len + 1, fin) == NULL) |
if (fgets(buffer, (int)len + 1, fin) == NULL) |
| 412 |
{ |
{ |
| 413 |
log_error("Reach EOF\n"); |
log_error("Reach EOF\n"); |
| 414 |
break; |
break; |
| 430 |
{ |
{ |
| 431 |
char buffer[LINE_BUFFER_LEN]; |
char buffer[LINE_BUFFER_LEN]; |
| 432 |
|
|
| 433 |
str_space(buffer, 20 - strlen(BBS_current_section_name)); |
str_space(buffer, 20 - (int)strnlen(BBS_current_section_name, sizeof(BBS_current_section_name))); |
| 434 |
|
|
| 435 |
moveto(1, 0); |
moveto(1, 0); |
| 436 |
clrtoeol(); |
clrtoeol(); |
| 450 |
struct tm *tm_online; |
struct tm *tm_online; |
| 451 |
|
|
| 452 |
get_time_str(str_time, sizeof(str_time)); |
get_time_str(str_time, sizeof(str_time)); |
| 453 |
str_space(buffer, 33 - strlen(BBS_username)); |
str_space(buffer, 33 - (int)strnlen(BBS_username, sizeof(BBS_username))); |
| 454 |
|
|
| 455 |
time_online = time(0) - BBS_login_tm; |
time_online = time(0) - BBS_login_tm; |
| 456 |
tm_online = gmtime(&time_online); |
tm_online = gmtime(&time_online); |
| 473 |
char buffer[LINE_BUFFER_LEN]; |
char buffer[LINE_BUFFER_LEN]; |
| 474 |
FILE *fin; |
FILE *fin; |
| 475 |
static int line; |
static int line; |
| 476 |
int len; |
unsigned int len; |
| 477 |
int end_of_line; |
int end_of_line; |
| 478 |
|
|
| 479 |
clrline(3, 2 + ACTIVE_BOARD_HEIGHT); |
clrline(3, 2 + ACTIVE_BOARD_HEIGHT); |