C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
Initializing View I/O

Populate the C-Menu View Struct and Connect Input. More...

Files

file  init_view.c
 Initialize C-Menu View Screen IO and Input.

Functions

int init_view_boxwin (Init *init)
 Initialize the C-Menu View in box window mode.
int init_view_full_screen (Init *init)
 Initialize C-Menu View in full screen mode.
void view_calc_boxwin_dimensions (Init *init)
 Calculate the dimensions and position of the box window for C-Menu View.
void view_calc_full_screen_dimensions (Init *init)
 Calculate the dimensions for full screen mode.
int view_init_input (Init *init, char *file_name)
 Initialize the input for the C-Menu View.

Detailed Description

Populate the C-Menu View Struct and Connect Input.

Function Documentation

◆ init_view_boxwin()

int init_view_boxwin ( Init * init)

Initialize the C-Menu View in box window mode.

Parameters
initPointer to the Init structure containing view settings.
Returns
0 on success, -1 on failure.

sets up the view structure for box window mode, adjusts dimensions based on screen size, and creates a new pad for the view. It also configures various parameters such as scroll lines, command line position, and tab size.

Definition at line 162 of file init_view.c.

162 {
163 View *view = init->view;
164 view->f_full_screen = false;
165 // -------------------> 1. BOX / WIN <-------------------
167
168 view->sfc = ui_surface_box(NULL, 0, view->lines + 2, view->cols + 2, view->begy, view->begx, NULL);
169
170 ui_surface_addwin(view->sfc, WIN, BOX, view->lines, view->cols, 1, 1);
171 // -------------------> 2. LNNO <-------------------
172 if (view->f_ln) {
173 ui_surface_addwin(view->sfc, LNNO, WIN, view->lines - 1, view->ln_win_cols, 0, 0);
174 ui_bkgd(view->sfc, LNNO, &cell_ln);
175 ui_bkgdset(view->sfc, LNNO, &cell_ln);
176 ui_scrollok(view->sfc, LNNO, true);
177 ui_setscrreg(view->sfc, LNNO, 0, view->scroll_lines);
178 }
179 // -------------------> 3. CMDLN <-------------------
180 ui_surface_addwin(view->sfc, CMDLN, WIN, 1, view->cols, view->lines - 1, 0);
181 ui_bkgd(view->sfc, CMDLN, &cell_nt);
182 ui_keypad(view->sfc, CMDLN, true);
183 ui_idlok(view->sfc, CMDLN, false);
184 ui_idcok(view->sfc, CMDLN, false);
185 ui_scrollok(view->sfc, CMDLN, false);
186 // -------------------> 4. PAD <-------------------
187 ui_surface_addpad(view->sfc, PAD, WIN, view->lines - 1, PAD_COLS - 1, 0, view->ln_win_cols);
188 ui_scrollok(view->sfc, PAD, true);
189 // ------------------------------------------------
190 return (0);
191}
int ui_surface_addwin(UiSurface *s, ss_t w, uint p, uint lines, uint cols, uint y, uint x)
Add a new window to the specified UiSurface.
Definition ui_ncurses.c:395
UiCell cell_nt
Definition ui_common.c:106
int ui_setscrreg(UiSurface *s, ss_t w, uint top, uint bottom)
Set the scrolling region for a UiSurface.
Definition ui_ncurses.c:820
int ui_idcok(UiSurface *s, ss_t w, bool enable)
Enable or disable the use of the insert/delete character capabilities for a UiSurface.
Definition ui_ncurses.c:803
UiCell cell_ln
Definition ui_common.c:114
int ui_surface_addpad(UiSurface *s, ss_t w, uint view_win, uint lines, uint cols, uint begy, uint begx)
Add a new pad to the specified UiSurface.
Definition ui_ncurses.c:369
int ui_bkgd(UiSurface *s, ss_t w, const UiCell *cell)
Set the background of a specific window within a UiSurface.
Definition ui_ncurses.c:927
int ui_idlok(UiSurface *s, ss_t w, bool enable)
Enable or disable the use of the insert/delete line capabilities for a UiSurface.
Definition ui_ncurses.c:787
UiSurface * ui_surface_box(UiSurface *parent, uint p, uint lines, uint cols, uint y, uint x, const char *title)
Create a new UI surface with a border box and optional title.
Definition ui_ncurses.c:288
int ui_scrollok(UiSurface *s, ss_t w, bool enable)
Enable or disable scrolling for a UiSurface.
Definition ui_ncurses.c:755
int ui_bkgdset(UiSurface *s, ss_t w, const UiCell *cell)
Set the background for new content to be written to a specific window within a UiSurface.
Definition ui_ncurses.c:941
int ui_keypad(UiSurface *s, ss_t w, bool enable)
Enable or disable the keypad for a UiSurface.
Definition ui_ncurses.c:771
#define PAD_COLS
Definition view.h:39
View * view
Definition mem.c:38
void view_calc_boxwin_dimensions(Init *)
Calculate the dimensions and position of the box window for C-Menu View.
Definition init_view.c:215
View * view
Definition common.h:193
Definition view.h:59

