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

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

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

1033 {
1034 int c;
1035 while (1) {
1036 get_next_char();
1037 if (view->f_eod)
1038 break;
1039 putchar(c);
1040 }
1041}
#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 2653 of file view_engine.c.

2653 {
2654 char earg_str[MAXLEN];
2655 char *eargv[MAXARGS];
2656 uint eargc;
2657 char tmp_dir[MAXLEN];
2658 char tmp_str[MAXLEN];
2659 char tmp_spec[MAXLEN];
2660 int rc = 0;
2661 FILE *tmp_fp;
2662 View *view = init->view;
2663 strnz__cpy(tmp_dir, init->mapp_home, MAXLEN - 1);
2664 strnz__cat(tmp_dir, "/tmp", MAXLEN - 1);
2665 expand_tilde(tmp_dir, MAXLEN - 1);
2666 if (!mk_dir(tmp_dir)) {
2667 ssnprintf(em0, MAXLEN - 1, _("%s, line: %d"), __FILE__, __LINE__ - 2);
2668 strnz__cpy(em1, _("Unable to "), MAXLEN - 1);
2669 strnz__cat(em1, "mkdir", MAXLEN - 1);
2670 strnz__cat(em1, tmp_dir, MAXLEN - 1);
2671 strerror__r(errno, em2, MAXLEN - 1);
2672 ui_display_error(em0, em1, em2, nullptr);
2673 return false;
2674 }
2675 while (rc == false) {
2676 strnz__cpy(tmp_spec, tmp_dir, MAXLEN - 1);
2677 strnz__cat(tmp_spec, "/tmp_XXXXXX", MAXLEN - 1);
2678 view->in_fd = mkstemp(tmp_spec);
2679 if (view->in_fd == -1) {
2680 ssnprintf(em0, MAXLEN - 1, _("%s, line: %d"), __FILE__, __LINE__ - 2);
2681 strnz__cpy(em1, _("unable to "), MAXLEN - 1);
2682 strnz__cat(em1, "mkstemp ", MAXLEN - 1);
2683 strnz__cat(em1, tmp_spec, MAXLEN - 1);
2684 strerror__r(errno, em2, MAXLEN - 1);
2685 ui_display_error(em0, em1, nullptr, nullptr);
2686 return false;
2687 }
2688 /* call form to get file_name
2689 write the name to a temporary file */
2690
2691 strnz__cpy(earg_str, _("form -d file_name.f -o "), MAXLEN - 1);
2692 strnz__cat(earg_str, tmp_spec, MAXLEN - 1);
2694 rc = popup_form(init, eargc, eargv, view->begy + view->lines - 7, 4);
2697 if (rc == FA_CANCEL || rc == 'q' || rc == 'Q' || rc == UIKEY_F09)
2698 return false;
2699 close(view->in_fd);
2700 tmp_fp = fopen(tmp_spec, "r");
2701 if (tmp_fp == nullptr) {
2702 ssnprintf(em0, MAXLEN - 1, _("%s, line: %d"), __FILE__, __LINE__ - 2);
2703 strnz__cpy(em1, _("unable to "), MAXLEN - 1);
2704 strnz__cat(em1, "fopen ", MAXLEN - 1);
2705 strnz__cat(em1, tmp_spec, MAXLEN - 1);
2706 strerror__r(errno, em2, MAXLEN - 1);
2707 ui_display_error(em0, em1, em2, nullptr);
2708 return false;
2709 }
2710 fgets(tmp_str, MAXLEN - 1, tmp_fp);
2711 strnz(tmp_str, MAXLEN - 1);
2712 fclose(tmp_fp);
2713 unlink(tmp_spec);
2714 if (!verify_spec_arg(file_spec, tmp_str, "~/menuapp/tmp", ".",
2715 S_WCOK | S_QUIET)) {
2716 ssnprintf(em0, MAXLEN - 1, _("Unable to open %s for writing"),
2717 tmp_str);
2718 strnz__cpy(em1, _("Try again? y (yes) or n (no) "), MAXLEN - 1);
2719 rc = ui_display_error(em0, em1, nullptr, nullptr);
2720 if (rc == 'y' || rc == 'Y')
2721 continue;
2722
2723 } else
2724 return true;
2725 }
2726 return true;
2727}
@ 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:62
#define MAXARGS
Definition cm.h:64
#define S_QUIET
Definition cm.h:264
#define S_WCOK
Definition cm.h:263
char em1[MAXLEN]
Definition ui_common.c:47
char em2[MAXLEN]
Definition ui_common.c:48
void ui_restore_wins()
Restore the state of all windows in the UI. This function refreshes the standard screen and all surfa...
char em0[MAXLEN]
Definition ui_common.c:46
#define UIKEY_F09
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:599
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
Definition futil.c:390
int str_to_args(char **, char *, uint)
Converts a string into an array of argument strings.
Definition futil.c:412
bool expand_tilde(char *, uint)
Replaces "~/" in string with the user's home directory.
Definition futil.c:989
bool mk_dir(char *dir)
If directory doesn't exist, make it.
Definition futil.c:1329
char * strerror__r(int errnum, char *buf, size_t buflen)
A thread-safe alternative to strerror() that writes the error message corresponding to errnum into th...
Definition futil.c:748
int destroy_argv(uint argc, char **argv)
Deallocates memory allocated for argument strings in argv.
Definition futil.c:468
bool 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:1200
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 871 of file view_engine.c.

