C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
View Engine

File mapping, user input, command processing, and display logic. More...

Macros

#define get_next_char()
 read the next characater from the virtual file
#define get_prev_char()
 read the previous characater from the virtual fileThere is no need to track line numbers when moving backwards as they are stored in the line table and accessed as needed. When reading in reverse, the Beginning of Data (BOD) flag is set when the file position is zero, and cleared when the position or reading direction changes. Carriage-returns are ignored as they should be.

Functions

void build_prompt (View *view)
 Build Prompt String.
void cat_file (View *view)
 Concatenate File to Standard Output.
bool enter_file_spec (Init *init, char *file_spec)
 use form to enter a file specification
int get_cmd_arg (View *view, char *prompt)
 Get Command Argument from User Input.
int get_cmd_char (View *view, off_t *n)
 Get Command Character from User Input.
void lp (View *view, char *PrintFile)
 Send File to Print Queue.
int view_cmd_processor (Init *init)
 Main Command Processing Loop for View.
int view_file (Init *init)
 Start view.
int write_view_buffer (Init *init, bool f_strip_ansi)
 Write buffer contents to files.

Detailed Description

File mapping, user input, command processing, and display logic.

Macro Definition Documentation

◆ get_next_char

#define get_next_char ( )
Value:
{ \
c = 0; \
do { \
if (view->file_pos == view->file_size) { \
view->f_eod = true; \
break; \
} else \
view->f_eod = false; \
c = view->buf[view->file_pos++]; \
} while (c == 0x0d); \
if (c == '\n') \
increment_ln(view); \
}
View * view
Definition mem.c:38

read the next characater from the virtual file

Line numbers are tracked when reading forward and stored in a line table for quick access when moving backwards. When reading forward, the End of Data (EOD) flag is set when the position is equal to the file size, and cleared when the position or reading direction changes.

Note
view_engine.c line numbering The macro, get_next_char() reads lines delimited by '
', advancing the line number index at the end of each record. The line number index is one record ahead for most operations, including line numbering as lines are displayed. Nevertheless, when providing a line number index to get_line(), you must use the zero origin index, which is one less than the line number index

Definition at line 53 of file view_engine.c.

53#define get_next_char() \
54 { \
55 c = 0; \
56 do { \
57 if (view->file_pos == view->file_size) { \
58 view->f_eod = true; \
59 break; \
60 } else \
61 view->f_eod = false; \
62 c = view->buf[view->file_pos++]; \
63 } while (c == 0x0d); \
64 if (c == '\n') \
65 increment_ln(view); \
66 }

◆ get_prev_char

#define get_prev_char ( )
Value:
{ \
c = 0; \
do { \
if (view->file_pos == 0) { \
view->f_bod = true; \
break; \
} else \
view->f_bod = false; \
c = view->buf[--view->file_pos]; \
} while (c == 0x0d); \
}

read the previous characater from the virtual fileThere is no need to track line numbers when moving backwards as they are stored in the line table and accessed as needed. When reading in reverse, the Beginning of Data (BOD) flag is set when the file position is zero, and cleared when the position or reading direction changes. Carriage-returns are ignored as they should be.

Definition at line 76 of file view_engine.c.

76#define get_prev_char() \
77 { \
78 c = 0; \
79 do { \
80 if (view->file_pos == 0) { \
81 view->f_bod = true; \
82 break; \
83 } else \
84 view->f_bod = false; \
85 c = view->buf[--view->file_pos]; \
86 } while (c == 0x0d); \
87 }

Function Documentation

◆ build_prompt()

void build_prompt ( View * view)

Build Prompt String.

Parameters
viewPointer to the View structure containing the state and parameters of the view application. This structure is used to access and modify the state of the application as needed.

This function constructs a prompt string that provides information about the current state of the view application. The prompt includes details such as the file name, current column, file number, file position, and whether the end of the document has been reached. The constructed prompt string is stored in the view->prompt_str buffer for display to the user.

Note
The prompt string is built based on the current state of the view application, and segments that are not relevant will be omitted. Less relevant segments will be omitted if the length of the prompt string exceeds more than half the available space. The length of the prompt string has a hard limit of view->cols - 4.

Definition at line 907 of file view_engine.c.

907 {
908 char tmp_str[MAXLEN];
909 uint prompt_maxlen = min(MAXLEN - 1, view->cols - 4);
910 uint prompt_l = 0;
911 // ----------------< File Name >----------------
912 if (view->f_is_pipe)
913 strnz__cpy(view->prompt_str, "stdin", prompt_maxlen);
914 else
915 strnz__cpy(view->prompt_str, view->file_name, prompt_maxlen);
916 // ----------------< Columns >----------------
917 if (view->pmincol > 0) {
918 sprintf(tmp_str, "Col %d of %d", view->pmincol, view->maxcol);
919 if (view->prompt_str[0] != '\0')
920 strnz__cat(view->prompt_str, "|", prompt_maxlen);
921 strnz__cat(view->prompt_str, tmp_str, prompt_maxlen);
922 }
923 // ----------------< File Number >----------------
924 if (view->argc > 1) {
925 prompt_l = (uint)strlen(view->prompt_str);
926 if (prompt_l > (view->cols - 4) / 2)
927 return;
928 if (view->argc > 0) {
929 sprintf(tmp_str, "File %d of %d", view->curr_argc + 1, view->argc);
930 if (view->prompt_str[0] != '\0') {
931 strnz__cat(view->prompt_str, "|", prompt_maxlen);
932 strnz__cat(view->prompt_str, tmp_str, prompt_maxlen);
933 }
934 }
935 }
936 // ----------------< File Position >----------------
937 prompt_l = (uint)strlen(view->prompt_str);
938 if (prompt_l > (view->cols - 4) / 2)
939 return;
940 view->page_top_pos = view->ln_tbl[view->page_top_ln_no];
941 if (view->page_top_pos == NULL_POSITION)
942 view->page_top_pos = view->file_size;
943 view->page_bot_pos = view->ln_tbl[view->page_bot_ln_no + 1];
944 if (view->page_bot_pos == NULL_POSITION)
945 view->page_bot_pos = view->file_size;
946 sprintf(tmp_str, "Pos %zd-%zd", view->page_top_pos, view->page_bot_pos);
947 if (view->prompt_str[0] != '\0') {
948 strnz__cat(view->prompt_str, "|", prompt_maxlen);
949 strnz__cat(view->prompt_str, tmp_str, prompt_maxlen);
950 }
951 if (!view->f_is_pipe) {
952 if (view->file_size > 0) {
953 sprintf(tmp_str, " of %zd", view->file_size);
954 strnz__cat(view->prompt_str, tmp_str, prompt_maxlen);
955 }
956 }
957 // ----------------< (End) >----------------
958 prompt_l = (uint)strlen(view->prompt_str);
959 if (prompt_l > (view->cols - 4) / 2)
960 return;
961 if (view->f_eod) {
962 if (view->prompt_str[0] != '\0')
963 strnz__cat(view->prompt_str, " ", prompt_maxlen);
964 strnz__cat(view->prompt_str, "(End)", prompt_maxlen);
965 if (view->curr_argc + 1 < view->argc) {
966 base_name(tmp_str, view->argv[view->curr_argc + 1]);
967 strnz__cpy(view->prompt_str, " Next File: ", prompt_maxlen);
968 strnz__cat(view->prompt_str, tmp_str, prompt_maxlen);
969 }
970 }
971}
#define min(x, y)
min macro evaluates two expressions, returning least result
Definition cm.h:91
#define NULL_POSITION
Definition view.h:38
#define MAXLEN
Definition curskeys.c:15
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition futil.c:537
size_t strnz__cat(char *, const char *, size_t)
safer alternative to strncat
Definition futil.c:566
bool base_name(char *, char *)
Returns the base name of a file specification.
Definition futil.c:1106

