/[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.54 by sysadm, Fri May 16 14:09:31 2025 UTC Revision 1.56 by sysadm, Sat May 17 06:14:22 2025 UTC
# Line 30  Line 30 
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    
# Line 232  int display_file_ex(const char *filename Line 232  int display_file_ex(const char *filename
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;
# Line 259  int display_file_ex(const char *filename Line 259  int display_file_ex(const char *filename
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                          {                          {
# Line 274  int display_file_ex(const char *filename Line 274  int display_file_ex(const char *filename
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                          {                          {
# Line 308  int display_file_ex(const char *filename Line 308  int display_file_ex(const char *filename
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);
# Line 327  int display_file_ex(const char *filename Line 327  int display_file_ex(const char *filename
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                                          }                                          }
# Line 357  int display_file_ex(const char *filename Line 357  int display_file_ex(const char *filename
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;
# Line 406  int display_file_ex(const char *filename Line 406  int display_file_ex(const char *filename
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);
# Line 424  int display_file_ex(const char *filename Line 424  int display_file_ex(const char *filename
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            char status_f[21];
442    
443          char space1[LINE_BUFFER_LEN];          strncpy(status_f, status, sizeof(status_f) - 1);
444          char space2[LINE_BUFFER_LEN];          status_f[sizeof(status_f) - 1] = '\0';
445    
446          len = split_line(status, 20, &end_of_line, &display_len);          len = split_line(status_f, 20, &truncate, &status_len);
447          if (end_of_line)          if (truncate)
448          {          {
449                  status[len] = '\0';                  log_error("Status string is truncated\n");
450                    status_f[len] = '\0';
451          }          }
         str_space(space1, 31 - display_len);  
452    
453          len = split_line(BBS_current_section_name, 20, &end_of_line, &display_len);          len = split_line(BBS_current_section_name, 20, &truncate, &section_name_len);
454          if (end_of_line)          if (truncate)
455          {          {
456                  status[len] = '\0';                  log_error("Section name is truncated\n");
457          }          }
         str_space(space2, 30 - display_len);  
458    
459          moveto(1, 0);          moveto(1, 0);
460          clrtoeol();          clrtoeol();
461          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",
462                     status, space1, BBS_name, space2, BBS_current_section_name);                     status_f, (39 - status_len), BBS_name, (30 - section_name_len), "", BBS_current_section_name);
463          iflush();          iflush();
464    
465          return 0;          return 0;


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

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