References View::begx, View::begy, cell_ln, cell_nt, View::cols, View::f_full_screen, View::f_ln, View::lines, View::ln_win_cols, View::scroll_lines, View::sfc, ui_bkgd(), ui_bkgdset(), ui_idcok(), ui_idlok(), ui_keypad(), ui_scrollok(), ui_setscrreg(), ui_surface_addpad(), ui_surface_addwin(), ui_surface_box(), Init::view, and view_calc_boxwin_dimensions().

Referenced by main(), new_pick_view(), popup_view(), and view_boxwin_resize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_view_full_screen()

int init_view_full_screen ( Init * init)

Initialize C-Menu View in full screen mode.

Parameters
initPointer to the Init structure containing view settings.
Returns
0 on success, -1 on failure.

This function sets up the view structure for full screen mode and creates a new pad for the view.

The function creates the following windows:
1. view->cmdln_win: Status or Command Line
2. view->lnno_win: Line Number Window
3. view->pad: Main Content Pad

Definition at line 47 of file init_view.c.

47 {
48 View *view = init->view;
49 view->f_full_screen = true;
50 // -------------------> 1. WIN <-------------------
52 ui_log(INFO, _("lines=%d, cols=%d"), view->lines, view->cols);
53 view->sfc = ui_surface_new(WIN, NULL, 0, view->lines, view->cols, 0, 0);
54 if (!view->sfc) {
55 ssnprintf(em0, MAXLEN - 1, _("newwin(LINES, COLS, 0, 0) failed in init_view_full_screen"));
56 ui_log(INFO, "%s", em0);
57 exit(EXIT_FAILURE);
58 return -1;
59 }
60 ui_log(INFO, _("created view->sfc"));
61 ui_bkgd(view->sfc, WIN, &cell_nt);
62 // -------------------> 2. LNNO <-------------------
63 if (view->f_ln) {
64 ui_surface_addwin(view->sfc, LNNO, WIN, view->scroll_lines, view->ln_win_cols, 0, 0);
65 if (view->sfc->lnno == nullptr) {
66 ssnprintf(em0, MAXLEN - 1, _("ui_sfc_addwin(LNNO, LINES - 1, COLS, 0, 0) failed in init_view_full_screen"));
67 ui_log(INFO, "%s", em0);
68 exit(EXIT_FAILURE);
69 }
70 ui_log(INFO, _("created view->sfc->lnno"));
71 ui_bkgd(view->sfc, LNNO, &cell_ln);
72 ui_bkgdset(view->sfc, LNNO, &cell_ln);
73 ui_scrollok(view->sfc, LNNO, true);
74 ui_setscrreg(view->sfc, LNNO, 0, view->scroll_lines);
75 }
76 // -------------------> 3. CMDLN <-------------------
77 ui_surface_addwin(view->sfc, CMDLN, WIN, 1, view->cols, view->scroll_lines, 0);
78 if (view->sfc->cmdln == nullptr) {
79 ssnprintf(em0, MAXLEN - 1, _("ui_sfc_addwin(CMDLN, 1, COLS, LINES - 1, 0) failed in init_view_full_screen"));
80 ui_log(INFO, "%s", em0);
81 exit(EXIT_FAILURE);
82 }
83 ui_log(INFO, _("created view->sfc->cmdln"));
84 ui_bkgd(view->sfc, CMDLN, &cell_nt);
85 ui_keypad(view->sfc, CMDLN, true);
86 ui_idlok(view->sfc, CMDLN, false);
87 ui_idcok(view->sfc, CMDLN, false);
88 ui_scrollok(view->sfc, CMDLN, false);
89 // -------------------> 4. PAD <-------------------
90
91 ui_surface_addpad(view->sfc, PAD, WIN, view->lines - 1, PAD_COLS - 1, 0, view->ln_win_cols);
92 ui_log(INFO, _("created view->sfc->mplane[PAD]"));
93 if (view->sfc->pad == nullptr) {
94 ssnprintf(em0, MAXLEN - 1, _("ui_sfc_addpan(CMDLN, 1, COLS, LINES - 1, 0) failed in init_view_full_screen"));
95 ui_log(INFO, "%s", em0);
96 exit(EXIT_FAILURE);
97 }
98 ui_scrollok(view->sfc, PAD, true);
99
100 // ------------------------------------------------
101 return 0;
102}
UiSurface * ui_surface_new(ss_t w, UiSurface *parent, uint p, uint lines, uint cols, uint y, uint x)
Create a new UI surface with the specified parameters.
Definition ui_ncurses.c:229
char em0[MAXLEN]
Definition ui_common.c:46
#define MAXLEN
Definition curskeys.c:15
#define _(String)
Definition amort.c:23
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
Definition futil.c:390
void view_calc_full_screen_dimensions(Init *)
Calculate the dimensions for full screen mode.
Definition init_view.c:128

References cell_ln, cell_nt, View::cols, em0, View::f_full_screen, View::f_ln, View::lines, View::ln_win_cols, View::scroll_lines, View::sfc, ssnprintf(), ui_bkgd(), ui_bkgdset(), ui_idcok(), ui_idlok(), ui_keypad(), ui_scrollok(), ui_setscrreg(), ui_surface_addpad(), ui_surface_addwin(), ui_surface_new(), Init::view, and view_calc_full_screen_dimensions().

Referenced by main(), and view_full_screen_resize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ view_calc_boxwin_dimensions()

void view_calc_boxwin_dimensions ( Init * init)

Calculate the dimensions and position of the box window for C-Menu View.

This function calculates the dimensions and position of the box window for the C-Menu View based on the screen size and any specified parameters in the Init structure. It ensures that the box window fits within the screen dimensions and adjusts its size and position accordingly.

Parameters
initPointer to the Init structure containing view settings.

Use view->lines and view->cols if set, otherwise calculate based on screen size with some padding. Ensure the view fits within the screen dimensions.

Definition at line 215 of file init_view.c.

215 {
216 View *view = init->view;
217
221 uint scr_lines, scr_cols;
222 ui_get_screen_size(&scr_lines, &scr_cols);
223#ifdef DEBUG_RESIZE
224 ssnprintf(em0, MAXLEN - 1,
225 _("%s:%d=%d calc lines=%d, cols=%d, begy=%d, begx=%d"),
226 __FILE__, __LINE__, 526, view->lines, view->cols, view->begy, view->begx);
227 write_cmenu_log(em0);
228#endif
229 if (view->lines == 0 && view->cols == 0 && view->begy == 0 && view->begx == 0) {
230 view->lines = scr_lines - 3;
231 view->cols = scr_cols - 2;
232 view->begy = 0;
233 view->begx = 0;
234 }
235 uint lines = max(scr_lines / 10, 8);
236 view->lines = max(view->lines, lines);
237 if (view->lines > scr_lines - 3)
238 view->lines = scr_lines - 3;
239 if (view->lines + view->begy > scr_lines - 3)
240 view->begy = scr_lines - (view->lines + 3);
241
242 uint cols = max(scr_cols / 3, 40);
243 view->cols = max(view->cols, cols);
244 if (view->cols > scr_cols - 2)
245 view->cols = scr_cols - 2;
246 if (view->cols + view->begx > scr_cols - 2)
247 view->begx = scr_cols - (view->cols + 2);
248
249 view->h_shift = view->cols / 3;
250 view->ln_win_lines = view->lines - 1;
251 if (view->f_ln)
252 view->ln_win_cols = 8;
253 else
254 view->ln_win_cols = 0;
255 view->scroll_lines = view->lines - 1;
256 view->cmd_line = 0;
257 view->pminrow = 0;
258 view->pmincol = 0;
259 view->sminrow = view->begy + 1;
260 view->smincol = view->begx + view->ln_win_cols + 1;
261 view->smaxrow = view->begy + view->lines;
262 view->smaxcol = view->begx + view->cols;
263 view->ln_no = view->page_top_ln_no + view->scroll_lines;
264 view->page_bot_ln_no = view->ln_no;
265#ifdef DEBUG_RESIZE
266 ssnprintf(em0, MAXLEN - 1,
267 _("%s:%d calc BOX lines=%d, cols=%d, begy=%d, begx=%d"),
268 __FILE__, __LINE__, view->lines + 2, view->cols + 2, view->begy, view->begx);
269 write_cmenu_log(em0);
270 ssnprintf(em0, MAXLEN - 1,
271 _("%s:%d calc WIN lines=%d, cols=%d, begy=%d, begx=%d"),
272 __FILE__, __LINE__, view->lines, view->cols, 1, 1);
273 write_cmenu_log(em0);
274 ssnprintf(em0, MAXLEN - 1,
275 _("%s:%d calc CMDLN lines=%d, cols=%d, begy=%d, begx=%d"),
276 __FILE__, __LINE__, 1, view->cols, view->lines - 1, 1);
277 write_cmenu_log(em0);
278 ssnprintf(em0, MAXLEN - 1,
279 _("%s:%d calc LNNO lines=%d, cols=%d, begy=%d, begx=%d"),
280 __FILE__, __LINE__, view->lines - 1, view->ln_win_cols, 0, 0);
281 write_cmenu_log(em0);
282 ssnprintf(em0, MAXLEN - 1,
283 _("%s:%d calc PAD lines=%d, cols=%d, begy=%d, begx=%d"),
284 __FILE__, __LINE__, view->lines - 1, view->cols - view->ln_win_cols, 0, view->ln_win_cols);
285 write_cmenu_log(em0);
286
287#endif
288}
#define max(a, b)
max macro evaluates two expressions, returning greatest result.
Definition cm.h:97
void ui_get_screen_size(uint *lines, uint *cols)
Get the current screen size (number of lines and columns).
Definition ui_ncurses.c:722

References View::begx, View::begy, View::cmd_line, View::cols, View::f_ln, View::h_shift, View::lines, View::ln_no, View::ln_win_cols, View::ln_win_lines, View::page_bot_ln_no, View::page_top_ln_no, View::pmincol, View::pminrow, View::scroll_lines, View::smaxcol, View::smaxrow, View::smincol, View::sminrow, ui_get_screen_size(), and Init::view.

Referenced by init_view_boxwin().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ view_calc_full_screen_dimensions()

void view_calc_full_screen_dimensions ( Init * init)

Calculate the dimensions for full screen mode.

This function calculates the dimensions for the full screen mode of the C-Menu View. It retrieves the maximum dimensions of the standard screen and sets the view parameters accordingly. It also resizes the line number window and command line window based on the new dimensions.

Parameters
initPointer to the Init structure containing view settings.

Definition at line 128 of file init_view.c.

128 {
129 View *view = init->view;
130 ui_get_screen_size(&view->lines, &view->cols);
131 view->ln_win_lines = view->lines;
132 view->ln_win_cols = 8;
133 view->scroll_lines = view->lines - 1;
134 view->h_shift = view->cols / 3;
135#ifdef DEBUG_RESIZE
136 char file[MAXLEN];
137 ssnprintf(
138 em0, MAXLEN - 1,
139 _("%s:%d view->lines=%d, view->cols=%d, view->maxrows=%d, view->maxcols=%d"),
140 __FILE__, __LINE__,
141 view->lines, view->cols, view->smaxrow, view->smaxcol);
142 write_cmenu_log(em0);
143#endif
144 view->cmd_line = 0;
145 view->pminrow = 0;
146 view->pmincol = 0;
147 view->sminrow = 0;
148 view->smincol = view->ln_win_cols;
149 view->smaxrow = view->lines - 1;
150 view->smaxcol = view->cols - 1;
151 view->ln_no = view->page_top_ln_no + view->scroll_lines;
152 view->page_bot_ln_no = view->ln_no;
153}

References View::cmd_line, View::cols, View::h_shift, View::lines, View::ln_no, View::ln_win_cols, View::ln_win_lines, View::page_bot_ln_no, View::page_top_ln_no, View::pmincol, View::pminrow, View::scroll_lines, View::smaxcol, View::smaxrow, View::smincol, View::sminrow, ui_get_screen_size(), and Init::view.

Referenced by init_view_full_screen(), and view_full_screen_resize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ view_init_input()

int view_init_input ( Init * init,
char * file_name )

Initialize the input for the C-Menu View.

Parameters
initPointer to the Init structure containing view settings.
file_nameName of the input file or "-" for standard input.
Returns
0 on success, -1 on failure.

This function initializes the input for the C-Menu View. It handles both regular files and standard input, setting up pipes if necessary. It also memory-maps the input file for efficient access and sets up the view structure accordingly.

Prevent child process from writing to terminal

Definition at line 299 of file init_view.c.

299 {
300 struct stat sb;
301 int idx = 0;
302 pid_t pid = -1;
303 int pipe_fd[2];
304 int s_argc = 0;
305 char *s_argv[MAXARGS];
306 char tmp_str[MAXLEN];
307 View *view = init->view;
308 view->f_in_pipe = false;
309 if (strcmp(file_name, "-") == 0) {
310 file_name = _("/dev/stdin");
311 view->f_in_pipe = true;
312 }
313 if (view->provider_cmd[0] != '\0') {
314 s_argc = str_to_args(s_argv, view->provider_cmd, MAXARGS - 1);
315 if (pipe(pipe_fd) == -1) {
316 ui_perror(_("pipe(pipe_fd) failed in init_view"));
317 return -1;
318 }
319 // endwin();
320 if ((pid = fork()) == -1) {
321 ui_perror(_("fork() failed in init_view"));
322 return -1;
323 }
324 if (pid == 0) { // Child
326 int dev_null = open(_("/dev/null"), O_WRONLY);
327 if (dev_null == -1) {
328 ui_perror(_("open(/dev/null) failed in init_pick child process"));
329 exit(EXIT_FAILURE);
330 }
331 dup2(dev_null, STDERR_FILENO);
332 close(dev_null);
333 close(pipe_fd[P_READ]);
334 dup2(pipe_fd[P_WRITE], STDOUT_FILENO);
335 close(pipe_fd[P_WRITE]);
336 execvp(s_argv[0], s_argv);
337 strnz__cpy(tmp_str, _("Can't exec view start cmd: "), MAXLEN - 1);
338 strnz__cat(tmp_str, s_argv[0], MAXLEN - 1);
339 ui_perror(tmp_str);
340 exit(EXIT_FAILURE);
341 }
342 // Back to parent
343 destroy_argv(s_argc, s_argv);
346 close(pipe_fd[P_WRITE]);
347 view->in_fd = dup(pipe_fd[P_READ]);
348 view->f_in_pipe = true;
349 } else {
350 if (view->f_in_pipe)
351 view->in_fd = dup(STDIN_FILENO);
352 else {
353 /*----------------------------------------------------------------------*/
354 /* Open the input file for reading and get its size. */
355 expand_tilde(file_name, MAXLEN - 1);
356 view->in_fd = open(file_name, O_RDONLY);
357 if (view->in_fd == -1) {
358 ssnprintf(em0, MAXLEN - 1, _("%s, line: %d"), __FILE__,
359 __LINE__ - 3);
360 ssnprintf(em1, MAXLEN - 1, _("open %s"), file_name);
361 strerror__r(errno, em2, MAXLEN);
363 nullptr);
364 return -1;
365 }
366 if (fstat(view->in_fd, &sb) == -1) {
367 ssnprintf(em0, MAXLEN - 1, _("%s, line: %d"), __FILE__,
368 __LINE__ - 1);
369 ssnprintf(em1, MAXLEN - 1, _("fstat %s"), file_name);
370 strerror__r(errno, em2, MAXLEN);
371 ui_display_error(em0, em1, em2, nullptr);
372 close(view->in_fd);
373 return -1;
374 }
375 view->file_size = sb.st_size;
376 if (view->file_size == 0) {
377 close(view->in_fd);
378 ssnprintf(em0, MAXLEN - 1, _("%s, line: %d"), __FILE__,
379 __LINE__ - 1);
380 ssnprintf(em1, MAXLEN - 1, _("file %s is empty"), file_name);
381 strerror__r(errno, em2, MAXLEN);
382 ui_display_error(em0, em1, em2, nullptr);
383 return -1;
384 }
385 if (!S_ISREG(sb.st_mode))
386 view->f_in_pipe = true;
387 }
388 /*----------------------------------------------------------------------*/
389 }
390 if (view->f_in_pipe) {
391 errno = 0;
392 view->tmp_fd = memfd_create(_("view_input"), MFD_CLOEXEC);
393 if (view->in_fd < 0 || errno != 0) {
394 ssnprintf(em0, MAXLEN - 1, "memfd_create failed\n");
395 ssnprintf(em1, MAXLEN - 1, "%s", strerror(errno));
396 ssnprintf(em2, MAXLEN - 1, _("%s, line: %d, errno: %d"), __FILE__,
397 __LINE__ - 4, errno);
398 ui_display_error(em0, em1, em2, nullptr);
399 exit(EXIT_FAILURE);
400 }
401 // ------------------------------------------------------
402 // transfer view->in_fd to view->tmp_fd
403 // ------------------------------------------------------
404 char buf[VBUFSIZ];
405 ssize_t bytes_read = 0;
406 // ------------------------------------------------------
407 // countdown to timeout if view->in_fd not ready
408 // ------------------------------------------------------
411 int status = ui_poll_reg_read_fd(500);
412 if (status == 0) {
413 int timeout_ms = init->timeout_secs * 1000;
414 status = ui_timeout_prompt(_("Waiting for input..."), _("from view_input"), timeout_ms, init->timeout_secs);
416 if (status != UIKEY_STREAM_DATA) {
417 if (status == UIKEY_F09)
418 cmenu_abend(init, -1, _("view: user pressed F9"));
419 if (status == UIKEY_TIMEOUT)
420 cmenu_abend(init, -1, _("view: timed out waiting for input"));
421 cmenu_abend(init, -1, _("view: no input data"));
422 }
423 }
424 // ------------------------------------------------------
425 // end wait
426 // ------------------------------------------------------
427 bytes_read = read(view->in_fd, buf, sizeof(buf));
428 if (bytes_read > 0) {
429 if (write(view->tmp_fd, buf, bytes_read) != bytes_read)
430 cmenu_abend(init, EXIT_FAILURE, _("view: unable to write view->tmp_fd"));
431 } else if (bytes_read == 0)
432 cmenu_abend(init, EXIT_FAILURE, _("view: unable to read view->tmp_fd"));
433 // ------------------------------------------------------
434 // end transfer
435 // ------------------------------------------------------
436 if (fstat(view->tmp_fd, &sb) == -1) {
437 ssnprintf(em0, MAXLEN - 1, "fstat(view->in_fd) failed\n");
438 ssnprintf(em1, MAXLEN - 1, "%s", strerror(errno));
439 ssnprintf(em2, MAXLEN - 1, _("%s, line: %d, errno: %d"), __FILE__,
440 __LINE__ - 4, errno);
441 ui_display_error(em0, em1, em2, nullptr);
442 exit(EXIT_FAILURE);
443 }
444 view->file_size = sb.st_size;
445 if (view->file_size == 0) {
446 close(view->tmp_fd);
447 strnz__cpy(tmp_str, _("view: no standard input"), MAXLEN - 1);
448 ui_abend(-1, tmp_str);
449 exit(EXIT_FAILURE);
450 }
451 waitpid(-1, nullptr, 0);
452 view->in_fd = view->tmp_fd;
453 }
454 view->buf =
455 mmap(nullptr, view->file_size, PROT_READ, MAP_PRIVATE, view->in_fd, 0);
456 if (view->buf == MAP_FAILED) {
457 ssnprintf(em0, MAXLEN - 1, _("%s, line: %d"), __FILE__, __LINE__ - 2);
458 ssnprintf(em1, MAXLEN - 1, _("mmap %s"), file_name);
459 strerror__r(errno, em2, MAXLEN);
460 ui_display_error(em0, em1, em2, nullptr);
461 close(view->in_fd);
462 return -1;
463 }
464 close(view->in_fd);
465 stdio_fdnames(stdio_names_str, _("init_view.c 422"));
466 view->file_size = sb.st_size;
467 view->prev_file_pos = NULL_POSITION;
468 view->buf_curr_ptr = view->buf;
469 if (view->cmd_all[0] != '\0')
470 strnz__cpy(view->cmd, view->cmd_all, MAXLEN - 1);
471 for (idx = 0; idx < NMARKS; idx++)
472 view->mark_tbl[idx] = NULL_POSITION;
473 strnz__cpy(view->cur_file_str, file_name, MAXLEN - 1);
474 base_name(view->file_name, view->cur_file_str);
475 return 0;
476}
#define P_READ
Definition common.h:53
#define P_WRITE
Definition common.h:54
char stdio_names_str[4096]
Definition futil.c:122
#define MAXARGS
Definition cm.h:64
char * stdio_fdnames(char *, char *)
Definition futil.c:1108
char em1[MAXLEN]
Definition ui_common.c:47
char em2[MAXLEN]
Definition ui_common.c:48
void ui_restore_wins()
Restore the state of all windows in the UI. This function refreshes the standard screen and all surfa...
#define NMARKS
Definition view.h:33
#define VBUFSIZ
Definition view.h:37
#define NULL_POSITION
Definition view.h:36
#define UIKEY_TIMEOUT
#define UIKEY_STREAM_DATA
#define UIKEY_F09
void ui_flush_input()
Flush any pending input events from the NotCurses context. This function discards any input events th...
void ui_abend(int ec, char *s)
Convert multibyte string to complex character array.
Definition ui_common.c:362
int pipe_fd[2]
Definition pick_engine.c:46
void cmenu_abend(Init *init, int ec, char *s)
Definition menu.c:94
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition whence.c:291
int str_to_args(char **, char *, uint)
Converts a string into an array of argument strings.
Definition futil.c:412
bool expand_tilde(char *, uint)
Replaces "~/" in string with the user's home directory.
Definition futil.c:989
size_t strnz__cat(char *, const char *, size_t)
safer alternative to strncat
Definition whence.c:320
char * strerror__r(int errnum, char *buf, size_t buflen)
A thread-safe alternative to strerror() that writes the error message corresponding to errnum into th...
Definition futil.c:748
int destroy_argv(uint argc, char **argv)
Deallocates memory allocated for argument strings in argv.
Definition futil.c:468
bool base_name(char *, char *)
Returns the base name of a file specification.
Definition futil.c:1132
void sig_prog_mode()
Set up signal handlers for interrupt signals.
Definition sig.c:61
int ui_perror(char *emsg_str)
Display a simple error message window or print to stderr.
Definition ui_common.c:1257
void ui_unregister_read_fd(int fd)
Unregister an external file descriptor from polling.
Definition ui_common.c:1134
void ui_register_read_fd(int fd, int token_id)
Register an external file descriptor for polling.
Definition ui_common.c:1117
int ui_timeout_prompt(char *msg0, char *msg1, uint timeout_ms, uint timeout_secs)
Display a timeout prompt window or print to stderr.
Definition ui_common.c:1033
int ui_poll_reg_read_fd(int timeout_ms)
Poll for input on registered external files.
Definition ui_common.c:1155
int ui_display_error(char *msg0, char *msg1, char *msg2, char *msg3)
Display an error message window or print to stderr.
Definition ui_common.c:1200
uint timeout_secs
Definition common.h:182

References base_name(), View::buf, View::buf_curr_ptr, View::cmd, View::cmd_all, cmenu_abend(), View::cur_file_str, destroy_argv(), em0, em1, em2, expand_tilde(), View::f_in_pipe, View::file_name, View::file_size, View::in_fd, View::mark_tbl, View::prev_file_pos, View::provider_cmd, sig_prog_mode(), ssnprintf(), stdio_fdnames(), stdio_names_str, str_to_args(), strerror__r(), strnz__cat(), strnz__cpy(), Init::timeout_secs, View::tmp_fd, ui_abend(), ui_display_error(), ui_flush_input(), ui_perror(), ui_poll_reg_read_fd(), ui_register_read_fd(), ui_restore_wins(), ui_timeout_prompt(), ui_unregister_read_fd(), and Init::view.

Referenced by new_view_file(), and view_file().

Here is the call graph for this function:
Here is the caller graph for this function: