/[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.57 by sysadm, Sat May 17 06:46:23 2025 UTC Revision 1.60 by sysadm, Sat May 17 12:28:47 2025 UTC
# Line 298  int display_file_ex(const char *filename Line 298  int display_file_ex(const char *filename
298                                  input_ok = 1;                                  input_ok = 1;
299                                  switch (ch)                                  switch (ch)
300                                  {                                  {
301                                  //case KEY_NULL:                                  // case KEY_NULL:
302                                  case KEY_TIMEOUT:                                  case KEY_TIMEOUT:
303                                          goto cleanup;                                          goto cleanup;
304                                  case KEY_HOME:                                  case KEY_HOME:
# Line 433  cleanup: Line 433  cleanup:
433    
434  int show_top(const char *status)  int show_top(const char *status)
435  {  {
436            char status_f[21];
437          int truncate;          int truncate;
438          int status_len;          int status_len;
439          int section_name_len;          int section_name_len;
440          int len;          int len;
         char status_f[21];  
441    
442          strncpy(status_f, status, sizeof(status_f) - 1);          strncpy(status_f, status, sizeof(status_f) - 1);
443          status_f[sizeof(status_f) - 1] = '\0';          status_f[sizeof(status_f) - 1] = '\0';
# Line 457  int show_top(const char *status) Line 457  int show_top(const char *status)
457    
458          moveto(1, 0);          moveto(1, 0);
459          clrtoeol();          clrtoeol();
460          prints("\033[1;44;33m%s \033[37m%*s%*s\033[33m ÌÖÂÛÇø [%s]\033[m",          prints("\033[1;44;33m%s\033[37m%*s%*s\033[33m ÌÖÂÛÇø [%s]\033[m",
461                     status_f, (39 - status_len), BBS_name, (30 - section_name_len), "", BBS_current_section_name);                     status_f, 32, BBS_name, 26, "", BBS_current_section_name);
462          iflush();          iflush();
463    
464          return 0;          return 0;
# Line 469  int show_bottom(const char *msg) Line 469  int show_bottom(const char *msg)
469          char str_time[LINE_BUFFER_LEN];          char str_time[LINE_BUFFER_LEN];
470          time_t time_online;          time_t time_online;
471          struct tm *tm_online;          struct tm *tm_online;
472          int len_username = (int)strnlen(BBS_username, sizeof(BBS_username));          char msg_f[21];
473            int truncate;
474            int msg_len;
475            int len;
476            int len_username;
477    
478          get_time_str(str_time, sizeof(str_time));          get_time_str(str_time, sizeof(str_time));
479    
480            strncpy(msg_f, msg, sizeof(msg_f) - 1);
481            msg_f[sizeof(msg_f) - 1] = '\0';
482    
483            len = split_line(msg_f, 20, &truncate, &msg_len);
484            if (truncate)
485            {
486                    log_error("Status string is truncated\n");
487                    msg_f[len] = '\0';
488            }
489    
490            len_username = (int)strnlen(BBS_username, sizeof(BBS_username));
491    
492          time_online = time(0) - BBS_login_tm;          time_online = time(0) - BBS_login_tm;
493          tm_online = gmtime(&time_online);          tm_online = gmtime(&time_online);
494    
495          moveto(SCREEN_ROWS, 0);          moveto(SCREEN_ROWS, 0);
496          clrtoeol();          clrtoeol();
497          prints("\033[1;44;33m[\033[36m%s\033[33m]%*sÕʺÅ[\033[36m%s\033[33m]"          prints("\033[1;44;33m[\033[36m%s\033[33m]%*s%*sÕʺÅ[\033[36m%s\033[33m]"
498                     "[\033[36m%1d\033[33m:\033[36m%2d\033[33m:\033[36m%2d\033[33m]\033[m",                     "[\033[36m%1d\033[33m:\033[36m%2d\033[33m:\033[36m%2d\033[33m]\033[m",
499                     str_time, 34 - len_username, "", BBS_username,                     str_time, 21, msg_f, 13 - len_username, "", BBS_username,
500                     tm_online->tm_mday - 1, tm_online->tm_hour, tm_online->tm_min);                     tm_online->tm_mday - 1, tm_online->tm_hour, tm_online->tm_min);
501          iflush();          iflush();
502    
# Line 489  int show_bottom(const char *msg) Line 505  int show_bottom(const char *msg)
505    
506  int show_active_board()  int show_active_board()
507  {  {
508          char filename[FILE_PATH_LEN];          static int line_current = 0;
509          char buffer[LINE_BUFFER_LEN];          static const void *p_file_shm = NULL;
510          FILE *fin;          static const void *p_data;
511          static int line;          static size_t data_len;
512          int len;          static long line_total;
513          int end_of_line;          static const long *p_line_offsets;
         int display_len;  
   
         clrline(3, 2 + ACTIVE_BOARD_HEIGHT);  
514    
515          if ((fin = fopen(DATA_ACTIVE_BOARD, "r")) == NULL)          char buffer[LINE_BUFFER_LEN];
516          {          long int len;
                 log_error("Unable to open file %s\n", filename);  
                 return -1;  
         }  
517    
518          for (int i = 0; i < line; i++)          if (p_file_shm == NULL)
519          {          {
520                  if (fgets(buffer, sizeof(buffer), fin) == NULL)                  if ((p_file_shm = get_file_shm(DATA_ACTIVE_BOARD)) == NULL)
521                  {                  {
522                          line = 0;                          log_error("get_file_shm(%s) error\n", DATA_ACTIVE_BOARD);
523                          rewind(fin);                          return KEY_NULL;
                         break;  
524                  }                  }
525    
526                    data_len = *((size_t *)p_file_shm);
527                    line_total = *((long *)(p_file_shm + sizeof(size_t)));
528                    p_data = p_file_shm + sizeof(data_len) + sizeof(line_total);
529                    p_line_offsets = p_data + data_len + 1;
530          }          }
531    
532            clrline(3, 2 + ACTIVE_BOARD_HEIGHT);
533    
534          for (int i = 0; i < ACTIVE_BOARD_HEIGHT; i++)          for (int i = 0; i < ACTIVE_BOARD_HEIGHT; i++)
535          {          {
536                  if (fgets(buffer, sizeof(buffer), fin) == NULL)                  len = p_line_offsets[line_current + 1] - p_line_offsets[line_current];
537                    if (len >= LINE_BUFFER_LEN)
538                  {                  {
539                          line = 0;                          log_error("Error length exceeds buffer size: %d\n", len);
540                          break;                          len = LINE_BUFFER_LEN - 1;
541                  }                  }
542                  line++;  
543                  len = split_line(buffer, SCREEN_COLS, &end_of_line, &display_len);                  memcpy(buffer, (const char *)p_data + p_line_offsets[line_current], (size_t)len);
544                  buffer[len] = '\0'; // Truncate over-length line                  buffer[len] = '\0';
545    
546                  moveto(3 + i, 0);                  moveto(3 + i, 0);
547                  prints("%s", buffer);                  prints("%s", buffer);
548    
549                    line_current++;
550                    if (line_current >= line_total)
551                    {
552                            line_current = 0;
553                            break;
554                    }
555          }          }
556          iflush();          iflush();
557    
         fclose(fin);  
   
558          return 0;          return 0;
559  }  }


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

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