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 52 of file view_engine.c.

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

◆ 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 75 of file view_engine.c.

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

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 913 of file view_engine.c.

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

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 1032 of file view_engine.c.

1032 {
1033 int c;
1034 while (1) {
1035 get_next_char();
1036 if (view->f_eod)
1037 break;
1038 putchar(c);
1039 }
1040}
#define get_next_char()
read the next characater from the virtual file
Definition view_engine.c:52

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

Definition at line 2692 of file view_engine.c.

2692 {
2693 char earg_str[MAXLEN];
2694 char *eargv[MAXARGS];
2695 uint eargc;
2696 char tmp_dir[MAXLEN];
2697 char tmp_str[MAXLEN];
2698 char tmp_spec[MAXLEN];
2699 int rc = 0;
2700 FILE *tmp_fp;
2701 View *view = init->view;
2702 strnz__cpy(tmp_dir, init->mapp_home, MAXLEN - 1);
2703 strnz__cat(tmp_dir, "/tmp", MAXLEN - 1);
2704 expand_tilde(tmp_dir, MAXLEN - 1);
2705 if (!mk_dir(tmp_dir)) {
2706 ssnprintf(em0, MAXLEN - 1, _("%s, line: %d"), __FILE__, __LINE__ - 2);
2707 strnz__cpy(em1, _("Unable to "), MAXLEN - 1);
2708 strnz__cat(em1, "mkdir", MAXLEN - 1);
2709 strnz__cat(em1, tmp_dir, MAXLEN - 1);
2710 strerror__r(errno, em2, MAXLEN - 1);
2711 ui_display_error(em0, em1, em2, nullptr);
2712 return false;
2713 }
2714 while (rc == false) {
2715 strnz__cpy(tmp_spec, tmp_dir, MAXLEN - 1);
2716 strnz__cat(tmp_spec, "/tmp_XXXXXX", MAXLEN - 1);
2717 view->in_fd = mkstemp(tmp_spec);
2718 if (view->in_fd == -1) {
2719 ssnprintf(em0, MAXLEN - 1, _("%s, line: %d"), __FILE__, __LINE__ - 2);
2720 strnz__cpy(em1, _("unable to "), MAXLEN - 1);
2721 strnz__cat(em1, "mkstemp ", MAXLEN - 1);
2722 strnz__cat(em1, tmp_spec, MAXLEN - 1);
2723 strerror__r(errno, em2, MAXLEN - 1);
2724 ui_display_error(em0, em1, nullptr, nullptr);
2725 return false;
2726 }
2727 /* call form to get file_name
2728 write the name to a temporary file */
2729
2730 strnz__cpy(earg_str, _("form -d file_name.f -o "), MAXLEN - 1);
2731 strnz__cat(earg_str, tmp_spec, MAXLEN - 1);
2733 rc = popup_form(init, eargc, eargv, view->begy + view->lines - 7, 4);
2736 if (rc == FA_CANCEL || rc == 'q' || rc == 'Q' || rc == UIKEY_F09)
2737 return false;
2738 close(view->in_fd);
2739 tmp_fp = fopen(tmp_spec, "r");
2740 if (tmp_fp == nullptr) {
2741 ssnprintf(em0, MAXLEN - 1, _("%s, line: %d"), __FILE__, __LINE__ - 2);
2742 strnz__cpy(em1, _("unable to "), MAXLEN - 1);
2743 strnz__cat(em1, "fopen ", MAXLEN - 1);
2744 strnz__cat(em1, tmp_spec, MAXLEN - 1);
2745 strerror__r(errno, em2, MAXLEN - 1);
2746 ui_display_error(em0, em1, em2, nullptr);
2747 return false;
2748 }
2749 fgets(tmp_str, MAXLEN - 1, tmp_fp);
2750 strnz(tmp_str, MAXLEN - 1);
2751 fclose(tmp_fp);
2752 unlink(tmp_spec);
2753 if (!verify_spec_arg(file_spec, tmp_str, "~/menuapp/tmp", ".",
2754 S_WCOK | S_QUIET)) {
2755 ssnprintf(em0, MAXLEN - 1, _("Unable to open %s for writing"),
2756 tmp_str);
2757 strnz__cpy(em1, _("Try again? y (yes) or n (no) "), MAXLEN - 1);
2758 rc = ui_display_error(em0, em1, nullptr, nullptr);
2759 if (rc == 'y' || rc == 'Y')
2760 continue;
2761
2762 } else
2763 return true;
2764 }
2765 return true;
2766}
@ FA_CANCEL
Definition form.h:33
int popup_form(Init *, int, char **, uint, uint)
instantiate a form popup window
Definition popups.c:113
#define MAXARGS
Definition cm.h:67
void ui_restore_wins()
Restore the state of all windows in the UI. This function refreshes the standard screen and all surfa...
#define UIKEY_F09
#define MAX_ARGS
Definition lf.h:37
#define S_QUIET
Definition lf.h:282
#define S_WCOK
Definition lf.h:281
char em1[MAXLEN]
Definition lf.c:43
char em2[MAXLEN]
Definition lf.c:44
char em0[MAXLEN]
Definition lf.c:42
char * eargv[MAXARGS]
Definition futil.c:51
int eargc
Definition futil.c:50
char earg_str[MAXLEN]
Definition futil.c:49
size_t strnz(char *, size_t)
terminates string at New Line, Carriage Return, or max_len
Definition futil.c:621
size_t ssnprintf(char *, size_t, const char *,...)
Custom safe string formatting utility (Variadic version).
Definition futil.c:398
int str_to_args(char **, char *, uint)
Converts a string into an array of argument strings.
Definition futil.c:418
bool expand_tilde(char *, uint)
Expand a tilde (~) in a file path to the user's home directory.
Definition lf.c:2089
bool mk_dir(char *dir)
If directory doesn't exist, make it.
Definition futil.c:1351
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:770
int destroy_argv(uint argc, char **argv)
Deallocates memory allocated for argument strings in argv.
Definition futil.c:474
bool verify_spec_arg(char *, char *, char *, char *, uint)
Verify file specification argument.
Definition mem.c:361
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:1261
char mapp_home[MAXLEN]
Definition common.h:150
View * view
Definition common.h:193
Definition view.h:59

