| 30 |
#include <sys/types.h> |
#include <sys/types.h> |
| 31 |
#include <sys/stat.h> |
#include <sys/stat.h> |
| 32 |
#include <sys/param.h> |
#include <sys/param.h> |
| 33 |
#include <sys/mman.h> |
#include <sys/shm.h> |
| 34 |
|
|
| 35 |
#define ACTIVE_BOARD_HEIGHT 8 |
#define ACTIVE_BOARD_HEIGHT 8 |
| 36 |
|
|
| 232 |
int ch = KEY_NULL; |
int ch = KEY_NULL; |
| 233 |
int input_ok, line, max_lines; |
int input_ok, line, max_lines; |
| 234 |
long int line_current = 0; |
long int line_current = 0; |
| 235 |
const FILE_MMAP *p_file_mmap; |
const void *p_file_shm; |
| 236 |
|
const void *p_data; |
| 237 |
|
size_t data_len; |
| 238 |
|
long line_total; |
| 239 |
|
const long *p_line_offsets; |
| 240 |
long int len; |
long int len; |
| 241 |
long int percentile; |
long int percentile; |
| 242 |
int loop; |
int loop; |
| 243 |
|
|
| 244 |
if ((p_file_mmap = get_file_mmap(filename)) == NULL) |
if ((p_file_shm = get_file_shm(filename)) == NULL) |
| 245 |
{ |
{ |
| 246 |
if (load_file_mmap(filename) < 0) |
log_error("get_file_shm(%s) error\n", filename); |
| 247 |
{ |
return KEY_NULL; |
|
log_error("load_file_mmap(%s) error\n", filename); |
|
|
return KEY_NULL; |
|
|
} |
|
|
|
|
|
if ((p_file_mmap = get_file_mmap(filename)) == NULL) |
|
|
{ |
|
|
log_error("get_file_mmap(%s) error\n", filename); |
|
|
return KEY_NULL; |
|
|
} |
|
| 248 |
} |
} |
| 249 |
|
|
| 250 |
|
data_len = *((size_t *)p_file_shm); |
| 251 |
|
line_total = *((long *)(p_file_shm + sizeof(size_t))); |
| 252 |
|
p_data = p_file_shm + sizeof(data_len) + sizeof(line_total); |
| 253 |
|
p_line_offsets = p_data + data_len + 1; |
| 254 |
|
|
| 255 |
clrline(begin_line, SCREEN_ROWS); |
clrline(begin_line, SCREEN_ROWS); |
| 256 |
line = begin_line; |
line = begin_line; |
| 257 |
max_lines = SCREEN_ROWS - 1; |
max_lines = SCREEN_ROWS - 1; |
| 259 |
loop = 1; |
loop = 1; |
| 260 |
while (!SYS_server_exit && loop) |
while (!SYS_server_exit && loop) |
| 261 |
{ |
{ |
| 262 |
if (line_current >= p_file_mmap->line_total && p_file_mmap->line_total <= SCREEN_ROWS - 2) |
if (line_current >= line_total && line_total <= SCREEN_ROWS - 2) |
| 263 |
{ |
{ |
| 264 |
if (wait) |
if (wait) |
| 265 |
{ |
{ |
| 274 |
break; |
break; |
| 275 |
} |
} |
| 276 |
|
|
| 277 |
if (line_current >= p_file_mmap->line_total || line >= max_lines) |
if (line_current >= line_total || line >= max_lines) |
| 278 |
{ |
{ |
| 279 |
if (line_current - (line - 1) + (SCREEN_ROWS - 2) < p_file_mmap->line_total) |
if (line_current - (line - 1) + (SCREEN_ROWS - 2) < line_total) |
| 280 |
{ |
{ |
| 281 |
percentile = (line_current - (line - 1) + (SCREEN_ROWS - 2)) * 100 / p_file_mmap->line_total; |
percentile = (line_current - (line - 1) + (SCREEN_ROWS - 2)) * 100 / line_total; |
| 282 |
} |
} |
| 283 |
else |
else |
| 284 |
{ |
{ |
| 308 |
clrline(begin_line, SCREEN_ROWS); |
clrline(begin_line, SCREEN_ROWS); |
| 309 |
break; |
break; |
| 310 |
case KEY_END: |
case KEY_END: |
| 311 |
line_current = p_file_mmap->line_total - (SCREEN_ROWS - 2); |
line_current = line_total - (SCREEN_ROWS - 2); |
| 312 |
line = begin_line; |
line = begin_line; |
| 313 |
max_lines = SCREEN_ROWS - 1; |
max_lines = SCREEN_ROWS - 1; |
| 314 |
clrline(begin_line, SCREEN_ROWS); |
clrline(begin_line, SCREEN_ROWS); |
| 327 |
case CR: |
case CR: |
| 328 |
igetch_reset(); |
igetch_reset(); |
| 329 |
case KEY_DOWN: |
case KEY_DOWN: |
| 330 |
if (line_current + ((SCREEN_ROWS - 2) - (line - 1)) >= p_file_mmap->line_total) // Reach bottom |
if (line_current + ((SCREEN_ROWS - 2) - (line - 1)) >= line_total) // Reach bottom |
| 331 |
{ |
{ |
| 332 |
break; |
break; |
| 333 |
} |
} |
| 357 |
case KEY_PGDN: |
case KEY_PGDN: |
| 358 |
case Ctrl('F'): |
case Ctrl('F'): |
| 359 |
case KEY_SPACE: |
case KEY_SPACE: |
| 360 |
if (line_current + (SCREEN_ROWS - 2) - (line - 1) >= p_file_mmap->line_total) // Reach bottom |
if (line_current + (SCREEN_ROWS - 2) - (line - 1) >= line_total) // Reach bottom |
| 361 |
{ |
{ |
| 362 |
break; |
break; |
| 363 |
} |
} |
| 364 |
line_current += (SCREEN_ROWS - 3) - (line - 1); |
line_current += (SCREEN_ROWS - 3) - (line - 1); |
| 365 |
if (line_current + SCREEN_ROWS - 2 > p_file_mmap->line_total) // No enough lines to display |
if (line_current + SCREEN_ROWS - 2 > line_total) // No enough lines to display |
| 366 |
{ |
{ |
| 367 |
line_current = p_file_mmap->line_total - (SCREEN_ROWS - 2); |
line_current = line_total - (SCREEN_ROWS - 2); |
| 368 |
} |
} |
| 369 |
line = begin_line; |
line = begin_line; |
| 370 |
max_lines = SCREEN_ROWS - 1; |
max_lines = SCREEN_ROWS - 1; |
| 406 |
continue; |
continue; |
| 407 |
} |
} |
| 408 |
|
|
| 409 |
len = p_file_mmap->line_offsets[line_current + 1] - p_file_mmap->line_offsets[line_current]; |
len = p_line_offsets[line_current + 1] - p_line_offsets[line_current]; |
| 410 |
if (len >= LINE_BUFFER_LEN) |
if (len >= LINE_BUFFER_LEN) |
| 411 |
{ |
{ |
| 412 |
log_error("Error length exceeds buffer size: %d\n", len); |
log_error("Error length exceeds buffer size: %d\n", len); |
| 413 |
len = LINE_BUFFER_LEN - 1; |
len = LINE_BUFFER_LEN - 1; |
| 414 |
} |
} |
| 415 |
|
|
| 416 |
memcpy(buffer, (const char *)p_file_mmap->p_data + p_file_mmap->line_offsets[line_current], (size_t)len); |
memcpy(buffer, (const char *)p_data + p_line_offsets[line_current], (size_t)len); |
| 417 |
buffer[len] = '\0'; |
buffer[len] = '\0'; |
| 418 |
|
|
| 419 |
moveto(line, 0); |
moveto(line, 0); |
| 424 |
} |
} |
| 425 |
|
|
| 426 |
cleanup: |
cleanup: |
| 427 |
|
if (shmdt(p_file_shm) == -1) |
| 428 |
|
{ |
| 429 |
|
log_error("shmdt() error (%d)\n", errno); |
| 430 |
|
} |
| 431 |
|
|
| 432 |
return ch; |
return ch; |
| 433 |
} |
} |
| 434 |
|
|
| 435 |
int show_top(char *status) |
int show_top(char *status) |
| 436 |
{ |
{ |
| 437 |
int end_of_line; |
int truncate; |
| 438 |
int display_len; |
int status_len; |
| 439 |
|
int section_name_len; |
| 440 |
int len; |
int len; |
| 441 |
|
|
| 442 |
char space1[LINE_BUFFER_LEN]; |
len = split_line(status, 20, &truncate, &status_len); |
| 443 |
char space2[LINE_BUFFER_LEN]; |
if (truncate) |
|
|
|
|
len = split_line(status, 20, &end_of_line, &display_len); |
|
|
if (end_of_line) |
|
| 444 |
{ |
{ |
| 445 |
status[len] = '\0'; |
status[len] = '\0'; |
| 446 |
} |
} |
|
str_space(space1, 31 - display_len); |
|
| 447 |
|
|
| 448 |
len = split_line(BBS_current_section_name, 20, &end_of_line, &display_len); |
len = split_line(BBS_current_section_name, 20, &truncate, §ion_name_len); |
| 449 |
if (end_of_line) |
if (truncate) |
| 450 |
{ |
{ |
| 451 |
status[len] = '\0'; |
status[len] = '\0'; |
| 452 |
} |
} |
|
str_space(space2, 30 - display_len); |
|
| 453 |
|
|
| 454 |
moveto(1, 0); |
moveto(1, 0); |
| 455 |
clrtoeol(); |
clrtoeol(); |
| 456 |
prints("\033[1;44;33m%s \033[37m%s%s%s\033[33m ÌÖÂÛÇø [%s]\033[m", |
prints("\033[1;44;33m%s \033[37m%*s%*s\033[33m ÌÖÂÛÇø [%s]\033[m", |
| 457 |
status, space1, BBS_name, space2, BBS_current_section_name); |
status, (39 - status_len), BBS_name, (30 - section_name_len), "", BBS_current_section_name); |
| 458 |
iflush(); |
iflush(); |
| 459 |
|
|
| 460 |
return 0; |
return 0; |