2
3
4
5
6
7
8
11
12
13
32
33
34
35
36
37
38
39
40
41
42
43
44#define get_next_char()
48 if (view->file_pos == view->file_size) {
53 c = view->buf[view->file_pos++];
59
60
61
62
63
64
65
66
67#define get_prev_char()
71 if (view->file_pos == 0
) {
76 c = view->buf[--view->file_pos];
94bool
search(View *,
int *,
char *);
112int a_toi(
char *, bool *);
121
122
123
124
125
126
127
128
172
173
174
175
176
177
184 int prev_search_cmd = 0;
186 ssize_t bytes_written;
188 char shell_cmd_spec[
MAXLEN];
210 if (c >=
'0' && c <=
'9') {
211 tmp_str[0] = (
char)c;
223 ssnprintf(em0, MAXLEN - 1,
224 "view->page_top_ln=%d, resized to lines: %d, cols: %d\n",
225 view->page_top_ln, view->lines, view->cols);
226 write_cmenu_log_nt(em0);
236
240
241
248
262
295 for (i = 0; i < n_cmd; i++) {
362 else if (c ==
'n' || c ==
'N')
384 view, "view->f_squeeze Multiple Blank lines (Y or N)->");
387 else if (c ==
'n' || c ==
'N')
397 if (i >= 1 && i <= 12) {
409
410
426 Perror("No previous search or search complete");
429 if (prev_search_cmd ==
'/') {
450 prev_search_cmd = search_cmd;
466 prev_search_cmd = search_cmd;
502 if (c ==
'@' || c == KEY_F(9) || c ==
'\033')
503 if (c >=
'A' && c <=
'Z')
505 if (c <
'a' || c >
'z')
514 if (c ==
'@' || c == KEY_F(9) || c ==
'\033')
516 if (c >=
'A' && c <=
'Z')
518 if (c <
'a' || c >
'z')
551 tfd = mkstemp(tmp_str);
554 Perror("Unable to create temporary file");
609 e = getenv(
"DEFAULTEDITOR");
610 if (e ==
nullptr || *e ==
'\0')
616 "View doesn't support editing current buffer directly",
623 if (rc !=
'y' && rc !=
'Y')
631 if (bytes_written == 0) {
658 if (bytes_written == 0) {
683
684
685
686
687
688
689
690
691
692
693
694
703 if ((c >=
'0' && c <=
'9') && i < 32) {
704 cmd_str[i++] = (
char)c;
712 }
while (c >=
'0' && c <=
'9');
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
736 int numeric_arg = false;
761 if (*n >=
'0' && *n <=
'9') {
780 if (*cmd_p <
' ' || *cmd_p == 0x7f) {
812 }
else if ((
uchar)c == 0x7f)
817 if (numeric_arg && (c <
'0' || c >
'9'))
825
826
827
828
829
874
875
876
877
878
880 ssize_t bytes_written = 0;
892 if (rc ==
'y' || rc ==
'Y')
895 f_strip_ansi = false;
917 bytes_written += write(view
->out_fd, tmp_line_s, l);
921 return bytes_written;
924
925
936
937
938void lp(
char *PrintFile) {
940 char shell_cmd_spec[
MAXLEN];
941 print_cmd_ptr = getenv(
"PRINTCMD");
942 if (print_cmd_ptr ==
nullptr || *print_cmd_ptr ==
'\0')
949
950
952
953
954
955
956
957
958
959
960
961
962
963
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993bool
search(View *view,
int *search_cmd,
char *regex_pattern) {
996 regmatch_t pmatch[1];
997 regex_t compiled_regex;
1003 bool f_page = false;
1004 if (*regex_pattern ==
'\0')
1007 REG_FLAGS = REG_ICASE | REG_EXTENDED;
1009 REG_FLAGS = REG_EXTENDED;
1010 reti = regcomp(&compiled_regex, regex_pattern, REG_FLAGS);
1018 if (*search_cmd ==
'/') {
1029 if (*search_cmd ==
'/')
1041 if (*search_cmd ==
'/') {
1056 compiled_regex.re_nsub + 1, pmatch, REG_FLAGS);
1057 if (reti == REG_NOMATCH) {
1060 if (*search_cmd ==
'?')
1064 (*search_cmd ==
'?' && view
->cury == 1)) {
1072 regerror(reti, &compiled_regex, err_str,
sizeof(err_str));
1076 regfree(&compiled_regex);
1081 if (*search_cmd ==
'/') {
1086 wmove(view
->pad, 0, 0);
1088 wclrtobot(view
->pad);
1091 if (*search_cmd ==
'?')
1095
1096
1103 view
->curx = line_offset + pmatch[0].rm_so;
1104 match_len = pmatch[0].rm_eo - pmatch[0].rm_so;
1110 line_offset += pmatch[0].rm_eo;
1111 if (line_offset >= line_len)
1115 compiled_regex.re_nsub + 1, pmatch, REG_FLAGS);
1116 if (reti == REG_NOMATCH)
1120 regerror(reti, &compiled_regex, msgbuf,
sizeof(msgbuf));
1121 sprintf(tmp_str,
"Regex match failed: %s", msgbuf);
1123 regfree(&compiled_regex);
1126 if (*search_cmd ==
'/') {
1128 regfree(&compiled_regex);
1131 }
else if (view
->cury == 1) {
1132 regfree(&compiled_regex);
1140 ssnprintf(view->tmp_prompt_str, MAXLEN - 1,
1141 "%s|%c%s|Pos %zu-%zu|(%zd) %zu %zu", view->file_name, *search_cmd,
1142 regex_pattern, view->page_top_pos, view->page_bot_pos,
1143 view->file_size, view->srch_beg_pos, view->srch_curr_pos);
1147 "%s|%c%s|Match Cols %d-%d of %d-%d|(%zd%%)", view
->file_name,
1157 regfree(&compiled_regex);
1162
1163
1165
1166
1167
1168
1185
1186
1188
1189
1190
1191
1192
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1226
1227
1228
1232 wmove(view
->pad, 0, 0);
1251 wclrtobot(view
->pad);
1256
1257
1258
1259
1277 wmove(view
->pad, 0, 0);
1278 wclrtobot(view
->pad);
1282 wscrl(view
->pad, n);
1288 for (i = 0; i < n; i++) {
1298
1299
1300
1301
1320 wscrl(view
->pad, -n);
1324 for (i = 0; i < n; i++) {
1341
1342
1343
1344
1345
1346
1385
1386
1387
1388
1389
1397
1398
1399
1400
1401
1432
1433
1434
1435
1436
1452
1453
1454
1455
1464
1465
1466
1482
1483
1484
1485
1488 Perror("Cannot determine file length");
1503
1504
1505
1506
1507
1508
1510 if (line_idx <= 1) {
1522
1523
1524
1525
1526
1527
1528
1533 Perror("Memory allocation failed");
1541
1542
1543
1544
1545
1546
1547
1548
1549
1559 Perror("Memory allocation failed");
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1597 while (view
->ln_tbl[idx] > target_pos)
1607
1608
1609
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1638 wclrtoeol(view
->pad);
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1660 attr_t attr = WA_NORMAL;
1663 wchar_t wstr[2] = {L'\0', L'\0'};
1670 memset(&mbstate, 0,
sizeof(mbstate));
1671 while (in_str[i] !=
'\0') {
1672 if (in_str[i] ==
'\033' && in_str[i + 1] ==
'[') {
1674 len = strcspn(&in_str[i],
"mK ") + 1;
1675 memcpy(ansi_tok, &in_str[i], len + 1);
1676 ansi_tok[len] =
'\0';
1677 if (ansi_tok[0] ==
'\0') {
1682 if (len == 0 || in_str[i + len - 1] ==
' ') {
1685 }
else if (in_str[i + len - 1] ==
'K') {
1693
1694
1695
1696
1697 if (in_str[i] ==
'\033') {
1706 setcchar(&cc, wstr, attr, cpx,
nullptr);
1708 cmplx_buf[j++] = cc;
1713 len = mbrtowc(wstr, s, MB_CUR_MAX, &mbstate);
1719 if (setcchar(&cc, wstr, attr, cpx,
nullptr) != ERR) {
1720 if (len > 0 && (j + len) <
PAD_COLS - 1) {
1722 cmplx_buf[j++] = cc;
1733 setcchar(&cc, wstr, WA_NORMAL, cpx,
nullptr);
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1803 char *ansi_p = ansi_str + 2;
1804 extended_pair_content(*cpx, &fg_clr, &bg_clr);
1808 tok = strtok((
char *)ansi_p,
";m");
1809 bool a_toi_error = false;
1811 if (tok ==
nullptr || *tok ==
'\0')
1817 if (t0 ==
'3' || t0 ==
'4') {
1827 }
else if (*tok ==
'2') {
1840 }
else if (t1 ==
'9') {
1845 }
else if (t1 >=
'0' && t1 <=
'7') {
1852 }
else if (t0 ==
'4') {
1860 }
else if (t0 ==
'0') {
1871 switch (
a_toi(tok
, &a_toi_error
)) {
1882 *attr |= WA_UNDERLINE;
1888 *attr |= WA_REVERSE;
1897 }
else if (len == 0) {
1904 if (!a_toi_error && (fg_clr != fg || bg_clr != bg)) {
1911
1912
1913
1933
1934
1939 waddstr(view
->pad,
"Remove File (Y or N)->");
1940 wclrtoeol(view
->pad);
1942 waddch(view
->pad, (
char)toupper(c));
1943 if (c ==
'Y' || c ==
'y')
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1978 eargv[eargc++] = strdup(
"view");
1979 eargv[eargc++] = strdup(
"-N");
1980 eargv[eargc++] = strdup(
"f");
1981 eargv[eargc++] = strdup(tmp_str);
1994
1995
1996
1997
1998
1999
2007
2008
2010
2011
2012
2013
2014
2015
2016
2017
2040 while (rc == false) {
2054
2062 if (rc ==
FA_CANCEL || rc ==
'q' || rc ==
'Q' || rc == KEY_F(9))
2065 tmp_fp = fopen(tmp_spec,
"r");
2075 fgets(tmp_str,
MAXLEN - 1, tmp_fp);
2085 if (rc ==
'y' || rc ==
'Y')
int popup_form(Init *, int, char **, int, int)
instantiate a form popup window
int popup_view(Init *, int, char **, int, int, int, int)
instantiate a view popup window
size_t rtrim(char *)
Trims trailing spaces from string s in place.
void go_to_position(View *, long)
char prev_regex_pattern[MAXLEN]
void view_win_resize(Init *, char *)
Resize the current window and its box, and update the title.
int xwgetch(WINDOW *, Chyron *, int)
Wrapper for wgetch that handles signals, mouse events, checks for clicks on the chyron line,...
void restore_wins()
Restore all windows after a screen resize.
void view_full_screen_resize(Init *)
Resize the full screen view and its components.
RGB xterm256_idx_to_rgb(int)
Convert XTerm 256 color index to RGB color.
int rgb_to_curses_clr(RGB *)
Get color index for RGB color.
int get_clr_pair(int fg, int bg)
Get color pair index for foreground and background colors.
int answer_yn(char *em0, char *em1, char *em2, char *em3)
Accept a single letter answer.
int Perror(char *)
Display a simple error message window or print to stderr.
int display_error(char *em0, char *em1, char *em2, char *em3)
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(View *, char *)
Initialize the input for a C-Menu View.
bool verify_spec_arg(char *, char *, char *, char *, int)
Verify file specification argument.
int view_file(Init *)
Start view.
void lp(char *)
Send File to Print Queue.
bool enter_file_spec(Init *, char *)
use form to enter a file specification
int write_view_buffer(Init *, bool)
Write buffer contents to files.
#define get_prev_char()
read the previous characater from the virtual fileThere is no need to track line numbers when moving ...
void cat_file(View *)
Concatenate File to Standard Output.
void remove_file(View *)
Remove File.
int get_cmd_arg(View *, char *)
Get Command Argument from User Input.
int view_cmd_processor(Init *)
Main Command Processing Loop for View.
int get_cmd_char(View *, off_t *)
Get Command Character and Numeric Argument.
void build_prompt(View *)
Build Prompt String.
#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
bool search(View *, int *, char *)
Search for Regular Expression Pattern.
void initialize_line_table(View *)
Initialize Line Table.
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.
void view_restore_wins()
Restore View Windows.
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]