aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/awk.c12
-rw-r--r--editors/sed.c26
-rw-r--r--editors/vi.c68
3 files changed, 43 insertions, 63 deletions
diff --git a/editors/awk.c b/editors/awk.c
index 0b573a065..77784dfc1 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -190,7 +190,7 @@ typedef struct tsplitter_s {
190 190
191/* combined token classes */ 191/* combined token classes */
192#define TC_BINOP (TC_BINOPX | TC_COMMA | TC_PIPE | TC_IN) 192#define TC_BINOP (TC_BINOPX | TC_COMMA | TC_PIPE | TC_IN)
193#define TC_UNARYOP (TC_UOPPRE | TC_UOPPOST) 193//#define TC_UNARYOP (TC_UOPPRE | TC_UOPPOST)
194#define TC_OPERAND (TC_VARIABLE | TC_ARRAY | TC_FUNCTION \ 194#define TC_OPERAND (TC_VARIABLE | TC_ARRAY | TC_FUNCTION \
195 | TC_BUILTIN | TC_GETLINE | TC_SEQSTART | TC_STRING | TC_NUMBER) 195 | TC_BUILTIN | TC_GETLINE | TC_SEQSTART | TC_STRING | TC_NUMBER)
196 196
@@ -2015,8 +2015,8 @@ static int fmt_num(char *b, int size, const char *format, double n, int int_as_i
2015 char c; 2015 char c;
2016 const char *s = format; 2016 const char *s = format;
2017 2017
2018 if (int_as_int && n == (int)n) { 2018 if (int_as_int && n == (long long)n) {
2019 r = snprintf(b, size, "%d", (int)n); 2019 r = snprintf(b, size, "%lld", (long long)n);
2020 } else { 2020 } else {
2021 do { c = *s; } while (c && *++s); 2021 do { c = *s; } while (c && *++s);
2022 if (strchr("diouxX", c)) { 2022 if (strchr("diouxX", c)) {
@@ -2662,7 +2662,7 @@ static var *evaluate(node *op, var *res)
2662 const char *sv_progname; 2662 const char *sv_progname;
2663 2663
2664 /* The body might be empty, still has to eval the args */ 2664 /* The body might be empty, still has to eval the args */
2665 if (!op->r.n->info) 2665 if (!op->r.n->info && !op->r.f->body.first)
2666 syntax_error(EMSG_UNDEF_FUNC); 2666 syntax_error(EMSG_UNDEF_FUNC);
2667 2667
2668 vbeg = v = nvalloc(op->r.f->nargs + 1); 2668 vbeg = v = nvalloc(op->r.f->nargs + 1);
@@ -2733,7 +2733,7 @@ static var *evaluate(node *op, var *res)
2733 2733
2734 switch (opn) { 2734 switch (opn) {
2735 case F_in: 2735 case F_in:
2736 R_d = (int)L_d; 2736 R_d = (long long)L_d;
2737 break; 2737 break;
2738 2738
2739 case F_rn: 2739 case F_rn:
@@ -2931,7 +2931,7 @@ static var *evaluate(node *op, var *res)
2931 case '%': 2931 case '%':
2932 if (R_d == 0) 2932 if (R_d == 0)
2933 syntax_error(EMSG_DIV_BY_ZERO); 2933 syntax_error(EMSG_DIV_BY_ZERO);
2934 L_d -= (int)(L_d / R_d) * R_d; 2934 L_d -= (long long)(L_d / R_d) * R_d;
2935 break; 2935 break;
2936 } 2936 }
2937 debug_printf_eval("BINARY/REPLACE result:%f\n", L_d); 2937 debug_printf_eval("BINARY/REPLACE result:%f\n", L_d);
diff --git a/editors/sed.c b/editors/sed.c
index f8ca5d351..3a0d917aa 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -330,7 +330,7 @@ static int get_address(const char *my_str, int *linenum, regex_t ** regex)
330 next = index_of_next_unescaped_regexp_delim(delimiter, ++pos); 330 next = index_of_next_unescaped_regexp_delim(delimiter, ++pos);
331 temp = copy_parsing_escapes(pos, next); 331 temp = copy_parsing_escapes(pos, next);
332 *regex = xzalloc(sizeof(regex_t)); 332 *regex = xzalloc(sizeof(regex_t));
333 xregcomp(*regex, temp, G.regex_type|REG_NEWLINE); 333 xregcomp(*regex, temp, G.regex_type);
334 free(temp); 334 free(temp);
335 /* Move position to next character after last delimiter */ 335 /* Move position to next character after last delimiter */
336 pos += (next+1); 336 pos += (next+1);
@@ -649,6 +649,12 @@ static void add_cmd(const char *cmdstr)
649 sed_cmd->cmd = *cmdstr++; 649 sed_cmd->cmd = *cmdstr++;
650 cmdstr = parse_cmd_args(sed_cmd, cmdstr); 650 cmdstr = parse_cmd_args(sed_cmd, cmdstr);
651 651
652 /* cmdstr now points past args.
653 * GNU sed requires a separator, if there are more commands,
654 * else it complains "char N: extra characters after command".
655 * Example: "sed 'p;d'". We also allow "sed 'pd'".
656 */
657
652 /* Add the command to the command array */ 658 /* Add the command to the command array */
653 *G.sed_cmd_tail = sed_cmd; 659 *G.sed_cmd_tail = sed_cmd;
654 G.sed_cmd_tail = &sed_cmd->next; 660 G.sed_cmd_tail = &sed_cmd->next;
@@ -1371,7 +1377,7 @@ static void process_files(void)
1371/* It is possible to have a command line argument with embedded 1377/* It is possible to have a command line argument with embedded
1372 * newlines. This counts as multiple command lines. 1378 * newlines. This counts as multiple command lines.
1373 * However, newline can be escaped: 's/e/z\<newline>z/' 1379 * However, newline can be escaped: 's/e/z\<newline>z/'
1374 * We check for this. 1380 * add_cmd() handles this.
1375 */ 1381 */
1376 1382
1377static void add_cmd_block(char *cmdstr) 1383static void add_cmd_block(char *cmdstr)
@@ -1381,22 +1387,8 @@ static void add_cmd_block(char *cmdstr)
1381 cmdstr = sv = xstrdup(cmdstr); 1387 cmdstr = sv = xstrdup(cmdstr);
1382 do { 1388 do {
1383 eol = strchr(cmdstr, '\n'); 1389 eol = strchr(cmdstr, '\n');
1384 next: 1390 if (eol)
1385 if (eol) {
1386 /* Count preceding slashes */
1387 int slashes = 0;
1388 char *sl = eol;
1389
1390 while (sl != cmdstr && *--sl == '\\')
1391 slashes++;
1392 /* Odd number of preceding slashes - newline is escaped */
1393 if (slashes & 1) {
1394 overlapping_strcpy(eol - 1, eol);
1395 eol = strchr(eol, '\n');
1396 goto next;
1397 }
1398 *eol = '\0'; 1391 *eol = '\0';
1399 }
1400 add_cmd(cmdstr); 1392 add_cmd(cmdstr);
1401 cmdstr = eol + 1; 1393 cmdstr = eol + 1;
1402 } while (eol); 1394 } while (eol);
diff --git a/editors/vi.c b/editors/vi.c
index d6c8c0dd8..ab49b3f7d 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -1707,65 +1707,53 @@ static char *new_screen(int ro, int co)
1707// search for pattern starting at p 1707// search for pattern starting at p
1708static char *char_search(char *p, const char *pat, int dir, int range) 1708static char *char_search(char *p, const char *pat, int dir, int range)
1709{ 1709{
1710 char *q;
1711 struct re_pattern_buffer preg; 1710 struct re_pattern_buffer preg;
1711 const char *err;
1712 char *q;
1712 int i; 1713 int i;
1713 int size; 1714 int size;
1714 1715
1715 re_syntax_options = RE_SYNTAX_POSIX_EXTENDED; 1716 re_syntax_options = RE_SYNTAX_POSIX_EXTENDED;
1716 preg.translate = 0; 1717 if (ignorecase)
1717 preg.fastmap = 0; 1718 re_syntax_options = RE_SYNTAX_POSIX_EXTENDED | RE_ICASE;
1718 preg.buffer = 0; 1719
1719 preg.allocated = 0; 1720 memset(&preg, 0, sizeof(preg));
1721 err = re_compile_pattern(pat, strlen(pat), &preg);
1722 if (err != NULL) {
1723 status_line_bold("bad search pattern '%s': %s", pat, err);
1724 return p;
1725 }
1720 1726
1721 // assume a LIMITED forward search 1727 // assume a LIMITED forward search
1722 q = next_line(p);
1723 q = end_line(q);
1724 q = end - 1; 1728 q = end - 1;
1725 if (dir == BACK) { 1729 if (dir == BACK)
1726 q = prev_line(p);
1727 q = text; 1730 q = text;
1728 }
1729 // count the number of chars to search over, forward or backward
1730 size = q - p;
1731 if (size < 0)
1732 size = p - q;
1733 // RANGE could be negative if we are searching backwards 1731 // RANGE could be negative if we are searching backwards
1734 range = q - p; 1732 range = q - p;
1735
1736 q = (char *)re_compile_pattern(pat, strlen(pat), (struct re_pattern_buffer *)&preg);
1737 if (q != 0) {
1738 // The pattern was not compiled
1739 status_line_bold("bad search pattern: '%s': %s", pat, q);
1740 i = 0; // return p if pattern not compiled
1741 goto cs1;
1742 }
1743
1744 q = p; 1733 q = p;
1734 size = range;
1745 if (range < 0) { 1735 if (range < 0) {
1736 size = -size;
1746 q = p - size; 1737 q = p - size;
1747 if (q < text) 1738 if (q < text)
1748 q = text; 1739 q = text;
1749 } 1740 }
1750 // search for the compiled pattern, preg, in p[] 1741 // search for the compiled pattern, preg, in p[]
1751 // range < 0- search backward 1742 // range < 0: search backward
1752 // range > 0- search forward 1743 // range > 0: search forward
1753 // 0 < start < size 1744 // 0 < start < size
1754 // re_search() < 0 not found or error 1745 // re_search() < 0: not found or error
1755 // re_search() > 0 index of found pattern 1746 // re_search() >= 0: index of found pattern
1756 // struct pattern char int int int struct reg 1747 // struct pattern char int int int struct reg
1757 // re_search (*pattern_buffer, *string, size, start, range, *regs) 1748 // re_search(*pattern_buffer, *string, size, start, range, *regs)
1758 i = re_search(&preg, q, size, 0, range, 0); 1749 i = re_search(&preg, q, size, /*start:*/ 0, range, /*struct re_registers*:*/ NULL);
1759 if (i == -1) { 1750 regfree(&preg);
1760 p = 0; 1751 if (i < 0)
1761 i = 0; // return NULL if pattern not found 1752 return NULL;
1762 } 1753 if (dir == FORWARD)
1763 cs1:
1764 if (dir == FORWARD) {
1765 p = p + i; 1754 p = p + i;
1766 } else { 1755 else
1767 p = p - i; 1756 p = p - i;
1768 }
1769 return p; 1757 return p;
1770} 1758}
1771 1759
@@ -1790,7 +1778,7 @@ static char *char_search(char *p, const char *pat, int dir, int range)
1790 1778
1791 len = strlen(pat); 1779 len = strlen(pat);
1792 if (dir == FORWARD) { 1780 if (dir == FORWARD) {
1793 stop = end - 1; // assume range is p - end-1 1781 stop = end - 1; // assume range is p..end-1
1794 if (range == LIMITED) 1782 if (range == LIMITED)
1795 stop = next_line(p); // range is to next line 1783 stop = next_line(p); // range is to next line
1796 for (start = p; start < stop; start++) { 1784 for (start = p; start < stop; start++) {
@@ -1799,7 +1787,7 @@ static char *char_search(char *p, const char *pat, int dir, int range)
1799 } 1787 }
1800 } 1788 }
1801 } else if (dir == BACK) { 1789 } else if (dir == BACK) {
1802 stop = text; // assume range is text - p 1790 stop = text; // assume range is text..p
1803 if (range == LIMITED) 1791 if (range == LIMITED)
1804 stop = prev_line(p); // range is to prev line 1792 stop = prev_line(p); // range is to prev line
1805 for (start = p - len; start >= stop; start--) { 1793 for (start = p - len; start >= stop; start--) {