References View::argc, View::argv, base_name(), View::cols, View::curr_argc, View::f_eod, View::f_is_pipe, View::file_name, View::file_size, View::ln_tbl, View::maxcol, View::page_bot_ln_no, View::page_bot_pos, View::page_top_ln_no, View::page_top_pos, View::pmincol, View::prompt_str, strnz__cat(), and strnz__cpy().

Referenced by get_cmd_char(), new_view_file(), and view_cmd_processor().

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

◆ cat_file()

void cat_file ( View * view)

Concatenate File to Standard Output.

Definition at line 1026 of file view_engine.c.

1026 {
1027 int c;
1028 while (1) {
1029 get_next_char();
1030 if (view->f_eod)
1031 break;
1032 putchar(c);
1033 }
1034}
#define get_next_char()
read the next characater from the virtual file
Definition view_engine.c:53

References View::f_eod.

◆ enter_file_spec()

bool enter_file_spec ( Init * init,
char * file_spec )

use form to enter a file specification

Parameters
initdata structure
file_spec- pointer to file specification the file_spec
Returns
true if successful

the user must provide a character array large enough to hold file_spec without overflowing

call form to get file_name write the name to a temporary file

Definition at line 2614 of file view_engine.c.

2614 {
2615 char earg_str[MAXLEN];
2616 char *eargv[MAXARGS];
2617 uint eargc;
2618 char tmp_dir[MAXLEN];
2619 char tmp_str[MAXLEN];
2620 char tmp_spec[MAXLEN];
2621 int rc = 0;
2622 FILE *tmp_fp;
2623 View *view = init->view;
2624 strnz__cpy(tmp_dir, init->mapp_home, MAXLEN - 1);
2625 strnz__cat(tmp_dir, "/tmp", MAXLEN - 1);
2626 expand_tilde(tmp_dir, MAXLEN - 1);
2627 if (!mk_dir(tmp_dir)) {
2628 ssnprintf(em0, MAXLEN - 1, "%s, line: %d", __FILE__, __LINE__ - 2);
2629 strnz__cpy(em1, "Unable to ", MAXLEN - 1);
2630 strnz__cat(em1, "mkdir", MAXLEN - 1);
2631 strnz__cat(em1, tmp_dir, MAXLEN - 1);
2632 strerror_r(errno, em2, MAXLEN - 1);
2633 display_error(em0, em1, em2, nullptr);
2634 return false;
2635 }
2636 while (rc == false) {
2637 strnz__cpy(tmp_spec, tmp_dir, MAXLEN - 1);
2638 strnz__cat(tmp_spec, "/tmp_XXXXXX", MAXLEN - 1);
2639 view->in_fd = mkstemp(tmp_spec);
2640 if (view->in_fd == -1) {
2641 ssnprintf(em0, MAXLEN - 1, "%s, line: %d", __FILE__, __LINE__ - 2);
2642 strnz__cpy(em1, "unable to ", MAXLEN - 1);
2643 strnz__cat(em1, "mkstemp ", MAXLEN - 1);
2644 strnz__cat(em1, tmp_spec, MAXLEN - 1);
2645 strerror_r(errno, em2, MAXLEN - 1);
2646 display_error(em0, em1, nullptr, nullptr);
2647 return false;
2648 }
2651
2652 strnz__cpy(earg_str, "form -d file_name.f -o ", MAXLEN - 1);
2653 strnz__cat(earg_str, tmp_spec, MAXLEN - 1);
2655 rc = popup_form(init, eargc, eargv, view->begy + view->lines - 7, 4);
2658 if (rc == FA_CANCEL || rc == 'q' || rc == 'Q' || rc == KEY_F09)
2659 return false;
2660 close(view->in_fd);
2661 tmp_fp = fopen(tmp_spec, "r");
2662 if (tmp_fp == nullptr) {
2663 ssnprintf(em0, MAXLEN - 1, "%s, line: %d", __FILE__, __LINE__ - 2);
2664 strnz__cpy(em1, "unable to ", MAXLEN - 1);
2665 strnz__cat(em1, "fopen ", MAXLEN - 1);
2666 strnz__cat(em1, tmp_spec, MAXLEN - 1);
2667 strerror_r(errno, em2, MAXLEN - 1);
2668 display_error(em0, em1, em2, nullptr);
2669 return false;
2670 }
2671 fgets(tmp_str, MAXLEN - 1, tmp_fp);
2672 strnz(tmp_str, MAXLEN - 1);
2673 fclose(tmp_fp);
2674 unlink(tmp_spec);
2675 if (!verify_spec_arg(file_spec, tmp_str, "~/menuapp/tmp", ".",
2676 S_WCOK | S_QUIET)) {
2677 ssnprintf(em0, MAXLEN - 1, "Unable to open %s for writing",
2678 tmp_str);
2679 strnz__cpy(em1, "Try again? y (yes) or n (no) ", MAXLEN - 1);
2680 rc = display_error(em0, em1, nullptr, nullptr);
2681 if (rc == 'y' || rc == 'Y')
2682 continue;
2683
2684 } else
2685 return true;
2686 }
2687 return true;
2688}
@ FA_CANCEL
Definition form.h:33
int popup_form(Init *, int, char **, uint, uint)
instantiate a form popup window
Definition popups.c:113
#define MAX_ARGS
Definition cm.h:48
#define MAXARGS
Definition cm.h:50
#define S_QUIET
Definition cm.h:328
#define S_WCOK
Definition cm.h:327
void ui_restore_wins()
#define KEY_F09
char * eargv[MAXARGS]
Definition futil.c:51
int eargc
Definition futil.c:50
char earg_str[MAXLEN]
Definition futil.c:49
char em1[MAXLEN]
Definition dwin.c:143
char em2[MAXLEN]
Definition dwin.c:144
char em0[MAXLEN]
Definition dwin.c:142
int display_error(char *msg0, char *msg1, char *msg2, char *msg3)
Display an error message window or print to stderr.
Definition dwin.c:778
size_t strnz(char *, size_t)
terminates string at New Line, Carriage Return, or max_len
Definition futil.c:608
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
Definition futil.c:413
int str_to_args(char **, char *, uint)
Converts a string into an array of argument strings.
Definition futil.c:433
bool expand_tilde(char *, uint)
Replaces "~/" in string with the user's home directory.
Definition futil.c:963
bool mk_dir(char *dir)
If directory doesn't exist, make it.
Definition futil.c:1303
int destroy_argv(uint argc, char **argv)
Deallocates memory allocated for argument strings in argv.
Definition futil.c:487
bool verify_spec_arg(char *, char *, char *, char *, uint)
Verify file specification argument.
Definition mem.c:369
char mapp_home[MAXLEN]
Definition common.h:147
View * view
Definition common.h:189
Definition view.h:61

References View::begy, destroy_argv(), display_error(), em0, em1, em2, expand_tilde(), FA_CANCEL, View::in_fd, View::lines, Init::mapp_home, mk_dir(), popup_form(), ssnprintf(), str_to_args(), strnz(), strnz__cat(), strnz__cpy(), ui_restore_wins(), verify_spec_arg(), and Init::view.

Referenced by view_cmd_processor().

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

◆ get_cmd_arg()

int get_cmd_arg ( View * view,
char * prompt )

Get Command Argument from User Input.

Parameters
viewPointer to the View structure containing the state and parameters of the view application. This structure is used to access and modify the state of the application as needed.
promptA string containing the prompt to be displayed to the user when requesting input for the command argument. This prompt is shown on the command line to guide the user in providing the necessary input for the command being executed.
Returns
Returns the command character entered by the user, or a special value if a mouse event is detected. The command argument entered by the user is stored in the view->cmd_arg buffer for use by the calling function. The function handles user input, including editing keys, and updates the command argument buffer accordingly. If the user enters a numeric argument, it is validated based on the context of the command being executed.

Definition at line 864 of file view_engine.c.

864 {
865 int c;
866 char prompt_s[MAXLEN];
867 UiSurface *sfc = view->sfc;
868 uint prompt_l = strnz__cpy(prompt_s, prompt, min(MAXLEN - 1, view->cols - 4));
869 if (view->cmd_arg[0] != '\0')
870 return 0;
871 ui_cursor_move(sfc, CMDLN, view->cmd_line, 0);
872 if (prompt_l > 1) {
874 ui_waddstr(sfc, CMDLN, prompt_s);
875 ui_bkgdset(sfc, CMDLN, &cell_nt);
876 }
877 view->curx = prompt_l;
878 ui_wclrtoeol(sfc, CMDLN);
880 ui_curs_set(1);
881 ui_mvwadd_wchnstr(sfc, CMDLN, view->cmd_line, view->curx, &cell_ran, 1);
882 ui_cursor_move(sfc, CMDLN, view->cmd_line, view->curx + 1);
883 ui_render();
884 uint flin = view->cmd_line;
885 uint fcol = prompt_l + 1;
886 uint flen = view->cols - prompt_l;
887 c = cf_accept(sfc, CMDLN, view->cmd_arg, flin, fcol, flen);
888 return c;
889}
void ui_render()
Definition ui_ncurses.c:800
int ui_cursor_move(UiSurface *s, uint w, uint y, uint x)
Definition ui_ncurses.c:727
int ui_bkgdset(UiSurface *s, uint w, const UiCell *cell)
Definition ui_ncurses.c:760
int ui_mvwadd_wchnstr(UiSurface *s, uint w, uint y, uint x, const UiCell *cell, uint m)
int ui_waddstr(UiSurface *s, uint w, const char *text)
int ui_wclrtoeol(UiSurface *s, uint w)
int ui_curs_set(int visibility)
Definition ui_ncurses.c:737
int cf_accept(UiSurface *sfc, uint w, char *accept_s, uint flin, uint fcol, uint flen)
Accepts input for a field in a C-Menu window.
Definition cm_fields.c:41
UiCell cell_nt
Definition dwin.c:94
UiCell cell_ran
Definition dwin.c:103
UiCell cell_nt_rev
Definition dwin.c:95
int pad_refresh(View *)
Refresh Pad and Line Number Window.
A drawable surface in the NotCurses backend.

References cell_nt, cell_nt_rev, cell_ran, cf_accept(), View::cmd_arg, View::cmd_line, CMDLN, View::cols, View::curx, pad_refresh(), View::sfc, strnz__cpy(), ui_bkgdset(), ui_curs_set(), ui_cursor_move(), ui_mvwadd_wchnstr(), ui_render(), ui_waddstr(), and ui_wclrtoeol().

Referenced by view_cmd_processor().

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

◆ get_cmd_char()

int get_cmd_char ( View * view,
off_t * n )

Get Command Character from User Input.

Parameters
viewPointer to the View structure containing the state and parameters of the view application. This structure is used to access and modify the state of the application as needed.
nPointer to an off_t variable where the numeric argument entered by the user will be stored. If the user enters a numeric argument, it will be converted to an off_t value and stored in this variable for use by the calling function.
Returns
Returns the command character entered by the user, or a special value if a mouse event is detected. The function handles user input, including editing keys, and updates the command argument buffer accordingly. If the user enters a numeric argument, it is validated based on the context of the command being executed.

Definition at line 732 of file view_engine.c.

732 {
733 int c = 0, i = 0;
734 char *d, *s;
735 uint prevx;
736 bool once = false;
737 char cmd_str[33];
738 cmd_str[0] = '\0';
739 UiSurface *sfc = view->sfc;
740 UiEvent event;
742 ui_mvwadd_wch(sfc, CMDLN, view->cmd_line, view->curx++, &cell_ran);
743 ui_cursor_enable_yx(sfc, CMDLN, 0, view->curx, true);
744 while (1) {
745 if (i == 1 && !once) {
746 once = true;
747 view->curx = 0;
748 ui_cursor_move(sfc, CMDLN, view->cmd_line, view->curx);
749 ui_wclrtoeol(sfc, CMDLN);
750 ui_mvwadd_wch(sfc, CMDLN, view->cmd_line, view->curx++, &cell_ran);
751 ui_mvwaddch(sfc, CMDLN, view->cmd_line, view->curx++, c);
752 }
753 ui_render();
754 event.y = event.x = -1;
755 c = ui_get_event_no_mouse(sfc, CMDLN, &event);
756 switch (c) {
757 case KEY_MOUSE:
758 break;
759 case KEY_RESIZE:
760 case '\n':
761 case '\r':
762 break;
763 case 'q':
764 case KEY_F09:
766 display_prompt(view, view->prompt_str);
767 c = KEY_F09;
768 return c;
769 case '\b':
770 case KEY_BACKSPACE:
771 if (i > 0) {
772 s = &cmd_str[i];
773 d = &cmd_str[--i];
774 view->curx--;
775 prevx = view->curx;
776 while (*s != '\0') {
777 ui_mvwaddch(sfc, CMDLN, view->cmd_line, view->curx++, *s);
778 *d++ = *s++;
779 }
780 *d = '\0';
781 ui_cursor_move(sfc, CMDLN, view->cmd_line, view->curx);
782 ui_wclrtoeol(sfc, CMDLN);
783 view->curx = prevx;
784 ui_cursor_move(sfc, CMDLN, view->cmd_line, view->curx);
785 }
786 continue;
787 case KEY_DC:
788 if (i < 32 && cmd_str[i] != '\0') {
789 s = &cmd_str[i + 1];
790 d = &cmd_str[i];
791 while (*s != '\0') {
792 ui_mvwaddch(sfc, CMDLN, view->cmd_line, view->curx++, *s);
793 *d++ = *s++;
794 }
795 *d = '\0';
796 ui_cursor_move(sfc, CMDLN, view->cmd_line, view->curx);
797 ui_wclrtoeol(sfc, CMDLN);
798 ui_cursor_move(sfc, CMDLN, view->cmd_line, view->curx);
799 }
800 continue;
801 case KEY_SRIGHT:
802 if (i < 32 && cmd_str[i] != '\0') {
803 i++;
804 ui_getyx(sfc, CMDLN, &view->cury, &view->curx);
805 if (view->curx < view->cols - 1) {
806 view->curx++;
807 ui_cursor_move(sfc, CMDLN, view->cmd_line, view->curx);
808 }
809 }
810 continue;
811 case KEY_SLEFT:
812 if (i > 0) {
813 i--;
814 ui_getyx(sfc, CMDLN, &view->cury, &view->curx);
815 if (view->curx > 0) {
816 view->curx--;
817 ui_cursor_move(sfc, CMDLN, view->cmd_line, view->curx);
818 }
819 }
820 continue;
821 default:
822 if (c < '0' || c > '9' || i == 32)
823 break;
824 cmd_str[i++] = (char)c;
825 cmd_str[i] = '\0';
826 ui_mvwaddch(sfc, CMDLN, view->cmd_line, view->curx, c);
827 view->curx++;
828 continue;
829 }
830 if (c < '0' || c > '9' || i == 32)
831 break;
832 }
833 if (cmd_str[0] == '\0') {
834 *n = 0;
835 view->cmd_arg[0] = '\0';
836 ui_mvwadd_wchnstr(sfc, CMDLN, view->cmd_line, view->curx, &cell_sp, 1);
837 ui_wclrtoeol(sfc, CMDLN);
838 return (c);
839 }
840 *n = atol(cmd_str);
841 view->cmd_arg[0] = '\0';
842 ui_getyx(sfc, CMDLN, &view->cmd_line, &view->curx);
843 ui_mvwadd_wchnstr(sfc, CMDLN, view->cmd_line, view->curx, &cell_sp, 1);
844 ui_wclrtoeol(sfc, CMDLN);
845 return (c);
846}
void ui_getyx(UiSurface *s, uint w, uint *lines, uint *cols)
Definition ui_ncurses.c:668
int ui_get_event_no_mouse(UiSurface *surface, uint w, UiEvent *ev)
int ui_mvwaddch(UiSurface *s, uint w, uint y, uint x, const char c)
int ui_mvwadd_wch(UiSurface *s, uint w, uint y, uint x, const UiCell *cell)
int ui_cursor_enable_yx(UiSurface *s, uint w, uint y, uint x, bool visible)
Disable (visible = false) or enable (visibile = true) the cursor at a specified position on the surfa...
Definition ui_ncurses.c:703
#define KEY_DC
#define KEY_BACKSPACE
#define KEY_SLEFT
#define KEY_RESIZE
#define KEY_SRIGHT
#define KEY_MOUSE
UiCell cell_sp
Definition dwin.c:120
void build_prompt(View *)
Build Prompt String.
int display_prompt(View *, char *)
Display Command Line Prompt.

References build_prompt(), cell_ran, cell_sp, View::cmd_arg, View::cmd_line, CMDLN, View::cols, View::curx, View::cury, display_prompt(), pad_refresh(), View::prompt_str, View::sfc, ui_cursor_enable_yx(), ui_cursor_move(), ui_get_event_no_mouse(), ui_getyx(), ui_mvwadd_wch(), ui_mvwadd_wchnstr(), ui_mvwaddch(), ui_render(), ui_wclrtoeol(), UiEvent::x, and UiEvent::y.

Referenced by view_cmd_processor().

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

◆ lp()

void lp ( View * view,
char * PrintFile )

Send File to Print Queue.

Parameters
viewPointer to the View structure containing the state and
PrintFile- file to print

Definition at line 1039 of file view_engine.c.

1039 {
1040 char *print_cmd_ptr;
1041 char shell_cmd_spec[MAXLEN];
1042 print_cmd_ptr = getenv("PRINTCMD");
1043 if (print_cmd_ptr == nullptr || *print_cmd_ptr == '\0')
1044 print_cmd_ptr = PRINTCMD;
1045 ssnprintf(shell_cmd_spec, MAXLEN - 1, "%s %s", print_cmd_ptr, PrintFile);
1046 display_prompt(view, shell_cmd_spec);
1047 shell(shell_cmd_spec);
1048}
#define PRINTCMD
Definition common.h:47
int shell(char *)
Execute a shell command.
Definition exec.c:74

References display_prompt(), shell(), and ssnprintf().

Referenced by view_cmd_processor().

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

◆ view_cmd_processor()

int view_cmd_processor ( Init * init)

Main Command Processing Loop for View.

Parameters
initPointer to the Init structure containing initialization parameters and state for the view application. This structure is used to pass necessary information and maintain state across different functions within the view application.

'd' Breakpoint for Debugging

< Ctrl('L') or KEY_RESIZE - Handle terminal resize

< KEY_ALTHOME - horizontal scroll to the first column

< KEY_ALTEND horizontal scroll to the last column

< 'h', Ctrl('H'), KEY_LEFT, KEY_BACKSPACE - Horizontal scroll left by two thirds of the page width

< 'l', KEY_RIGHT - Horizontal scroll right by two thirds of the page width

'k', KEY_UP - Scroll up one line

'j', KEY_DOWN, KEY_ENTER - scroll down one line

Ctrl('B'), KEY_PPAGE - Previous Page

Ctrl('F'), KEY_NPAGE Next Page

'!', Execute Shell Command from within C-Menu View

'+', Set Startup Command

'-', Change View Settings

-i ignore_case in search

-n line numbers

-s squeeze multiple blank lines

-t n set tab stop columns

-w wrap long lines

-h display help

-n line numbers

-s Squeeze Multiple Blank Lines

-t n Set Tab Stop Columns

-h Display Help

'n' - Repeat Previous Search

'/' or '?' - Search Forward fromk top of page

