| 104 |
|
|
| 105 |
inline int press_any_key() |
inline int press_any_key() |
| 106 |
{ |
{ |
| 107 |
return press_any_key_ex(" \033[1;33m按任意键继续...\033[m"); |
return press_any_key_ex(" \033[1;33m按任意键继续...\033[m", 60); |
| 108 |
} |
} |
| 109 |
|
|
| 110 |
int press_any_key_ex(const char *msg) |
int press_any_key_ex(const char *msg, int sec) |
| 111 |
{ |
{ |
| 112 |
int ch = 0; |
int ch = 0; |
|
int wait_seconds = 60; |
|
| 113 |
int duration = 0; |
int duration = 0; |
| 114 |
time_t t_begin = time(NULL); |
time_t t_begin = time(NULL); |
| 115 |
|
|
| 119 |
prints(msg); |
prints(msg); |
| 120 |
iflush(); |
iflush(); |
| 121 |
|
|
| 122 |
|
igetch_reset(); |
| 123 |
|
|
| 124 |
do |
do |
| 125 |
{ |
{ |
| 126 |
ch = igetch_t(wait_seconds - duration); |
ch = igetch_t(sec - duration); |
| 127 |
duration = (int)(time(NULL) - t_begin); |
duration = (int)(time(NULL) - t_begin); |
| 128 |
} while (!SYS_server_exit && ch == 0 && duration < 60); |
} while (!SYS_server_exit && ch == 0 && duration < 60); |
| 129 |
|
|
| 182 |
offset--; |
offset--; |
| 183 |
if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8 |
if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8 |
| 184 |
{ |
{ |
| 185 |
while (offset > 0 && (buffer[offset] & 0b11000000) != 0b11000000) |
while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0) |
| 186 |
{ |
{ |
| 187 |
offset--; |
offset--; |
| 188 |
} |
} |
| 203 |
else if ((ch & 0xff80) == 0x80) // head of multi-byte character |
else if ((ch & 0xff80) == 0x80) // head of multi-byte character |
| 204 |
{ |
{ |
| 205 |
str_len = 0; |
str_len = 0; |
| 206 |
c = (char)(ch & 0b11110000); |
c = (char)(ch & 0xf0); |
| 207 |
while (c & 0b10000000) |
while (c & 0x80) |
| 208 |
{ |
{ |
| 209 |
input_str[str_len] = (char)(ch - 256); |
input_str[str_len] = (char)(ch - 256); |
| 210 |
str_len++; |
str_len++; |
| 211 |
c = (c & 0b01111111) << 1; |
c = (c & 0x7f) << 1; |
| 212 |
|
|
| 213 |
if ((c & 0b10000000) == 0) // Input completed |
if ((c & 0x80) == 0) // Input completed |
| 214 |
{ |
{ |
| 215 |
break; |
break; |
| 216 |
} |
} |
| 300 |
iflush(); |
iflush(); |
| 301 |
|
|
| 302 |
return len; |
return len; |
| 303 |
}; |
} |
| 304 |
|
|
| 305 |
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) |
| 306 |
{ |
{ |
| 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--; |
| 383 |
if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character |
if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character |
| 384 |
{ |
{ |
| 385 |
str_len = 0; |
str_len = 0; |
| 386 |
c = (char)(buffer[offset] & 0b11110000); |
c = (char)(buffer[offset] & 0xf0); |
| 387 |
while (c & 0b10000000) |
while (c & 0x80) |
| 388 |
{ |
{ |
| 389 |
str_len++; |
str_len++; |
| 390 |
c = (c & 0b01111111) << 1; |
c = (c & 0x7f) << 1; |
| 391 |
} |
} |
| 392 |
display_len--; |
display_len--; |
| 393 |
} |
} |
| 417 |
offset--; |
offset--; |
| 418 |
if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8 |
if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8 |
| 419 |
{ |
{ |
| 420 |
while (offset > 0 && (buffer[offset] & 0b11000000) != 0b11000000) |
while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0) |
| 421 |
{ |
{ |
| 422 |
str_len++; |
str_len++; |
| 423 |
offset--; |
offset--; |
| 438 |
str_len = 0; |
str_len = 0; |
| 439 |
if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character |
if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character |
| 440 |
{ |
{ |
| 441 |
c = (char)(buffer[offset] & 0b11110000); |
c = (char)(buffer[offset] & 0xf0); |
| 442 |
while (c & 0b10000000) |
while (c & 0x80) |
| 443 |
{ |
{ |
| 444 |
str_len++; |
str_len++; |
| 445 |
c = (c & 0b01111111) << 1; |
c = (c & 0x7f) << 1; |
| 446 |
} |
} |
| 447 |
col_cur++; |
col_cur++; |
| 448 |
} |
} |
| 490 |
else if ((ch & 0xff80) == 0x80) // head of multi-byte character |
else if ((ch & 0xff80) == 0x80) // head of multi-byte character |
| 491 |
{ |
{ |
| 492 |
str_len = 0; |
str_len = 0; |
| 493 |
c = (char)(ch & 0b11110000); |
c = (char)(ch & 0xf0); |
| 494 |
while (c & 0b10000000) |
while (c & 0x80) |
| 495 |
{ |
{ |
| 496 |
input_str[str_len] = (char)(ch - 256); |
input_str[str_len] = (char)(ch - 256); |
| 497 |
str_len++; |
str_len++; |
| 498 |
c = (c & 0b01111111) << 1; |
c = (c & 0x7f) << 1; |
| 499 |
|
|
| 500 |
if ((c & 0b10000000) == 0) // Input completed |
if ((c & 0x80) == 0) // Input completed |
| 501 |
{ |
{ |
| 502 |
break; |
break; |
| 503 |
} |
} |