2
3
4
5
6
7
8
11
12
13
33
34
35
36
37
38
39
40
41
42
43
44
45#define get_next_char()
49 if (view->file_pos == view->file_size) {
54 c = view->buf[view->file_pos++];
60
61
62
63
64
65
66
67
68#define get_prev_char()
72 if (view->file_pos == 0
) {
77 c = view->buf[--view->file_pos];
89void lp(View *,
char *);
95bool search(View *,
int,
char *);
113int a_toi(
char *,
bool *);
122
123
124
125
126
127
128
129
178
179
180
181
182
183
190 int prev_search_cmd = 0;
192 ssize_t bytes_written;
194 char shell_cmd_spec[
MAXLEN];
212 if (c >=
'0' && c <=
'9') {
213 tmp_str[0] = (
char)c;
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);
227 write_cmenu_log_nt(em0);
236
240
241
248
254 else if (n_cmd == 0) {
267
272 else if (n_cmd == 0) {
283 max_pmincol = view
->maxcol - swidth;
371 else if (c ==
'n' || c ==
'N')
393 view
, "view->f_squeeze Multiple Blank lines (Y or N)->");
396 else if (c ==
'n' || c ==
'N')
402 "Tabstop Colums Currently %d:", view
->tab_stop);
406 if (i >= 1 && i <= 12) {
418
419
435 Perror("Search complete, no more matches");
438 if (prev_search_cmd == 0) {
442 if (prev_search_cmd ==
'/') {
461 if (c == KEY_F(9) || c ==
'\033')
463 if (c == KEY_ENTER) {
473 prev_search_cmd = search_cmd;
483 if (c == KEY_F(9) || c ==
'\033')
495 prev_search_cmd = search_cmd;
531 if (c ==
'@' || c == KEY_F(9) || c ==
'\033')
532 if (c >=
'A' && c <=
'Z')
534 if (c <
'a' || c >
'z')
543 if (c ==
'@' || c == KEY_F(9) || c ==
'\033')
545 if (c >=
'A' && c <=
'Z')
547 if (c <
'a' || c >
'z')
580 tfd = mkstemp(tmp_str);
583 Perror("Unable to create temporary file");
639 e = getenv(
"DEFAULTEDITOR");
640 if (e ==
nullptr || *e ==
'\0')
646 "View doesn't support editing current buffer directly",
653 if (rc !=
'y' && rc !=
'Y')
661 if (bytes_written == 0) {
688 if (bytes_written == 0) {
713
714
715
716
717
718
719
720
721
722
723
724
725
726
745 if (i == 1 && !once) {
796 if (i < 32 && cmd_str[i] !=
'\0') {
810 if (i < 32 && cmd_str[i] !=
'\0') {
830 if (c <
'0' || c >
'9' || i == 32)
832 cmd_str[i++] = (
char)c;
838 if (c <
'0' || c >
'9' || i == 32)
841 if (cmd_str[0] ==
'\0') {
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
893 int fcol = prompt_l + 1;
894 int flen = view
->cols - prompt_l;
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
934 if (prompt_l > (view
->cols - 4) / 2)
946 if (prompt_l > (view
->cols - 4) / 2)
967 if (prompt_l > (view
->cols - 4) / 2)
981
982
983
984
985
987 ssize_t bytes_written = 0;
999 if (rc ==
'y' || rc ==
'Y')
1000 f_strip_ansi =
true;
1002 f_strip_ansi =
false;
1024 bytes_written += write(view
->out_fd, tmp_line_s, l);
1028 return bytes_written;
1031
1032
1043
1044
1045
1046void lp(View *view,
char *PrintFile) {
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')
1057
1058
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101bool search(View *view,
int search_cmd,
char *regex_pattern) {
1104 regmatch_t pmatch[1];
1105 regex_t compiled_regex;
1111 bool f_page =
false;
1112 if (*regex_pattern ==
'\0')
1115 REG_FLAGS = REG_ICASE | REG_EXTENDED;
1117 REG_FLAGS = REG_EXTENDED;
1118 reti = regcomp(&compiled_regex, regex_pattern, REG_FLAGS);
1126 if (search_cmd ==
'/') {
1137 if (search_cmd ==
'/')
1149 if (search_cmd ==
'/') {
1166 compiled_regex.re_nsub + 1, pmatch, REG_FLAGS);
1167 if (reti == REG_NOMATCH) {
1170 if (search_cmd ==
'?')
1174 (search_cmd ==
'?' && view
->cury == 1)) {
1182 regerror(reti, &compiled_regex, err_str,
sizeof(err_str));
1186 regfree(&compiled_regex);
1192 if (search_cmd ==
'/') {
1197 wmove(view
->pad, 0, 0);
1199 wclrtobot(view
->pad);
1202 if (search_cmd ==
'?')
1206
1207
1214 view
->curx = line_offset + pmatch[0].rm_so;
1215 match_len = pmatch[0].rm_eo - pmatch[0].rm_so;
1221 line_offset += pmatch[0].rm_eo;
1222 if (line_offset >= line_len)
1226 compiled_regex.re_nsub + 1, pmatch, REG_FLAGS);
1227 if (reti == REG_NOMATCH)
1231 regerror(reti, &compiled_regex, msgbuf,
sizeof(msgbuf));
1232 sprintf(tmp_str,
"Regex match failed: %s", msgbuf);
1234 regfree(&compiled_regex);
1237 if (search_cmd ==
'/') {
1239 regfree(&compiled_regex);
1242 }
else if (view
->cury == 1) {
1243 regfree(&compiled_regex);
1251 ssnprintf(view->tmp_prompt_str, MAXLEN - 1,
1252 "%s|%c%s|Pos %zu-%zu|(%zd) %zu %zu", view->file_name, search_cmd,
1253 regex_pattern, view->page_top_pos, view->page_bot_pos,
1254 view->file_size, view->srch_beg_pos, view->srch_curr_pos);
1258 "%s|%c%s|Match Cols %d-%d of %d-%d|(%zd%%)", view
->file_name,
1268 regfree(&compiled_regex);
1273
1274
1276
1277
1278
1279
1282 touchwin(view
->pad);
1293 ssnprintf(em0, MAXLEN - 1
, "%s:%d prefresh(view->pad_view_win, pminrow=%d, pmincol=%d, smaxrow=%d, smaxcol=%d) returned %d\n",
1300
1301
1303
1304
1305
1306
1307
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1341
1342
1343
1347 wmove(view
->pad, 0, 0);
1366 wclrtobot(view
->pad);
1371
1372
1373
1374
1392 wmove(view
->pad, 0, 0);
1393 wclrtobot(view
->pad);
1397 wscrl(view
->pad, n);
1404 for (i = 0; i < n; i++) {
1414
1415
1416
1417
1433 wscrl(view
->pad, -n);
1437 for (i = 0; i < n; i++) {
1454
1455
1456
1457
1458
1459
1498
1499
1500
1501
1502
1510
1511
1512
1513
1514
1545
1546
1547
1548
1549
1565
1566
1567
1568
1577
1578
1579
1595
1596
1597
1598
1601 Perror("Cannot determine file length");
1616
1617
1618
1619
1620
1621
1623 if (line_idx <= 1) {
1635
1636
1637
1638
1639
1640
1641
1646 Perror("Memory allocation failed");
1663
1664
1665
1666
1667
1668
1669
1670
1671
1681 Perror("Memory allocation failed");
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1719 while (view
->ln_tbl[idx] > target_pos)
1729
1730
1731
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1760 wclrtoeol(view
->pad);
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1782 attr_t attr = WA_NORMAL;
1785 wchar_t wstr[2] = {L'\0', L'\0'};
1792 memset(&mbstate, 0,
sizeof(mbstate));
1793 while (in_str[i] !=
'\0') {
1794 if (in_str[i] ==
'\033' && in_str[i + 1] ==
'[') {
1796 len = strcspn(&in_str[i],
"mK ") + 1;
1797 memcpy(ansi_tok, &in_str[i], len + 1);
1798 ansi_tok[len] =
'\0';
1799 if (ansi_tok[0] ==
'\0') {
1804 if (len == 0 || in_str[i + len - 1] ==
' ') {
1807 }
else if (in_str[i + len - 1] ==
'K') {
1815
1816
1817
1818
1819 if (in_str[i] ==
'\033') {
1828 setcchar(&cc, wstr, attr, cpx,
nullptr);
1830 cmplx_buf[j++] = cc;
1835 len = mbrtowc(wstr, s, MB_CUR_MAX, &mbstate);
1841 if (setcchar(&cc, wstr, attr, cpx,
nullptr) != ERR) {
1842 if (len > 0 && (j + len) <
PAD_COLS - 1) {
1844 cmplx_buf[j++] = cc;
1855 setcchar(&cc, wstr, WA_NORMAL, cpx,
nullptr);
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1925 char *ansi_p = ansi_str + 2;
1926 extended_pair_content(*cpx, &fg_clr, &bg_clr);
1930 tok = strtok((
char *)ansi_p,
";m");
1931 bool a_toi_error =
false;
1933 if (tok ==
nullptr || *tok ==
'\0')
1939 if (t0 ==
'3' || t0 ==
'4') {
1941 tok = strtok(
nullptr,
";m");
1942 if (tok !=
nullptr) {
1944 tok = strtok(
nullptr,
";m");
1945 if (tok !=
nullptr) {
1949 }
else if (*tok ==
'2') {
1950 tok = strtok(
nullptr,
";m");
1952 tok = strtok(
nullptr,
";m");
1954 tok = strtok(
nullptr,
";m");
1962 }
else if (t1 ==
'9') {
1967 }
else if (t1 >=
'0' && t1 <=
'7') {
1974 }
else if (t0 ==
'4') {
1982 }
else if (t0 ==
'0') {
1993 switch (
a_toi(tok
, &a_toi_error
)) {
2004 *attr |= WA_UNDERLINE;
2010 *attr |= WA_REVERSE;
2019 }
else if (len == 0) {
2024 tok = strtok(
nullptr,
";m");
2026 if (!a_toi_error && (fg_clr != fg || bg_clr != bg)) {
2033
2034
2035
2057
2058
2063 waddstr(view
->pad,
"Remove File (Y or N)->");
2064 wclrtoeol(view
->pad);
2068 waddch(view
->pad, (
char)toupper(c));
2069 if (c ==
'Y' || c ==
'y')
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2105 eargv[eargc++] = strdup(
"view");
2106 eargv[eargc++] = strdup(
"-N");
2107 eargv[eargc++] = strdup(
"f");
2108 eargv[eargc++] = strdup(tmp_str);
2109 eargv[eargc] =
nullptr;
2121
2122
2124
2125
2126
2127
2128
2129
2130
2131
2154 while (rc ==
false) {
2157 view
->in_fd = mkstemp(tmp_spec);
2168
2176 if (rc ==
FA_CANCEL || rc ==
'q' || rc ==
'Q' || rc == KEY_F(9))
2179 tmp_fp = fopen(tmp_spec,
"r");
2180 if (tmp_fp ==
nullptr) {
2189 fgets(tmp_str,
MAXLEN - 1, tmp_fp);
2199 if (rc ==
'y' || rc ==
'Y')
2209
2210
2211
2212
2213
2214
2215
2216
2217
2219 s
->items = malloc(initial_capacity *
sizeof(View));
2227
2228
2229
2230
2231
2232
2233
2234
2235
2239 View *new_items = realloc(s
->items, new_capacity *
sizeof(View));
2249
2250
2251
2252
2253
2254
2255
2256
2264
2265
2266
2267
2268
2269
2270
2271
2279
2280
2281
2282
2283
int popup_form(Init *, int, char **, int, int)
instantiate a form popup window
void destroy_view_win(Init *)
int popup_view(Init *, int, char **, int, int, int, int)
instantiate a view popup window
void destroy_line_table(View *)
size_t rtrim(char *)
Trims trailing spaces from string s in place.
#define min(x, y)
min macro evaluates two expressions, returning least result
void go_to_position(View *, long)
char prev_regex_pattern[MAXLEN]
int cf_accept(WINDOW *win, char *accept_s, int flin, int fcol, int flen)
Accepts input for a field in a C-Menu window.
int border_title(WINDOW *, char *)
Draw a box with a title around the specified window.
void restore_wins()
Restore all windows after a screen resize.
void view_full_screen_resize(Init *)
Resize the full screen view and its components.
void view_boxwin_resize(Init *)
Resize the current window and its box.
int vgetch(WINDOW *, int)
Wrapper for wgetch that handles signals and mouse events, and accepts a single character answer.
RGB xterm256_idx_to_rgb(int)
Convert XTerm 256 color index to RGB.
int rgb_to_curses_clr(RGB *)
Get color index for RGB color.
int get_clr_pair(int, int)
Get color pair index for foreground and background colors.
int answer_yn(char *, char *, char *, char *)
Accept a single letter answer.
int Perror(char *)
Display a simple error message window or print to stderr.
int display_error(char *, char *, char *, char *)
Display an error message window or print to stderr.
int shell(char *)
Execute a shell command.
int full_screen_shell(char *)
Execute a shell command in full screen mode.
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
int destroy_argv(int argc, char **argv)
Deallocates memory allocated for argument strings in argv.
size_t strnz(char *, size_t)
terminates string at New Line, Carriage Return, or max_len
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
bool expand_tilde(char *, int)
Replaces "~/" in string with the user's home directory.
size_t strip_ansi(char *, char *)
Strips ANSI SGR escape sequences (ending in 'm') from string s to d.
bool mk_dir(char *dir)
If directory doesn't exist, make it.
size_t strnz__cat(char *, const char *, size_t)
safer alternative to strncat
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...
size_t strnlf(char *, size_t)
terminates string with line feed
int a_toi(char *, bool *)
a safer alternative to atoi() for converting ASCII strings to integers.
bool base_name(char *, char *)
Returns the base name of a file specification.
int str_to_args(char **, char *, int)
Converts a string into an array of argument strings.
int view_init_input(Init *, char *)
Initialize the input for the C-Menu View.
View * destroy_view(Init *init)
Destroy View structure.
bool verify_spec_arg(char *, char *, char *, char *, int)
Verify file specification argument.
int view_file(Init *)
Start view.
bool view_stack_pop(ViewStack *, View *)
Pop Item from View Stack.
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.
#define get_prev_char()
read the previous characater from the virtual fileThere is no need to track line numbers when moving ...
bool view_stack_peek(const ViewStack *, View *)
Peek at Top Item of View Stack.
void cat_file(View *)
Concatenate File to Standard Output.
void remove_file(View *)
Remove File.
void view_stack_free(ViewStack *)
Free View Stack.
int get_cmd_arg(View *, char *)
Get Command Argument from User Input.
int view_cmd_processor(Init *)
Main Command Processing Loop for View.
bool view_stack_init(ViewStack *, size_t)
Initialize View Stack.
int get_cmd_char(View *, off_t *)
Get Command Character from User Input.
void build_prompt(View *)
Build Prompt String.
bool view_stack_push(ViewStack *, View)
Push Item onto View Stack.
#define get_next_char()
read the next characater from the virtual file
void sync_ln(View *)
Synchronize Line Table with Current File Position.
off_t get_next_line(View *, off_t)
Get Next Line from View->buf.
void go_to_eof(View *)
Go to End of File.
void prev_page(View *)
display previous page
void initialize_line_table(View *)
Initialize Line Table.
bool search(View *, int, char *)
Search for Regular Expression Pattern.
void scroll_down_n_lines(View *, int)
Scroll N Lines.
off_t get_pos_prev_line(View *, off_t)
Get Position of Previous Line.
void scroll_up_n_lines(View *, int)
Scroll Up N Lines.
off_t get_prev_line(View *, off_t)
Get Previous Line from View->buf.
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 increment_ln(View *)
Increment Line Index and Update Line Table.
void go_to_percent(View *, int)
Go to Percent of File.
off_t get_pos_next_line(View *, off_t)
Get Position of Next Line.
void display_line(View *)
Display Line on Padparam View *view data structure.
int pad_refresh(View *)
Refresh Pad and Line Number Window.
int display_prompt(View *, char *)
Display Command Line Prompt.
int fmt_line(View *)
Format Line for Display.
void parse_ansi_str(char *, attr_t *, int *)
Parse ANSI SGR Escape Sequence.
void view_display_help(Init *)
Display View Help File.
void view_display_page(View *)
Display Current Page.
char * next_file_spec_ptr
char stripped_line_out[PAD_COLS]
char tmp_prompt_str[MAXLEN]
char cur_file_str[MAXLEN]
char line_out_s[PAD_COLS]
cchar_t cmplx_buf[PAD_COLS]