'?' - Search Backward

'o' - Open a File

'G' - Go to the Beginning of the Document or line

'H' or KEY_F01 - Display Help Information

'm' - Set a Mark at the Current Position

'M' - Go to a Mark

'N' - Close Current File and Open Next File

'p' or '' - Go to a Percent of the File

Ctrl('Z') - Send File to Print Queue with Notation

'P' Print Current File

'P' or KEY_F09 or ESC - Close Current File and Open Next

'q' or 'Q' or KEY_F09 or ESC - Quit the Application

'v' - Open Current File in Editor

'w' - Write the current buffer to file

'V' - Display Version Information

Definition at line 214 of file view_engine.c.

214 {
215 char tmp_str[MAXLEN];
216 int tfd;
217 int c;
218 uint shift = 0;
219 int search_cmd = 0;
220 int prev_search_cmd = 0;
221 int rc;
222 uint i;
223 bool ans = true;
224 ssize_t bytes_written;
225 char *e;
226 char shell_cmd_spec[MAXLEN];
227 off_t n_cmd = 0L;
228 off_t prev_file_pos;
229 uint max_pmincol;
230 View *view = init->view;
231 UiSurface *sfc = view->sfc;
232 view->cmd[0] = '\0';
233 while (1) {
234 if (view->f_redisplay_page) {
236 view->f_redisplay_page = false;
237 }
238 c = view->next_cmd_char;
239 view->next_cmd_char = 0;
240 if (!c) {
242 display_prompt(view, view->prompt_str);
243 c = get_cmd_char(view, &n_cmd);
244 if (c >= '0' && c <= '9') {
245 tmp_str[0] = (char)c;
246 tmp_str[1] = '\0';
247 c = get_cmd_arg(view, tmp_str);
248 }
249 }
250 switch (c) {
251
252 case 'd':
253 break;
254 case Ctrl('L'):
255 case KEY_RESIZE:
256 ui_get_screen_size(&view->lines, &view->cols);
257#ifdef DEBUG_RESIZE
258 ssnprintf(em0, MAXLEN - 1,
259 "%s:%d view->page_top_ln_no=%d, resized to lines: %d, cols: %d\n",
260 __FILE__, __LINE__, view->page_top_ln_no, view->lines, view->cols);
262#endif
263 if (view->f_full_screen)
265 else
266 view_boxwin_resize(init);
267 view->f_redisplay_page = true;
268 continue;
269 case KEY_ALTHOME:
271 view->pmincol = 0;
272 break;
273 case KEY_ALTEND:
276 if (view->maxcol > view->cols)
277 view->pmincol = view->maxcol - view->cols;
278 else
279 view->pmincol = 0;
280 break;
281 case 'h':
283 case KEY_LEFT:
284 case KEY_BACKSPACE:
285 if (n_cmd > 0)
286 view->h_shift = (uint)n_cmd;
287 else if (n_cmd == 0) {
288 if (view->h_shift > 0)
289 n_cmd = view->h_shift;
290 else
291 n_cmd = 1;
292 }
293 shift = (uint)n_cmd;
294 if (view->pmincol - shift > 0)
295 view->pmincol -= shift;
296 else
297 view->pmincol = 0;
298 break;
299 case 'l':
300 case KEY_RIGHT:
301 if (n_cmd > 0)
302 view->h_shift = n_cmd;
303 else if (n_cmd == 0) {
304 if (view->h_shift > 0)
305 n_cmd = view->h_shift;
306 else
307 n_cmd = 1;
308 }
309 shift = (uint)n_cmd;
310 max_pmincol = (view->maxcol > view->cols) ? (view->maxcol - view->cols) : 0;
311 if (view->pmincol + shift < max_pmincol)
312 view->pmincol += shift;
313 else
314 view->pmincol = max_pmincol;
315 break;
316 case 'k':
317 case KEY_UP:
318 if (n_cmd <= 0)
319 n_cmd = 1;
320 scroll_up(view, (uint)n_cmd);
321 break;
323 case 'j':
324 case '\n':
325 case KEY_DOWN:
326 case KEY_ENTER:
327 if (n_cmd <= 0)
328 n_cmd = 1;
329 scroll_down(view, (uint)n_cmd);
330 break;
332 case KEY_PPAGE:
333 case Ctrl('B'):
335 break;
337 case KEY_NPAGE:
338 case Ctrl('F'):
339 view->ln_no++;
341 break;
343 case '!':
344 if (view->f_displaying_help)
345 break;
346 if (get_cmd_arg(view, "!") == 0) {
347 if (!view->f_is_pipe) {
348 view->prev_file_pos = view->page_top_pos;
349 view->next_file_spec_ptr = view->file_spec_ptr;
350 str_subc(shell_cmd_spec, view->cmd_arg, '%',
351 view->cur_file_str, MAXLEN - 1);
352 } else
353 strnz__cpy(shell_cmd_spec, view->cmd_arg, MAXLEN - 1);
354 full_screen_shell(shell_cmd_spec);
355 if (!view->f_is_pipe) {
356 view->next_file_spec_ptr = view->cur_file_str;
357 return 0;
358 }
359 }
360 break;
362 case '+':
363 if (get_cmd_arg(view, "Startup Command:") == 0)
364 strnz__cpy(view->cmd, view->cmd_arg, MAXLEN - 1);
365 break;
367 case '-':
368 display_prompt(view, "(i, n, s, t, w, or h)->");
369 c = get_cmd_char(view, &n_cmd);
370 c = S_TOLOWER(c);
371 switch (c) {
378 case 'i':
379 display_prompt(view, "Ignore Case in search (Y or N)->");
380 confirm();
381 if (ans)
382 view->f_ignore_case = true;
383 else if (c == 'n' || c == 'N')
384 view->f_ignore_case = false;
385 break;
387 case 'n':
388 display_prompt(view, "Line Numbering (Y or N)->");
389 confirm();
390 if (view->f_ln == ans)
391 break;
392 view->f_ln = ans;
393 view->f_redisplay_page = true;
394 (view->f_full_screen) ? view_full_screen_resize(init) : view_boxwin_resize(init);
395 break;
397 case 's':
399 view, "view->f_squeeze Multiple Blank lines (Y or N)->");
400 confirm();
401 view->f_squeeze = ans;
402 break;
403 case 'w':
405 view, "Line Wrapping (Y or N)->");
406 if ((c = get_cmd_char(view, &n_cmd)) == 'y' || c == 'Y')
407 ans = true;
408 else if (c == 'n' || c == 'N')
409 ans = false;
410 if (view->wrap == ans)
411 break;
412 view->wrap = ans;
413 view->f_redisplay_page = true;
414 (view->f_full_screen) ? view_full_screen_resize(init) : view_boxwin_resize(init);
415 break;
417 case 't':
418 sprintf(tmp_str,
419 "Tabstop Colums Currently %d:", view->tab_stop);
420 i = 0;
421 if (get_cmd_arg(view, tmp_str) == 0)
422 i = atoi(view->cmd_arg);
423 if (i >= 1 && i <= 12) {
424 view->tab_stop = i;
425 view->f_redisplay_page = true;
426 } else
427 Perror("Tab stops not changed");
428 break;
430 case KEY_F01:
431 case 'h':
432 if (!view->f_displaying_help) {
433 view_display_help(init);
434 view = init->view;
435 }
436 view->next_cmd_char = '-';
437 break;
438 default:
439 break;
440 }
441 break;
443 case 'n':
444 if (view->f_search_complete) {
445 Perror("Search complete, no more matches");
446 break;
447 }
448 if (prev_search_cmd == 0) {
449 Perror("No previouis search");
450 break;
451 }
452 if (prev_search_cmd == '/') {
453 view->cury = 0;
454 view->srch_curr_pos = view->page_bot_pos;
455 } else {
456 view->cury = view->scroll_lines + 1;
457 view->srch_curr_pos = view->page_top_pos;
458 }
459 rc = search(view, prev_search_cmd, prev_regex_pattern);
460 if (rc == false) {
461 Perror("No matches found");
462 break;
463 }
464 break;
466 case '/':
467 view->f_search_complete = false;
468 strnz__cpy(tmp_str, " Forward:", MAXLEN - 1);
469 search_cmd = c;
470 c = get_cmd_arg(view, tmp_str);
471 if (c == KEY_F09 || c == '\033')
472 break;
473 if (c == KEY_ENTER) {
474 view->cury = 0;
475 view->f_first_iter = true;
476 view->srch_beg_pos = view->page_top_pos;
477 view->srch_curr_pos = view->page_top_pos;
478 rc = search(view, search_cmd, view->cmd_arg);
479 if (rc == false) {
480 Perror("No matches found");
481 break;
482 }
483 prev_search_cmd = search_cmd;
485 }
486 break;
488 case '?':
489 view->f_search_complete = false;
490 strnz__cpy(tmp_str, " Backward:", MAXLEN - 1);
491 search_cmd = c;
492 c = get_cmd_arg(view, tmp_str);
493 if (c == KEY_F09 || c == '\033')
494 break;
495 if (c == '\n') {
496 view->cury = view->scroll_lines;
497 view->f_first_iter = true;
498 view->srch_beg_pos = view->page_bot_pos;
499 view->srch_curr_pos = view->page_bot_pos;
500 rc = search(view, search_cmd, view->cmd_arg);
501 if (rc == false) {
502 Perror("No matches found");
503 break;
504 }
505 prev_search_cmd = search_cmd;
507 }
508 break;
510 case 'o':
511 if (get_cmd_arg(view, "File name:") == 0) {
512 strtok(view->cmd_arg, " ");
513 view->next_file_spec_ptr = strdup(view->cmd_arg);
514 view->f_redisplay_page = true;
515 return 0;
516 }
517 break;
518 case 'G':
519 case KEY_HOME:
520 if (n_cmd > 0) {
521 n_cmd -= 1;
522 go_to_line(view, n_cmd);
523 } else
525 break;
527 case 'H':
528 case KEY_F01:
529 if (!view->f_displaying_help) {
530 view_display_help(init);
531 view = init->view;
532 }
533 break;
535 case 'm':
536 display_prompt(view, "Mark label (A-Z)->");
537 c = get_cmd_char(view, &n_cmd);
538 if (c == '@' || c == KEY_F09 || c == '\033')
539 if (c >= 'A' && c <= 'Z')
540 c += ' ';
541 if (c < 'a' || c > 'z')
542 Perror("Not (a-z)");
543 else
544 view->mark_tbl[c - 'a'] = view->page_top_pos;
545 break;
547 case 'M':
548 display_prompt(view, "Goto mark (A-Z)->");
549 c = get_cmd_char(view, &n_cmd);
550 if (c == '@' || c == KEY_F09 || c == '\033')
551 break;
552 if (c >= 'A' && c <= 'Z')
553 c += ' ';
554 if (c < 'a' || c > 'z')
555 Perror("Not (A-Z)");
556 else
557 go_to_mark(view, c);
558 break;
560 case 'N':
561 if (n_cmd <= 0)
562 n_cmd = 1;
563 if (view->curr_argc + n_cmd >= view->argc) {
564 Perror("no more files");
565 view->curr_argc = view->argc - 1;
566 } else {
567 view->curr_argc++;
568 if (view->curr_argc < view->argc)
569 view->next_file_spec_ptr = view->argv[view->curr_argc];
570 return 0;
571 }
572 break;
574 case 'p':
575 case '%':
576 if (n_cmd < 0)
577 go_to_line(view, 1);
578 if (n_cmd >= 100)
580 else
581 go_to_percent(view, n_cmd);
582 break;
584 case Ctrl('Z'):
585 get_cmd_arg(view, "Enter Notation:");
586 strnz__cpy(tmp_str, "/tmp/view-XXXXXX", MAXLEN - 1);
587 tfd = mkstemp(tmp_str);
588 strnz__cpy(view->tmp_file_name_ptr, tmp_str, MAXLEN - 1);
589 if (tfd == -1) {
590 Perror("Unable to create temporary file");
591 break;
592 }
593 strnz__cpy(shell_cmd_spec, "echo ", MAXLEN - 5);
594 strnz__cat(shell_cmd_spec, view->cmd_arg, MAXLEN - 5);
595 strnz__cat(shell_cmd_spec, view->tmp_file_name_ptr, MAXLEN - 5);
596 shell(shell_cmd_spec);
597 strnz__cpy(shell_cmd_spec, "cat ", MAXLEN - 5);
598 strnz__cat(shell_cmd_spec, view->cmd_arg, MAXLEN - 5);
599 strnz__cat(shell_cmd_spec, ">>", MAXLEN - 5);
600 strnz__cat(shell_cmd_spec, view->tmp_file_name_ptr, MAXLEN - 5);
601 shell(shell_cmd_spec);
602 lp(view, view->cur_file_str);
603 shell(shell_cmd_spec);
604 ssnprintf(shell_cmd_spec, (size_t)(MAXLEN - 5), "rm %s",
605 view->tmp_file_name_ptr);
606 strnz__cpy(shell_cmd_spec, "rm ", MAXLEN - 5);
607 strnz__cat(shell_cmd_spec, view->tmp_file_name_ptr, MAXLEN - 5);
608 shell(shell_cmd_spec);
610 view->f_redisplay_page = true;
611 unlink(tmp_str);
612 break;
614 case Ctrl('P'):
615 lp(view, view->cur_file_str);
616 view->f_redisplay_page = true;
617 break;
619 case 'P':
620 if (n_cmd <= 0)
621 n_cmd = 1;
622 if (view->curr_argc - n_cmd < 0) {
623 Perror("No previous file");
624 view->curr_argc = 0;
625 } else {
626 view->curr_argc--;
627 if (view->curr_argc >= 0)
628 view->next_file_spec_ptr = view->argv[view->curr_argc];
629 return 0;
630 }
631 break;
633 case 'q':
634 case 'Q':
635 case KEY_F09:
636 case '\033':
637 ui_mvwadd_wchnstr(sfc, CMDLN, view->cmd_line, view->curx, &cell_sp, 1);
638 view->curr_argc = view->argc;
639 view->next_file_spec_ptr = nullptr;
640 return 0;
642 case 'v':
643 if (init->editor[0] == 0) {
644 e = getenv("DEFAULTEDITOR");
645 if (e == nullptr || *e == '\0')
646 strnz__cpy(init->editor, DEFAULTEDITOR, MAXLEN);
647 else
648 strnz__cpy(init->editor, e, MAXLEN);
649 }
651 "View doesn't support editing current buffer directly",
652 MAXLEN - 1);
653 strnz__cpy(em1, "Would you like to write the buffer to a file?",
654 MAXLEN - 1);
655 strnz__cpy(em2, "Enter Y for yes or any other key to cancel.",
656 MAXLEN - 1);
657 rc = display_error(em0, em1, em2, nullptr);
658 if (rc != 'y' && rc != 'Y')
659 break;
660 if (!enter_file_spec(init, view->out_spec)) {
661 view->f_redisplay_page = true;
662 break;
663 }
664 prev_file_pos = view->page_top_pos;
665 bytes_written = write_view_buffer(init, view->f_strip_ansi);
666 if (bytes_written == 0) {
667 ssnprintf(em0, MAXLEN - 1, "%s, line: %d", __FILE__,
668 __LINE__ - 2);
669 strnz__cpy(em1, "0 bytes written", MAXLEN - 1);
670 strerror_r(errno, em1, MAXLEN - 1);
671 display_error(em0, em1, nullptr, nullptr);
672 break;
673 }
674 view->next_file_spec_ptr = view->in_spec;
675 strnz__cpy(shell_cmd_spec, init->editor, MAXLEN - 5);
676 strnz__cat(shell_cmd_spec, " ", MAXLEN - 5);
677 strnz__cat(shell_cmd_spec, view->in_spec, MAXLEN - 5);
678 full_screen_shell(shell_cmd_spec);
679 view->file_pos = view->page_top_pos = view->page_bot_pos =
680 prev_file_pos;
681
683 view->f_redisplay_page = true;
684 return 0;
686 case 'w':
687 if (!enter_file_spec(init, view->out_spec)) {
688 view->f_redisplay_page = true;
689 break;
690 }
691 // prev_file_pos = view->page_top_pos;
692 bytes_written = write_view_buffer(init, view->f_strip_ansi);
693 if (bytes_written == 0) {
694 ssnprintf(em0, MAXLEN - 1, "%s, line: %d", __FILE__,
695 __LINE__ - 2);
696 strnz__cpy(em1, "0 bytes written", MAXLEN - 1);
697 strerror_r(errno, em1, MAXLEN - 1);
698 display_error(em0, em1, nullptr, nullptr);
699 break;
700 }
701 display_prompt(view, tmp_str);
702 view->f_redisplay_page = true;
703 break;
704 case CT_VIEW:
705 break;
707 case 'V':
708 ssnprintf(em0, MAXLEN - 1, "C-Menu Version: %s", CM_VERSION);
709 display_error(em0, em1, nullptr, nullptr);
710 break;
711 default:
712 break;
713 }
714 view->cmd_arg[0] = '\0';
715 }
716}
#define KEY_ALTEND
Definition cm.h:560
#define KEY_ALTHOME
Definition cm.h:557
#define S_TOLOWER(c)
Definition cm.h:144
#define Ctrl(c)
Definition cm.h:54
#define CM_VERSION
Definition version.h:7
@ CT_VIEW
Definition menu.h:47
void ui_get_screen_size(uint *lines, uint *cols)
Definition ui_ncurses.c:692
#define KEY_F01
#define KEY_RIGHT
#define KEY_DOWN
#define KEY_PPAGE
#define KEY_NPAGE
#define KEY_ENTER
#define KEY_LEFT
#define KEY_HOME
#define KEY_UP
char prev_regex_pattern[MAXLEN]
#define confirm()
Definition view_engine.c:89
void view_full_screen_resize(Init *)
Resize the full screen view and its components.
Definition init_view.c:97
void view_boxwin_resize(Init *)
Resize the current window and its box.
Definition init_view.c:178
int Perror(char *emsg_str)
Display a simple error message window or print to stderr.
Definition dwin.c:841
int full_screen_shell(char *)
Execute a shell command in full screen mode.
Definition exec.c:58
void write_cmenu_log(char *)
Write message to C-Menu log file without timestamp.
Definition futil.c:1684
bool str_subc(char *, char *, char, char *, uint)
Replaces "ReplaceChr" in "s" with "Withstr" in "d" won't copy more than "l" bytes to "d" Replaces all...
Definition futil.c:683
bool enter_file_spec(Init *, char *)
use form to enter a file specification
int write_view_buffer(Init *, bool)
Write buffer contents to files.
void lp(View *, char *)
Send File to Print Queue.
int get_cmd_arg(View *, char *)
Get Command Argument from User Input.
int get_cmd_char(View *, off_t *)
Get Command Character from User Input.
void go_to_percent(View *, uint)
Go to Percent of File.
void scroll_up(View *, uint)
Scroll Up by n Lines.
void go_to_eof(View *)
Go to End of File.
void prev_page(View *)
display previous page
void go_to_mark(View *, uint)
Go to Mark.
void scroll_down(View *, uint)
Scroll Down by n Lines.
bool search(View *, int, char *)
Search for Regular Expression Pattern.
int go_to_line(View *, off_t)
Go to Specific Line.
void next_page(View *)
Advance to Next Page.
void view_display_help(Init *)
Display View Help File.
void view_display_page(View *)
Display Current Page.
char editor[MAXLEN]
Definition common.h:172

References View::argc, View::argv, build_prompt(), cell_sp, View::cmd, View::cmd_arg, View::cmd_line, CMDLN, View::cols, CT_VIEW, View::cur_file_str, View::curr_argc, View::curx, View::cury, display_error(), display_prompt(), Init::editor, em0, em1, em2, enter_file_spec(), View::f_displaying_help, View::f_first_iter, View::f_full_screen, View::f_ignore_case, View::f_is_pipe, View::f_ln, View::f_redisplay_page, View::f_search_complete, View::f_squeeze, View::f_strip_ansi, View::file_pos, View::file_spec_ptr, full_screen_shell(), get_cmd_arg(), get_cmd_char(), go_to_eof(), go_to_line(), go_to_mark(), go_to_percent(), View::h_shift, View::in_spec, View::lines, View::ln_no, lp(), View::mark_tbl, View::maxcol, View::next_cmd_char, View::next_file_spec_ptr, next_page(), View::out_spec, View::page_bot_pos, View::page_top_pos, Perror(), View::pmincol, View::prev_file_pos, prev_page(), prev_regex_pattern, View::prompt_str, scroll_down(), View::scroll_lines, scroll_up(), search(), View::sfc, shell(), View::srch_beg_pos, View::srch_curr_pos, ssnprintf(), str_subc(), strnz__cat(), strnz__cpy(), View::tab_stop, View::tmp_file_name_ptr, ui_get_screen_size(), ui_mvwadd_wchnstr(), ui_restore_wins(), Init::view, view_boxwin_resize(), view_display_help(), view_display_page(), view_full_screen_resize(), View::wrap, and write_view_buffer().

Referenced by picker(), and view_file().

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

◆ view_file()

int view_file ( Init * init)

Start view.

Parameters
initPointer to the Init structure containing initialization parameters and state for the view application. This structure is used to pass necessary information and maintain state across different functions within the view application.
Returns
Returns 0 on successful completion of the view application, or a non-zero value if an error occurs during initialization or execution.

Definition at line 161 of file view_engine.c.

161 {
162 View *view = init->view;
163 if (view->argc < 1) {
164 view->curr_argc = -1;
165 view->argc = 0;
166 view->next_file_spec_ptr = "-";
167 } else
168 view->next_file_spec_ptr = view->argv[0];
169 while (view->curr_argc < view->argc) {
170 if (view->next_file_spec_ptr == nullptr ||
171 *view->next_file_spec_ptr == '\0') {
172 break;
173 }
174 view->file_spec_ptr = view->next_file_spec_ptr;
175 view->next_file_spec_ptr = nullptr;
176 strnz__cpy(view->cur_file_str, view->file_spec_ptr, MAXLEN - 1);
177 if (view_init_input(init, view->cur_file_str) == 0) {
178 if (view->buf) {
179 view->f_eod = 0;
180 view->f_bod = 0;
181 view->maxcol = 0;
182 view->page_top_pos = 0;
183 view->page_top_ln_no = 0;
184 view->page_bot_ln_no = 0;
185 view->ln_max_pos = 0;
186 view->page_bot_pos = 0;
187 view->file_pos = 0;
188 strnz__cpy(view->title, view->cur_file_str, MAXLEN - 1);
189 if (!view->f_full_screen)
190 border_title(view->sfc, view->title);
193 view_cmd_processor(init);
195 munmap(view->buf, view->file_size);
196 }
197 } else {
198 view->curr_argc++;
199 if (view->curr_argc < view->argc) {
200 view->next_file_spec_ptr = view->argv[view->curr_argc];
201 }
202 }
203 }
205 return 0;
206}
void ui_surface_destroy(UiSurface *s)
Definition ui_ncurses.c:377
int border_title(UiSurface *sfc, char *title)
Draw a box with a title around the specified window.
Definition dwin.c:676
int view_init_input(Init *init, char *file_name)
Initialize the input for the C-Menu View.
Definition init_view.c:279
int view_cmd_processor(Init *)
Main Command Processing Loop for View.
void initialize_line_table(View *)
Initialize Line Table.
void destroy_line_table(View *)
Destroy Line Table.

References View::argc, View::argv, border_title(), View::buf, View::cur_file_str, View::curr_argc, destroy_line_table(), View::f_bod, View::f_eod, View::f_full_screen, View::file_pos, View::file_size, View::file_spec_ptr, initialize_line_table(), View::ln_max_pos, View::maxcol, View::next_file_spec_ptr, next_page(), View::page_bot_ln_no, View::page_bot_pos, View::page_top_ln_no, View::page_top_pos, View::sfc, strnz__cpy(), View::title, ui_surface_destroy(), Init::view, view_cmd_processor(), and view_init_input().

Referenced by main(), and popup_view().

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

◆ write_view_buffer()

int write_view_buffer ( Init * init,
bool f_strip_ansi )

Write buffer contents to files.

Parameters
initdata structure
f_strip_ansistrip ANSI escape sequences

write the buffer

Definition at line 978 of file view_engine.c.

978 {
979 ssize_t bytes_written = 0;
980 View *view = init->view;
981 int rc;
982 size_t l;
983 char tmp_line_s[PAD_COLS];
984 if (!f_strip_ansi) {
985 strnz__cpy(em0, "Would you like to strip ansi escape sequences?",
986 MAXLEN - 1);
987 strnz__cpy(em1, "Enter Y for yes or any other key to cancel.",
988 MAXLEN - 1);
989 rc = answer_yn(nullptr, em0, em1, nullptr);
990 if (rc == 'y' || rc == 'Y')
991 f_strip_ansi = true;
992 else
993 f_strip_ansi = false;
994 }
997 view->out_fd = open(view->out_spec, O_CREAT | O_TRUNC | O_WRONLY, 0644);
998 if (view->out_fd == -1) {
999 ssnprintf(em0, MAXLEN - 1, "%s, line: %d", __FILE__, __LINE__ - 2);
1000 strnz__cpy(em1, "fwrite ", MAXLEN - 1);
1001 strnz__cat(em1, view->out_spec, MAXLEN - 1);
1002 strerror_r(errno, em2, MAXLEN - 1);
1003 display_error(em0, em1, em2, nullptr);
1004 return false;
1005 }
1006 bytes_written = 0;
1007 while (!view->f_eod) {
1008 off_t ln_no = 0;
1009 get_line(view, ln_no);
1010 if (f_strip_ansi)
1011 strip_ansi(tmp_line_s, view->line_in_s);
1012 else
1013 strnz__cpy(tmp_line_s, view->line_in_s, MAXLEN - 1);
1014 l = strnlf(tmp_line_s, PAD_COLS - 1);
1015 bytes_written += write(view->out_fd, tmp_line_s, l);
1016 if (ln_no >= view->ln_tbl_size - 1)
1017 break;
1018 }
1019 close(view->out_fd);
1020 strnz__cpy(view->in_spec, view->out_spec, MAXLEN - 1);
1021 return bytes_written;
1022}
#define PAD_COLS
Definition view.h:41
void get_line(View *, off_t)
int answer_yn(char *msg0, char *msg1, char *msg2, char *msg3)
Accept a single letter answer.
Definition dwin.c:715
size_t strip_ansi(char *, char *)
Strips ANSI SGR escape sequences (ending in 'm') from string s to d.
Definition futil.c:822
size_t strnlf(char *, size_t)
terminates string with line feed
Definition futil.c:626

References answer_yn(), display_error(), em0, em1, em2, View::f_eod, get_line(), View::in_spec, View::line_in_s, View::ln_tbl_size, View::out_fd, View::out_spec, ssnprintf(), strip_ansi(), strnlf(), strnz__cat(), strnz__cpy(), ui_restore_wins(), and Init::view.

Referenced by view_cmd_processor().

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