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 *);
113int a_toi(
char *, bool *);
122
123
124
125
126
127
128
129
173
174
175
176
177
178
185 int prev_search_cmd = 0;
187 ssize_t bytes_written;
189 char shell_cmd_spec[
MAXLEN];
209 if (c >=
'0' && c <=
'9') {
210 tmp_str[0] = (
char)c;
217
222
226
233
247
280 for (i = 0; i < n_cmd; i++) {
337 if (c >=
'A' && c <=
'Z')
345 else if (c ==
'n' || c ==
'N')
365 view, "view->f_squeeze Multiple Blank lines (Y or N)->");
368 else if (c ==
'n' || c ==
'N')
378 if (i >= 1 && i <= 12) {
390
391
407 Perror("No previous search or search complete");
410 if (prev_search_cmd ==
'/') {
431 prev_search_cmd = search_cmd;
447 prev_search_cmd = search_cmd;
483 if (c ==
'@' || c == KEY_F(9) || c ==
'\033')
484 if (c >=
'A' && c <=
'Z')
486 if (c <
'a' || c >
'z')
495 if (c ==
'@' || c == KEY_F(9) || c ==
'\033')
497 if (c >=
'A' && c <=
'Z')
499 if (c <
'a' || c >
'z')
532 tfd = mkstemp(tmp_str);
535 Perror("Unable to create temporary file");
590 e = getenv(
"DEFAULTEDITOR");
591 if (e ==
nullptr || *e ==
'\0')
597 "View doesn't support editing current buffer directly",
604 if (rc !=
'y' && rc !=
'Y')
612 if (bytes_written == 0) {
639 if (bytes_written == 0) {
664
665
666
667
668
669
670
671
672
673
674
683 if ((c >=
'0' && c <=
'9') && i < 32) {
684 cmd_str[i++] = (
char)c;
692 }
while (c >=
'0' && c <=
'9');
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
715 int numeric_arg = false;
730 wstandout(view
->win);
731 waddch(view
->win,
' ');
732 waddstr(view
->win, prompt_s);
733 waddch(view
->win,
' ');
734 wstandend(view
->win);
740 if (*n >=
'0' && *n <=
'9') {
746 waddstr(view
->win, prompt_s);
749 wclrtoeol(view
->win);
759 if (*cmd_p <
' ' || *cmd_p == 0x7f) {
764 waddch(view
->win,
' ');
772 waddch(view
->win,
' ');
789 waddch(view
->win,
'^');
791 }
else if ((
uchar)c == 0x7f)
793 waddch(view
->win, (
char)c);
796 if (numeric_arg && (c <
'0' || c >
'9'))
804
805
806
807
808
853
854
855
856
857
859 ssize_t bytes_written = 0;
871 if (rc ==
'y' || rc ==
'Y')
874 f_strip_ansi = false;
896 bytes_written += write(view
->out_fd, tmp_line_s, l);
900 return bytes_written;
903
904
915
916
917void lp(
char *PrintFile) {
919 char shell_cmd_spec[
MAXLEN];
920 print_cmd_ptr = getenv(
"PRINTCMD");
921 if (print_cmd_ptr ==
nullptr || *print_cmd_ptr ==
'\0')
928
929
931
932
933
934
935
936
937
938
939
940
941
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971bool
search(View *view,
int *search_cmd,
char *regex_pattern) {
974 regmatch_t pmatch[1];
975 regex_t compiled_regex;
982 if (*regex_pattern ==
'\0')
985 REG_FLAGS = REG_ICASE | REG_EXTENDED;
987 REG_FLAGS = REG_EXTENDED;
988 reti = regcomp(&compiled_regex, regex_pattern, REG_FLAGS);
996 if (*search_cmd ==
'/') {
1007 if (*search_cmd ==
'/')
1019 if (*search_cmd ==
'/') {
1034 compiled_regex.re_nsub + 1, pmatch, REG_FLAGS);
1035 if (reti == REG_NOMATCH) {
1038 if (*search_cmd ==
'?')
1042 (*search_cmd ==
'?' && view
->cury == 1)) {
1050 regerror(reti, &compiled_regex, err_str,
sizeof(err_str));
1054 regfree(&compiled_regex);
1059 if (*search_cmd ==
'/') {
1064 wmove(view
->pad, 0, 0);
1066 wclrtobot(view
->pad);
1069 if (*search_cmd ==
'?')
1073
1074
1081 view
->curx = line_offset + pmatch[0].rm_so;
1082 match_len = pmatch[0].rm_eo - pmatch[0].rm_so;
1088 line_offset += pmatch[0].rm_eo;
1089 if (line_offset >= line_len)
1093 compiled_regex.re_nsub + 1, pmatch, REG_FLAGS);
1094 if (reti == REG_NOMATCH)
1098 regerror(reti, &compiled_regex, msgbuf,
sizeof(msgbuf));
1099 sprintf(tmp_str,
"Regex match failed: %s", msgbuf);
1101 regfree(&compiled_regex);
1104 if (*search_cmd ==
'/') {
1106 regfree(&compiled_regex);
1109 }
else if (view
->cury == 1) {
1110 regfree(&compiled_regex);
1119 "%s|%c%s|Pos %zu-%zu|(%zd) %zu %zu", view
->file_name, *search_cmd
,
1123 if (view->last_match_x > view->maxcol)
1124 ssnprintf(view->tmp_prompt_str, MAXLEN - 1,
1125 "%s|%c%s|Match Cols %d-%d of %d-%d|(%zd%%)", view->file_name,
1126 *search_cmd, regex_pattern, view->first_match_x,
1127 view->last_match_x, view->pmincol, view->smaxcol - view->begx,
1128 (view->page_bot_pos * 100 / view->file_size));
1130 ssnprintf(view->tmp_prompt_str, MAXLEN - 1,
1131 "%s|%c%s|Pos %zu-%zu|(%zd%%)", view->file_name, *search_cmd,
1132 regex_pattern, view->page_top_pos, view->page_bot_pos,
1133 (view->page_bot_pos * 100 / view->file_size));
1135 regfree(&compiled_regex);
1140
1141
1143
1144
1146 int scr_lines, scr_cols;
1147 bool f_resize = false;
1150 getmaxyx(stdscr, scr_lines, scr_cols);
1175
1176
1177
1178
1189 wrefresh(view
->win);
1195
1196
1198
1199
1200
1201
1202
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1236
1237
1238
1241 wmove(view
->pad, 0, 0);
1260 wclrtobot(view
->pad);
1265
1266
1267
1268
1286 wmove(view
->pad, 0, 0);
1287 wclrtobot(view
->pad);
1291 wscrl(view
->pad, n);
1297 for (i = 0; i < n; i++) {
1307
1308
1309
1310
1328 wscrl(view
->pad, -n);
1332 for (i = 0; i < n; i++) {
1344
1345
1346
1347
1348
1349
1388
1389
1390
1391
1392
1400
1401
1402
1403
1404
1435
1436
1437
1438
1439
1455
1456
1457
1458
1467
1468
1469
1485
1486
1487
1488
1491 Perror("Cannot determine file length");
1506
1507
1508
1509
1510
1511
1513 if (line_idx <= 1) {
1525
1526
1527
1528
1529
1530
1531
1536 Perror("Memory allocation failed");
1544
1545
1546
1547
1548
1549
1550
1551
1552
1562 Perror("Memory allocation failed");
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1599 while (view
->ln_tbl[idx] > target_pos)
1609
1610
1611
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] ==
'[') {
1673 len = strcspn(&in_str[i],
"mK ") + 1;
1674 memcpy(ansi_tok, &in_str[i], len + 1);
1675 ansi_tok[len] =
'\0';
1676 if (ansi_tok[0] ==
'\0') {
1681 if (len == 0 || in_str[i + len - 1] ==
' ') {
1684 }
else if (in_str[i + len - 1] ==
'K') {
1691 if (in_str[i] ==
'\033') {
1699 setcchar(&cc, wstr, attr, cpx,
nullptr);
1701 cmplx_buf[j++] = cc;
1706 len = mbrtowc(wstr, s, MB_CUR_MAX, &mbstate);
1712 if (setcchar(&cc, wstr, attr, cpx,
nullptr) != ERR) {
1713 if (len > 0 && (j + len) <
PAD_COLS - 1) {
1715 cmplx_buf[j++] = cc;
1726 setcchar(&cc, wstr, WA_NORMAL, cpx,
nullptr);
1732
1733
1734
1735
1736
1737
1738
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
1792 char *ansi_p = ansi_str + 2;
1793 extended_pair_content(*cpx, &fg_clr, &bg_clr);
1797 tok = strtok((
char *)ansi_p,
";m");
1798 bool a_toi_error = false;
1800 if (tok ==
nullptr || *tok ==
'\0')
1806 if (t0 ==
'3' || t0 ==
'4') {
1816 }
else if (*tok ==
'2') {
1829 }
else if (t1 ==
'9') {
1834 }
else if (t1 >=
'0' && t1 <=
'7') {
1839 }
else if (t0 ==
'4') {
1845 }
else if (t0 ==
'0') {
1856 switch (
a_toi(tok
, &a_toi_error
)) {
1867 *attr |= WA_UNDERLINE;
1873 *attr |= WA_REVERSE;
1882 }
else if (len == 0) {
1889 if (!a_toi_error && (fg_clr != fg || bg_clr != bg)) {
1896
1897
1898
1905 wclrtoeol(view
->win);
1906 wattron(view
->win, WA_REVERSE);
1907 waddstr(view
->win,
" ");
1908 waddstr(view
->win, message_str);
1909 waddstr(view
->win,
" ");
1910 wattroff(view
->win, WA_REVERSE);
1911 waddstr(view
->win,
" ");
1918
1919
1924 waddstr(view
->pad,
"Remove File (Y or N)->");
1925 wclrtoeol(view
->pad);
1927 waddch(view
->pad, (
char)toupper(c));
1928 if (c ==
'Y' || c ==
'y')
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1963 eargv[eargc++] = strdup(
"view");
1964 eargv[eargc++] = strdup(
"-N");
1965 eargv[eargc++] = strdup(
"f");
1966 eargv[eargc++] = strdup(tmp_str);
1986
1987
1989
1990
1991
1992
1993
1994
1995
1996
2016 while (rc == false) {
2030
2038 if (rc ==
P_CANCEL || rc ==
'q' || rc ==
'Q' || rc == KEY_F(9))
2041 tmp_fp = fopen(tmp_spec,
"r");
2051 fgets(tmp_str,
MAXLEN - 1, tmp_fp);
2061 if (rc ==
'y' || rc ==
'Y')
int popup_form(Init *, int, char **, int, int)
int popup_view(Init *, int, char **, int, int, int, int)
size_t rtrim(char *)
Trims trailing spaces from string s in place.
void go_to_position(View *, long)
char prev_regex_pattern[MAXLEN]
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 win_resize(int, int, char *)
Resize the current window and its box, and update the title.
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.
void destroy_argv(int argc, char **argv)
Deallocates memory allocated for argument strings in argv.
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
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.
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 expand_tilde(char *, int)
Replace Leading Tilde With Home Directory.
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 file
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.
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 resize_page(Init *)
Resize Viewing Page.
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]