871 {
872 int c;
873 char prompt_s[MAXLEN];
874 UiSurface *sfc = view->sfc;
875 uint prompt_l = strnz__cpy(prompt_s, prompt, min(MAXLEN - 1, view->cols - 4));
876 if (view->cmd_arg[0] != '\0')
877 return 0;
878 ui_cursor_move(sfc, CMDLN, view->cmd_line, 0);
879 if (prompt_l > 1) {
880 ui_bkgdset(sfc, CMDLN, &cell_nt_rev);
881 ui_waddstr(sfc, CMDLN, prompt_s);
882 ui_bkgdset(sfc, CMDLN, &cell_nt);
883 }
884 view->curx = prompt_l;
885 ui_wclrtoeol(sfc, CMDLN);
886 ui_cursor_enable_yx(sfc, CMDLN, view->cmd_line, view->curx, true);
888 ui_mvwadd_wchnstr(sfc, CMDLN, view->cmd_line, view->curx, &cell_ran, 1);
889 ui_cursor_move(sfc, CMDLN, view->cmd_line, view->curx + 1);
890 ui_render();
891 uint flin = view->cmd_line;
892 uint fcol = prompt_l + 1;
893 uint flen = view->cols - prompt_l;
894 c = cf_accept(sfc, CMDLN, view->cmd_arg, flin, fcol, flen);
895 return c;
896}
void ui_render()
Render the UI by updating panels and refreshing the display.
Definition ui_ncurses.c:884
UiCell cell_nt
Definition ui_common.c:106
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:855
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:666
UiCell cell_ran
Definition ui_common.c:115
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:941
UiCell cell_nt_rev
Definition ui_common.c:107
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 731 of file view_engine.c.

