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.
void remove_file (View *view)
 Remove File.
int view_cmd_processor (Init *init)
 Main Command Processing Loop for View.
int view_file (Init *init)
 Start view.
void view_stack_free (ViewStack *s)
 Free View Stack.
bool view_stack_init (ViewStack *s, size_t initial_capacity)
 Initialize View Stack.
bool view_stack_peek (const ViewStack *s, View *out_item)
 Peek at Top Item of View Stack.
bool view_stack_pop (ViewStack *s, View *out_item)
 Pop Item from View Stack.
bool view_stack_push (ViewStack *s, View item)
 Push Item onto View Stack.
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:49

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. Carriage-returns are ignored as they should be. View uses the kernel's demand paged virtual address space to map files directly into memory. This allows for efficient access to file contents without the need for explicit buffering or read system calls, as the kernel handles loading the necessary pages into memory on demand.

Definition at line 45 of file view_engine.c.

45#define get_next_char() \
46 { \
47 c = 0; \
48 do { \
49 if (view->file_pos == view->file_size) { \
50 view->f_eod = true; \
51 break; \
52 } else \
53 view->f_eod = false; \
54 c = view->buf[view->file_pos++]; \
55 } while (c == 0x0d); \
56 if (c == '\n') \
57 increment_ln(view); \
58 }

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

68#define get_prev_char() \
69 { \
70 c = 0; \
71 do { \
72 if (view->file_pos == 0) { \
73 view->f_bod = true; \
74 break; \
75 } else \
76 view->f_bod = false; \
77 c = view->buf[--view->file_pos]; \
78 } while (c == 0x0d); \
79 }

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

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

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, View::page_bot_pos, View::page_top_ln, 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:45

References View::f_eod.

◆ enter_file_spec()

bool enter_file_spec ( Init * init,
char * file_spec )

use form to enter a file specification

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

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

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

Definition at line 2132 of file view_engine.c.

2132 {
2133 char earg_str[MAXLEN];
2134 char *eargv[MAXARGS];
2135 int eargc;
2136 char tmp_dir[MAXLEN];
2137 char tmp_str[MAXLEN];
2138 char tmp_spec[MAXLEN];
2139 int rc = false;
2140 FILE *tmp_fp;
2141 View *view = init->view;
2142 strnz__cpy(tmp_dir, init->mapp_home, MAXLEN - 1);
2143 strnz__cat(tmp_dir, "/tmp", MAXLEN - 1);
2144 expand_tilde(tmp_dir, MAXLEN - 1);
2145 if (!mk_dir(tmp_dir)) {
2146 ssnprintf(em0, MAXLEN - 1, "%s, line: %d", __FILE__, __LINE__ - 2);
2147 strnz__cpy(em1, "Unable to ", MAXLEN - 1);
2148 strnz__cat(em1, "mkdir", MAXLEN - 1);
2149 strnz__cat(em1, tmp_dir, MAXLEN - 1);
2150 strerror_r(errno, em2, MAXLEN - 1);
2151 display_error(em0, em1, em2, nullptr);
2152 return false;
2153 }
2154 while (rc == false) {
2155 strnz__cpy(tmp_spec, tmp_dir, MAXLEN - 1);
2156 strnz__cat(tmp_spec, "/tmp_XXXXXX", MAXLEN - 1);
2157 view->in_fd = mkstemp(tmp_spec);
2158 if (view->in_fd == -1) {
2159 ssnprintf(em0, MAXLEN - 1, "%s, line: %d", __FILE__, __LINE__ - 2);
2160 strnz__cpy(em1, "unable to ", MAXLEN - 1);
2161 strnz__cat(em1, "mkstemp ", MAXLEN - 1);
2162 strnz__cat(em1, tmp_spec, MAXLEN - 1);
2163 strerror_r(errno, em2, MAXLEN - 1);
2164 display_error(em0, em1, nullptr, nullptr);
2165 return false;
2166 }
2169
2170 strnz__cpy(earg_str, "form -d file_name.f -o ", MAXLEN - 1);
2171 strnz__cat(earg_str, tmp_spec, MAXLEN - 1);
2173 rc = popup_form(init, eargc, eargv, view->begy + view->lines - 7, 4);
2175 restore_wins();
2176 if (rc == FA_CANCEL || rc == 'q' || rc == 'Q' || rc == KEY_F(9))
2177 return false;
2178 close(view->in_fd);
2179 tmp_fp = fopen(tmp_spec, "r");
2180 if (tmp_fp == nullptr) {
2181 ssnprintf(em0, MAXLEN - 1, "%s, line: %d", __FILE__, __LINE__ - 2);
2182 strnz__cpy(em1, "unable to ", MAXLEN - 1);
2183 strnz__cat(em1, "fopen ", MAXLEN - 1);
2184 strnz__cat(em1, tmp_spec, MAXLEN - 1);
2185 strerror_r(errno, em2, MAXLEN - 1);
2186 display_error(em0, em1, em2, nullptr);
2187 return false;
2188 }
2189 fgets(tmp_str, MAXLEN - 1, tmp_fp);
2190 strnz(tmp_str, MAXLEN - 1);
2191 fclose(tmp_fp);
2192 unlink(tmp_spec);
2193 if (!verify_spec_arg(file_spec, tmp_str, "~/menuapp/tmp", ".",
2194 S_WCOK | S_QUIET)) {
2195 ssnprintf(em0, MAXLEN - 1, "Unable to open %s for writing",
2196 tmp_str);
2197 strnz__cpy(em1, "Try again? y (yes) or n (no) ", MAXLEN - 1);
2198 rc = display_error(em0, em1, nullptr, nullptr);
2199 if (rc == 'y' || rc == 'Y')
2200 continue;
2201
2202 } else
2203 return true;
2204 }
2205 return true;
2206}
@ FA_CANCEL
Definition form.h:33
int popup_form(Init *, int, char **, int, int)
instantiate a form popup window
Definition popups.c:112
#define MAX_ARGS
Definition cm.h:46
char em1[MAXLEN]
Definition dwin.c:176
#define MAXARGS
Definition cm.h:48
char em0[MAXLEN]
Definition dwin.c:175
#define S_QUIET
Definition cm.h:286
#define S_WCOK
Definition cm.h:285
char em2[MAXLEN]
Definition dwin.c:177
int eargc
Definition futil.c:57
char earg_str[MAXLEN]
Definition futil.c:56
char * eargv[MAXARGS]
Definition futil.c:58
void restore_wins()
Restore all windows after a screen resize.
Definition dwin.c:1225
int display_error(char *, char *, char *, char *)
Display an error message window or print to stderr.
Definition dwin.c:1467
int destroy_argv(int argc, char **argv)
Deallocates memory allocated for argument strings in argv.
Definition futil.c:494
size_t strnz(char *, size_t)
terminates string at New Line, Carriage Return, or max_len
Definition futil.c:615
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
Definition futil.c:420
bool expand_tilde(char *, int)
Replaces "~/" in string with the user's home directory.
Definition futil.c:970
bool mk_dir(char *dir)
If directory doesn't exist, make it.
Definition futil.c:1320
int str_to_args(char **, char *, int)
Converts a string into an array of argument strings.
Definition futil.c:440
bool verify_spec_arg(char *, char *, char *, char *, int)
Verify file specification argument.
Definition mem.c:380
char mapp_home[MAXLEN]
Definition common.h:146
View * view
Definition common.h:188
Definition view.h:42

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

Referenced by view_cmd_processor().

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

◆ get_cmd_arg()

int get_cmd_arg ( View * view,
char * prompt )

Get Command Argument from User Input.

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

Definition at line 872 of file view_engine.c.

872 {
873 int c;
874 char prompt_s[MAXLEN];
875 int prompt_l = strnz__cpy(prompt_s, prompt, min(MAXLEN - 1, view->cols - 4));
876 if (view->cmd_arg[0] != '\0')
877 return 0;
878 wmove(view->cmdln_win, view->cmd_line, 0);
879 if (prompt_l > 1) {
880 wbkgrndset(view->cmdln_win, &CC_NT_REV);
881 waddstr(view->cmdln_win, prompt_s);
882 wbkgrndset(view->cmdln_win, &CC_NT);
883 }
884 view->curx = prompt_l;
885 wclrtoeol(view->cmdln_win);
887 update_panels();
888 curs_set(1);
889 mvwadd_wchnstr(view->cmdln_win, view->cmd_line, view->curx, &ran, 1);
890 wmove(view->cmdln_win, view->cmd_line, view->curx + 1);
891 doupdate();
892 int flin = view->cmd_line;
893 int fcol = prompt_l + 1;
894 int flen = view->cols - prompt_l;
895 c = cf_accept(view->cmdln_win, view->cmd_arg, flin, fcol, flen);
896 return c;
897}
cchar_t CC_NT
Definition dwin.c:204
cchar_t ran
Definition cm.h:631
cchar_t CC_NT_REV
Definition dwin.c:205
int cf_accept(WINDOW *win, char *accept_s, int flin, int fcol, int flen)
Accepts input for a field in a C-Menu window.
Definition cm_fields.c:51
int pad_refresh(View *)
Refresh Pad and Line Number Window.

References CC_NT, CC_NT_REV, cf_accept(), View::cmd_arg, View::cmd_line, View::cmdln_win, View::cols, View::curx, pad_refresh(), ran, and strnz__cpy().

Referenced by view_cmd_processor().

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

◆ get_cmd_char()

int get_cmd_char ( View * view,
off_t * n )

Get Command Character from User Input.

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

Definition at line 727 of file view_engine.c.

727 {
728 int c = 0, i = 0;
729 char *d, *s;
730 int prevx;
731 bool once = false;
732 char cmd_str[33];
733 cmd_str[0] = '\0';
735 update_panels();
736 curs_set(1);
737 getyx(view->cmdln_win, view->cmd_line, view->curx);
738 wbkgrndset(view->cmdln_win, &CC_IND);
739 wmove(view->cmdln_win, view->cmd_line, view->curx);
740 mvwadd_wchnstr(view->cmdln_win, view->cmd_line, view->curx, &ran, 1);
741 wmove(view->cmdln_win, view->cmd_line, view->curx + 1);
742 update_panels();
743 doupdate();
744 while (1) {
745 if (i == 1 && !once) {
746 once = true;
747 view->curx = 0;
748 wmove(view->cmdln_win, view->cmd_line, view->curx);
749 wclrtoeol(view->cmdln_win);
750 mvwadd_wchnstr(view->cmdln_win, view->cmd_line, view->curx, &ran, 1);
751 mvwaddch(view->cmdln_win, view->cmd_line, view->curx + 1, (chtype)c);
752 }
753 getyx(view->cmdln_win, view->cmd_line, view->curx);
754 update_panels();
755 wmove(view->cmdln_win, view->cmd_line, view->curx);
756 doupdate();
757 c = vgetch(view->cmdln_win, 0);
758 switch (c) {
759 case KEY_MOUSE:
760 // if (getmouse(event) == OK) {
761 // if (event.bstate & BUTTON1_CLICKED) {
762 // c = KEY_MOUSE;
763 // break;
764 // }
765 // }
766 break;
767 case KEY_RESIZE:
768 case '\n':
769 case '\r':
770 break;
771 case 'q':
772 case KEY_F(9):
774 display_prompt(view, view->prompt_str);
775 c = KEY_F(9);
776 return c;
777 case '\b':
778 case KEY_BACKSPACE:
779 if (i > 0) {
780 s = &cmd_str[i];
781 d = &cmd_str[--i];
782 view->curx--;
783 prevx = view->curx;
784 while (*s != '\0') {
785 mvwaddch(view->cmdln_win, view->cmd_line, view->curx++, *s);
786 *d++ = *s++;
787 }
788 *d = '\0';
789 wmove(view->cmdln_win, view->cmd_line, view->curx);
790 wclrtoeol(view->cmdln_win);
791 view->curx = prevx;
792 wmove(view->cmdln_win, view->cmd_line, view->curx);
793 }
794 continue;
795 case KEY_DC:
796 if (i < 32 && cmd_str[i] != '\0') {
797 s = &cmd_str[i + 1];
798 d = &cmd_str[i];
799 while (*s != '\0') {
800 mvwaddch(view->cmdln_win, view->cmd_line, view->curx++, *s);
801 *d++ = *s++;
802 }
803 *d = '\0';
804 wmove(view->cmdln_win, view->cmd_line, view->curx);
805 wclrtoeol(view->cmdln_win);
806 wmove(view->cmdln_win, view->cmd_line, view->curx);
807 }
808 continue;
809 case KEY_SRIGHT:
810 if (i < 32 && cmd_str[i] != '\0') {
811 i++;
812 getyx(view->cmdln_win, view->cury, view->curx);
813 if (view->curx < view->cols - 1) {
814 view->curx++;
815 wmove(view->cmdln_win, view->cmd_line, view->curx);
816 }
817 }
818 continue;
819 case KEY_SLEFT:
820 if (i > 0) {
821 i--;
822 getyx(view->cmdln_win, view->cury, view->curx);
823 if (view->curx > 0) {
824 view->curx--;
825 wmove(view->cmdln_win, view->cmd_line, view->curx);
826 }
827 }
828 continue;
829 default:
830 if (c < '0' || c > '9' || i == 32)
831 break;
832 cmd_str[i++] = (char)c;
833 cmd_str[i] = '\0';
834 mvwaddch(view->cmdln_win, view->cmd_line, view->curx, (chtype)c);
835 view->curx++;
836 continue;
837 }
838 if (c < '0' || c > '9' || i == 32)
839 break;
840 }
841 if (cmd_str[0] == '\0') {
842 *n = 0;
843 view->cmd_arg[0] = '\0';
844 mvwadd_wchnstr(view->cmdln_win, view->cmd_line, view->curx + 1, &sp, 1);
845 wclrtoeol(view->cmdln_win);
846 return (c);
847 }
848 *n = atol(cmd_str);
849 view->cmd_arg[0] = '\0';
850 getyx(view->cmdln_win, view->cmd_line, view->curx);
851 mvwadd_wchnstr(view->cmdln_win, view->cmd_line, view->curx + 1, &sp, 1);
852 wclrtoeol(view->cmdln_win);
853 return (c);
854}
cchar_t CC_IND
Definition dwin.c:200
cchar_t sp
Definition cm.h:631
int vgetch(WINDOW *, int)
Wrapper for wgetch that handles signals and mouse events, and accepts a single character answer.
Definition dwin.c:2258
void build_prompt(View *)
Build Prompt String.
int display_prompt(View *, char *)
Display Command Line Prompt.

References build_prompt(), CC_IND, View::cmd_arg, View::cmd_line, View::cmdln_win, View::cols, View::curx, View::cury, display_prompt(), pad_refresh(), View::prompt_str, ran, sp, and vgetch().

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:47
int shell(char *)
Execute a shell command.
Definition exec.c:78

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:

◆ remove_file()

void remove_file ( View * view)

Remove File.

Parameters
viewis the current view data structure

Definition at line 2059 of file view_engine.c.

2059 {
2060 char c;
2061 if (view->f_at_end_remove) {
2062 wmove(view->pad, view->cmd_line, 0);
2063 waddstr(view->pad, "Remove File (Y or N)->");
2064 wclrtoeol(view->pad);
2065 update_panels();
2066 doupdate();
2067 c = (char)vgetch(view->cmdln_win, -1);
2068 waddch(view->pad, (char)toupper(c));
2069 if (c == 'Y' || c == 'y')
2070 remove(view->cur_file_str);
2071 }
2072}

References View::cmd_line, View::cmdln_win, View::cur_file_str, View::f_at_end_remove, View::pad, and vgetch().

Here is the call 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.

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

< KEY_ALTHOME - horizontal scroll to the first column

< KEY_ALTEND horizontal scroll to the last column

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

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

'k', 'K', KEY_UP, Ctrl('K') - Scroll up one line

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

'b', 'B', Ctrl('B'), KEY_PPAGE - Previous Page

'f', 'F', Ctrl('F'), KEY_NPAGE Next Page

'g', KEY_HOME - Go to the beginning of the document

KEY_LL - Go to the end of the document

'!', 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

-h display help

-n line numbers

-s Squeeze Multiple Blank Lines

-t n Set Tab Stop Columns

-h Display Help

Pedantic reassignment of view pointer as the init->view pointer was was reassigned during view_display_help

':' - Set a Prompt String

'n' - Repeat Previous Search

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

'?' - Search Backward

'o' or 'O' - Open a File

'g' or 'G' - Go to the End of the Document

'H' or KEY_F(1) - 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' or KEY_CATAB or KEY_PRINT - Print Current File

'P' or KEY_F(9) or ESC - Close Current File and Open Next

'q' or 'Q' or KEY_F(9) 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 184 of file view_engine.c.

184 {
185 char tmp_str[MAXLEN];
186 int tfd;
187 int c;
188 int shift = 0;
189 int search_cmd = 0;
190 int prev_search_cmd = 0;
191 int rc, i;
192 ssize_t bytes_written;
193 char *e;
194 char shell_cmd_spec[MAXLEN];
195 off_t n_cmd = 0L;
196 off_t prev_file_pos;
197 int swidth;
198 int max_pmincol;
199 View *view = init->view;
200 view->cmd[0] = '\0';
201 while (1) {
202 if (view->f_redisplay_page) {
204 view->f_redisplay_page = false;
205 }
206 c = view->next_cmd_char;
207 view->next_cmd_char = 0;
208 if (!c) {
210 display_prompt(view, view->prompt_str);
211 c = get_cmd_char(view, &n_cmd);
212 if (c >= '0' && c <= '9') {
213 tmp_str[0] = (char)c;
214 tmp_str[1] = '\0';
215 c = get_cmd_arg(view, tmp_str);
216 }
217 }
218 switch (c) {
219 case Ctrl('R'):
220 case 'x':
221 case KEY_RESIZE:
222 getmaxyx(stdscr, view->lines, view->cols);
223#ifdef DEBUG_RESIZE
224 ssnprintf(em0, MAXLEN - 1,
225 "%s:%d view->page_top_ln=%d, resized to lines: %d, cols: %d\n",
226 __FILE__, __LINE__, view->page_top_ln, view->lines, view->cols);
228#endif
229 if (view->f_full_screen)
231 else
232 view_boxwin_resize(init);
233 view->f_redisplay_page = true;
234 continue;
235 case KEY_ALTHOME:
237 view->pmincol = 0;
238 break;
239 case KEY_ALTEND:
242 if (view->maxcol > view->cols)
243 view->pmincol = view->maxcol - view->cols;
244 else
245 view->pmincol = 0;
246 break;
247 case 'h':
249 case Ctrl('H'):
250 case KEY_LEFT:
251 case KEY_BACKSPACE:
252 if (n_cmd > 0)
253 view->h_shift = n_cmd;
254 else if (n_cmd == 0) {
255 if (view->h_shift > 0)
256 n_cmd = view->h_shift;
257 else
258 n_cmd = 1;
259 }
260 shift = (int)n_cmd;
261 if (view->pmincol - shift > 0)
262 view->pmincol -= shift;
263 else
264 view->pmincol = 0;
265 break;
266 case 'l':
268 case 'L':
269 case KEY_RIGHT:
270 if (n_cmd > 0)
271 view->h_shift = n_cmd;
272 else if (n_cmd == 0) {
273 if (view->h_shift > 0)
274 n_cmd = view->h_shift;
275 else
276 n_cmd = 1;
277 }
278 shift = (int)n_cmd;
279 swidth = view->smaxcol - view->smincol + 1;
280 if (view->f_ln)
281 max_pmincol = view->maxcol - swidth + view->ln_win_cols;
282 else
283 max_pmincol = view->maxcol - swidth;
284 if (view->pmincol + shift < max_pmincol)
285 view->pmincol += shift;
286 else
287 view->pmincol = max_pmincol;
288 break;
289 case 'k':
290 case 'K':
291 case KEY_UP:
292 case Ctrl('K'):
293 if (n_cmd <= 0)
294 n_cmd = 1;
295 scroll_up_n_lines(view, n_cmd);
296 break;
298 case 'j':
299 case 'J':
300 case '\n':
301 case ' ':
302 case KEY_DOWN:
303 case KEY_ENTER:
304 if (n_cmd <= 0)
305 n_cmd = 1;
307 break;
309 case KEY_PPAGE:
310 case 'b':
311 case 'B':
312 case Ctrl('B'):
314 break;
316 case 'f':
317 case 'F':
318 case KEY_NPAGE:
319 case Ctrl('F'):
321 break;
323 case 'g':
324 case KEY_HOME:
325 view->pmincol = 0;
326 go_to_line(view, 0);
327 break;
329 case KEY_LL:
331 break;
333 case '!':
334 if (view->f_displaying_help)
335 break;
336 if (get_cmd_arg(view, "!") == 0) {
337 if (!view->f_is_pipe) {
338 view->prev_file_pos = view->page_top_pos;
339 view->next_file_spec_ptr = view->file_spec_ptr;
340 str_subc(shell_cmd_spec, view->cmd_arg, '%',
341 view->cur_file_str, MAXLEN - 1);
342 } else
343 strnz__cpy(shell_cmd_spec, view->cmd_arg, MAXLEN - 1);
344 full_screen_shell(shell_cmd_spec);
345 if (!view->f_is_pipe) {
346 view->next_file_spec_ptr = view->cur_file_str;
347 return 0;
348 }
349 }
350 break;
352 case '+':
353 if (get_cmd_arg(view, "Startup Command:") == 0)
354 strnz__cpy(view->cmd, view->cmd_arg, MAXLEN - 1);
355 break;
357 case '-':
358 display_prompt(view, "(i, n, s, t, or h)->");
359 c = get_cmd_char(view, &n_cmd);
360 c = S_TOLOWER(c);
361 switch (c) {
367 case 'i':
368 display_prompt(view, "Ignore Case in search (Y or N)->");
369 if ((c = get_cmd_char(view, &n_cmd)) == 'y' || c == 'Y')
370 view->f_ignore_case = true;
371 else if (c == 'n' || c == 'N')
372 view->f_ignore_case = false;
373 break;
375 case 'n':
376 if (view->f_ln)
377 view->f_ln = false;
378 else
379 view->f_ln = true;
380 view_boxwin_resize(init);
381 view->ln = view->page_top_ln;
382 view->file_pos = view->ln_tbl[view->ln];
383 view->maxcol = 0;
384 view->cury = 0;
385 view->page_top_ln = view->ln;
386 mvwaddstr(view->pad, view->cmd_line, 0, " ");
389 break;
391 case 's':
393 view, "view->f_squeeze Multiple Blank lines (Y or N)->");
394 if ((c = get_cmd_char(view, &n_cmd)) == 'y' || c == 'Y')
395 view->f_squeeze = true;
396 else if (c == 'n' || c == 'N')
397 view->f_squeeze = false;
398 break;
400 case 't':
401 sprintf(tmp_str,
402 "Tabstop Colums Currently %d:", view->tab_stop);
403 i = 0;
404 if (get_cmd_arg(view, tmp_str) == 0)
405 i = atoi(view->cmd_arg);
406 if (i >= 1 && i <= 12) {
407 view->tab_stop = i;
408 view->f_redisplay_page = true;
409 } else
410 Perror("Tab stops not changed");
411 break;
413 case 'h':
414 case KEY_F(1):
415 if (!view->f_displaying_help) {
416 view_display_help(init);
420 view = init->view;
421 }
422 view->next_cmd_char = '-';
423 break;
424 default:
425 break;
426 }
427 break;
429 case ':':
430 view->next_cmd_char = get_cmd_arg(view, ":");
431 break;
433 case 'n':
434 if (view->f_search_complete) {
435 Perror("Search complete, no more matches");
436 break;
437 }
438 if (prev_search_cmd == 0) {
439 Perror("No previouis search");
440 break;
441 }
442 if (prev_search_cmd == '/') {
443 view->cury = 0;
444 view->srch_curr_pos = view->page_bot_pos;
445 } else {
446 view->cury = view->scroll_lines + 1;
447 view->srch_curr_pos = view->page_top_pos;
448 }
449 rc = search(view, prev_search_cmd, prev_regex_pattern);
450 if (rc == false) {
451 Perror("No matches found");
452 break;
453 }
454 break;
456 case '/':
457 view->f_search_complete = false;
458 strnz__cpy(tmp_str, " Forward", MAXLEN - 1);
459 search_cmd = c;
460 c = get_cmd_arg(view, tmp_str);
461 if (c == KEY_F(9) || c == '\033')
462 break;
463 if (c == KEY_ENTER) {
464 view->cury = 0;
465 view->f_first_iter = true;
466 view->srch_beg_pos = view->page_top_pos;
467 view->srch_curr_pos = view->page_top_pos;
468 rc = search(view, search_cmd, view->cmd_arg);
469 if (rc == false) {
470 Perror("No matches found");
471 break;
472 }
473 prev_search_cmd = search_cmd;
475 }
476 break;
478 case '?':
479 view->f_search_complete = false;
480 strnz__cpy(tmp_str, " Backward", MAXLEN - 1);
481 search_cmd = c;
482 c = get_cmd_arg(view, tmp_str);
483 if (c == KEY_F(9) || c == '\033')
484 break;
485 if (c == '\n') {
486 view->cury = view->scroll_lines;
487 view->f_first_iter = true;
488 view->srch_beg_pos = view->page_bot_pos;
489 view->srch_curr_pos = view->page_bot_pos;
490 rc = search(view, search_cmd, view->cmd_arg);
491 if (rc == false) {
492 Perror("No matches found");
493 break;
494 }
495 prev_search_cmd = search_cmd;
497 }
498 break;
500 case 'o':
501 case 'O':
502 case 'e':
503 case 'E':
504 if (get_cmd_arg(view, "File name:") == 0) {
505 strtok(view->cmd_arg, " ");
506 view->next_file_spec_ptr = strdup(view->cmd_arg);
507 view->f_redisplay_page = true;
508 return 0;
509 }
510 break;
512 case 'G':
513 case KEY_END:
514 if (n_cmd <= 0)
516 else
517 go_to_line(view, n_cmd);
518 break;
520 case 'H':
521 case KEY_F(1):
522 if (!view->f_displaying_help) {
523 view_display_help(init);
524 view = init->view;
525 }
526 break;
528 case 'm':
529 display_prompt(view, "Mark label (A-Z)->");
530 c = get_cmd_char(view, &n_cmd);
531 if (c == '@' || c == KEY_F(9) || c == '\033')
532 if (c >= 'A' && c <= 'Z')
533 c += ' ';
534 if (c < 'a' || c > 'z')
535 Perror("Not (a-z)");
536 else
537 view->mark_tbl[c - 'a'] = view->page_top_pos;
538 break;
540 case 'M':
541 display_prompt(view, "Goto mark (A-Z)->");
542 c = get_cmd_char(view, &n_cmd);
543 if (c == '@' || c == KEY_F(9) || c == '\033')
544 break;
545 if (c >= 'A' && c <= 'Z')
546 c += ' ';
547 if (c < 'a' || c > 'z')
548 Perror("Not (A-Z)");
549 else
550 go_to_mark(view, c);
551 break;
553 case 'N':
554 if (n_cmd <= 0)
555 n_cmd = 1;
556 if (view->curr_argc + n_cmd >= view->argc) {
557 Perror("no more files");
558 view->curr_argc = view->argc - 1;
559 } else {
560 view->curr_argc++;
561 if (view->curr_argc < view->argc)
562 view->next_file_spec_ptr = view->argv[view->curr_argc];
563 return 0;
564 }
565 break;
567 case 'p':
568 case '%':
569 if (n_cmd < 0)
570 go_to_line(view, 1);
571 if (n_cmd >= 100)
573 else
574 go_to_percent(view, n_cmd);
575 break;
577 case Ctrl('Z'):
578 get_cmd_arg(view, "Enter Notation:");
579 strnz__cpy(tmp_str, "/tmp/view-XXXXXX", MAXLEN - 1);
580 tfd = mkstemp(tmp_str);
581 strnz__cpy(view->tmp_file_name_ptr, tmp_str, MAXLEN - 1);
582 if (tfd == -1) {
583 Perror("Unable to create temporary file");
584 break;
585 }
586 strnz__cpy(shell_cmd_spec, "echo ", MAXLEN - 5);
587 strnz__cat(shell_cmd_spec, view->cmd_arg, MAXLEN - 5);
588 strnz__cat(shell_cmd_spec, view->tmp_file_name_ptr, MAXLEN - 5);
589 shell(shell_cmd_spec);
590 strnz__cpy(shell_cmd_spec, "cat ", MAXLEN - 5);
591 strnz__cat(shell_cmd_spec, view->cmd_arg, MAXLEN - 5);
592 strnz__cat(shell_cmd_spec, ">>", MAXLEN - 5);
593 strnz__cat(shell_cmd_spec, view->tmp_file_name_ptr, MAXLEN - 5);
594 shell(shell_cmd_spec);
595 lp(view, view->cur_file_str);
596 shell(shell_cmd_spec);
597 ssnprintf(shell_cmd_spec, (size_t)(MAXLEN - 5), "rm %s",
598 view->tmp_file_name_ptr);
599 strnz__cpy(shell_cmd_spec, "rm ", MAXLEN - 5);
600 strnz__cat(shell_cmd_spec, view->tmp_file_name_ptr, MAXLEN - 5);
601 shell(shell_cmd_spec);
602 restore_wins();
603 view->f_redisplay_page = true;
604 unlink(tmp_str);
605 break;
607 case Ctrl('P'):
608 case KEY_CATAB:
609 case KEY_PRINT:
610 lp(view, view->cur_file_str);
611 view->f_redisplay_page = true;
612 break;
614 case 'P':
615 if (n_cmd <= 0)
616 n_cmd = 1;
617 if (view->curr_argc - n_cmd < 0) {
618 Perror("No previous file");
619 view->curr_argc = 0;
620 } else {
621 view->curr_argc--;
622 if (view->curr_argc >= 0)
623 view->next_file_spec_ptr = view->argv[view->curr_argc];
624 return 0;
625 }
626 break;
628 case 'q':
629 case 'Q':
630 case KEY_F(9):
631 case '\033':
632 mvwadd_wchnstr(view->cmdln_win, view->cmd_line, view->curx, &sp, 1);
633 view->curr_argc = view->argc;
634 view->next_file_spec_ptr = nullptr;
635 return 0;
637 case 'v':
638 if (init->editor[0] == 0) {
639 e = getenv("DEFAULTEDITOR");
640 if (e == nullptr || *e == '\0')
641 strnz__cpy(init->editor, DEFAULTEDITOR, MAXLEN);
642 else
643 strnz__cpy(init->editor, e, MAXLEN);
644 }
646 "View doesn't support editing current buffer directly",
647 MAXLEN - 1);
648 strnz__cpy(em1, "Would you like to write the buffer to a file?",
649 MAXLEN - 1);
650 strnz__cpy(em2, "Enter Y for yes or any other key to cancel.",
651 MAXLEN - 1);
652 rc = display_error(em0, em1, em2, nullptr);
653 if (rc != 'y' && rc != 'Y')
654 break;
655 if (!enter_file_spec(init, view->out_spec)) {
656 view->f_redisplay_page = true;
657 break;
658 }
659 prev_file_pos = view->page_top_pos;
660 bytes_written = write_view_buffer(init, view->f_strip_ansi);
661 if (bytes_written == 0) {
662 ssnprintf(em0, MAXLEN - 1, "%s, line: %d", __FILE__,
663 __LINE__ - 2);
664 strnz__cpy(em1, "0 bytes written", MAXLEN - 1);
665 strerror_r(errno, em1, MAXLEN - 1);
666 display_error(em0, em1, nullptr, nullptr);
667 break;
668 }
669 view->next_file_spec_ptr = view->in_spec;
670 strnz__cpy(shell_cmd_spec, init->editor, MAXLEN - 5);
671 strnz__cat(shell_cmd_spec, " ", MAXLEN - 5);
672 strnz__cat(shell_cmd_spec, view->in_spec, MAXLEN - 5);
673 full_screen_shell(shell_cmd_spec);
674 view->file_pos = view->page_top_pos = view->page_bot_pos =
675 prev_file_pos;
676
677 restore_wins();
678 view->f_redisplay_page = true;
679 return 0;
681 case 'w':
682 if (!enter_file_spec(init, view->out_spec)) {
683 view->f_redisplay_page = true;
684 break;
685 }
686 // prev_file_pos = view->page_top_pos;
687 bytes_written = write_view_buffer(init, view->f_strip_ansi);
688 if (bytes_written == 0) {
689 ssnprintf(em0, MAXLEN - 1, "%s, line: %d", __FILE__,
690 __LINE__ - 2);
691 strnz__cpy(em1, "0 bytes written", MAXLEN - 1);
692 strerror_r(errno, em1, MAXLEN - 1);
693 display_error(em0, em1, nullptr, nullptr);
694 break;
695 }
696 display_prompt(view, tmp_str);
697 view->f_redisplay_page = true;
698 break;
699 case CT_VIEW:
700 break;
702 case 'V':
703 ssnprintf(em0, MAXLEN - 1, "C-Menu Version: %s", CM_VERSION);
704 display_error(em0, em1, nullptr, nullptr);
705 break;
706 default:
707 break;
708 }
709 view->cmd_arg[0] = '\0';
710 }
711}
#define KEY_ALTEND
Definition cm.h:560
#define KEY_ALTHOME
Definition cm.h:557
#define S_TOLOWER(c)
Definition cm.h:142
#define Ctrl(c)
Definition cm.h:52
#define CM_VERSION
Definition version.h:7
@ CT_VIEW
Definition menu.h:47
char prev_regex_pattern[MAXLEN]
Definition view_engine.c:81
void view_full_screen_resize(Init *)
Resize the full screen view and its components.
Definition init_view.c:140
void view_boxwin_resize(Init *)
Resize the current window and its box.
Definition init_view.c:346
int Perror(char *)
Display a simple error message window or print to stderr.
Definition dwin.c:1526
int full_screen_shell(char *)
Execute a shell command in full screen mode.
Definition exec.c:62
bool str_subc(char *, char *, char, char *, int)
Replaces "ReplaceChr" in "s" with "Withstr" in "d" won't copy more than "l" bytes to "d" Replaces all...
Definition futil.c:690
void write_cmenu_log_nt(char *)
Write message to C-Menu log file without timestamp.
Definition futil.c:1701
bool enter_file_spec(Init *, char *)
use form to enter a file specification
int write_view_buffer(Init *, bool)
Write buffer contents to files.
void lp(View *, char *)
Send File to Print Queue.
int get_cmd_arg(View *, char *)
Get Command Argument from User Input.
int get_cmd_char(View *, off_t *)
Get Command Character from User Input.
void go_to_eof(View *)
Go to End of File.
void prev_page(View *)
display previous page
bool search(View *, int, char *)
Search for Regular Expression Pattern.
void scroll_down_n_lines(View *, int)
Scroll N Lines.
void scroll_up_n_lines(View *, int)
Scroll Up N Lines.
int go_to_line(View *, off_t)
Go to Specific Line.
void next_page(View *)
Advance to Next Page.
void go_to_mark(View *, int)
Go to Mark.
void go_to_percent(View *, int)
Go to Percent of File.
void view_display_help(Init *)
Display View Help File.
void view_display_page(View *)
Display Current Page.
char editor[MAXLEN]
Definition common.h:171

References View::argc, View::argv, build_prompt(), View::cmd, View::cmd_arg, View::cmd_line, View::cmdln_win, View::cols, CT_VIEW, View::cur_file_str, View::curr_argc, View::curx, View::cury, display_error(), display_prompt(), Init::editor, em0, em1, em2, enter_file_spec(), View::f_displaying_help, View::f_first_iter, View::f_full_screen, View::f_ignore_case, View::f_is_pipe, View::f_ln, View::f_redisplay_page, View::f_search_complete, View::f_squeeze, View::f_strip_ansi, View::file_pos, View::file_spec_ptr, full_screen_shell(), get_cmd_arg(), get_cmd_char(), go_to_eof(), go_to_line(), go_to_mark(), go_to_percent(), View::h_shift, View::in_spec, View::lines, View::ln, View::ln_tbl, View::ln_win_cols, lp(), View::mark_tbl, View::maxcol, View::next_cmd_char, View::next_file_spec_ptr, next_page(), View::out_spec, View::pad, pad_refresh(), View::page_bot_pos, View::page_top_ln, View::page_top_pos, Perror(), View::pmincol, View::prev_file_pos, prev_page(), prev_regex_pattern, View::prompt_str, restore_wins(), scroll_down_n_lines(), View::scroll_lines, scroll_up_n_lines(), search(), shell(), View::smaxcol, View::smincol, sp, View::srch_beg_pos, View::srch_curr_pos, ssnprintf(), str_subc(), strnz__cat(), strnz__cpy(), View::tab_stop, View::tmp_file_name_ptr, Init::view, view_boxwin_resize(), view_display_help(), view_display_page(), view_full_screen_resize(), 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 130 of file view_engine.c.

130 {
131 View *view = init->view;
132 if (view->argc < 1) {
133 view->curr_argc = -1;
134 view->argc = 0;
135 view->next_file_spec_ptr = "-";
136 } else
137 view->next_file_spec_ptr = view->argv[0];
138 while (view->curr_argc < view->argc) {
139 if (view->next_file_spec_ptr == nullptr ||
140 *view->next_file_spec_ptr == '\0') {
141 break;
142 }
143 view->file_spec_ptr = view->next_file_spec_ptr;
144 view->next_file_spec_ptr = nullptr;
145 strnz__cpy(view->cur_file_str, view->file_spec_ptr, MAXLEN - 1);
146 if (view_init_input(init, view->cur_file_str) == 0) {
147 if (view->buf) {
148 view->f_eod = 0;
149 view->f_bod = 0;
150 view->maxcol = 0;
151 view->page_top_pos = 0;
152 view->page_top_ln = 0;
153 view->page_bot_ln = 0;
154 view->ln_max_pos = 0;
155 view->ln = 0;
156 view->page_bot_pos = 0;
157 view->file_pos = 0;
158 strnz__cpy(view->title, view->cur_file_str, MAXLEN - 1);
159 border_title(view->box_win, view->title);
162 view_cmd_processor(init);
164 munmap(view->buf, view->file_size);
165 }
166 } else {
167 view->curr_argc++;
168 if (view->curr_argc < view->argc) {
169 view->next_file_spec_ptr = view->argv[view->curr_argc];
170 }
171 }
172 }
173 destroy_view_win(init);
174 destroy_view(init);
175 return 0;
176}
void destroy_view_win(Init *)
Definition init_view.c:318
void destroy_line_table(View *)
int border_title(WINDOW *, char *)
Draw a box with a title around the specified window.
Definition dwin.c:1327
int view_init_input(Init *, char *)
Initialize the input for the C-Menu View.
Definition init_view.c:447
View * destroy_view(Init *init)
Destroy View structure.
Definition mem.c:356
int view_cmd_processor(Init *)
Main Command Processing Loop for View.
void initialize_line_table(View *)
Initialize Line Table.

References View::argc, View::argv, border_title(), View::box_win, View::buf, View::cur_file_str, View::curr_argc, destroy_line_table(), destroy_view(), destroy_view_win(), View::f_bod, View::f_eod, View::file_pos, View::file_size, View::file_spec_ptr, initialize_line_table(), View::ln, View::ln_max_pos, View::maxcol, View::next_file_spec_ptr, next_page(), View::page_bot_ln, View::page_bot_pos, View::page_top_ln, View::page_top_pos, strnz__cpy(), View::title, 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:

◆ view_stack_free()

void view_stack_free ( ViewStack * s)

Free View Stack.

Parameters
spointer to ViewStack structure

This function frees the memory allocated for the items array in the ViewStack structure and resets the capacity and top index to zero.

Definition at line 2284 of file view_engine.c.

2284 {
2285 free(s->items);
2286 s->items = NULL;
2287 s->capacity = 0;
2288 s->top = 0;
2289}
size_t capacity
Definition view.h:185
size_t top
Definition view.h:186
View * items
Definition view.h:184

References ViewStack::capacity, ViewStack::items, and ViewStack::top.

◆ view_stack_init()

bool view_stack_init ( ViewStack * s,
size_t initial_capacity )

Initialize View Stack.

Parameters
spointer to ViewStack structure
initial_capacityinitial capacity of the stack
Returns
true if successful, false if memory allocation fails

This function initializes a ViewStack structure by allocating memory for the items array with the specified initial capacity. It sets the capacity and top index accordingly. If memory allocation fails, it returns false.

Definition at line 2218 of file view_engine.c.

2218 {
2219 s->items = malloc(initial_capacity * sizeof(View));
2220 if (!s->items)
2221 return false;
2222 s->capacity = initial_capacity;
2223 s->top = 0;
2224 return true;
2225}

References ViewStack::capacity, ViewStack::items, and ViewStack::top.

◆ view_stack_peek()

bool view_stack_peek ( const ViewStack * s,
View * out_item )

Peek at Top Item of View Stack.

Parameters
spointer to ViewStack structure
out_itempointer to View structure where the top item will be stored
Returns
true if successful, false if the stack is empty

This function retrieves the top item of the stack without removing it. If the stack is empty, it returns false.

Definition at line 2272 of file view_engine.c.

2272 {
2273 if (s->top == 0)
2274 return false;
2275 *out_item = s->items[s->top - 1];
2276 return true;
2277}

References ViewStack::items, and ViewStack::top.

◆ view_stack_pop()

bool view_stack_pop ( ViewStack * s,
View * out_item )

Pop Item from View Stack.

Parameters
spointer to ViewStack structure
out_itempointer to View structure where the popped item will be stored
Returns
true if successful, false if the stack is empty (underflow)

This function pops a View item from the stack and stores it in the provided out_item pointer. If the stack is empty, it returns false.

Definition at line 2257 of file view_engine.c.

2257 {
2258 if (s->top == 0)
2259 return false; // Stack underflow
2260 *out_item = s->items[--s->top];
2261 return true;
2262}

References ViewStack::items, and ViewStack::top.

◆ view_stack_push()

bool view_stack_push ( ViewStack * s,
View item )

Push Item onto View Stack.

Parameters
spointer to ViewStack structure
itemView item to push onto the stack
Returns
true if successful, false if memory allocation fails during resizing

This function pushes a View item onto the stack. If the stack is full, it reallocates memory to double the capacity. If memory allocation fails during resizing, it returns false.

Definition at line 2236 of file view_engine.c.

2236 {
2237 if (s->top >= s->capacity) {
2238 size_t new_capacity = s->capacity * 2;
2239 View *new_items = realloc(s->items, new_capacity * sizeof(View));
2240 if (!new_items)
2241 return false; // Out of memory
2242 s->items = new_items;
2243 s->capacity = new_capacity;
2244 }
2245 s->items[s->top++] = item; // Structure copy
2246 return true;
2247}

References ViewStack::capacity, ViewStack::items, and ViewStack::top.

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

986 {
987 ssize_t bytes_written = 0;
988 off_t pos;
989 View *view = init->view;
990 int rc;
991 size_t l;
992 char tmp_line_s[PAD_COLS];
993 if (!f_strip_ansi) {
994 strnz__cpy(em0, "Would you like to strip ansi escape sequences?",
995 MAXLEN - 1);
996 strnz__cpy(em1, "Enter Y for yes or any other key to cancel.",
997 MAXLEN - 1);
998 rc = answer_yn(nullptr, em0, em1, nullptr);
999 if (rc == 'y' || rc == 'Y')
1000 f_strip_ansi = true;
1001 else
1002 f_strip_ansi = false;
1003 }
1004 restore_wins();
1006 pos = 0;
1007 view->out_fd = open(view->out_spec, O_CREAT | O_TRUNC | O_WRONLY, 0644);
1008 if (view->out_fd == -1) {
1009 ssnprintf(em0, MAXLEN - 1, "%s, line: %d", __FILE__, __LINE__ - 2);
1010 strnz__cpy(em1, "fwrite ", MAXLEN - 1);
1011 strnz__cat(em1, view->out_spec, MAXLEN - 1);
1012 strerror_r(errno, em2, MAXLEN - 1);
1013 display_error(em0, em1, em2, nullptr);
1014 return false;
1015 }
1016 bytes_written = 0;
1017 while (!view->f_eod) {
1018 pos = get_next_line(view, pos);
1019 if (f_strip_ansi)
1020 strip_ansi(tmp_line_s, view->line_in_s);
1021 else
1022 strnz__cpy(tmp_line_s, view->line_in_s, MAXLEN - 1);
1023 l = strnlf(tmp_line_s, PAD_COLS - 1);
1024 bytes_written += write(view->out_fd, tmp_line_s, l);
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:32
int answer_yn(char *, char *, char *, char *)
Accept a single letter answer.
Definition dwin.c:1406
size_t strip_ansi(char *, char *)
Strips ANSI SGR escape sequences (ending in 'm') from string s to d.
Definition futil.c:829
size_t strnlf(char *, size_t)
terminates string with line feed
Definition futil.c:633
off_t get_next_line(View *, off_t)
Get Next Line from View->buf.

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

Referenced by view_cmd_processor().

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