2
3
4
5
6
7
8
9
12
13
14
23#include <sys/sysmacros.h>
37
38
39
40
41
42
43
44
45
46
47
48
59 view
->win_win = newwin(LINES, COLS, 0, 0);
71 ssnprintf(em0, MAXLEN - 1
, "derwin(view->win_win, LINES - 1, COLS, 0, 0) failed in init_view_full_screen");
86 ssnprintf(em0, MAXLEN - 1
, "derwin(view->win_win, 1, COLS, LINES - 1, 0) failed in init_view_full_screen");
109 if (view
->pad ==
nullptr) {
115 immedok(view
->pad,
true);
118 "subpad(view->pad, LINES - 1, COLS - view->ln_win_cols, 0, 0) failed in init_view_full_screen");
124 keypad(view
->pad,
true);
125 keypad(view
->pad,
true);
126 idlok(view
->pad,
false);
127 idcok(view
->pad,
false);
128 scrollok(view
->pad,
true);
133
134
135
136
137
138
139
152
153
154
155
156
157
158
170 "%s:%d view->lines=%d, view->cols=%d, view->maxrows=%d, view->maxcols=%d",
172 view->lines, view->cols, view->smaxrow, view->smaxcol);
173 write_cmenu_log_nt(em0);
187
188
189
190
191
192
193
213 ssnprintf(em0, MAXLEN - 1,
214 "%s:%d init BOX: lines=%d, cols=%d, begy=%d, begx=%d",
215 __FILE__, __LINE__, view->lines + 2, view->cols + 2, view->begy, view->begx);
216 write_cmenu_log_nt(em0);
279 if (view
->pad ==
nullptr) {
294 "%s:%d PAD: lines=%d, cols=%d, begy=%d, begx=%d",
307 wbkgrnd(view->pad, &CC_GREEN);
308 wbkgrndset(view->pad, &CC_GREEN);
313 scrollok(view
->pad,
true);
328 wnoutrefresh(stdscr);
342
343
344
345
354
355
356
357
358
359
360
361
363 int scr_lines, scr_cols;
367
368
370 getmaxyx(stdscr, scr_lines, scr_cols);
372 ssnprintf(em0, MAXLEN - 1,
373 "%s:%d=%d calc lines=%d, cols=%d, begy=%d, begx=%d",
374 __FILE__, __LINE__, 526, view->lines, view->cols, view->begy, view->begx);
375 write_cmenu_log_nt(em0);
379 view
->cols = scr_cols - 2;
383 int lines =
max(scr_lines / 10, 8);
385 if (view
->lines > scr_lines - 3)
390 int cols =
max(scr_cols / 3, 40);
392 if (view
->cols > scr_cols - 2)
393 view
->cols = scr_cols - 2;
414 ssnprintf(em0, MAXLEN - 1,
415 "%s:%d calc BOX lines=%d, cols=%d, begy=%d, begx=%d",
416 __FILE__, __LINE__, view->lines + 2, view->cols + 2, view->begy, view->begx);
417 write_cmenu_log_nt(em0);
418 ssnprintf(em0, MAXLEN - 1,
419 "%s:%d calc WIN lines=%d, cols=%d, begy=%d, begx=%d",
420 __FILE__, __LINE__, view->lines, view->cols, 1, 1);
421 write_cmenu_log_nt(em0);
422 ssnprintf(em0, MAXLEN - 1,
423 "%s:%d calc CMDLN lines=%d, cols=%d, begy=%d, begx=%d",
424 __FILE__, __LINE__, 1, view->cols, view->lines - 1, 1);
425 write_cmenu_log_nt(em0);
426 ssnprintf(em0, MAXLEN - 1,
427 "%s:%d calc LNNO lines=%d, cols=%d, begy=%d, begx=%d",
428 __FILE__, __LINE__, view->lines - 1, view->ln_win_cols, 0, 0);
429 write_cmenu_log_nt(em0);
430 ssnprintf(em0, MAXLEN - 1,
431 "%s:%d calc PAD lines=%d, cols=%d, begy=%d, begx=%d",
432 __FILE__, __LINE__, view->lines - 1, view->cols - view->ln_win_cols, 0, view->ln_win_cols);
433 write_cmenu_log_nt(em0);
438
439
440
441
442
443
444
445
446
457 if (strcmp(file_name,
"-") == 0) {
458 file_name =
"/dev/stdin";
463 if (pipe(pipe_fd) == -1) {
464 Perror("pipe(pipe_fd) failed in init_view");
468 if ((pid = fork()) == -1) {
469 Perror("fork() failed in init_view");
474 int dev_null = open(
"/dev/null", O_WRONLY);
475 if (dev_null == -1) {
476 Perror("open(/dev/null) failed in init_pick child process");
479 dup2(dev_null, STDERR_FILENO);
482 dup2(pipe_fd[
P_WRITE], STDOUT_FILENO);
484 execvp(s_argv[0], s_argv);
495 dup2(pipe_fd[
P_READ], STDIN_FILENO);
496 view
->in_fd = dup(STDIN_FILENO);
500 view
->in_fd = dup(STDIN_FILENO);
505 view
->in_fd = open(file_name, O_RDONLY);
514 if (fstat(view
->in_fd, &sb) == -1) {
533 if (!S_ISREG(sb.st_mode))
541 view
->in_fd = memfd_create(
"view_input", MFD_CLOEXEC);
542 if (view
->in_fd < 0 || errno != 0) {
546 __LINE__ - 4
, errno
);
551 ssize_t bytes_read = 0;
552 ssize_t bytes_written = 0;
553 while ((bytes_read = read(STDIN_FILENO, buf,
sizeof(buf))) > 0) {
554 if ((bytes_written = write(view
->in_fd, buf, bytes_read)) != bytes_read) {
555 abend(-1
, "unable to write view->in_fd");
559 if (fstat(view
->in_fd, &sb) == -1) {
563 __LINE__ - 4
, errno
);
574 waitpid(-1,
nullptr, 0);
578 if (view
->buf == MAP_FAILED) {
587 SIO *sio = init
->sio;
598 for (idx = 0; idx <
NMARKS; idx++)
void destroy_view_win(Init *)
char * stdio_names(char *, char *)
char stdio_names_str[MAXLEN]
char * stdio_fdnames(char *, char *)
#define max(a, b)
max macro evaluates two expressions, returning greatest result.
void view_win_del(PANEL *, WINDOW *)
int border_title(WINDOW *, char *)
Draw a box with a title around the specified window.
void restore_wins()
Restore all windows after a screen resize.
void view_full_screen_resize(Init *)
Resize the full screen view and its components.
void view_boxwin_resize(Init *)
Resize the current window and its box.
int Perror(char *)
Display a simple error message window or print to stderr.
void abend(int, char *)
Abnormal program termination.
int display_error(char *, char *, char *, char *)
Display an error message window or print to stderr.
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
int destroy_argv(int argc, char **argv)
Deallocates memory allocated for argument strings in argv.
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
bool expand_tilde(char *, int)
Replaces "~/" in string with the user's home directory.
size_t strnz__cat(char *, const char *, size_t)
safer alternative to strncat
bool base_name(char *, char *)
Returns the base name of a file specification.
int str_to_args(char **, char *, int)
Converts a string into an array of argument strings.
void view_calc_boxwin_dimensions(Init *)
Calculate the dimensions and position of the box window for C-Menu View.
int init_view_full_screen(Init *)
Initialize C-Menu View in full screen mode.
int init_view_boxwin(Init *)
Initialize the C-Menu View in box window mode.
void view_calc_full_screen_dimensions(Init *)
Calculate the dimensions for full screen mode.
int view_init_input(Init *, char *)
Initialize the input for the C-Menu View.
char provider_cmd[MAXLEN]
char cur_file_str[MAXLEN]