731 {
732 int c = 0, i = 0;
733 char *d, *s;
734 uint prevx;
735 bool once = false;
736 char cmd_str[33];
737 cmd_str[0] = '\0';
738 UiSurface *sfc = view->sfc;
739 UiEvent event;
741 ui_mvwadd_wch(sfc, CMDLN, view->cmd_line, view->curx++, &cell_ran);
742 ui_top_surface(sfc, CMDLN);
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(sfc, CMDLN, NULL, &event, -1);
756 switch (c) {
757 case UIKEY_BUTTON1:
758 case UIKEY_SCROLL_UP:
760 break;
761 case UIKEY_RESIZE:
762 case '\n':
763 case '\r':
764 break;
765 case 'q':
766 case UIKEY_F09:
768 display_prompt(view, view->prompt_str);
769 c = UIKEY_F09;
770 return c;
771 case UIKEY_F12:
772 ssnprintf(view->prompt_str, MAXLEN - 1, _("set break at line: %d and restart gdb"), __LINE__);
773 get_cmd_arg(view, view->prompt_str);
774 break;
775 case '\b':
776 case UIKEY_BACKSPACE:
777 if (i > 0) {
778 s = &cmd_str[i];
779 d = &cmd_str[--i];
780 view->curx--;
781 prevx = view->curx;
782 while (*s != '\0') {
783 ui_mvwaddch(sfc, CMDLN, view->cmd_line, view->curx++, *s);
784 *d++ = *s++;
785 }
786 *d = '\0';
787 ui_cursor_move(sfc, CMDLN, view->cmd_line, view->curx);
788 ui_wclrtoeol(sfc, CMDLN);
789 view->curx = prevx;
790 ui_cursor_move(sfc, CMDLN, view->cmd_line, view->curx);
791 }
792 continue;
793 case UIKEY_DC:
794 if (i < 32 && cmd_str[i] != '\0') {
795 s = &cmd_str[i + 1];
796 d = &cmd_str[i];
797 while (*s != '\0') {
798 ui_mvwaddch(sfc, CMDLN, view->cmd_line, view->curx++, *s);
799 *d++ = *s++;
800 }
801 *d = '\0';
802 ui_cursor_move(sfc, CMDLN, view->cmd_line, view->curx);
803 ui_wclrtoeol(sfc, CMDLN);
804 ui_cursor_move(sfc, CMDLN, view->cmd_line, view->curx);
805 }
806 continue;
807 case UIKEY_RSHIFT:
808 if (i < 32 && cmd_str[i] != '\0') {
809 i++;
810 ui_getyx(sfc, CMDLN, &view->cury, &view->curx);
811 if (view->curx < view->cols - 1) {
812 view->curx++;
813 ui_cursor_move(sfc, CMDLN, view->cmd_line, view->curx);
814 }
815 }
816 continue;
817 case UIKEY_LSHIFT:
818 if (i > 0) {
819 i--;
820 ui_getyx(sfc, CMDLN, &view->cury, &view->curx);
821 if (view->curx > 0) {
822 view->curx--;
823 ui_cursor_move(sfc, CMDLN, view->cmd_line, view->curx);
824 }
825 }
826 continue;
827 default:
828 if (c < '0' || c > '9' || i == 32)
829 break;
830 cmd_str[i++] = (char)c;
831 cmd_str[i] = '\0';
832 ui_mvwaddch(sfc, CMDLN, view->cmd_line, view->curx, c);
833 view->curx++;
834 continue;
835 }
836 if (c < '0' || c > '9' || i == 32)
837 break;
838 }
839 if (cmd_str[0] == '\0') {
840 *n = 0;
841 view->cmd_arg[0] = '\0';
842 ui_mvwadd_wchnstr(sfc, CMDLN, view->cmd_line, view->curx, &cell_sp, 1);
843 ui_wclrtoeol(sfc, CMDLN);
844 return (c);
845 }
846 *n = atol(cmd_str);
847 view->cmd_arg[0] = '\0';
848 ui_getyx(sfc, CMDLN, &view->cmd_line, &view->curx);
849 ui_mvwadd_wchnstr(sfc, CMDLN, view->cmd_line, view->curx, &cell_sp, 1);
850 ui_wclrtoeol(sfc, CMDLN);
851 return (c);
852}
UiCell cell_sp
Definition ui_common.c:132
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:675
int ui_top_surface(UiSurface *s, ss_t w)
Hide a UiSurface, making it invisible on the screen.
Definition ui_ncurses.c:623
#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.
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 1046 of file view_engine.c.

