2
3
4
5
6
7
8
11
12
14#include "include/common.h"
27int picker(Init *,
char *field);
49 "vi",
"vim",
"nano",
"nvim",
50 "pico",
"emacs",
"edit",
""};
53
54
55
56
57
58
59
60
61
62
63
64
65
66int init_pick(Init *init,
int argc,
char **argv,
int by,
int bx) {
80 Perror("pipe(pipe_fd) failed in init_pick");
83 if ((pid = fork()) == -1) {
84 Perror("fork() failed in init_pick");
89 int dev_null = open(
"/dev/null", O_WRONLY);
91 Perror("open(/dev/null) failed in init_pick child process");
94 dup2(dev_null, STDERR_FILENO);
102 execvp(s_argv[0], s_argv);
109
118 pick
->in_fp = fdopen(STDIN_FILENO,
"rb");
130 if (sb.st_size == 0) {
160 waitpid(pid,
nullptr, 0);
165 keypad(pick
->win,
true);
168 Perror("No pick objects available");
200
201
202
203
204
205
211 if (view
->buf !=
nullptr) {
221
222
223
224
225
226
227
228
241 for (i = 1; i < pick
->argc; i++)
251
252
253
254
255
256
257
258
259
263 int whitespace_ratio = 15;
266 int tbl_max_cols, pg_max_objs;
267 bool f_processed =
false;
270 getmaxyx(stdscr, maxy, maxx);
277 pick
->begy = (maxy * whitespace_ratio) / 200;
278 usable_lines = maxy - (maxy * whitespace_ratio) / 100;
279 usable_lines -= pick
->begy;
283 pick
->lines = usable_lines * pick_ratio / 100;
302 pg_max_objs = pick
->lines * tbl_max_cols;
326 Perror("Failed to open pick window");
358 mvwaddstr(pick
->win2, 0, 0,
"Selection Processed");
369
370
371
372
373
374
375
376
404
405
406
407
408
409
410
428
429
430
431
432
433
434
439 wclrtoeol(pick
->win);
462
463
464
465
466
467
468
469
476 if (s ==
nullptr || s[0] ==
'\0' || strstr(pick
->m_object[pick
->m_idx], s) !=
nullptr) {
485
486
487
488
489
490
491
492
493
513
514
515
516
517
518
519
520
521
522
536 mvwadd_wchnstr(pick
->win, pick
->y, 0, &
sp, 1);
548 mvwadd_wchnstr(pick
->win, pick
->y, 0, &
sp, 1);
552
553
554
555
556
557
558
559
560
561
562
563
569 mvwadd_wchnstr(pick
->win, pick
->y, 0, &
sp, 1);
577
578
584 mvwadd_wchnstr(pick
->win, pick
->y, 0, &
sp, 1);
593 SIO *sio = init
->sio;
601
602
603
604
605
606
607
608
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
665 char tmp_str[
MAXLEN] = {
'\0'};
672 bool f_append_objects =
false;
676 if (pick
->cmd[0] ==
'\0')
678 if (pick
->cmd[0] ==
'\\' || pick
->cmd[0] ==
'\"') {
679 size_t len = strlen(pick
->cmd);
680 if (len > 1 && pick
->cmd[len - 1] ==
'\"') {
682 pick
->cmd[len - 2] =
'\0';
688 for (i = 0; i < pick
->d_cnt; i++) {
690 if (tmp_str[0] !=
'\0')
695 eargv[eargc++] = strdup(tmp_str);
697 f_append_objects =
false;
701 if (strstr(eargv[i],
"%%") !=
nullptr) {
703 f_append_objects =
true;
710 for (i = 0; i < pick
->d_cnt; i++) {
713 if (f_append_objects ==
true) {
714 if (tmp_str[0] !=
'\0')
722 if (f_append_objects ==
true) {
723 if (eargv[eargx] !=
nullptr) {
725 eargv[eargx] =
nullptr;
728 if (out_s ==
nullptr || out_s[0] ==
'\0') {
731 if (eargv[i] !=
nullptr)
735 Perror("rep_substring() failed in exec_objects");
739 eargv[eargx] = strdup(out_s);
740 if (out_s !=
nullptr) {
747 eargv[eargc] =
nullptr;
750 tok = strtok_r(tmp_str,
" ", &sav_ptr);
753 if (tmp_str[0] !=
'\0' && (strcmp(tmp_str,
"view") == 0 || strcmp(tmp_str,
"view") == 0)) {
755
760 if (title[0] !=
'\0')
768 if (eargv[i] !=
nullptr)
776 if ((pid = fork()) == -1) {
780 if (eargv[i] !=
nullptr)
784 Perror("fork() failed in exec_objects");
786 }
else if (pid == 0) {
795 execvp(eargv[0], eargv);
799 waitpid(pid,
nullptr, 0);
806
807
808
809
810
811
812
813
814
819 int split_win_lines = 2;
832 keypad(pick
->win,
true);
838
839
840
841
842
843
857 eargv[eargc++] = strdup(
"view");
858 eargv[eargc++] = strdup(
"-Nf");
859 eargv[eargc++] = strdup(tmp_str);
860 eargv[eargc] =
nullptr;
872
873
874
875
876
877
878
879
880
881
882
883
884
886 bool f_insert =
false;
890 char *accept_s = field;
894 char *fend = field + flen;
895 char *str_end = field + strlen(field);
899 char *prev_ptr = prev_field;
900 char view_file[
MAXLEN] = {
'\0'};
909 mousemask(BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED,
nullptr);
913 keypad(pick
->win,
true);
919
920
949 mvwadd_wchnstr(pick
->win, pick
->y, 0, &
sp, 1);
960 wchar_t wstr[2] = {
BW_RAN, L'\0'};
961 setcchar(&cc, wstr, WA_NORMAL,
cp_box,
nullptr);
962 mvwadd_wch(pick
->win2, 0, 0, &cc);
1023
1047 wnoutrefresh(pick
->win);
1052
1121
1139
1164
1173
1200
1201
1219 if (accept_s !=
nullptr && accept_s[0] !=
'\0') {
1240 mvwaddstr(pick
->win2, 0, col, accept_s);
1248 pos = col + strlen(accept_s);
1251 mvwadd_wchnstr(pick
->win2, 0, 0, &
ran, 1);
1253 wmove(pick
->win2, 0, pos);
1258 if (in_key == KEY_F(13)) {
1299 while (*ptr !=
'\0')
1301 pos = col + (ptr - accept_s);
1342 if (ptr > accept_s) {
1355 if (ptr == accept_s) {
1370 if (ptr > accept_s) {
1379 if (ptr < fend && ptr <= str_end) {
1393 fend = accept_s + flen;
1394 str_end = accept_s + strlen(accept_s);
1395 ptr = accept_s + (pos - col);
1396 ptr =
min(ptr, str_end);
1397 pos = col + (ptr - accept_s);
1403 if (in_key <
' ' || in_key >
'~') {
1412 if (str_end < fend) {
1423 if (ptr < str_end) {
1426 }
else if (ptr == str_end) {
1443
1444
1445
1446
1447
1448
1449
1450
1451
1471 e = getenv(
"VIEW_HELP_FILE");
1472 if (e && e[0] !=
'\0') {
1477 "~/menuapp/help", R_OK
);
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1499 if (view
->buf !=
nullptr) {
1502 view
->buf =
nullptr;
int process_config_file(char *, Init *)
void destroy_view_win(Init *)
int popup_view(Init *, int, char **, int, int, int, int)
instantiate a view popup window
void destroy_line_table(View *)
size_t rtrim(char *)
Trims trailing spaces from string s in place.
WINDOW * win_win2[MAXWIN]
char stdio_names_str[MAXLEN]
#define min(x, y)
min macro evaluates two expressions, returning least result
char * stdio_fdnames(char *, char *)
#define max(a, b)
max macro evaluates two expressions, returning greatest result.
void end_pick_view(Init *)
char const pagers_editors[12][10]
void remove_right_angle(Pick *)
int border_title(WINDOW *, char *)
Draw a box with a title around the specified window.
int dxwgetch(WINDOW *, WINDOW *, WINDOW *, WINDOW *, WINDOW *, Chyron *, int)
Wrapper for wgetch that handles signals, mouse events, checks for clicks on the chyron line,...
void restore_wins()
Restore all windows after a screen resize.
void win_del()
Delete the current window and its associated box window.
int border_hsplit_text(WINDOW *, char *, int)
Draw a box with a separator line and text around the specified window.
void mvwaddstr_fill(WINDOW *, int, int, char *, int)
For lines shorter than their display area, fill the rest with spaces.
int box_hsplit_new(int, int, int, int, int, char *)
Create a new window with optional box and title, and a second window inside it, split horizontally.
void initialize_local_colors(SIO *)
Initialize local color variables and color pairs based on SIO settings.
int Perror(char *)
Display a simple error message window or print to stderr.
void abend(int, char *)
Abnormal program termination.
void set_chyron_key(Chyron *, int, char *, int)
Set chyron key with default color pair (cp_nt_rev).
void display_chyron(WINDOW *, Chyron *, int, int)
Display chyron on window.
Chyron * destroy_chyron(Chyron *chyron)
Destroy Chyron structure.
void set_chyron_key_cp(Chyron *, int, char *, int, int)
Set chyron key with color pair (cp).
void compile_chyron(Chyron *)
construct the chyron string from the chyron structure
Chyron * new_chyron()
Create and initialize Chyron structure.
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
char * rep_substring(const char *, const char *, const char *)
Replace all occurrences of "tgt_s" in "org_s" with "rep_s".
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.
int init_view_boxwin(Init *)
Initialize the C-Menu View in box window mode.
int view_init_input(Init *, char *)
Initialize the input for the C-Menu View.
View * destroy_view(Init *init)
Destroy View structure.
bool verify_spec_arg(char *, char *, char *, char *, int)
Verify file specification argument.
View * new_view(Init *)
Create and initialize View structure.
Pick * new_pick(Init *, int, char **, int, int)
Create and initialize Pick structure.
void save_object(Pick *, char *)
Saves a string as an object in the pick structure.
void toggle_object(Pick *)
Toggles the selection state of the currently selected object in pick window.
int picker(Init *, char *field)
Main loop for handling user input and interactions in the pick interface.
int init_pick(Init *, int, char **, int, int)
Initializes pick structure and opens pick input file or pipe.
int new_pick_view(Init *)
Initializes a new view for displaying file contents in the pick interface.
void unreverse_object(Pick *)
Unreverses the display of the currently selected object in pick window.
void destroy_pick_view(Init *)
Destroys pick view, unmaps file buffer, and cleans up resources.
void pick_std_chyron(Pick *)
Sets standard chyron key states based on pick structure.
int output_objects(Pick *)
Outputs selected objects to specified output file.
int match_objects(Pick *pick, char *s)
Displays current page of objects in pick window.
void deselect_object(Pick *)
Deselects the currently selected object in pick window.
int read_pick_input(Init *)
Reads pick input from file pointer and saves objects into pick structure.
void reverse_object(Pick *)
Reverses the display of the currently selected object in pick window.
int pick_engine(Init *)
Initializes pick interface, calculates window size and position, and enters picker loop.
void display_pick_page(Pick *)
Displays current page of objects in pick window.
void new_view_file(Init *, char *)
Initializes a new view for displaying the contents of a specified file in the pick interface.
void display_pick_help(Init *)
Displays the help screen for the pick interface using view.
int open_pick_win(Init *)
Initializes the pick window based on the parameters specified in the Pick structure.
int exec_objects(Init *)
Executes specified command with selected objects as arguments.
bool restore_curses_tioctl()
restore_curses_tioctl() - restore curses terminal settings
void sig_prog_mode()
Set up signal handlers for interrupt signals.
int view_cmd_processor(Init *)
Main Command Processing Loop for View.
void build_prompt(View *)
Build Prompt String.
void initialize_line_table(View *)
Initialize Line Table.
void next_page(View *)
Advance to Next Page.
int pad_refresh(View *)
Refresh Pad and Line Number Window.
int display_prompt(View *, char *)
Display Command Line Prompt.
ChyronKey * key[CHYRON_KEYS]
bool f_selected[OBJ_MAXCNT]
char provider_cmd[MAXLEN]
char provider_cmd[MAXLEN]
char receiver_cmd[MAXLEN]