C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
init_view.c
Go to the documentation of this file.
1/** @file init_view.c
2 @brief Initialize C-Menu View Screen IO and Input
3 @ingroup init_view
4 @author Bill Waller
5 Copyright (c) 2025
6 MIT License
7 billxwaller@gmail.com
8 @date 2026-02-09
9 */
10
11/**
12 @defgroup init_view Initializing View I/O
13 @brief Populate the C-Menu View Struct and Connect Input
14 */
15#include <common.h>
16#include <errno.h>
17#include <fcntl.h>
18#include <stddef.h>
19#include <stdlib.h>
20#include <string.h>
21#include <sys/mman.h>
22#include <sys/stat.h>
23#include <sys/sysmacros.h>
24#include <unistd.h>
25#include <wait.h>
26
28void view_full_screen_resize(Init *);
29void view_calc_win_dimensions(Init *, char *title);
30void view_win_resize(Init *, char *);
31
32/** @brief Initialize C-Menu View in full screen mode.
33 @ingroup init_view
34 @note This function sets up the view structure for full screen mode and
35 creates a new pad for the view.
36 @param init Pointer to the Init structure containing view settings.
37 @return 0 on success, -1 on failure.
38 @verbatim
39 The function creates the following windows:
40 1. view->cmdln_win: Status or Command Line
41 2. view->ln_win: Line Number Window
42 3. view->pad: Main Content Pad
43 @endverbatim
44 */
45int init_view_full_screen(Init *init) {
46 view = init->view;
47
48 if (view->tab_stop <= 0)
49 view->tab_stop = TABSIZE;
50 set_tabsize(view->tab_stop);
53#ifdef DEBUG_RESIZE
54 ssnprintf(em0, MAXLEN - 1,
55 "init_view_full_screen(): lines=%d, cols=%d, "
56 "ln_win_lines=%d, ln_win_cols=%d, "
57 "scroll_lines=%d",
58 view->lines, view->cols, view->ln_win_lines, view->ln_win_cols,
59 view->scroll_lines);
60#endif
61 /** view->cmdln_win: status or command line window */
64 keypad(view->cmdln_win, true);
65 idlok(view->cmdln_win, false);
66 idcok(view->cmdln_win, false);
67 wbkgrnd(view->cmdln_win, &CCC_WIN);
68 wbkgrndset(view->cmdln_win, &CCC_WIN);
69 scrollok(view->cmdln_win, false);
70#ifdef DEBUG_IMMEDOK
71 immedok(view->cmdln_win, true);
72#endif
73 /** view->ln_win: line number window */
75 keypad(view->ln_win, false);
76 idlok(view->ln_win, false);
77 idcok(view->ln_win, false);
78 wbkgrnd(view->ln_win, &CCC_LN);
79 wbkgrndset(view->ln_win, &CCC_LN);
80 scrollok(view->ln_win, true);
81 wsetscrreg(view->ln_win, 0, view->scroll_lines - 1);
82#ifdef DEBUG_IMMEDOK
83 immedok(view->ln_win, true);
84#endif
85 /** view->cmdln_win: status or command line window */
86 view->pad = newpad(view->lines - 1, PAD_COLS);
87 if (view->pad == nullptr) {
88 ssnprintf(em0, MAXLEN - 1, "%s, line: %d", __FILE__, __LINE__ - 2);
89 ssnprintf(em1, MAXLEN - 1, "newpad(%d, %d) failed", view->lines,
91 em2[0] = '\0';
93 abend(-1, "init_view_full_screen: newpad() failed");
94 }
95 keypad(view->pad, false);
96 idlok(view->pad, false);
97 idcok(view->pad, false);
98 wbkgrnd(view->pad, &CCC_WIN);
99 wbkgrndset(view->pad, &CCC_WIN);
100 scrollok(view->pad, true);
101 wsetscrreg(view->pad, 0, view->scroll_lines - 1);
102#ifdef DEBUG_IMMEDOK
103 immedok(view->pad, true);
104#endif
105 return 0;
106}
107/** @brief Resize the full screen view and its components.
108 @ingroup window_support
109 @param init Pointer to the Init structure containing view settings.
110 @note This function resizes the full screen view and its components,
111 including the command line window, line number window, and main content pad.
112 It also recalculates the dimensions for the full screen mode and updates the
113 scroll regions accordingly.
114 */
115void view_full_screen_resize(Init *init) {
116 erase();
117 wnoutrefresh(stdscr);
118 wrefresh(stdscr);
120 mvwin(view->cmdln_win, view->lines - 1, 0);
121 wresize(view->cmdln_win, 1, view->cols);
122 wnoutrefresh(view->cmdln_win);
123
124 // wresize(view->ln_win, view->ln_win_lines, view->ln_win_cols);
126 wsetscrreg(view->ln_win, 0, view->scroll_lines - 1);
127 wnoutrefresh(view->ln_win);
128
129 wresize(view->pad, view->lines - 1, PAD_COLS);
130 wsetscrreg(view->pad, 0, view->lines - 1);
131}
132/** @brief Calculate the dimensions for full screen mode.
133 @ingroup init_view
134 @details This function calculates the dimensions for the full screen mode of
135 the C-Menu View. It retrieves the maximum dimensions of the standard screen
136 and sets the view parameters accordingly. It also resizes the line number
137 window and command line window based on the new dimensions.
138 @param init Pointer to the Init structure containing view settings.
139 */
141 view = init->view;
142 getmaxyx(stdscr, view->lines, view->cols);
146#ifdef DEBUG_RESIZE
147 ssnprintf(
148 em0, MAXLEN - 1,
149 "view->lines=%d, view->cols=%d, view->maxrows=%d, view->maxcols=%d",
150 view->lines, view->cols, view->smaxrow, view->smaxcol);
151 write_cmenu_log_nt(em0);
152#endif
153 view->cmd_line = 0;
154 view->pminrow = 0;
155 view->pmincol = 0;
156 view->sminrow = 0;
157 view->smincol = 0;
162}
163/** @brief Initialize the C-Menu View in box window mode.
164 @ingroup init_view
165 @note sets up the view structure for box window mode, adjusts dimensions
166 based on screen size, and creates a new pad for the view. It also configures
167 various parameters such as scroll lines, command line position, and tab size.
168 @param init Pointer to the Init structure containing view settings.
169 @param title Title for the box window.
170 @return 0 on success, -1 on failure.
171 */
172int init_view_boxwin(Init *init, char *title) {
173 view = init->view;
174
175 if (view->tab_stop <= 0)
176 view->tab_stop = TABSIZE;
177 set_tabsize(view->tab_stop);
178 view->f_full_screen = false;
179
181 if (title != nullptr && title[0] != '\0')
183 else {
184 if (view->argv != nullptr && view->argv[0] != nullptr &&
185 view->argv[0][0] != '\0')
187 }
188#ifdef DEBUG_RESIZE
189 ssnprintf(em0, MAXLEN - 1,
190 "init_view_boxwin(): view->box: begy=%d, begx=%d, lines=%d, "
191 "cols=%d, title=%s",
192 view->begy, view->begx, view->lines + 2, view->cols + 2,
193 view->title);
194 write_cmenu_log_nt(em0);
195#endif
197 false)) {
198 ssnprintf(em0, MAXLEN - 1, "%s, line: %d", __FILE__, __LINE__ - 1);
199 ssnprintf(em1, MAXLEN - 1, "win_new(%d, %d, %d, %d, %s) failed",
201 em2[0] = '\0';
203 return (-1);
204 }
206
207 /** view->cmdln_win: status or command line window */
209 newwin(1, view->cols, view->begy + view->lines, view->begx + 1);
210 keypad(view->cmdln_win, true);
211 idlok(view->cmdln_win, false);
212 idcok(view->cmdln_win, false);
213 wbkgrnd(view->cmdln_win, &CCC_WIN);
214 wbkgrndset(view->cmdln_win, &CCC_WIN);
215 scrollok(view->cmdln_win, false);
216#ifdef DEBUG_IMMEDOK
217 immedok(view->cmdln_win, true);
218#endif
219
220 /** view->ln_win: line number window */
221#ifdef DEBUG_RESIZE
222 ssnprintf(em0, MAXLEN - 1,
223 "init_view_boxwin(): view->ln_win: begy=%d, begx=%d, lines=%d, "
224 "cols=%d, scroll_lines=%d",
225 view->begy, view->begx, view->ln_win_lines, view->ln_win_cols,
226 view->scroll_lines);
227 write_cmenu_log_nt(em0);
228#endif
229 if (view->f_ln) {
231 view->begy + 1, view->begx + 1);
232 keypad(view->ln_win, false);
233 idlok(view->ln_win, false);
234 idcok(view->ln_win, false);
235 wbkgrnd(view->ln_win, &CCC_LN);
236 wbkgrndset(view->ln_win, &CCC_LN);
237 scrollok(view->ln_win, true);
238 wsetscrreg(view->ln_win, 0, view->scroll_lines - 1);
239 }
240#ifdef DEBUG_IMMEDOK
241 immedok(view->ln_win, true);
242#endif
243 /** pad for main content */
244 view->pad = newpad(view->lines - 1, PAD_COLS);
245 keypad(view->pad, true);
246 idlok(view->pad, false);
247 idcok(view->pad, false);
248 wbkgrnd(view->pad, &CCC_WIN);
249 wbkgrndset(view->pad, &CCC_WIN);
250 scrollok(view->pad, true);
251 wsetscrreg(view->pad, 0, view->scroll_lines - 1);
252#ifdef DEBUG_IMMEDOK
253 immedok(view->pad, true);
254#endif
255 return (0);
256}
257/** @brief Resize the current window and its box, and update the title
258 @ingroup window_support
259 @param init Pointer to the Init structure containing view settings.
260 @param title Window title
261 @note This function resizes the current window and its associated box window
262 to the specified number of lines and columns. It also updates the title of
263 the box window if a title is provided. After resizing, it refreshes the
264 windows to apply the changes. */
265void view_win_resize(Init *init, char *title) {
266 int maxx;
267 erase();
268 wnoutrefresh(stdscr);
269 wrefresh(stdscr);
271#ifdef DEBUG_RESIZE
272 ssnprintf(em0, MAXLEN - 1, "view->box: begy=%d, begx=%d, lines=%d, cols=%d",
273 view->begy, view->begx, view->lines + 2, view->cols + 2);
274 write_cmenu_log_nt(em0);
275#endif
277 wresize(view->box, view->lines + 2, view->cols + 2);
278 wbkgrnd(view->box, &CCC_BOX);
279 wbkgrndset(view->box, &CCC_BOX);
281 if (title != nullptr && *title != '\0') {
282 wmove(view->box, 0, 1);
283 waddnstr(view->box, (const char *)&bw_rt, 1);
284 wmove(view->box, 0, 2);
285 waddnstr(view->box, (const char *)&bw_sp, 1);
286 mvwaddnwstr(view->box, 0, 1, &bw_rt, 1);
287 mvwaddnwstr(view->box, 0, 2, &bw_sp, 1);
288 int len = strlen(title);
289 if (len > (view->cols - 4)) {
290 len -= (view->cols - 4);
291 mvwaddstr(view->box, 0, 3, &title[len]);
292 } else
293 mvwaddstr(view->box, 0, 3, title);
294 maxx = getmaxx(view->box);
295 int s = strlen(title);
296 if ((s + 3) < maxx)
297 mvwaddch(view->box, 0, (s + 3), ' ');
298 if ((s + 4) < maxx)
299 mvwaddnwstr(view->box, 0, (s + 4), &bw_lt, 1);
300 }
301 wnoutrefresh(view->box);
302#ifdef DEBUG_RESIZE
303 ssnprintf(em0, MAXLEN - 1,
304 "view->cmdln_win: begy=%d, begx=%d, lines=%d, cols=%d",
305 view->begy + view->lines, view->begx + 1, 1, view->cols);
306 write_cmenu_log_nt(em0);
307#endif
309 wresize(view->cmdln_win, 1, view->cols);
310 wnoutrefresh(view->cmdln_win);
311#ifdef DEBUG_RESIZE
312 ssnprintf(em0, MAXLEN - 1,
313 "(285)view->ln_win: begy=%d, begx=%d, lines=%d, cols=%d, "
314 "scroll_lines %d",
315 view->begy + 1, view->begx + 1, view->ln_win_lines + 2,
316 view->ln_win_cols, view->scroll_lines);
317 write_cmenu_log_nt(em0);
318#endif
319 if (view->f_ln) {
320 if (view->ln_win == nullptr) {
322 view->begy + 1, view->begx + 1);
323 keypad(view->ln_win, false);
324 idlok(view->ln_win, false);
325 idcok(view->ln_win, false);
326 wbkgrnd(view->ln_win, &CCC_LN);
327 wbkgrndset(view->ln_win, &CCC_LN);
328 scrollok(view->ln_win, true);
329 wsetscrreg(view->ln_win, 0, view->scroll_lines - 1);
330#ifdef DEBUG_IMMEDOK
331 immedok(view->ln_win, true);
332#endif
333 } else {
334 mvwin(view->ln_win, view->begy + 1, view->begx + 1);
336 wsetscrreg(view->ln_win, 0, view->scroll_lines);
337 wnoutrefresh(view->ln_win);
338 }
339 } else if (view->ln_win != nullptr) {
340 delwin(view->ln_win);
342 }
347#ifdef DEBUG_RESIZE
348 ssnprintf(em0, MAXLEN - 1,
349 "view->pad: sminrow=%d, smincol=%d, smaxrow=%d, smaxcol=%d",
350 view->sminrow, view->smincol, view->smaxrow, view->smaxcol);
351 write_cmenu_log_nt(em0);
352#endif
353 wresize(view->pad, view->lines - 1, PAD_COLS);
354 wsetscrreg(view->pad, 0, view->scroll_lines);
355}
356/** @brief Calculate the dimensions and position of the box window for C-Menu
357 View.
358 @ingroup init_view
359 @details This function calculates the dimensions and position of the box
360 window for the C-Menu View based on the screen size and any specified
361 parameters in the Init structure. It ensures that the box window fits within
362 the screen dimensions and adjusts its size and position accordingly.
363 @param init Pointer to the Init structure containing view settings.
364 @param title Title for the box window, used to ensure minimum width if
365 provided.
366 */
367void view_calc_win_dimensions(Init *init, char *title) {
368 int scr_lines, scr_cols;
369 view = init->view;
370 getmaxyx(stdscr, scr_lines, scr_cols);
371 int len = strlen(title);
372
373 /** Use view->lines and view->cols if set, otherwise calculate based on
374 * screen size with some padding. Ensure the view fits within the screen
375 * dimensions. */
376
377 if (init->lines != 0 && view->lines == 0)
378 view->lines = init->lines;
379 if (view->lines == 0)
380 view->lines = scr_lines * 3 / 4;
381 if (view->lines > scr_lines - 3)
382 view->lines = scr_lines - 3;
383
384 if (init->cols != 0 && view->cols == 0)
385 view->cols = init->cols;
386 if (view->cols == 0)
387 view->cols = scr_cols * 3 / 4;
388 if (view->cols < len + 4)
389 view->cols = len + 4;
390 if (view->cols > scr_cols - 4)
391 view->cols = scr_cols - 4;
392
393 if (init->begy != 0 && view->begy == 0)
394 view->begy = init->begy;
395 if (view->begy == 0)
396 view->begy = (scr_lines - view->lines) / 5;
397 if (view->begy + view->lines > scr_lines - 2)
398 view->begy = scr_lines - view->lines - 2;
399
400 if (init->begx != 0 && view->begx == 0)
401 view->begx = init->begx;
402 if (view->begx == 0)
403 view->begx = (scr_cols - view->cols) / 5;
404 if (view->begx + view->cols > scr_cols - 2)
405 view->begx = scr_cols - view->cols - 2;
406
408 if (view->f_ln)
410 else
412
414 view->cmd_line = 0;
415
416 view->pminrow = 0;
417 view->pmincol = 0;
422
425}
426/** @brief Initialize the input for a C-Menu View.
427@ingroup init_view
428@details This function initializes the input for view, which can be a file,
429standard input, or a provider command to be initiated by view. It handles
430different input sources and sets up the necessary file descriptors and memory
431mapping for efficient access.
432@param view Pointer to the View structure to be initialized.
433@param file_name Name of the input file or "-" for standard input.
434@return true on success, false on failure.
435@note if a provider command is specified, set up a pipe to read its output.
436A child process is spawned, and view, the parent process, reads from the
437pipe.
438@note If input is from a pipe or standard input, clone it to a temporary
439file. This allows for memory-mapping the input later. It does not support
440real-time updates to the input, but it allows for efficient access to the
441data.
442*/
443int view_init_input(View *view, char *file_name) {
444 struct stat sb;
445 int idx = 0;
446 pid_t pid = -1;
447 int pipe_fd[2];
448 int s_argc = 0;
449 char *s_argv[MAXARGS];
450 char tmp_str[MAXLEN];
451 view->f_in_pipe = false;
452 if (strcmp(file_name, "-") == 0) {
453 file_name = "/dev/stdin";
454 view->f_in_pipe = true;
455 }
456 if (view->provider_cmd[0] != '\0') {
457 s_argc = str_to_args(s_argv, view->provider_cmd, MAXARGS - 1);
458 if (pipe(pipe_fd) == -1) {
459 Perror("pipe(pipe_fd) failed in init_view");
460 return -1;
461 }
462 if ((pid = fork()) == -1) {
463 Perror("fork() failed in init_view");
464 return -1;
465 }
466 if (pid == 0) { // Child
467 close(pipe_fd[P_READ]);
468 dup2(pipe_fd[P_WRITE], STDOUT_FILENO);
469 close(pipe_fd[P_WRITE]);
470 execvp(s_argv[0], s_argv);
471 strnz__cpy(tmp_str, "Can't exec view start cmd: ", MAXLEN - 1);
472 strnz__cat(tmp_str, s_argv[0], MAXLEN - 1);
473 Perror(tmp_str);
474 exit(EXIT_FAILURE);
475 }
476 // Back to parent
477 destroy_argv(s_argc, s_argv);
478 close(pipe_fd[P_WRITE]);
479 dup2(pipe_fd[P_READ], STDIN_FILENO);
480 view->in_fd = dup(STDIN_FILENO);
481 view->f_in_pipe = true;
482 } else {
483 if (view->f_in_pipe)
484 view->in_fd = dup(STDIN_FILENO);
485 else {
486 /*----------------------------------------------------------------------*/
487 /** Open the input file for reading and get its size. */
488 expand_tilde(file_name, MAXLEN - 1);
489 view->in_fd = open(file_name, O_RDONLY);
490 if (view->in_fd == -1) {
491 ssnprintf(em0, MAXLEN - 1, "%s, line: %d", __FILE__,
492 __LINE__ - 3);
493 ssnprintf(em1, MAXLEN - 1, "open %s", file_name);
494 strerror_r(errno, em2, MAXLEN);
496 return -1;
497 }
498 if (fstat(view->in_fd, &sb) == -1) {
499 ssnprintf(em0, MAXLEN - 1, "%s, line: %d", __FILE__,
500 __LINE__ - 1);
501 ssnprintf(em1, MAXLEN - 1, "fstat %s", file_name);
502 strerror_r(errno, em2, MAXLEN);
504 close(view->in_fd);
505 return -1;
506 }
507 view->file_size = sb.st_size;
508 if (view->file_size == 0) {
509 close(view->in_fd);
510 ssnprintf(em0, MAXLEN - 1, "%s, line: %d", __FILE__,
511 __LINE__ - 1);
512 ssnprintf(em1, MAXLEN - 1, "file %s is empty", file_name);
513 strerror_r(errno, em2, MAXLEN);
515 return -1;
516 }
517 if (!S_ISREG(sb.st_mode))
518 view->f_in_pipe = true;
519 }
520 /*----------------------------------------------------------------------*/
521 }
522 if (view->f_in_pipe) {
523 char tmp_filename[] = "/tmp/view_XXXXXX";
524 char buf[VBUFSIZ];
525 ssize_t bytes_read = 0;
526 ssize_t bytes_written = 0;
527 close(view->in_fd);
528 view->in_fd = mkstemp(tmp_filename);
529 if (view->in_fd == -1) {
530 abend(-1, "failed to mkstemp");
531 exit(EXIT_FAILURE);
532 }
533 unlink(tmp_filename);
534 /*-----------------------------------------------------------------*/
535 bool f_wait = false;
536 int ready;
537 fd_set read_fds;
538 struct timeval timeout;
539 Chyron *wait_chyron = nullptr;
540 WINDOW *wait_win = nullptr;
541 int remaining;
542 FD_ZERO(&read_fds);
543 FD_SET(STDIN_FILENO, &read_fds);
544 timeout.tv_sec = 0;
545 timeout.tv_usec = 200000; /**< 200ms timeout to check for input */
546 ready = select(STDIN_FILENO + 1, &read_fds, nullptr, nullptr, &timeout);
547 if (ready == 0) {
548 f_wait = true;
549 remaining = wait_timeout;
550 wait_chyron = wait_mk_chyron();
551 wait_win = wait_mk_win(wait_chyron, "WAITING for VIEW INPUT");
552 }
553 cmd_key = 0;
554 while (ready == 0 && remaining > 0 && cmd_key != KEY_F(9)) {
555 cmd_key = wait_continue(wait_win, wait_chyron, remaining);
556 if (cmd_key == KEY_F(9))
557 break;
558 FD_ZERO(&read_fds);
559 FD_SET(STDIN_FILENO, &read_fds);
560 timeout.tv_sec = 0;
561 timeout.tv_usec = 0;
562 ready =
563 select(STDIN_FILENO + 1, &read_fds, nullptr, nullptr, &timeout);
564 remaining--;
565 }
566 if (f_wait) {
567 if (wait_chyron != nullptr)
568 wait_destroy(wait_chyron);
569 }
570 if (cmd_key == KEY_F(9)) {
571 if (view->f_in_pipe && pid > 0) {
572 /** If user cancels while waiting for view input, kill
573 * provider_cmd child process and close pipe */
574 kill(pid, SIGKILL);
575 waitpid(pid, nullptr, 0);
576 close(pipe_fd[P_READ]);
577 }
578 Perror("No view input available");
579 return -1;
580 }
581 if (ready == -1) {
582 Perror("Error waiting for view input");
583 if (view->f_in_pipe && pid > 0) {
584 /** If error occurs while waiting for view input, kill
585 * provider_cmd child process and close pipe */
586 kill(pid, SIGKILL);
587 waitpid(pid, nullptr, 0);
588 close(pipe_fd[P_READ]);
589 }
590 return -1;
591 }
592 if (ready == 0) {
593 Perror("Timeout waiting for view input");
594 if (view->f_in_pipe && pid > 0) {
595 /** If timeout occurs while waiting for view input, kill
596 * provider_cmd child process and close pipe */
597 kill(pid, SIGKILL);
598 waitpid(pid, nullptr, 0);
599 close(pipe_fd[P_READ]);
600 }
601 return -1;
602 }
603 if (ready == 1 && !FD_ISSET(STDIN_FILENO, &read_fds)) {
604 Perror("Unexpected error waiting for view input");
605 if (view->f_in_pipe && pid > 0) {
606 /** If unexpected error occurs while waiting for view input,
607 * kill provider_cmd child process and close pipe */
608 kill(pid, SIGKILL);
609 waitpid(pid, nullptr, 0);
610 close(pipe_fd[P_READ]);
611 }
612 return -1;
613 }
614 /*-----------------------------------------------------------------*/
615 while ((bytes_read = read(STDIN_FILENO, buf, sizeof(buf))) > 0) {
616 if (write(view->in_fd, buf, bytes_read) != bytes_read) {
617 abend(-1, "unable to write tmp");
618 exit(EXIT_FAILURE);
619 }
620 bytes_written += bytes_read;
621 }
622 if (bytes_written == 0) {
623 abend(-1, "unable to read stdin");
624 exit(EXIT_FAILURE);
625 }
626 if (fstat(view->in_fd, &sb) == -1) {
627 abend(-1, "fstat failed");
628 exit(EXIT_FAILURE);
629 }
630 view->file_size = sb.st_size;
631 if (view->file_size == 0) {
632 close(view->in_fd);
633 strnz__cpy(tmp_str, "no standard input", MAXLEN - 1);
634 abend(-1, tmp_str);
635 exit(EXIT_FAILURE);
636 }
638 // waitpid(-1, nullptr, 0);
639 }
640 // Memory-map the input file for efficient access.
641 view->buf =
642 mmap(nullptr, view->file_size, PROT_READ, MAP_PRIVATE, view->in_fd, 0);
643 if (view->buf == MAP_FAILED) {
644 ssnprintf(em0, MAXLEN - 1, "%s, line: %d", __FILE__, __LINE__ - 2);
645 ssnprintf(em1, MAXLEN - 1, "mmap %s", file_name);
646 strerror_r(errno, em2, MAXLEN);
648 close(view->in_fd);
649 return -1;
650 }
651 close(view->in_fd);
652 view->file_size = sb.st_size;
654 view->buf_curr_ptr = view->buf;
655 if (view->cmd_all[0] != '\0')
657 for (idx = 0; idx < NMARKS; idx++)
658 view->mark_tbl[idx] = NULL_POSITION;
659 strnz__cpy(view->cur_file_str, file_name, MAXLEN - 1);
661 return 0;
662}
#define P_READ
Definition common.h:47
#define P_WRITE
Definition common.h:48
#define MAXARGS
Definition cm.h:30
int wait_timeout
Definition futil.c:107
#define nullptr
Definition cm.h:25
#define NMARKS
Definition view.h:24
#define VBUFSIZ
Definition view.h:28
#define PAD_COLS
Definition view.h:30
#define NULL_POSITION
Definition view.h:27
View * view
Definition mem.c:48
#define MAXLEN
Definition curskeys.c:15
unsigned int cmd_key
Definition dwin.c:118
const wchar_t bw_rt
Definition dwin.c:103
cchar_t CCC_LN
Definition dwin.c:152
bool waitpid_with_timeout(pid_t pid, int timeout)
Definition dwin.c:1436
char em1[MAXLEN]
Definition dwin.c:134
cchar_t CCC_WIN
Definition dwin.c:147
const wchar_t bw_sp
Definition dwin.c:104
const wchar_t bw_lt
Definition dwin.c:102
cchar_t CCC_BOX
Definition dwin.c:149
int win_ptr
Definition dwin.c:122
char em0[MAXLEN]
Definition dwin.c:133
WINDOW * win_box[MAXWIN]
Definition dwin.c:116
char em2[MAXLEN]
Definition dwin.c:135
void view_win_resize(Init *, char *)
Resize the current window and its box, and update the title.
Definition init_view.c:265
int box_new(int, int, int, int, char *, bool)
Create a new window with optional box and title.
Definition dwin.c:783
void view_full_screen_resize(Init *)
Resize the full screen view and its components.
Definition init_view.c:115
void cbox(WINDOW *)
Draw a box around the specified window.
Definition dwin.c:965
bool wait_destroy(Chyron *)
Destroy the waiting message window and chyron.
Definition dwin.c:1208
int wait_continue(WINDOW *, Chyron *, int)
Update the waiting message with remaining time and check for user input.
Definition dwin.c:1220
WINDOW * wait_mk_win(Chyron *, char *)
Display a popup waiting message.
Definition dwin.c:1177
int Perror(char *)
Display a simple error message window or print to stderr.
Definition dwin.c:1115
int display_error(char *em0, char *em1, char *em2, char *em3)
Display an error message window or print to stderr.
Definition dwin.c:1059
void abend(int, char *)
Abnormal program termination.
Definition dwin.c:1336
Chyron * wait_mk_chyron()
Create a Chyron struct for the waiting message.
Definition dwin.c:1166
void destroy_argv(int argc, char **argv)
Deallocates memory allocated for argument strings in argv.
Definition futil.c:230
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition futil.c:278
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
Definition futil.c:156
size_t strnz__cat(char *, const char *, size_t)
safer alternative to strncat
Definition futil.c:307
bool expand_tilde(char *, int)
Replace Leading Tilde With Home Directory.
Definition futil.c:709
bool base_name(char *, char *)
Returns the base name of a file specification.
Definition futil.c:800
int str_to_args(char **, char *, int)
Converts a string into an array of argument strings.
Definition futil.c:176
void view_calc_win_dimensions(Init *, char *title)
Calculate the dimensions and position of the box window for C-Menu View.
Definition init_view.c:367
int init_view_full_screen(Init *)
Initialize C-Menu View in full screen mode.
Definition init_view.c:45
int init_view_boxwin(Init *, char *)
Initialize the C-Menu View in box window mode.
Definition init_view.c:172
void view_calc_full_screen_dimensions(Init *)
Calculate the dimensions for full screen mode.
Definition init_view.c:140
int view_init_input(View *, char *)
Initialize the input for a C-Menu View.
Definition init_view.c:443
int begx
Definition common.h:109
int cols
Definition common.h:107
int begy
Definition common.h:108
View * view
Definition common.h:175
int lines
Definition common.h:106
char provider_cmd[MAXLEN]
Definition view.h:52
char ** argv
Definition view.h:59
int smaxrow
Definition view.h:113
char * buf
Definition view.h:146
int in_fd
Definition view.h:139
WINDOW * pad
Definition view.h:69
off_t page_top_ln
Definition view.h:163
int smincol
Definition view.h:111
off_t prev_file_pos
Definition view.h:132
char cmd[MAXLEN]
Definition view.h:54
off_t ln
Definition view.h:157
bool f_in_pipe
Definition view.h:138
WINDOW * cmdln_win
Definition view.h:68
char * buf_curr_ptr
Definition view.h:147
int smaxcol
Definition view.h:115
int cols
Definition view.h:49
bool f_full_screen
Definition view.h:89
int ln_win_cols
Definition view.h:155
bool f_ln
Definition view.h:156
off_t mark_tbl[NMARKS]
Definition view.h:137
WINDOW * ln_win
Definition view.h:70
int lines
Definition view.h:48
int pminrow
Definition view.h:107
int pmincol
Definition view.h:108
off_t file_size
Definition view.h:130
char cur_file_str[MAXLEN]
Definition view.h:94
int sminrow
Definition view.h:109
int cmd_line
Definition view.h:105
int tab_stop
Definition view.h:77
off_t page_bot_ln
Definition view.h:164
char title[MAXLEN]
Definition view.h:57
char cmd_all[MAXLEN]
Definition view.h:55
int begy
Definition view.h:50
WINDOW * box
Definition view.h:67
int scroll_lines
Definition view.h:104
int ln_win_lines
Definition view.h:154
char file_name[MAXLEN]
Definition view.h:84
int begx
Definition view.h:51