1046 {
1047 char *print_cmd_ptr;
1048 char shell_cmd_spec[MAXLEN];
1049 print_cmd_ptr = getenv("PRINTCMD");
1050 if (print_cmd_ptr == nullptr || *print_cmd_ptr == '\0')
1051 print_cmd_ptr = PRINTCMD;
1052 ssnprintf(shell_cmd_spec, MAXLEN - 1, "%s %s", print_cmd_ptr, PrintFile);
1053 display_prompt(view, shell_cmd_spec);
1054 shell(shell_cmd_spec);
1055}
#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 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 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 max_pmincol = (view->maxcol > view->cols) ? (view->maxcol - view->cols) : 0;
307 if (view->pmincol + shift < max_pmincol)
308 view->pmincol += shift;
309 else
310 view->pmincol = max_pmincol;
311 break;
312 case 'k':
313 case UIKEY_SCROLL_UP:
314 case UIKEY_UP:
315 if (n_cmd <= 0)
316 n_cmd = 1;
317 scroll_prev(view, (uint)n_cmd);
318 break;
320 case 'j':
321 case '\n':
323 case UIKEY_DOWN:
324 case UIKEY_ENTER:
325 if (n_cmd <= 0)
326 n_cmd = 1;
327 scroll_next(view, (uint)n_cmd);
328 break;
330 case UIKEY_PPAGE:
331 case Ctrl('B'):
333 break;
335 case UIKEY_NPAGE:
336 case Ctrl('F'):
337 view->ln_no++;
339 break;
341 case '!':
342 if (view->f_displaying_help)
343 break;
344 if (get_cmd_arg(view, "!") == 0) {
345 if (!view->f_is_pipe) {
346 view->prev_file_pos = view->page_top_pos;
347 view->next_file_spec_ptr = view->file_spec_ptr;
348 str_subc(shell_cmd_spec, view->cmd_arg, '%',
349 view->cur_file_str, MAXLEN - 1);
350 } else
351 strnz__cpy(shell_cmd_spec, view->cmd_arg, MAXLEN - 1);
352 full_screen_shell(shell_cmd_spec);
353 if (!view->f_is_pipe) {
354 view->next_file_spec_ptr = view->cur_file_str;
355 return 0;
356 }
357 }
358 break;
360 case '+':
361 if (get_cmd_arg(view, _("Startup Command:")) == 0)
362 strnz__cpy(view->cmd, view->cmd_arg, MAXLEN - 1);
363 break;
365 case '-':
366 display_prompt(view, "(i, n, s, t, w, or h)->");
367 c = get_cmd_char(view, &n_cmd);
368 c = S_TOLOWER(c);
369 switch (c) {
376 case 'i':
377 display_prompt(view, _("Ignore Case in search (Y or N)->"));
378 confirm();
379 if (ans)
380 view->f_ignore_case = true;
381 else if (c == 'n' || c == 'N')
382 view->f_ignore_case = false;
383 break;
385 case 'n':
386 display_prompt(view, _("Line Numbering (Y or N)->"));
387 confirm();
388 if (view->f_ln == ans)
389 break;
390 view->f_ln = ans;
391 view->f_redisplay_page = true;
392 (view->f_full_screen) ? view_full_screen_resize(init) : view_boxwin_resize(init);
393 break;
395 case 's':
397 view, _("view->f_squeeze Multiple Blank lines (Y or N)->"));
398 confirm();
399 view->f_squeeze = ans;
400 break;
401 case 'w':
403 view, _("Line Wrapping (Y or N)->"));
404 if ((c = get_cmd_char(view, &n_cmd)) == 'y' || c == 'Y')
405 ans = true;
406 else if (c == 'n' || c == 'N')
407 ans = false;
408 if (view->wrap == ans)
409 break;
410 view->wrap = ans;
411 view->f_redisplay_page = true;
412 (view->f_full_screen) ? view_full_screen_resize(init) : view_boxwin_resize(init);
413 break;
415 case 't':
416 sprintf(tmp_str,
417 _("Tabstop Colums Currently %d:"), view->tab_stop);
418 i = 0;
419 if (get_cmd_arg(view, tmp_str) == 0)
420 i = atoi(view->cmd_arg);
421 if (i >= 1 && i <= 12) {
422 view->tab_stop = i;
423 view->f_redisplay_page = true;
424 } else
425 ui_perror(_("Tab stops not changed"));
426 break;
428 case UIKEY_F01:
429 case 'h':
430 if (!view->f_displaying_help) {
431 view_display_help(init);
432 view = init->view;
433 }
434 view->next_cmd_char = '-';
435 break;
436 default:
437 break;
438 }
439 break;
441 case 'n':
442 if (view->f_search_complete) {
443 ui_perror(_("Search complete, no more matches"));
444 break;
445 }
446 if (prev_search_cmd == 0) {
447 ui_perror(_("No previouis search"));
448 break;
449 }
450 if (prev_search_cmd == '/') {
451 view->cury = 0;
452 view->srch_curr_pos = view->page_bot_pos;
453 } else {
454 view->cury = view->scroll_lines + 1;
455 view->srch_curr_pos = view->page_top_pos;
456 }
457 rc = search(view, prev_search_cmd, prev_regex_pattern);
458 if (rc == false) {
459 ui_perror(_("No matches found"));
460 break;
461 }
462 break;
464 case '/':
465 view->f_search_complete = false;
466 strnz__cpy(tmp_str, _(" Forward:"), MAXLEN - 1);
467 search_cmd = c;
468 c = get_cmd_arg(view, tmp_str);
469 if (c == UIKEY_F09 || c == '\033')
470 break;
471 if (c == UIKEY_ENTER) {
472 view->cury = 0;
473 view->f_first_iter = true;
474 view->srch_beg_pos = view->page_top_pos;
475 view->srch_curr_pos = view->page_top_pos;
476 rc = search(view, search_cmd, view->cmd_arg);
477 if (rc == false) {
478 ui_perror(_("No matches found"));
479 break;
480 }
481 prev_search_cmd = search_cmd;
483 }
484 break;
486 case '?':
487 view->f_search_complete = false;
488 strnz__cpy(tmp_str, _(" Backward:"), MAXLEN - 1);
489 search_cmd = c;
490 c = get_cmd_arg(view, tmp_str);
491 if (c == UIKEY_F09 || c == '\033')
492 break;
493 if (c == '\n') {
494 view->cury = view->scroll_lines;
495 view->f_first_iter = true;
496 view->srch_beg_pos = view->page_bot_pos;
497 view->srch_curr_pos = view->page_bot_pos;
498 rc = search(view, search_cmd, view->cmd_arg);
499 if (rc == false) {
500 ui_perror(_("No matches found"));
501 break;
502 }
503 prev_search_cmd = search_cmd;
505 }
506 break;
508 case 'o':
509 if (get_cmd_arg(view, _("File name:")) == 0) {
510 strtok(view->cmd_arg, " ");
511 view->next_file_spec_ptr = strdup(view->cmd_arg);
512 view->f_redisplay_page = true;
513 return 0;
514 }
515 break;
516 case 'G':
517 case UIKEY_HOME:
518 if (n_cmd > 0) {
519 n_cmd -= 1;
520 go_to_line(view, n_cmd);
521 } else
523 break;
525 case 'H':
526 case UIKEY_F01:
527 if (!view->f_displaying_help) {
528 view_display_help(init);
529 view = init->view;
530 }
531 break;
533 case 'm':
534 display_prompt(view, _("Mark label (A-Z)->"));
535 c = get_cmd_char(view, &n_cmd);
536 if (c == '@' || c == UIKEY_F09 || c == '\033')
537 if (c >= 'A' && c <= 'Z')
538 c += ' ';
539 if (c < 'a' || c > 'z')
540 ui_perror(_("Not (a-z)"));
541 else
542 view->mark_tbl[c - 'a'] = view->page_top_pos;
543 break;
545 case 'M':
546 display_prompt(view, _("Goto mark (A-Z)->"));
547 c = get_cmd_char(view, &n_cmd);
548 if (c == '@' || c == UIKEY_F09 || c == '\033')
549 break;
550 if (c >= 'A' && c <= 'Z')
551 c += ' ';
552 if (c < 'a' || c > 'z')
553 ui_perror(_("Not (A-Z)"));
554 else
555 go_to_mark(view, c);
556 break;
558 case 'N':
559 if (n_cmd <= 0)
560 n_cmd = 1;
561 if (view->curr_argc + n_cmd >= view->argc) {
562 ui_perror(_("no more files"));
563 view->curr_argc = view->argc - 1;
564 } else {
565 view->curr_argc++;
566 if (view->curr_argc < view->argc)
567 view->next_file_spec_ptr = view->argv[view->curr_argc];
568 return 0;
569 }
570 break;
572 case 'p':
573 case '%':
574 if (n_cmd < 0)
575 go_to_line(view, 1);
576 if (n_cmd >= 100)
578 else
579 go_to_percent(view, n_cmd);
580 break;
582 case Ctrl('Z'):
583 get_cmd_arg(view, _("Enter Notation:"));
584 strnz__cpy(tmp_str, "/tmp/view-XXXXXX", MAXLEN - 1);
585 tfd = mkstemp(tmp_str);
586 strnz__cpy(view->tmp_file_name_ptr, tmp_str, MAXLEN - 1);
587 if (tfd == -1) {
588 ui_perror(_("Unable to create temporary file"));
589 break;
590 }
591 strnz__cpy(shell_cmd_spec, "echo ", MAXLEN - 5);
592 strnz__cat(shell_cmd_spec, view->cmd_arg, MAXLEN - 5);
593 strnz__cat(shell_cmd_spec, view->tmp_file_name_ptr, MAXLEN - 5);
594 shell(shell_cmd_spec);
595 strnz__cpy(shell_cmd_spec, "cat ", MAXLEN - 5);
596 strnz__cat(shell_cmd_spec, view->cmd_arg, MAXLEN - 5);
597 strnz__cat(shell_cmd_spec, ">>", MAXLEN - 5);
598 strnz__cat(shell_cmd_spec, view->tmp_file_name_ptr, MAXLEN - 5);
599 shell(shell_cmd_spec);
600 lp(view, view->cur_file_str);
601 shell(shell_cmd_spec);
602 ssnprintf(shell_cmd_spec, (size_t)(MAXLEN - 5), "rm %s",
603 view->tmp_file_name_ptr);
604 strnz__cpy(shell_cmd_spec, "rm ", MAXLEN - 5);
605 strnz__cat(shell_cmd_spec, view->tmp_file_name_ptr, MAXLEN - 5);
606 shell(shell_cmd_spec);
608 view->f_redisplay_page = true;
609 unlink(tmp_str);
610 break;
612 case Ctrl('P'):
613 lp(view, view->cur_file_str);
614 view->f_redisplay_page = true;
615 break;
617 case 'P':
618 if (n_cmd <= 0)
619 n_cmd = 1;
620 if (view->curr_argc - n_cmd < 0) {
621 ui_perror(_("No previous file"));
622 view->curr_argc = 0;
623 } else {
624 view->curr_argc--;
625 if (view->curr_argc >= 0)
626 view->next_file_spec_ptr = view->argv[view->curr_argc];
627 return 0;
628 }
629 break;
631 case 'q':
632 case 'Q':
633 case UIKEY_F09:
634 case '\033':
635 ui_mvwadd_wchnstr(sfc, CMDLN, view->cmd_line, view->curx, &cell_sp, 1);
636 view->curr_argc = view->argc;
637 view->next_file_spec_ptr = nullptr;
638 return 0;
640 case 'v':
641 if (init->editor[0] == 0) {
642 e = getenv("DEFAULTEDITOR");
643 if (e == nullptr || *e == '\0')
644 strnz__cpy(init->editor, DEFAULTEDITOR, MAXLEN);
645 else
646 strnz__cpy(init->editor, e, MAXLEN);
647 }
649 _("View doesn't support editing current buffer directly"),
650 MAXLEN - 1);
651 strnz__cpy(em1, _("Would you like to write the buffer to a file?"),
652 MAXLEN - 1);
653 strnz__cpy(em2, _("Enter Y for yes or any other key to cancel."),
654 MAXLEN - 1);
655 rc = ui_display_error(em0, em1, em2, nullptr);
656 if (rc != 'y' && rc != 'Y')
657 break;
658 if (!enter_file_spec(init, view->out_spec)) {
659 view->f_redisplay_page = true;
660 break;
661 }
662 prev_file_pos = view->page_top_pos;
663 bytes_written = write_view_buffer(init, view->f_strip_ansi);
664 if (bytes_written == 0) {
665 ssnprintf(em0, MAXLEN - 1, _("%s, line: %d"), __FILE__,
666 __LINE__ - 2);
667 strnz__cpy(em1, _("0 bytes written"), MAXLEN - 1);
668 strerror__r(errno, em1, MAXLEN - 1);
669 ui_display_error(em0, em1, nullptr, nullptr);
670 break;
671 }
672 view->next_file_spec_ptr = view->in_spec;
673 strnz__cpy(shell_cmd_spec, init->editor, MAXLEN - 5);
674 strnz__cat(shell_cmd_spec, " ", MAXLEN - 5);
675 strnz__cat(shell_cmd_spec, view->in_spec, MAXLEN - 5);
676 full_screen_shell(shell_cmd_spec);
677 view->file_pos = view->page_top_pos = view->page_bot_pos =
678 prev_file_pos;
679
681 view->f_redisplay_page = true;
682 return 0;
684 case 'w':
685 if (!enter_file_spec(init, view->out_spec)) {
686 view->f_redisplay_page = true;
687 break;
688 }
689 // prev_file_pos = view->page_top_pos;
690 bytes_written = write_view_buffer(init, view->f_strip_ansi);
691 if (bytes_written == 0) {
692 ssnprintf(em0, MAXLEN - 1, _("%s, line: %d"), __FILE__,
693 __LINE__ - 2);
694 strnz__cpy(em1, _("0 bytes written"), MAXLEN - 1);
695 strerror__r(errno, em1, MAXLEN - 1);
696 ui_display_error(em0, em1, nullptr, nullptr);
697 break;
698 }
699 display_prompt(view, tmp_str);
700 view->f_redisplay_page = true;
701 break;
702 case CT_VIEW:
703 break;
705 case 'V':
706 ssnprintf(em0, MAXLEN - 1, _("C-Menu Version: %s"), CM_VERSION);
707 ui_display_error(em0, em1, nullptr, nullptr);
708 break;
709 default:
710 break;
711 }
712 view->cmd_arg[0] = '\0';
713 }
714}
#define S_TOLOWER(c)
Definition cm.h:157
#define Ctrl(c)
Definition cm.h:67
#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:722
#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:111
void view_boxwin_resize(Init *)
Resize the current window and its box.
Definition init_view.c:198
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:680
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:1257
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, 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_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 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_pos_max = 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 ui_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)
Destroy a UiSurface, cleaning up its windows and panels.
Definition ui_ncurses.c:468
int ui_border_title(UiSurface *sfc, const char *title)
Draw a box with a title around the specified window.
Definition ui_common.c:563
int view_init_input(Init *init, char *file_name)
Initialize the input for the C-Menu View.
Definition init_view.c:299
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 985 of file view_engine.c.

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

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: