2
3
4
5
6
7
8
9
12
13
14
23#include <sys/sysmacros.h>
35
36
37
38
39
40
41
42
43
44
45
46
61 if (view
->sfc->lnno ==
nullptr) {
72 if (view
->sfc->cmdln ==
nullptr) {
90
91
92
93
94
95
96
106
107
108
109
110
111
112
124 "%s:%d view->lines=%d, view->cols=%d, view->maxrows=%d, view->maxcols=%d",
126 view->lines, view->cols, view->smaxrow, view->smaxcol);
127 write_cmenu_log(em0);
140
141
142
143
144
145
146
174
175
176
177
187
188
189
190
191
192
193
194
199
200
201 uint scr_lines, scr_cols;
204 ssnprintf(em0, MAXLEN - 1,
205 "%s:%d=%d calc lines=%d, cols=%d, begy=%d, begx=%d",
206 __FILE__, __LINE__, 526, view->lines, view->cols, view->begy, view->begx);
207 write_cmenu_log(em0);
211 view
->cols = scr_cols - 2;
215 uint lines =
max(scr_lines / 10, 8);
217 if (view
->lines > scr_lines - 3)
222 uint cols =
max(scr_cols / 3, 40);
224 if (view
->cols > scr_cols - 2)
225 view
->cols = scr_cols - 2;
246 ssnprintf(em0, MAXLEN - 1,
247 "%s:%d calc BOX lines=%d, cols=%d, begy=%d, begx=%d",
248 __FILE__, __LINE__, view->lines + 2, view->cols + 2, view->begy, view->begx);
249 write_cmenu_log(em0);
250 ssnprintf(em0, MAXLEN - 1,
251 "%s:%d calc WIN lines=%d, cols=%d, begy=%d, begx=%d",
252 __FILE__, __LINE__, view->lines, view->cols, 1, 1);
253 write_cmenu_log(em0);
254 ssnprintf(em0, MAXLEN - 1,
255 "%s:%d calc CMDLN lines=%d, cols=%d, begy=%d, begx=%d",
256 __FILE__, __LINE__, 1, view->cols, view->lines - 1, 1);
257 write_cmenu_log(em0);
258 ssnprintf(em0, MAXLEN - 1,
259 "%s:%d calc LNNO lines=%d, cols=%d, begy=%d, begx=%d",
260 __FILE__, __LINE__, view->lines - 1, view->ln_win_cols, 0, 0);
261 write_cmenu_log(em0);
262 ssnprintf(em0, MAXLEN - 1,
263 "%s:%d calc PAD lines=%d, cols=%d, begy=%d, begx=%d",
264 __FILE__, __LINE__, view->lines - 1, view->cols - view->ln_win_cols, 0, view->ln_win_cols);
265 write_cmenu_log(em0);
270
271
272
273
274
275
276
277
278
289 if (strcmp(file_name,
"-") == 0) {
290 file_name =
"/dev/stdin";
295 if (pipe(pipe_fd) == -1) {
296 Perror("pipe(pipe_fd) failed in init_view");
300 if ((pid = fork()) == -1) {
301 Perror("fork() failed in init_view");
306 int dev_null = open(
"/dev/null", O_WRONLY);
307 if (dev_null == -1) {
308 Perror("open(/dev/null) failed in init_pick child process");
311 dup2(dev_null, STDERR_FILENO);
314 dup2(pipe_fd[
P_WRITE], STDOUT_FILENO);
316 execvp(s_argv[0], s_argv);
331 view
->in_fd = dup(STDIN_FILENO);
336 view
->in_fd = open(file_name, O_RDONLY);
345 if (fstat(view
->in_fd, &sb) == -1) {
364 if (!S_ISREG(sb.st_mode))
371 view
->tmp_fd = memfd_create(
"view_input", MFD_CLOEXEC);
372 if (view
->in_fd < 0 || errno != 0) {
376 __LINE__ - 4
, errno
);
381 ssize_t bytes_read = 0;
382 ssize_t bytes_written = 0;
383 while ((bytes_read = read(view
->in_fd, buf,
sizeof(buf))) > 0) {
384 if ((bytes_written = write(view
->tmp_fd, buf, bytes_read)) != bytes_read) {
385 abend(-1
, "unable to write view->tmp_fd");
389 if (fstat(view
->tmp_fd, &sb) == -1) {
393 __LINE__ - 4
, errno
);
404 waitpid(-1,
nullptr, 0);
409 if (view
->buf == MAP_FAILED) {
424 for (idx = 0; idx <
NMARKS; idx++)
char stdio_names_str[4096]
char * stdio_fdnames(char *, char *)
#define max(a, b)
max macro evaluates two expressions, returning greatest result.
int ui_bkgdset(UiSurface *s, uint w, const UiCell *cell)
UiSurface * ui_surface_new(uint w, UiSurface *parent, uint p, uint lines, uint cols, uint y, uint x)
int ui_setscrreg(UiSurface *s, uint w, uint top, uint bottom)
int ui_scrollok(UiSurface *s, uint w, bool enable)
int ui_bkgd(UiSurface *s, uint w, const UiCell *cell)
void ui_surface_destroy(UiSurface *s)
int ui_idlok(UiSurface *s, uint w, bool enable)
void ui_get_screen_size(uint *lines, uint *cols)
UiSurface * ui_box_surface_new(UiSurface *parent, uint p, uint lines, uint cols, uint y, uint x, char *title)
int ui_keypad(UiSurface *s, uint w, bool enable)
int ui_idcok(UiSurface *s, uint w, bool enable)
int ui_surface_addpad(UiSurface *s, uint w, uint view_win, uint lines, uint cols)
int ui_surface_addwin(UiSurface *s, uint w, uint p, uint lines, uint cols, uint y, uint x)
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 border_title(UiSurface *sfc, char *title)
Draw a box with a title around the specified window.
int Perror(char *emsg_str)
Display a simple error message window or print to stderr.
void abend(int ec, char *s)
Abnormal program termination.
int display_error(char *msg0, char *msg1, char *msg2, char *msg3)
Display an error message window or print to stderr.
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
int str_to_args(char **, char *, uint)
Converts a string into an array of argument strings.
bool expand_tilde(char *, uint)
Replaces "~/" in string with the user's home directory.
size_t strnz__cat(char *, const char *, size_t)
safer alternative to strncat
int destroy_argv(uint argc, char **argv)
Deallocates memory allocated for argument strings in argv.
bool base_name(char *, char *)
Returns the base name of a file specification.
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 *init)
Initialize C-Menu View in full screen mode.
int init_view_boxwin(Init *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 *init, char *file_name)
Initialize the input for the C-Menu View.
void sig_prog_mode()
Set up signal handlers for interrupt signals.
char provider_cmd[MAXLEN]
char cur_file_str[MAXLEN]