References View::begy, destroy_argv(), em0, em1, em2, expand_tilde(), FA_CANCEL, View::in_fd, View::lines, Init::mapp_home, mk_dir(), popup_form(), ssnprintf(), str_to_args(), strerror__r(), strnz(), strnz__cat(), strnz__cpy(), ui_display_error(), 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. __get_cmd_arg

Definition at line 870 of file view_engine.c.

870 {
871 int c;
872 char prompt_s[MAXLEN];
873 UiSurface *sfc = view->sfc;
874 uint prompt_l = strnz__cpy(prompt_s, prompt, min(MAXLEN - 1, view->cols - 4));
875 if (view->cmd_arg[0] != '\0')
876 return 0;
877 ui_cursor_move(sfc, CMDLN, view->cmd_line, 0);
878 if (prompt_l > 1) {
879 ui_bkgdset(sfc, CMDLN, &cell_nt_rev);
880 ui_waddstr(sfc, CMDLN, prompt_s);
881 ui_bkgdset(sfc, CMDLN, &cell_nt);
882 }
883 view->curx = prompt_l;
884 ui_wclrtoeol(sfc, CMDLN);
885 ui_cursor_enable_yx(sfc, CMDLN, view->cmd_line, view->curx, true);
887 ui_mvwadd_wchnstr(sfc, CMDLN, view->cmd_line, view->curx, &cell_ran, 1);
888 ui_cursor_move(sfc, CMDLN, view->cmd_line, view->curx + 1);
889 ui_render();
890 uint flin = view->cmd_line;
891 uint fcol = prompt_l + 1;
892 uint flen = view->cols - prompt_l;
893 c = cf_accept(sfc, CMDLN, view->cmd_arg, flin, fcol, flen);
894 return c;
895}
void ui_render()
Render the UI by updating panels and refreshing the display.
Definition ui_ncurses.c:931
int ui_cursor_enable_yx(UiSurface *s, ss_t w, uint y, uint x, bool visible)
Enable or disable the cursor at a specific position within a UiSurface.
Definition ui_ncurses.c:896
int ui_cursor_move(UiSurface *s, ss_t w, uint y, uint x)
Move the cursor to a specified position within a UiSurface.
Definition ui_ncurses.c:698
int ui_wclrtoeol(UiSurface *s, ss_t w)
Clear to the end of the line in a surface window.
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:988
UiCell cell_nt
Definition ui_common.c:123
UiCell cell_ran
Definition ui_common.c:132
UiCell cell_nt_rev
Definition ui_common.c:124
int ui_mvwadd_wchnstr(UiSurface *s, ss_t w, uint y, uint x, const UiCell *cmplx_buf, uint n)
Draw a complex character string at a specific position in a surface window, with a maximum length.
int ui_waddstr(UiSurface *s, ss_t w, const char *text)
Draw a text string in a surface window.
int cf_accept(UiSurface *sfc, ss_t 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
int pad_refresh(View *)
Refresh Pad and Line Number Window.

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

Referenced by get_cmd_char(), and 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. __get_cmd_char

Definition at line 729 of file view_engine.c.

729 {
730 int c = 0, i = 0;
731 char *d, *s;
732 uint prevx;
733 bool once = false;
734 char cmd_str[33];
735 cmd_str[0] = '\0';
736 UiSurface *sfc = view->sfc;
737 UiEvent event;
738 ui_render();
740 ui_mvwadd_wch(sfc, CMDLN, view->cmd_line, view->curx++, &cell_ran);
741 ui_top_surface(sfc, CMDLN);
742 ui_cursor_enable_yx(sfc, CMDLN, 0, view->curx, true);
743 while (1) {
744 if (i == 1 && !once) {
745 once = true;
746 view->curx = 0;
747 ui_cursor_move(sfc, CMDLN, view->cmd_line, view->curx);
748 ui_wclrtoeol(sfc, CMDLN);
749 ui_mvwadd_wch(sfc, CMDLN, view->cmd_line, view->curx++, &cell_ran);
750 ui_mvwaddch(sfc, CMDLN, view->cmd_line, view->curx++, c);
751 }
752 ui_render();
753 event.y = event.x = -1;
754 c = ui_get_event(sfc, CMDLN, NULL, &event, -1);
755 switch (c) {
756 case UIKEY_BUTTON1:
757 case UIKEY_SCROLL_UP:
759 break;
760 case UIKEY_RESIZE:
761 case '\n':
762 case '\r':
763 break;
764 case 'q':
765 case UIKEY_F09:
767 display_prompt(view, view->prompt_str);
768 c = UIKEY_F09;
769 return c;
770 case UIKEY_F12:
771 ssnprintf(view->prompt_str, MAXLEN - 1, _("set break at line: %d and restart gdb"), __LINE__);
772 get_cmd_arg(view, view->prompt_str);
773 break;
774 case '\b':
775 case UIKEY_BACKSPACE:
776 if (i > 0) {
777 s = &cmd_str[i];
778 d = &cmd_str[--i];
779 view->curx--;
780 prevx = view->curx;
781 while (*s != '\0') {
782 ui_mvwaddch(sfc, CMDLN, view->cmd_line, view->curx++, *s);
783 *d++ = *s++;
784 }
785 *d = '\0';
786 ui_cursor_move(sfc, CMDLN, view->cmd_line, view->curx);
787 ui_wclrtoeol(sfc, CMDLN);
788 view->curx = prevx;
789 ui_cursor_move(sfc, CMDLN, view->cmd_line, view->curx);
790 }
791 continue;
792 case UIKEY_DC:
793 if (i < 32 && cmd_str[i] != '\0') {
794 s = &cmd_str[i + 1];
795 d = &cmd_str[i];
796 while (*s != '\0') {
797 ui_mvwaddch(sfc, CMDLN, view->cmd_line, view->curx++, *s);
798 *d++ = *s++;
799 }
800 *d = '\0';
801 ui_cursor_move(sfc, CMDLN, view->cmd_line, view->curx);
802 ui_wclrtoeol(sfc, CMDLN);
803 ui_cursor_move(sfc, CMDLN, view->cmd_line, view->curx);
804 }
805 continue;
806 case UIKEY_RSHIFT:
807 if (i < 32 && cmd_str[i] != '\0') {
808 i++;
809 ui_getyx(sfc, CMDLN, &view->cury, &view->curx);
810 if (view->curx < view->cols - 1) {
811 view->curx++;
812 ui_cursor_move(sfc, CMDLN, view->cmd_line, view->curx);
813 }
814 }
815 continue;
816 case UIKEY_LSHIFT:
817 if (i > 0) {
818 i--;
819 ui_getyx(sfc, CMDLN, &view->cury, &view->curx);
820 if (view->curx > 0) {
821 view->curx--;
822 ui_cursor_move(sfc, CMDLN, view->cmd_line, view->curx);
823 }
824 }
825 continue;
826 default:
827 if (c < '0' || c > '9' || i == 32)
828 break;
829 cmd_str[i++] = (char)c;
830 cmd_str[i] = '\0';
831 ui_mvwaddch(sfc, CMDLN, view->cmd_line, view->curx, c);
832 view->curx++;
833 continue;
834 }
835 if (c < '0' || c > '9' || i == 32)
836 break;
837 }
838 if (cmd_str[0] == '\0') {
839 *n = 0;
840 view->cmd_arg[0] = '\0';
841 ui_mvwadd_wchnstr(sfc, CMDLN, view->cmd_line, view->curx, &cell_sp, 1);
842 ui_wclrtoeol(sfc, CMDLN);
843 return (c);
844 }
845 *n = atol(cmd_str);
846 view->cmd_arg[0] = '\0';
847 ui_getyx(sfc, CMDLN, &view->cmd_line, &view->curx);
848 ui_mvwadd_wchnstr(sfc, CMDLN, view->cmd_line, view->curx, &cell_sp, 1);
849 ui_wclrtoeol(sfc, CMDLN);
850 return (c);
851}
void ui_getyx(UiSurface *s, ss_t w, uint *lines, uint *cols)
Get the current cursor position within a window of a UI surface.
Definition ui_ncurses.c:707
int ui_top_surface(UiSurface *s, ss_t w)
Hide a UiSurface, making it invisible on the screen.
Definition ui_ncurses.c:655
#define UIKEY_DC
#define UIKEY_BACKSPACE
#define UIKEY_F12
#define UIKEY_LSHIFT
#define UIKEY_RESIZE
#define UIKEY_RSHIFT
#define UIKEY_BUTTON1
#define UIKEY_SCROLL_UP
#define UIKEY_SCROLL_DOWN
int ui_get_event(UiSurface *s, ss_t w, UiChyron *chyron, UiEvent *ev, int timeout_ms)
Read input events.
UiCell cell_sp
Definition ui_common.c:149
int ui_mvwaddch(UiSurface *s, ss_t w, uint y, uint x, const char c)
Draw a character in a surface window.
int ui_mvwadd_wch(UiSurface *s, ss_t w, uint y, uint x, const UiCell *cell)
Draw a complex character at a specific position in a surface window.
int get_cmd_arg(View *, char *)
Get Command Argument from User Input.
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, View::cols, View::curx, View::cury, display_prompt(), get_cmd_arg(), pad_refresh(), View::prompt_str, View::sfc, ssnprintf(), ui_cursor_enable_yx(), ui_cursor_move(), ui_get_event(), ui_getyx(), ui_mvwadd_wch(), ui_mvwadd_wchnstr(), ui_mvwaddch(), ui_render(), ui_top_surface(), 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 1045 of file view_engine.c.

1045 {
1046 char *print_cmd_ptr;
1047 char shell_cmd_spec[MAXLEN];
1048 print_cmd_ptr = getenv("PRINTCMD");
1049 if (print_cmd_ptr == nullptr || *print_cmd_ptr == '\0')
1050 print_cmd_ptr = PRINTCMD;
1051 ssnprintf(shell_cmd_spec, MAXLEN - 1, "%s %s", print_cmd_ptr, PrintFile);
1052 display_prompt(view, shell_cmd_spec);
1053 shell(shell_cmd_spec);
1054}
#define PRINTCMD
Definition common.h:50
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 UIKEY_RESIZE - Handle terminal resize

< UIKEY_ALTHOME - horizontal scroll to the first column

< UIKEY_ALTEND horizontal scroll to the last column

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

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

'k', UIKEY_UP - Scroll up one line

'j', UIKEY_DOWN, UIKEY_ENTER - scroll down one line

Ctrl('B'), UIKEY_PPAGE - Previous Page

Ctrl('F'), UIKEY_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 UIKEY_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 UIKEY_F09 or ESC - Close Current File and Open Next

'q' or 'Q' or UIKEY_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 215 of file view_engine.c.

215 {
216 char tmp_str[MAXLEN];
217 int tfd;
218 int c;
219 uint shift = 0;
220 int search_cmd = 0;
221 int prev_search_cmd = 0;
222 int rc;
223 uint i;
224 bool ans = true;
225 ssize_t bytes_written;
226 char *e;
227 char shell_cmd_spec[MAXLEN];
228 off_t n_cmd = 0L;
229 off_t prev_file_pos;
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 UIKEY_RESIZE:
256 ui_log(INFO, _("Resize key received"));
257 ui_get_screen_size(&view->lines, &view->cols);
258 ui_log(INFO, _("Resize: lines=%d, cols=%d"), view->lines, view->cols);
259 if (view->f_full_screen)
261 else
262 view_boxwin_resize(init);
263 view->f_redisplay_page = true;
264 continue;
265 case UIKEY_F05:
267 view->pmincol = 0;
268 break;
269 case UIKEY_F06:
272 if (view->maxcol > view->cols)
273 view->pmincol = view->maxcol - view->cols;
274 else
275 view->pmincol = 0;
276 break;
277 case 'h':
279 case UIKEY_LEFT:
280 case UIKEY_BACKSPACE:
281 if (n_cmd > 0)
282 view->h_shift = (uint)n_cmd;
283 else if (n_cmd == 0) {
284 if (view->h_shift > 0)
285 n_cmd = view->h_shift;
286 else
287 n_cmd = 1;
288 }
289 shift = (uint)n_cmd;
290 if (view->pmincol - shift > 0)
291 view->pmincol -= shift;
292 else
293 view->pmincol = 0;
294 break;
295 case 'l':
296 case UIKEY_RIGHT:
297 if (n_cmd > 0)
298 view->h_shift = n_cmd;
299 else if (n_cmd == 0) {
300 if (view->h_shift > 0)
301 n_cmd = view->h_shift;
302 else
303 n_cmd = 1;
304 }
305 shift = (uint)n_cmd;
306 if ((view->pmincol + shift + view->cols) > view->maxcol)
307 view->pmincol = view->maxcol - view->cols + view->ln_win_cols;
308 else
309 view->pmincol += shift;
310 break;
311 case 'k':
312 case UIKEY_SCROLL_UP:
313 case UIKEY_UP:
314 if (n_cmd <= 0)
315 n_cmd = 1;
316 scroll_prev(view, (uint)n_cmd);
317 break;
319 case 'j':
320 case '\n':
322 case UIKEY_DOWN:
323 case UIKEY_ENTER:
324 if (n_cmd <= 0)
325 n_cmd = 1;
326 scroll_next(view, (uint)n_cmd);
327 break;
329 case UIKEY_PPAGE:
330 case Ctrl('B'):
332 break;
334 case UIKEY_NPAGE:
335 case Ctrl('F'):
336 view->ln_no++;
338 break;
340 case '!':
341 if (view->f_displaying_help)
342 break;
343 if (get_cmd_arg(view, "!") == 0) {
344 if (!view->f_is_pipe) {
345 view->prev_file_pos = view->page_top_pos;
346 view->next_file_spec_ptr = view->file_spec_ptr;
347 str_subc(shell_cmd_spec, view->cmd_arg, '%',
348 view->cur_file_str, MAXLEN - 1);
349 } else
350 strnz__cpy(shell_cmd_spec, view->cmd_arg, MAXLEN - 1);
351 full_screen_shell(shell_cmd_spec);
352 if (!view->f_is_pipe) {
353 view->next_file_spec_ptr = view->cur_file_str;
354 return 0;
355 }
356 }
357 break;
359 case '+':
360 if (get_cmd_arg(view, _("Startup Command:")) == 0)
361 strnz__cpy(view->cmd, view->cmd_arg, MAXLEN - 1);
362 break;
364 case '-':
365 display_prompt(view, "(i, n, s, t, w, or h)->");
366 c = get_cmd_char(view, &n_cmd);
367 c = S_TOLOWER(c);
368 switch (c) {
375 case 'i':
376 display_prompt(view, _("Ignore Case in search (Y or N)->"));
377 confirm();
378 if (ans)
379 view->f_ignore_case = true;
380 else if (c == 'n' || c == 'N')
381 view->f_ignore_case = false;
382 break;
384 case 'n':
385 display_prompt(view, _("Line Numbering (Y or N)->"));
386 confirm();
387 if (view->f_ln == ans)
388 break;
389 view->f_ln = ans;
390 view->f_redisplay_page = true;
391 (view->f_full_screen) ? view_full_screen_resize(init) : view_boxwin_resize(init);
392 break;
394 case 's':
396 view, _("view->f_squeeze Multiple Blank lines (Y or N)->"));
397 confirm();
398 view->f_squeeze = ans;
399 break;
400 case 'w':
402 view, _("Line Wrapping (Y or N)->"));
403 if ((c = get_cmd_char(view, &n_cmd)) == 'y' || c == 'Y')
404 ans = true;
405 else if (c == 'n' || c == 'N')
406 ans = false;
407 if (view->wrap == ans)
408 break;
409 view->wrap = ans;
410 view->f_redisplay_page = true;
411 (view->f_full_screen) ? view_full_screen_resize(init) : view_boxwin_resize(init);
412 break;
414 case 't':
415 sprintf(tmp_str,
416 _("Tabstop Colums Currently %d:"), view->tab_stop);
417 i = 0;
418 if (get_cmd_arg(view, tmp_str) == 0)
419 i = atoi(view->cmd_arg);
420 if (i >= 1 && i <= 12) {
421 view->tab_stop = i;
422 view->f_redisplay_page = true;
423 } else
424 ui_perror(_("Tab stops not changed"));
425 break;
427 case UIKEY_F01:
428 case 'h':
429 if (!view->f_displaying_help) {
430 view_display_help(init);
431 view = init->view;
432 }
433 view->next_cmd_char = '-';
434 break;
435 default:
436 break;
437 }
438 break;
440 case 'n':
441 if (view->f_search_complete) {
442 ui_perror(_("Search complete, no more matches"));
443 break;
444 }
445 if (prev_search_cmd == 0) {
446 ui_perror(_("No previouis search"));
447 break;
448 }
449 if (prev_search_cmd == '/') {
450 view->cury = 0;
451 view->srch_curr_pos = view->page_bot_pos;
452 } else {
453 view->cury = view->scroll_lines + 1;
454 view->srch_curr_pos = view->page_top_pos;
455 }
456 rc = search(view, prev_search_cmd, prev_regex_pattern);
457 if (rc == false) {
458 ui_perror(_("No matches found"));
459 break;
460 }
461 break;
463 case '/':
464 view->f_search_complete = false;
465 strnz__cpy(tmp_str, _(" Forward:"), MAXLEN - 1);
466 search_cmd = c;
467 c = get_cmd_arg(view, tmp_str);
468 if (c == UIKEY_F09 || c == '\033')
469 break;
470 if (c == UIKEY_ENTER) {
471 view->cury = 0;
472 view->f_first_iter = true;
473 view->srch_beg_pos = view->page_top_pos;
474 view->srch_curr_pos = view->page_top_pos;
475 rc = search(view, search_cmd, view->cmd_arg);
476 if (rc == false) {
477 ui_perror(_("No matches found"));
478 break;
479 }
480 prev_search_cmd = search_cmd;
482 }
483 break;
485 case '?':
486 view->f_search_complete = false;
487 strnz__cpy(tmp_str, _(" Backward:"), MAXLEN - 1);
488 search_cmd = c;
489 c = get_cmd_arg(view, tmp_str);
490 if (c == UIKEY_F09 || c == '\033')
491 break;
492 if (c == '\n') {
493 view->cury = view->scroll_lines;
494 view->f_first_iter = true;
495 view->srch_beg_pos = view->page_bot_pos;
496 view->srch_curr_pos = view->page_bot_pos;
497 rc = search(view, search_cmd, view->cmd_arg);
498 if (rc == false) {
499 ui_perror(_("No matches found"));
500 break;
501 }
502 prev_search_cmd = search_cmd;
504 }
505 break;
507 case 'o':
508 if (get_cmd_arg(view, _("File name:")) == 0) {
509 strtok(view->cmd_arg, " ");
510 view->next_file_spec_ptr = strdup(view->cmd_arg);
511 view->f_redisplay_page = true;
512 return 0;
513 }
514 break;
515 case 'G':
516 case UIKEY_HOME:
517 if (n_cmd > 0) {
518 n_cmd -= 1;
519 go_to_line(view, n_cmd);
520 } else
522 break;
524 case 'H':
525 case UIKEY_F01:
526 if (!view->f_displaying_help) {
527 view_display_help(init);
528 view = init->view;
529 }
530 break;
532 case 'm':
533 display_prompt(view, _("Mark label (A-Z)->"));
534 c = get_cmd_char(view, &n_cmd);
535 if (c == '@' || c == UIKEY_F09 || c == '\033')
536 if (c >= 'A' && c <= 'Z')
537 c += ' ';
538 if (c < 'a' || c > 'z')
539 ui_perror(_("Not (a-z)"));
540 else
541 view->mark_tbl[c - 'a'] = view->page_top_pos;
542 break;
544 case 'M':
545 display_prompt(view, _("Goto mark (A-Z)->"));
546 c = get_cmd_char(view, &n_cmd);
547 if (c == '@' || c == UIKEY_F09 || c == '\033')
548 break;
549 if (c >= 'A' && c <= 'Z')
550 c += ' ';
551 if (c < 'a' || c > 'z')
552 ui_perror(_("Not (A-Z)"));
553 else
554 go_to_mark(view, c);
555 break;
557 case 'N':
558 if (n_cmd <= 0)
559 n_cmd = 1;
560 if (view->curr_argc + n_cmd >= view->argc) {
561 ui_perror(_("no more files"));
562 view->curr_argc = view->argc - 1;
563 } else {
564 view->curr_argc++;
565 if (view->curr_argc < view->argc)
566 view->next_file_spec_ptr = view->argv[view->curr_argc];
567 return 0;
568 }
569 break;
571 case 'p':
572 case '%':
573 if (n_cmd < 0)
574 go_to_line(view, 1);
575 if (n_cmd >= 100)
577 else
578 go_to_percent(view, n_cmd);
579 break;
581 case Ctrl('Z'):
582 get_cmd_arg(view, _("Enter Notation:"));
583 strnz__cpy(tmp_str, "/tmp/view-XXXXXX", MAXLEN - 1);
584 tfd = mkstemp(tmp_str);
585 strnz__cpy(view->tmp_file_name_ptr, tmp_str, MAXLEN - 1);
586 if (tfd == -1) {
587 ui_perror(_("Unable to create temporary file"));
588 break;
589 }
590 strnz__cpy(shell_cmd_spec, "echo ", MAXLEN - 5);
591 strnz__cat(shell_cmd_spec, view->cmd_arg, MAXLEN - 5);
592 strnz__cat(shell_cmd_spec, view->tmp_file_name_ptr, MAXLEN - 5);
593 shell(shell_cmd_spec);
594 strnz__cpy(shell_cmd_spec, "cat ", MAXLEN - 5);
595 strnz__cat(shell_cmd_spec, view->cmd_arg, MAXLEN - 5);
596 strnz__cat(shell_cmd_spec, ">>", MAXLEN - 5);
597 strnz__cat(shell_cmd_spec, view->tmp_file_name_ptr, MAXLEN - 5);
598 shell(shell_cmd_spec);
599 lp(view, view->cur_file_str);
600 shell(shell_cmd_spec);
601 ssnprintf(shell_cmd_spec, (size_t)(MAXLEN - 5), "rm %s",
602 view->tmp_file_name_ptr);
603 strnz__cpy(shell_cmd_spec, "rm ", MAXLEN - 5);
604 strnz__cat(shell_cmd_spec, view->tmp_file_name_ptr, MAXLEN - 5);
605 shell(shell_cmd_spec);
607 view->f_redisplay_page = true;
608 unlink(tmp_str);
609 break;
611 case Ctrl('P'):
612 lp(view, view->cur_file_str);
613 view->f_redisplay_page = true;
614 break;
616 case 'P':
617 if (n_cmd <= 0)
618 n_cmd = 1;
619 if (view->curr_argc - n_cmd < 0) {
620 ui_perror(_("No previous file"));
621 view->curr_argc = 0;
622 } else {
623 view->curr_argc--;
624 if (view->curr_argc >= 0)
625 view->next_file_spec_ptr = view->argv[view->curr_argc];
626 return 0;
627 }
628 break;
630 case 'q':
631 case 'Q':
632 case UIKEY_F09:
633 ui_mvwadd_wchnstr(sfc, CMDLN, view->cmd_line, view->curx, &cell_sp, 1);
634 view->curr_argc = view->argc;
635 view->next_file_spec_ptr = nullptr;
636 return 0;
638 case 'v':
639 if (init->editor[0] == 0) {
640 e = getenv("DEFAULTEDITOR");
641 if (e == nullptr || *e == '\0')
642 strnz__cpy(init->editor, DEFAULTEDITOR, MAXLEN);
643 else
644 strnz__cpy(init->editor, e, MAXLEN);
645 }
647 _("View doesn't support editing current buffer directly"),
648 MAXLEN - 1);
649 strnz__cpy(em1, _("Would you like to write the buffer to a file?"),
650 MAXLEN - 1);
651 strnz__cpy(em2, _("Enter Y for yes or any other key to cancel."),
652 MAXLEN - 1);
653 rc = ui_display_error(em0, em1, em2, nullptr);
654 if (rc != 'y' && rc != 'Y')
655 break;
656 if (!enter_file_spec(init, view->out_spec)) {
657 view->f_redisplay_page = true;
658 break;
659 }
660 prev_file_pos = view->page_top_pos;
661 bytes_written = write_view_buffer(init, view->f_strip_ansi);
662 if (bytes_written == 0) {
663 ssnprintf(em0, MAXLEN - 1, _("%s, line: %d"), __FILE__,
664 __LINE__ - 2);
665 strnz__cpy(em1, _("0 bytes written"), MAXLEN - 1);
666 strerror__r(errno, em1, MAXLEN - 1);
667 ui_display_error(em0, em1, nullptr, nullptr);
668 break;
669 }
670 view->next_file_spec_ptr = view->in_spec;
671 strnz__cpy(shell_cmd_spec, init->editor, MAXLEN - 5);
672 strnz__cat(shell_cmd_spec, " ", MAXLEN - 5);
673 strnz__cat(shell_cmd_spec, view->in_spec, MAXLEN - 5);
674 full_screen_shell(shell_cmd_spec);
675 view->file_pos = view->page_top_pos = view->page_bot_pos =
676 prev_file_pos;
677
679 view->f_redisplay_page = true;
680 return 0;
682 case 'w':
683 if (!enter_file_spec(init, view->out_spec)) {
684 view->f_redisplay_page = true;
685 break;
686 }
687 // prev_file_pos = view->page_top_pos;
688 bytes_written = write_view_buffer(init, view->f_strip_ansi);
689 if (bytes_written == 0) {
690 ssnprintf(em0, MAXLEN - 1, _("%s, line: %d"), __FILE__,
691 __LINE__ - 2);
692 strnz__cpy(em1, _("0 bytes written"), MAXLEN - 1);
693 strerror__r(errno, em1, MAXLEN - 1);
694 ui_display_error(em0, em1, nullptr, nullptr);
695 break;
696 }
697 display_prompt(view, tmp_str);
698 view->f_redisplay_page = true;
699 break;
700 case CT_VIEW:
701 break;
703 case 'V':
704 ssnprintf(em0, MAXLEN - 1, _("C-Menu Version: %s"), CM_VERSION);
705 ui_display_error(em0, em1, nullptr, nullptr);
706 break;
707 default:
708 break;
709 }
710 view->cmd_arg[0] = '\0';
711 }
712}
#define Ctrl(c)
Definition cm.h:70
#define CM_VERSION
Definition version.h:5
@ CT_VIEW
Definition menu.h:46
void ui_get_screen_size(uint *lines, uint *cols)
Get the current screen size (number of lines and columns).
Definition ui_ncurses.c:754
#define UIKEY_LEFT
#define UIKEY_PPAGE
#define UIKEY_F01
#define UIKEY_RIGHT
#define UIKEY_UP
#define UIKEY_HOME
#define UIKEY_F05
#define UIKEY_ENTER
#define UIKEY_F06
#define UIKEY_DOWN
#define UIKEY_NPAGE
void view_full_screen_resize(Init *)
Resize the full screen view and its components.
Definition init_view.c:93
void view_boxwin_resize(Init *)
Resize the current window and its box.
Definition init_view.c:228
#define S_TOLOWER(c)
Definition lf.h:183
char prev_regex_pattern[MAXLEN]
#define confirm()
Definition view_engine.c:88
int full_screen_shell(char *)
Execute a shell command in full screen mode.
Definition exec.c:58
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:702
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_char(View *, off_t *)
Get Command Character from User Input.
void go_to_percent(View *, uint)
Go to Percent of File.
void go_to_eof(View *)
Go to End of File.
void go_to_mark(View *, uint)
Go to Mark.
void page_prev(View *)
display previous page
bool search(View *, int, char *)
Search for Regular Expression Pattern.
int go_to_line(View *, off_t)
Go to Specific Line.
void page_next(View *)
Advance to Next Page.
void scroll_next(View *view, uint n)
Scroll Down by n Lines.
void scroll_prev(View *view, uint n)
Move the view scope n lines toward the beginning of the file.
void view_display_help(Init *)
Display View Help File.
void view_display_page(View *)
Display Current Page.
int ui_perror(char *emsg_str)
Display a simple error message window or print to stderr.
Definition ui_common.c:1323
char editor[MAXLEN]
Definition common.h:175

References View::argc, View::argv, build_prompt(), cell_sp, View::cmd, View::cmd_arg, View::cmd_line, View::cols, CT_VIEW, View::cur_file_str, View::curr_argc, View::curx, View::cury, 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, View::ln_win_cols, lp(), View::mark_tbl, View::maxcol, View::next_cmd_char, View::next_file_spec_ptr, View::out_spec, View::page_bot_pos, page_next(), page_prev(), View::page_top_pos, View::pmincol, View::prev_file_pos, prev_regex_pattern, View::prompt_str, View::scroll_lines, scroll_next(), scroll_prev(), search(), View::sfc, shell(), View::srch_beg_pos, View::srch_curr_pos, ssnprintf(), str_subc(), strerror__r(), strnz__cat(), strnz__cpy(), View::tab_stop, View::tmp_file_name_ptr, ui_display_error(), ui_get_screen_size(), ui_log_write(), ui_mvwadd_wchnstr(), ui_perror(), 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 162 of file view_engine.c.

162 {
163 View *view = init->view;
164 if (view->argc < 1) {
165 view->curr_argc = -1;
166 view->argc = 0;
167 view->next_file_spec_ptr = "-";
168 } else
169 view->next_file_spec_ptr = view->argv[0];
170 while (view->curr_argc < view->argc) {
171 if (view->next_file_spec_ptr == nullptr ||
172 *view->next_file_spec_ptr == '\0') {
173 break;
174 }
175 view->file_spec_ptr = view->next_file_spec_ptr;
176 view->next_file_spec_ptr = nullptr;
177 strnz__cpy(view->cur_file_str, view->file_spec_ptr, MAXLEN - 1);
178 if (view_init_input(init, view->cur_file_str) == 0) {
179 if (view->buf) {
180 view->f_eod = 0;
181 view->f_bod = 0;
182 view->maxcol = 0;
183 view->page_top_pos = 0;
184 view->page_top_ln_no = 0;
185 view->page_bot_ln_no = 0;
186 view->ln_pos_max = 0;
187 view->page_bot_pos = 0;
188 view->file_pos = 0;
189 strnz__cpy(view->title, view->cur_file_str, MAXLEN - 1);
190 if (!view->f_full_screen)
191 ui_border_title(view->sfc, BOX, view->title);
194 view_cmd_processor(init);
196 munmap(view->buf, view->file_size);
197 }
198 } else {
199 view->curr_argc++;
200 if (view->curr_argc < view->argc) {
201 view->next_file_spec_ptr = view->argv[view->curr_argc];
202 }
203 }
204 }
206 return 0;
207}
void ui_surface_destroy(UiSurface *s)
Destroy a UiSurface, cleaning up its windows and panels.
Definition ui_ncurses.c:499
int ui_border_title(UiSurface *sfc, ss_t w, const char *title)
Draw a box with a title around the specified window.
Definition ui_common.c:621
int view_init_input(Init *init, char *file_name)
Initialize the input for the C-Menu View.
Definition init_view.c:331
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, 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_pos_max, View::maxcol, View::next_file_spec_ptr, View::page_bot_ln_no, View::page_bot_pos, page_next(), View::page_top_ln_no, View::page_top_pos, View::sfc, strnz__cpy(), View::title, ui_border_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 984 of file view_engine.c.

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

References 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(), strerror__r(), strip_ansi(), strnlf(), strnz__cat(), strnz__cpy(), ui_answer_yn(), ui_display_error(), 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: