annotate src/regexp.c @ 30332:462d122636b3

Added tag v9.0.0501 for changeset ddbac2551dacc3dce403cc1c00c1c354434bc44e
author Bram Moolenaar <Bram@vim.org>
date Mon, 19 Sep 2022 12:45:05 +0200
parents 085406413994
children c0be6563fa39
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10042
4aead6a9b7a9 commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents: 9723
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * Handling of regular expressions: vim_regcomp(), vim_regexec(), vim_regsub()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5
16395
a849fe2a4b21 patch 8.1.1202: always get regexp debugging logs when building with -DDEBUG
Bram Moolenaar <Bram@vim.org>
parents: 16054
diff changeset
6 // By default: do not create debugging logs or files related to regular
a849fe2a4b21 patch 8.1.1202: always get regexp debugging logs when building with -DDEBUG
Bram Moolenaar <Bram@vim.org>
parents: 16054
diff changeset
7 // expressions, even when compiling with -DDEBUG.
a849fe2a4b21 patch 8.1.1202: always get regexp debugging logs when building with -DDEBUG
Bram Moolenaar <Bram@vim.org>
parents: 16054
diff changeset
8 // Uncomment the second line to get the regexp debugging.
a849fe2a4b21 patch 8.1.1202: always get regexp debugging logs when building with -DDEBUG
Bram Moolenaar <Bram@vim.org>
parents: 16054
diff changeset
9 #undef DEBUG
a849fe2a4b21 patch 8.1.1202: always get regexp debugging logs when building with -DDEBUG
Bram Moolenaar <Bram@vim.org>
parents: 16054
diff changeset
10 // #define DEBUG
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
11
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 #include "vim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
14 #ifdef DEBUG
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
15 // show/save debugging data when BT engine is used
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
16 # define BT_REGEXP_DUMP
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
17 // save the debugging data to a file instead of displaying it
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
18 # define BT_REGEXP_LOG
4460
fe8a0a6a1c2a updated for version 7.3.978
Bram Moolenaar <bram@vim.org>
parents: 4444
diff changeset
19 # define BT_REGEXP_DEBUG_LOG
fe8a0a6a1c2a updated for version 7.3.978
Bram Moolenaar <bram@vim.org>
parents: 4444
diff changeset
20 # define BT_REGEXP_DEBUG_LOG_NAME "bt_regexp_debug.log"
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
21 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22
29071
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 29048
diff changeset
23 #ifdef FEAT_RELTIME
29245
b12fd2b3be63 patch 8.2.5141: using "volatile int" in a signal handler might be wrong
Bram Moolenaar <Bram@vim.org>
parents: 29220
diff changeset
24 static sig_atomic_t dummy_timeout_flag = 0;
b12fd2b3be63 patch 8.2.5141: using "volatile int" in a signal handler might be wrong
Bram Moolenaar <Bram@vim.org>
parents: 29220
diff changeset
25 static volatile sig_atomic_t *timeout_flag = &dummy_timeout_flag;
29071
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 29048
diff changeset
26 #endif
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 29048
diff changeset
27
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 * Magic characters have a special meaning, they don't match literally.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 * Magic characters are negative. This separates them from literal characters
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 * (possibly multi-byte). Only ASCII characters can be Magic.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 #define Magic(x) ((int)(x) - 256)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 #define un_Magic(x) ((x) + 256)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 #define is_Magic(x) ((x) < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 static int
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
38 no_Magic(int x)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 if (is_Magic(x))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 return un_Magic(x);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 return x;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 static int
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
46 toggle_Magic(int x)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 if (is_Magic(x))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 return un_Magic(x);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 return Magic(x);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52
29071
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 29048
diff changeset
53 #ifdef FEAT_RELTIME
29888
a63d3a0e9aba patch 9.0.0282: a nested timout stops the previous timeout
Bram Moolenaar <Bram@vim.org>
parents: 29527
diff changeset
54 static int timeout_nesting = 0;
a63d3a0e9aba patch 9.0.0282: a nested timout stops the previous timeout
Bram Moolenaar <Bram@vim.org>
parents: 29527
diff changeset
55
a63d3a0e9aba patch 9.0.0282: a nested timout stops the previous timeout
Bram Moolenaar <Bram@vim.org>
parents: 29527
diff changeset
56 /*
a63d3a0e9aba patch 9.0.0282: a nested timout stops the previous timeout
Bram Moolenaar <Bram@vim.org>
parents: 29527
diff changeset
57 * Start a timer that will cause the regexp to abort after "msec".
a63d3a0e9aba patch 9.0.0282: a nested timout stops the previous timeout
Bram Moolenaar <Bram@vim.org>
parents: 29527
diff changeset
58 * This doesn't work well recursively. In case it happens anyway, the first
a63d3a0e9aba patch 9.0.0282: a nested timout stops the previous timeout
Bram Moolenaar <Bram@vim.org>
parents: 29527
diff changeset
59 * set timeout will prevail, nested ones are ignored.
a63d3a0e9aba patch 9.0.0282: a nested timout stops the previous timeout
Bram Moolenaar <Bram@vim.org>
parents: 29527
diff changeset
60 * The caller must make sure there is a matching disable_regexp_timeout() call!
a63d3a0e9aba patch 9.0.0282: a nested timout stops the previous timeout
Bram Moolenaar <Bram@vim.org>
parents: 29527
diff changeset
61 */
29071
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 29048
diff changeset
62 void
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 29048
diff changeset
63 init_regexp_timeout(long msec)
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 29048
diff changeset
64 {
29888
a63d3a0e9aba patch 9.0.0282: a nested timout stops the previous timeout
Bram Moolenaar <Bram@vim.org>
parents: 29527
diff changeset
65 if (timeout_nesting == 0)
a63d3a0e9aba patch 9.0.0282: a nested timout stops the previous timeout
Bram Moolenaar <Bram@vim.org>
parents: 29527
diff changeset
66 timeout_flag = start_timeout(msec);
a63d3a0e9aba patch 9.0.0282: a nested timout stops the previous timeout
Bram Moolenaar <Bram@vim.org>
parents: 29527
diff changeset
67 ++timeout_nesting;
29071
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 29048
diff changeset
68 }
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 29048
diff changeset
69
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 29048
diff changeset
70 void
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 29048
diff changeset
71 disable_regexp_timeout(void)
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 29048
diff changeset
72 {
29888
a63d3a0e9aba patch 9.0.0282: a nested timout stops the previous timeout
Bram Moolenaar <Bram@vim.org>
parents: 29527
diff changeset
73 if (timeout_nesting == 0)
a63d3a0e9aba patch 9.0.0282: a nested timout stops the previous timeout
Bram Moolenaar <Bram@vim.org>
parents: 29527
diff changeset
74 iemsg("disable_regexp_timeout() called without active timer");
a63d3a0e9aba patch 9.0.0282: a nested timout stops the previous timeout
Bram Moolenaar <Bram@vim.org>
parents: 29527
diff changeset
75 else if (--timeout_nesting == 0)
a63d3a0e9aba patch 9.0.0282: a nested timout stops the previous timeout
Bram Moolenaar <Bram@vim.org>
parents: 29527
diff changeset
76 {
a63d3a0e9aba patch 9.0.0282: a nested timout stops the previous timeout
Bram Moolenaar <Bram@vim.org>
parents: 29527
diff changeset
77 stop_timeout();
a63d3a0e9aba patch 9.0.0282: a nested timout stops the previous timeout
Bram Moolenaar <Bram@vim.org>
parents: 29527
diff changeset
78 timeout_flag = &dummy_timeout_flag;
a63d3a0e9aba patch 9.0.0282: a nested timout stops the previous timeout
Bram Moolenaar <Bram@vim.org>
parents: 29527
diff changeset
79 }
29071
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 29048
diff changeset
80 }
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 29048
diff changeset
81 #endif
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 29048
diff changeset
82
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 /*
18019
68fd5296bf73 patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17966
diff changeset
84 * The first byte of the BT regexp internal "program" is actually this magic
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 * number; the start node begins in the second byte. It's used to catch the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 * most severe mutilation of the program by the caller.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 #define REGMAGIC 0234
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 * Utility definitions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 #define UCHARAT(p) ((int)*(char_u *)(p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
96 // Used for an error (down from) vim_regcomp(): give the error message, set
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
97 // rc_did_emsg and return NULL
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15339
diff changeset
98 #define EMSG_RET_NULL(m) return (emsg((m)), rc_did_emsg = TRUE, (void *)NULL)
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15339
diff changeset
99 #define IEMSG_RET_NULL(m) return (iemsg((m)), rc_did_emsg = TRUE, (void *)NULL)
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15339
diff changeset
100 #define EMSG_RET_FAIL(m) return (emsg((m)), rc_did_emsg = TRUE, FAIL)
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15339
diff changeset
101 #define EMSG2_RET_NULL(m, c) return (semsg((const char *)(m), (c) ? "" : "\\"), rc_did_emsg = TRUE, (void *)NULL)
15480
bd12ace1bab2 patch 8.1.0748: using sprintf() instead of semsg()
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
102 #define EMSG3_RET_NULL(m, c, a) return (semsg((const char *)(m), (c) ? "" : "\\", (a)), rc_did_emsg = TRUE, (void *)NULL)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15339
diff changeset
103 #define EMSG2_RET_FAIL(m, c) return (semsg((const char *)(m), (c) ? "" : "\\"), rc_did_emsg = TRUE, FAIL)
26913
d4e61d61afd9 patch 8.2.3985: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26841
diff changeset
104 #define EMSG_ONE_RET_NULL EMSG2_RET_NULL(_(e_invalid_item_in_str_brackets), reg_magic == MAGIC_ALL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105
10359
66f1b5bf3fa6 commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents: 10245
diff changeset
106
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 #define MAX_LIMIT (32767L << 16L)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 #define NOT_MULTI 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 #define MULTI_ONE 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 #define MULTI_MULT 2
18019
68fd5296bf73 patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17966
diff changeset
112
68fd5296bf73 patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17966
diff changeset
113 // return values for regmatch()
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
114 #define RA_FAIL 1 // something failed, abort
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
115 #define RA_CONT 2 // continue in inner loop
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
116 #define RA_BREAK 3 // break inner loop
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
117 #define RA_MATCH 4 // successful match
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
118 #define RA_NOMATCH 5 // didn't match
18019
68fd5296bf73 patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17966
diff changeset
119
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 * Return NOT_MULTI if c is not a "multi" operator.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 * Return MULTI_ONE if c is a single "multi" operator.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 * Return MULTI_MULT if c is a multi "multi" operator.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 static int
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
126 re_multi_type(int c)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 if (c == Magic('@') || c == Magic('=') || c == Magic('?'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 return MULTI_ONE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 if (c == Magic('*') || c == Magic('+') || c == Magic('{'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 return MULTI_MULT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 return NOT_MULTI;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 308
diff changeset
135 static char_u *reg_prev_sub = NULL;
6c62b9b939bd updated for version 7.0093
vimboss
parents: 308
diff changeset
136
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 * REGEXP_INRANGE contains all characters which are always special in a []
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 * range after '\'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 * REGEXP_ABBR contains all characters which act as abbreviations after '\'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 * These are:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 * \n - New line (NL).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 * \r - Carriage Return (CR).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 * \t - Tab (TAB).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 * \e - Escape (ESC).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 * \b - Backspace (Ctrl_H).
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
147 * \d - Character code in decimal, eg \d123
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
148 * \o - Character code in octal, eg \o80
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
149 * \x - Character code in hex, eg \x4a
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
150 * \u - Multibyte character code, eg \u20ac
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
151 * \U - Long multibyte character code, eg \U12345678
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 static char_u REGEXP_INRANGE[] = "]^-n\\";
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
154 static char_u REGEXP_ABBR[] = "nrtebdoxuU";
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 * Translate '\x' to its control character, except "\n", which is Magic.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 static int
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
160 backslash_trans(int c)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 case 'r': return CAR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 case 't': return TAB;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 case 'e': return ESC;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 case 'b': return BS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 return c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 /*
167
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
173 * Check for a character class name "[:name:]". "pp" points to the '['.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 * Returns one of the CLASS_ items. CLASS_NONE means that no item was
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 * recognized. Otherwise "pp" is advanced to after the item.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 static int
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
178 get_char_class(char_u **pp)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 static const char *(class_names[]) =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 "alnum:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 #define CLASS_ALNUM 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 "alpha:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 #define CLASS_ALPHA 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 "blank:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 #define CLASS_BLANK 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 "cntrl:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 #define CLASS_CNTRL 3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 "digit:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 #define CLASS_DIGIT 4
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 "graph:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 #define CLASS_GRAPH 5
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 "lower:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 #define CLASS_LOWER 6
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 "print:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 #define CLASS_PRINT 7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 "punct:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 #define CLASS_PUNCT 8
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 "space:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 #define CLASS_SPACE 9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 "upper:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 #define CLASS_UPPER 10
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 "xdigit:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 #define CLASS_XDIGIT 11
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 "tab:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 #define CLASS_TAB 12
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 "return:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 #define CLASS_RETURN 13
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 "backspace:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 #define CLASS_BACKSPACE 14
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 "escape:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 #define CLASS_ESCAPE 15
15709
2e2f07561f4b patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents: 15603
diff changeset
214 "ident:]",
2e2f07561f4b patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents: 15603
diff changeset
215 #define CLASS_IDENT 16
2e2f07561f4b patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents: 15603
diff changeset
216 "keyword:]",
2e2f07561f4b patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents: 15603
diff changeset
217 #define CLASS_KEYWORD 17
2e2f07561f4b patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents: 15603
diff changeset
218 "fname:]",
2e2f07561f4b patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents: 15603
diff changeset
219 #define CLASS_FNAME 18
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 #define CLASS_NONE 99
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224 if ((*pp)[1] == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 {
24768
7334bf933510 patch 8.2.2922: computing array length is done in various ways
Bram Moolenaar <Bram@vim.org>
parents: 24745
diff changeset
226 for (i = 0; i < (int)ARRAY_LENGTH(class_names); ++i)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 if (STRNCMP(*pp + 2, class_names[i], STRLEN(class_names[i])) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 *pp += STRLEN(class_names[i]) + 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 return i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 return CLASS_NONE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 * Specific version of character class functions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238 * Using a table to keep this fast.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 static short class_tab[256];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 #define RI_DIGIT 0x01
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 #define RI_HEX 0x02
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 #define RI_OCTAL 0x04
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 #define RI_WORD 0x08
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 #define RI_HEAD 0x10
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 #define RI_ALPHA 0x20
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 #define RI_LOWER 0x40
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 #define RI_UPPER 0x80
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 #define RI_WHITE 0x100
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 static void
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
253 init_class_tab(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 static int done = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 if (done)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 for (i = 0; i < 256; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 if (i >= '0' && i <= '7')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 class_tab[i] = RI_DIGIT + RI_HEX + RI_OCTAL + RI_WORD;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 else if (i >= '8' && i <= '9')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 class_tab[i] = RI_DIGIT + RI_HEX + RI_WORD;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 else if (i >= 'a' && i <= 'f')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 class_tab[i] = RI_HEX + RI_WORD + RI_HEAD + RI_ALPHA + RI_LOWER;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 else if (i >= 'g' && i <= 'z')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 class_tab[i] = RI_WORD + RI_HEAD + RI_ALPHA + RI_LOWER;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 else if (i >= 'A' && i <= 'F')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 class_tab[i] = RI_HEX + RI_WORD + RI_HEAD + RI_ALPHA + RI_UPPER;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 else if (i >= 'G' && i <= 'Z')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 class_tab[i] = RI_WORD + RI_HEAD + RI_ALPHA + RI_UPPER;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 else if (i == '_')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 class_tab[i] = RI_WORD + RI_HEAD;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 class_tab[i] = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 class_tab[' '] |= RI_WHITE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 class_tab['\t'] |= RI_WHITE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 done = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284
27752
c1d1639b52dd patch 8.2.4402: missing parenthesis may cause unexpected problems
Bram Moolenaar <Bram@vim.org>
parents: 27490
diff changeset
285 #define ri_digit(c) ((c) < 0x100 && (class_tab[c] & RI_DIGIT))
c1d1639b52dd patch 8.2.4402: missing parenthesis may cause unexpected problems
Bram Moolenaar <Bram@vim.org>
parents: 27490
diff changeset
286 #define ri_hex(c) ((c) < 0x100 && (class_tab[c] & RI_HEX))
c1d1639b52dd patch 8.2.4402: missing parenthesis may cause unexpected problems
Bram Moolenaar <Bram@vim.org>
parents: 27490
diff changeset
287 #define ri_octal(c) ((c) < 0x100 && (class_tab[c] & RI_OCTAL))
c1d1639b52dd patch 8.2.4402: missing parenthesis may cause unexpected problems
Bram Moolenaar <Bram@vim.org>
parents: 27490
diff changeset
288 #define ri_word(c) ((c) < 0x100 && (class_tab[c] & RI_WORD))
c1d1639b52dd patch 8.2.4402: missing parenthesis may cause unexpected problems
Bram Moolenaar <Bram@vim.org>
parents: 27490
diff changeset
289 #define ri_head(c) ((c) < 0x100 && (class_tab[c] & RI_HEAD))
c1d1639b52dd patch 8.2.4402: missing parenthesis may cause unexpected problems
Bram Moolenaar <Bram@vim.org>
parents: 27490
diff changeset
290 #define ri_alpha(c) ((c) < 0x100 && (class_tab[c] & RI_ALPHA))
c1d1639b52dd patch 8.2.4402: missing parenthesis may cause unexpected problems
Bram Moolenaar <Bram@vim.org>
parents: 27490
diff changeset
291 #define ri_lower(c) ((c) < 0x100 && (class_tab[c] & RI_LOWER))
c1d1639b52dd patch 8.2.4402: missing parenthesis may cause unexpected problems
Bram Moolenaar <Bram@vim.org>
parents: 27490
diff changeset
292 #define ri_upper(c) ((c) < 0x100 && (class_tab[c] & RI_UPPER))
c1d1639b52dd patch 8.2.4402: missing parenthesis may cause unexpected problems
Bram Moolenaar <Bram@vim.org>
parents: 27490
diff changeset
293 #define ri_white(c) ((c) < 0x100 && (class_tab[c] & RI_WHITE))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
295 // flags for regflags
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
296 #define RF_ICASE 1 // ignore case
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
297 #define RF_NOICASE 2 // don't ignore case
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
298 #define RF_HASNL 4 // can match a NL
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
299 #define RF_ICOMBINE 8 // ignore combining characters
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
300 #define RF_LOOKBH 16 // uses "\@<=" or "\@<!"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 * Global work variables for vim_regcomp().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
306 static char_u *regparse; // Input-scan pointer.
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
307 static int regnpar; // () count.
23471
a7cdfc8e4b6e patch 8.2.2278: falling back to old regexp engine can some patterns
Bram Moolenaar <Bram@vim.org>
parents: 22167
diff changeset
308 static int wants_nfa; // regex should use NFA engine
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 #ifdef FEAT_SYN_HL
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
310 static int regnzpar; // \z() count.
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
311 static int re_has_z; // \z item detected
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 #endif
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
313 static unsigned regflags; // RF_ flags for prog
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314 #if defined(FEAT_SYN_HL) || defined(PROTO)
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
315 static int had_eol; // TRUE when EOL found by vim_regcomp()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317
23505
bb29b09902d5 patch 8.2.2295: incsearch does not detect empty pattern properly
Bram Moolenaar <Bram@vim.org>
parents: 23471
diff changeset
318 static magic_T reg_magic; // magicness of the pattern
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
320 static int reg_string; // matching with a string instead of a buffer
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
321 // line
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
322 static int reg_strict; // "[abc" is illegal
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325 * META contains all characters that may be magic, except '^' and '$'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
328 // META[] is used often enough to justify turning it into a table.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 static char_u META_flags[] = {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
332 // % & ( ) * + .
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0,
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
334 // 1 2 3 4 5 6 7 8 9 < = > ?
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1,
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
336 // @ A C D F H I K L M O
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1,
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
338 // P S U V W X Z [ _
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1,
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
340 // a c d f h i k l m n o
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1,
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
342 // p s u v w x z { | ~
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
346 static int curchr; // currently parsed character
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
347 // Previous character. Note: prevchr is sometimes -1 when we are not at the
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
348 // start, eg in /[ ^I]^ the pattern was never found even if it existed,
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
349 // because ^ was taken to be magic -- webb
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
350 static int prevchr;
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
351 static int prevprevchr; // previous-previous character
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
352 static int nextchr; // used for ungetchr()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
354 // arguments for reg()
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
355 #define REG_NOPAREN 0 // toplevel reg()
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
356 #define REG_PAREN 1 // \(\)
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
357 #define REG_ZPAREN 2 // \z(\)
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
358 #define REG_NPAREN 3 // \%(\)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359
4679
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
360 typedef struct
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
361 {
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
362 char_u *regparse;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
363 int prevchr_len;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
364 int curchr;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
365 int prevchr;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
366 int prevprevchr;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
367 int nextchr;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
368 int at_start;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
369 int prev_at_start;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
370 int regnpar;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
371 } parse_state_T;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
372
7805
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7009
diff changeset
373 static void initchr(char_u *);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7009
diff changeset
374 static int getchr(void);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7009
diff changeset
375 static void skipchr_keepstart(void);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7009
diff changeset
376 static int peekchr(void);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7009
diff changeset
377 static void skipchr(void);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7009
diff changeset
378 static void ungetchr(void);
12752
09c856605191 patch 8.0.1254: undefined left shift in gethexchrs()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
379 static long gethexchrs(int maxinputlen);
09c856605191 patch 8.0.1254: undefined left shift in gethexchrs()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
380 static long getoctchrs(void);
09c856605191 patch 8.0.1254: undefined left shift in gethexchrs()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
381 static long getdecchrs(void);
7805
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7009
diff changeset
382 static int coll_get_char(void);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7009
diff changeset
383 static int prog_magic_wrong(void);
18019
68fd5296bf73 patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17966
diff changeset
384 static int cstrncmp(char_u *s1, char_u *s2, int *n);
68fd5296bf73 patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17966
diff changeset
385 static char_u *cstrchr(char_u *, int);
68fd5296bf73 patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17966
diff changeset
386 static int re_mult_next(char *what);
15709
2e2f07561f4b patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents: 15603
diff changeset
387 static int reg_iswordc(int);
23471
a7cdfc8e4b6e patch 8.2.2278: falling back to old regexp engine can some patterns
Bram Moolenaar <Bram@vim.org>
parents: 22167
diff changeset
388 #ifdef FEAT_EVAL
a7cdfc8e4b6e patch 8.2.2278: falling back to old regexp engine can some patterns
Bram Moolenaar <Bram@vim.org>
parents: 22167
diff changeset
389 static void report_re_switch(char_u *pat);
a7cdfc8e4b6e patch 8.2.2278: falling back to old regexp engine can some patterns
Bram Moolenaar <Bram@vim.org>
parents: 22167
diff changeset
390 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
392 static regengine_T bt_regengine;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
393 static regengine_T nfa_regengine;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
394
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 * Return TRUE if compiled regular expression "prog" can match a line break.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398 int
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
399 re_multiline(regprog_T *prog)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401 return (prog->regflags & RF_HASNL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404 /*
167
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
405 * Check for an equivalence class name "[=a=]". "pp" points to the '['.
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
406 * Returns a character representing the class. Zero means that no item was
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
407 * recognized. Otherwise "pp" is advanced to after the item.
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
408 */
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
409 static int
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
410 get_equi_class(char_u **pp)
167
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
411 {
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
412 int c;
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
413 int l = 1;
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
414 char_u *p = *pp;
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
415
15854
4ac1c185b0b8 patch 8.1.0934: invalid memory access in search pattern
Bram Moolenaar <Bram@vim.org>
parents: 15792
diff changeset
416 if (p[1] == '=' && p[2] != NUL)
167
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
417 {
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
418 if (has_mbyte)
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 418
diff changeset
419 l = (*mb_ptr2len)(p + 2);
167
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
420 if (p[l + 2] == '=' && p[l + 3] == ']')
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
421 {
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
422 if (has_mbyte)
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
423 c = mb_ptr2char(p + 2);
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
424 else
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
425 c = p[2];
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
426 *pp += l + 4;
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
427 return c;
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
428 }
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
429 }
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
430 return 0;
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
431 }
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
432
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
433 /*
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
434 * Check for a collating element "[.a.]". "pp" points to the '['.
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
435 * Returns a character. Zero means that no item was recognized. Otherwise
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
436 * "pp" is advanced to after the item.
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
437 * Currently only single characters are recognized!
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
438 */
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
439 static int
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
440 get_coll_element(char_u **pp)
167
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
441 {
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
442 int c;
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
443 int l = 1;
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
444 char_u *p = *pp;
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
445
15860
9cd9bf2897de patch 8.1.0937: invalid memory access in search pattern
Bram Moolenaar <Bram@vim.org>
parents: 15856
diff changeset
446 if (p[0] != NUL && p[1] == '.' && p[2] != NUL)
167
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
447 {
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
448 if (has_mbyte)
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 418
diff changeset
449 l = (*mb_ptr2len)(p + 2);
167
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
450 if (p[l + 2] == '.' && p[l + 3] == ']')
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
451 {
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
452 if (has_mbyte)
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
453 c = mb_ptr2char(p + 2);
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
454 else
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
455 c = p[2];
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
456 *pp += l + 4;
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
457 return c;
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
458 }
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
459 }
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
460 return 0;
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
461 }
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
462
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
463 static int reg_cpo_lit; // 'cpoptions' contains 'l' flag
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
464 static int reg_cpo_bsl; // 'cpoptions' contains '\' flag
4744
a62695305e03 updated for version 7.3.1119
Bram Moolenaar <bram@vim.org>
parents: 4732
diff changeset
465
a62695305e03 updated for version 7.3.1119
Bram Moolenaar <bram@vim.org>
parents: 4732
diff changeset
466 static void
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
467 get_cpo_flags(void)
4744
a62695305e03 updated for version 7.3.1119
Bram Moolenaar <bram@vim.org>
parents: 4732
diff changeset
468 {
a62695305e03 updated for version 7.3.1119
Bram Moolenaar <bram@vim.org>
parents: 4732
diff changeset
469 reg_cpo_lit = vim_strchr(p_cpo, CPO_LITERAL) != NULL;
a62695305e03 updated for version 7.3.1119
Bram Moolenaar <bram@vim.org>
parents: 4732
diff changeset
470 reg_cpo_bsl = vim_strchr(p_cpo, CPO_BACKSL) != NULL;
a62695305e03 updated for version 7.3.1119
Bram Moolenaar <bram@vim.org>
parents: 4732
diff changeset
471 }
167
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
472
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
473 /*
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
474 * Skip over a "[]" range.
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
475 * "p" must point to the character after the '['.
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
476 * The returned pointer is on the matching ']', or the terminating NUL.
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
477 */
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
478 static char_u *
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
479 skip_anyof(char_u *p)
167
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
480 {
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
481 int l;
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
482
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
483 if (*p == '^') // Complement of range.
167
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
484 ++p;
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
485 if (*p == ']' || *p == '-')
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
486 ++p;
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
487 while (*p != NUL && *p != ']')
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
488 {
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 418
diff changeset
489 if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1)
167
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
490 p += l;
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
491 else
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
492 if (*p == '-')
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
493 {
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
494 ++p;
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
495 if (*p != ']' && *p != NUL)
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11121
diff changeset
496 MB_PTR_ADV(p);
167
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
497 }
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
498 else if (*p == '\\'
4744
a62695305e03 updated for version 7.3.1119
Bram Moolenaar <bram@vim.org>
parents: 4732
diff changeset
499 && !reg_cpo_bsl
167
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
500 && (vim_strchr(REGEXP_INRANGE, p[1]) != NULL
4744
a62695305e03 updated for version 7.3.1119
Bram Moolenaar <bram@vim.org>
parents: 4732
diff changeset
501 || (!reg_cpo_lit && vim_strchr(REGEXP_ABBR, p[1]) != NULL)))
167
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
502 p += 2;
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
503 else if (*p == '[')
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
504 {
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
505 if (get_char_class(&p) == CLASS_NONE
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
506 && get_equi_class(&p) == 0
6830
70fdcdaf96a6 patch 7.4.736
Bram Moolenaar <bram@vim.org>
parents: 6785
diff changeset
507 && get_coll_element(&p) == 0
70fdcdaf96a6 patch 7.4.736
Bram Moolenaar <bram@vim.org>
parents: 6785
diff changeset
508 && *p != NUL)
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
509 ++p; // it is not a class name and not NUL
167
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
510 }
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
511 else
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
512 ++p;
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
513 }
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
514
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
515 return p;
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
516 }
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
517
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
518 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
519 * Skip past regular expression.
20113
2c23053c654a patch 8.2.0612: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
520 * Stop at end of "startp" or where "delim" is found ('/', '?', etc).
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
521 * Take care of characters with a backslash in front of it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522 * Skip strings inside [ and ].
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
523 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
524 char_u *
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
525 skip_regexp(
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
526 char_u *startp,
20113
2c23053c654a patch 8.2.0612: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
527 int delim,
19892
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19405
diff changeset
528 int magic)
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19405
diff changeset
529 {
23505
bb29b09902d5 patch 8.2.2295: incsearch does not detect empty pattern properly
Bram Moolenaar <Bram@vim.org>
parents: 23471
diff changeset
530 return skip_regexp_ex(startp, delim, magic, NULL, NULL, NULL);
20113
2c23053c654a patch 8.2.0612: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
531 }
2c23053c654a patch 8.2.0612: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
532
2c23053c654a patch 8.2.0612: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
533 /*
2c23053c654a patch 8.2.0612: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
534 * Call skip_regexp() and when the delimiter does not match give an error and
2c23053c654a patch 8.2.0612: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
535 * return NULL.
2c23053c654a patch 8.2.0612: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
536 */
2c23053c654a patch 8.2.0612: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
537 char_u *
2c23053c654a patch 8.2.0612: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
538 skip_regexp_err(
2c23053c654a patch 8.2.0612: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
539 char_u *startp,
2c23053c654a patch 8.2.0612: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
540 int delim,
2c23053c654a patch 8.2.0612: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
541 int magic)
2c23053c654a patch 8.2.0612: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
542 {
2c23053c654a patch 8.2.0612: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
543 char_u *p = skip_regexp(startp, delim, magic);
2c23053c654a patch 8.2.0612: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
544
2c23053c654a patch 8.2.0612: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
545 if (*p != delim)
2c23053c654a patch 8.2.0612: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
546 {
26952
b34ddbca305c patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26917
diff changeset
547 semsg(_(e_missing_delimiter_after_search_pattern_str), startp);
20113
2c23053c654a patch 8.2.0612: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
548 return NULL;
2c23053c654a patch 8.2.0612: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
549 }
2c23053c654a patch 8.2.0612: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
550 return p;
19892
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19405
diff changeset
551 }
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19405
diff changeset
552
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19405
diff changeset
553 /*
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19405
diff changeset
554 * skip_regexp() with extra arguments:
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19405
diff changeset
555 * When "newp" is not NULL and "dirc" is '?', make an allocated copy of the
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19405
diff changeset
556 * expression and change "\?" to "?". If "*newp" is not NULL the expression
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19405
diff changeset
557 * is changed in-place.
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19405
diff changeset
558 * If a "\?" is changed to "?" then "dropped" is incremented, unless NULL.
23505
bb29b09902d5 patch 8.2.2295: incsearch does not detect empty pattern properly
Bram Moolenaar <Bram@vim.org>
parents: 23471
diff changeset
559 * If "magic_val" is not NULL, returns the effective magicness of the pattern
19892
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19405
diff changeset
560 */
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19405
diff changeset
561 char_u *
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19405
diff changeset
562 skip_regexp_ex(
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19405
diff changeset
563 char_u *startp,
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19405
diff changeset
564 int dirc,
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
565 int magic,
19892
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19405
diff changeset
566 char_u **newp,
23505
bb29b09902d5 patch 8.2.2295: incsearch does not detect empty pattern properly
Bram Moolenaar <Bram@vim.org>
parents: 23471
diff changeset
567 int *dropped,
bb29b09902d5 patch 8.2.2295: incsearch does not detect empty pattern properly
Bram Moolenaar <Bram@vim.org>
parents: 23471
diff changeset
568 magic_T *magic_val)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
569 {
23505
bb29b09902d5 patch 8.2.2295: incsearch does not detect empty pattern properly
Bram Moolenaar <Bram@vim.org>
parents: 23471
diff changeset
570 magic_T mymagic;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
571 char_u *p = startp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
572
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573 if (magic)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574 mymagic = MAGIC_ON;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576 mymagic = MAGIC_OFF;
4744
a62695305e03 updated for version 7.3.1119
Bram Moolenaar <bram@vim.org>
parents: 4732
diff changeset
577 get_cpo_flags();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11121
diff changeset
579 for (; p[0] != NUL; MB_PTR_ADV(p))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580 {
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
581 if (p[0] == dirc) // found end of regexp
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
583 if ((p[0] == '[' && mymagic >= MAGIC_ON)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
584 || (p[0] == '\\' && p[1] == '[' && mymagic <= MAGIC_OFF))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
585 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
586 p = skip_anyof(p + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
587 if (p[0] == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590 else if (p[0] == '\\' && p[1] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
591 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
592 if (dirc == '?' && newp != NULL && p[1] == '?')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
593 {
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
594 // change "\?" to "?", make a copy first.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595 if (*newp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597 *newp = vim_strsave(startp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
598 if (*newp != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
599 p = *newp + (p - startp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600 }
19892
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19405
diff changeset
601 if (dropped != NULL)
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19405
diff changeset
602 ++*dropped;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603 if (*newp != NULL)
1621
82b5078be2dd updated for version 7.2a
vimboss
parents: 1602
diff changeset
604 STRMOVE(p, p + 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
605 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
606 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
607 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
608 else
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
609 ++p; // skip next character
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
610 if (*p == 'v')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
611 mymagic = MAGIC_ALL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
612 else if (*p == 'V')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
613 mymagic = MAGIC_NONE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
614 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
615 }
23505
bb29b09902d5 patch 8.2.2295: incsearch does not detect empty pattern properly
Bram Moolenaar <Bram@vim.org>
parents: 23471
diff changeset
616 if (magic_val != NULL)
bb29b09902d5 patch 8.2.2295: incsearch does not detect empty pattern properly
Bram Moolenaar <Bram@vim.org>
parents: 23471
diff changeset
617 *magic_val = mymagic;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
618 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
619 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
620
11525
14b6b79d685b patch 8.0.0645: no error for illegal back reference in NFA engine
Christian Brabandt <cb@256bit.org>
parents: 11521
diff changeset
621 /*
18019
68fd5296bf73 patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17966
diff changeset
622 * Functions for getting characters from the regexp input.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
623 */
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
624 static int prevchr_len; // byte length of previous char
14354
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
625 static int at_start; // True when on the first character
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
626 static int prev_at_start; // True when on the second character
8021
b6b4f354df23 commit https://github.com/vim/vim/commit/7c29f387819b5817b003d2ba73e2b5cf3cb3d0dd
Christian Brabandt <cb@256bit.org>
parents: 7833
diff changeset
627
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
628 /*
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
629 * Start parsing at "str".
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
630 */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
631 static void
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
632 initchr(char_u *str)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
633 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
634 regparse = str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
635 prevchr_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
636 curchr = prevprevchr = prevchr = nextchr = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
637 at_start = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
638 prev_at_start = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
639 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
640
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
641 /*
4679
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
642 * Save the current parse state, so that it can be restored and parsing
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
643 * starts in the same state again.
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
644 */
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
645 static void
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
646 save_parse_state(parse_state_T *ps)
4679
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
647 {
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
648 ps->regparse = regparse;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
649 ps->prevchr_len = prevchr_len;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
650 ps->curchr = curchr;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
651 ps->prevchr = prevchr;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
652 ps->prevprevchr = prevprevchr;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
653 ps->nextchr = nextchr;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
654 ps->at_start = at_start;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
655 ps->prev_at_start = prev_at_start;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
656 ps->regnpar = regnpar;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
657 }
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
658
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
659 /*
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
660 * Restore a previously saved parse state.
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
661 */
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
662 static void
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
663 restore_parse_state(parse_state_T *ps)
4679
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
664 {
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
665 regparse = ps->regparse;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
666 prevchr_len = ps->prevchr_len;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
667 curchr = ps->curchr;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
668 prevchr = ps->prevchr;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
669 prevprevchr = ps->prevprevchr;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
670 nextchr = ps->nextchr;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
671 at_start = ps->at_start;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
672 prev_at_start = ps->prev_at_start;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
673 regnpar = ps->regnpar;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
674 }
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
675
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
676
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
677 /*
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
678 * Get the next character without advancing.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
679 */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
680 static int
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
681 peekchr(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
682 {
167
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
683 static int after_slash = FALSE;
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
684
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
685 if (curchr == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
686 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
687 switch (curchr = regparse[0])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
688 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
689 case '.':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
690 case '[':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
691 case '~':
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
692 // magic when 'magic' is on
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
693 if (reg_magic >= MAGIC_ON)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
694 curchr = Magic(curchr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
695 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
696 case '(':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
697 case ')':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
698 case '{':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
699 case '%':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
700 case '+':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
701 case '=':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
702 case '?':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
703 case '@':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
704 case '!':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
705 case '&':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
706 case '|':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
707 case '<':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
708 case '>':
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
709 case '#': // future ext.
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
710 case '"': // future ext.
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
711 case '\'': // future ext.
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
712 case ',': // future ext.
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
713 case '-': // future ext.
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
714 case ':': // future ext.
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
715 case ';': // future ext.
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
716 case '`': // future ext.
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
717 case '/': // Can't be used in / command
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
718 // magic only after "\v"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
719 if (reg_magic == MAGIC_ALL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
720 curchr = Magic(curchr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
721 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
722 case '*':
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
723 // * is not magic as the very first character, eg "?*ptr", when
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
724 // after '^', eg "/^*ptr" and when after "\(", "\|", "\&". But
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
725 // "\(\*" is not magic, thus must be magic if "after_slash"
167
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
726 if (reg_magic >= MAGIC_ON
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
727 && !at_start
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
728 && !(prev_at_start && prevchr == Magic('^'))
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
729 && (after_slash
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
730 || (prevchr != Magic('(')
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
731 && prevchr != Magic('&')
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
732 && prevchr != Magic('|'))))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
733 curchr = Magic('*');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
734 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
735 case '^':
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
736 // '^' is only magic as the very first character and if it's after
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
737 // "\(", "\|", "\&' or "\n"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
738 if (reg_magic >= MAGIC_OFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
739 && (at_start
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
740 || reg_magic == MAGIC_ALL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
741 || prevchr == Magic('(')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
742 || prevchr == Magic('|')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
743 || prevchr == Magic('&')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
744 || prevchr == Magic('n')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
745 || (no_Magic(prevchr) == '('
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
746 && prevprevchr == Magic('%'))))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
747 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
748 curchr = Magic('^');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
749 at_start = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
750 prev_at_start = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
751 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
752 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
753 case '$':
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
754 // '$' is only magic as the very last char and if it's in front of
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
755 // either "\|", "\)", "\&", or "\n"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
756 if (reg_magic >= MAGIC_OFF)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
757 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
758 char_u *p = regparse + 1;
6041
761687c6808f updated for version 7.4.360
Bram Moolenaar <bram@vim.org>
parents: 5901
diff changeset
759 int is_magic_all = (reg_magic == MAGIC_ALL);
761687c6808f updated for version 7.4.360
Bram Moolenaar <bram@vim.org>
parents: 5901
diff changeset
760
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
761 // ignore \c \C \m \M \v \V and \Z after '$'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
762 while (p[0] == '\\' && (p[1] == 'c' || p[1] == 'C'
6041
761687c6808f updated for version 7.4.360
Bram Moolenaar <bram@vim.org>
parents: 5901
diff changeset
763 || p[1] == 'm' || p[1] == 'M'
761687c6808f updated for version 7.4.360
Bram Moolenaar <bram@vim.org>
parents: 5901
diff changeset
764 || p[1] == 'v' || p[1] == 'V' || p[1] == 'Z'))
761687c6808f updated for version 7.4.360
Bram Moolenaar <bram@vim.org>
parents: 5901
diff changeset
765 {
761687c6808f updated for version 7.4.360
Bram Moolenaar <bram@vim.org>
parents: 5901
diff changeset
766 if (p[1] == 'v')
761687c6808f updated for version 7.4.360
Bram Moolenaar <bram@vim.org>
parents: 5901
diff changeset
767 is_magic_all = TRUE;
761687c6808f updated for version 7.4.360
Bram Moolenaar <bram@vim.org>
parents: 5901
diff changeset
768 else if (p[1] == 'm' || p[1] == 'M' || p[1] == 'V')
761687c6808f updated for version 7.4.360
Bram Moolenaar <bram@vim.org>
parents: 5901
diff changeset
769 is_magic_all = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
770 p += 2;
6041
761687c6808f updated for version 7.4.360
Bram Moolenaar <bram@vim.org>
parents: 5901
diff changeset
771 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
772 if (p[0] == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
773 || (p[0] == '\\'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
774 && (p[1] == '|' || p[1] == '&' || p[1] == ')'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
775 || p[1] == 'n'))
6041
761687c6808f updated for version 7.4.360
Bram Moolenaar <bram@vim.org>
parents: 5901
diff changeset
776 || (is_magic_all
761687c6808f updated for version 7.4.360
Bram Moolenaar <bram@vim.org>
parents: 5901
diff changeset
777 && (p[0] == '|' || p[0] == '&' || p[0] == ')'))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
778 || reg_magic == MAGIC_ALL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
779 curchr = Magic('$');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
780 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
781 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
782 case '\\':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
783 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
784 int c = regparse[1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
785
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
786 if (c == NUL)
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
787 curchr = '\\'; // trailing '\'
27490
fb4c30606b4a patch 8.2.4273: the EBCDIC support is outdated
Bram Moolenaar <Bram@vim.org>
parents: 27468
diff changeset
788 else if (c <= '~' && META_flags[c])
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
789 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
790 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
791 * META contains everything that may be magic sometimes,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
792 * except ^ and $ ("\^" and "\$" are only magic after
6830
70fdcdaf96a6 patch 7.4.736
Bram Moolenaar <bram@vim.org>
parents: 6785
diff changeset
793 * "\V"). We now fetch the next character and toggle its
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
794 * magicness. Therefore, \ is so meta-magic that it is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
795 * not in META.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
796 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
797 curchr = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
798 prev_at_start = at_start;
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
799 at_start = FALSE; // be able to say "/\*ptr"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
800 ++regparse;
167
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
801 ++after_slash;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
802 peekchr();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
803 --regparse;
167
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
804 --after_slash;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
805 curchr = toggle_Magic(curchr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
806 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
807 else if (vim_strchr(REGEXP_ABBR, c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
808 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
809 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
810 * Handle abbreviations, like "\t" for TAB -- webb
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
811 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
812 curchr = backslash_trans(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
813 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
814 else if (reg_magic == MAGIC_NONE && (c == '$' || c == '^'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
815 curchr = toggle_Magic(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
816 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
817 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
818 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
819 * Next character can never be (made) magic?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
820 * Then backslashing it won't do anything.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
821 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
822 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
823 curchr = (*mb_ptr2char)(regparse + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
824 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
825 curchr = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
826 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
827 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
828 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
829
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
830 default:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
831 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
832 curchr = (*mb_ptr2char)(regparse);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
833 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
834 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
835
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
836 return curchr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
837 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
838
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
839 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
840 * Eat one lexed character. Do this in a way that we can undo it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
841 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
842 static void
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
843 skipchr(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
844 {
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
845 // peekchr() eats a backslash, do the same here
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
846 if (*regparse == '\\')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
847 prevchr_len = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
848 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
849 prevchr_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
850 if (regparse[prevchr_len] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
851 {
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 692
diff changeset
852 if (enc_utf8)
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
853 // exclude composing chars that mb_ptr2len does include
1449
799c1db62b42 updated for version 7.1-164
vimboss
parents: 1347
diff changeset
854 prevchr_len += utf_ptr2len(regparse + prevchr_len);
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 692
diff changeset
855 else if (has_mbyte)
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 418
diff changeset
856 prevchr_len += (*mb_ptr2len)(regparse + prevchr_len);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
857 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
858 ++prevchr_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
859 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
860 regparse += prevchr_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
861 prev_at_start = at_start;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
862 at_start = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
863 prevprevchr = prevchr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
864 prevchr = curchr;
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
865 curchr = nextchr; // use previously unget char, or -1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
866 nextchr = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
867 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
868
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
869 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
870 * Skip a character while keeping the value of prev_at_start for at_start.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
871 * prevchr and prevprevchr are also kept.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
872 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
873 static void
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
874 skipchr_keepstart(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
875 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
876 int as = prev_at_start;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
877 int pr = prevchr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
878 int prpr = prevprevchr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
879
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
880 skipchr();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
881 at_start = as;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
882 prevchr = pr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
883 prevprevchr = prpr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
884 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
885
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
886 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
887 * Get the next character from the pattern. We know about magic and such, so
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
888 * therefore we need a lexical analyzer.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
889 */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
890 static int
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
891 getchr(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
892 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
893 int chr = peekchr();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
894
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
895 skipchr();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
896 return chr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
897 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
898
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
899 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
900 * put character back. Works only once!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
901 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
902 static void
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
903 ungetchr(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
904 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
905 nextchr = curchr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
906 curchr = prevchr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
907 prevchr = prevprevchr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
908 at_start = prev_at_start;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
909 prev_at_start = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
910
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
911 // Backup regparse, so that it's at the same position as before the
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
912 // getchr().
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
913 regparse -= prevchr_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
914 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
915
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
916 /*
29
ac33b7c03fac updated for version 7.0018
vimboss
parents: 24
diff changeset
917 * Get and return the value of the hex string at the current position.
ac33b7c03fac updated for version 7.0018
vimboss
parents: 24
diff changeset
918 * Return -1 if there is no valid hex number.
ac33b7c03fac updated for version 7.0018
vimboss
parents: 24
diff changeset
919 * The position is updated:
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
920 * blahblah\%x20asdf
856
8cd729851562 updated for version 7.0g
vimboss
parents: 840
diff changeset
921 * before-^ ^-after
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
922 * The parameter controls the maximum number of input characters. This will be
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
923 * 2 when reading a \%x20 sequence and 4 when reading a \%u20AC sequence.
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
924 */
12752
09c856605191 patch 8.0.1254: undefined left shift in gethexchrs()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
925 static long
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
926 gethexchrs(int maxinputlen)
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
927 {
12752
09c856605191 patch 8.0.1254: undefined left shift in gethexchrs()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
928 long_u nr = 0;
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
929 int c;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
930 int i;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
931
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
932 for (i = 0; i < maxinputlen; ++i)
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
933 {
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
934 c = regparse[0];
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
935 if (!vim_isxdigit(c))
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
936 break;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
937 nr <<= 4;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
938 nr |= hex2nr(c);
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
939 ++regparse;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
940 }
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
941
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
942 if (i == 0)
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
943 return -1;
12752
09c856605191 patch 8.0.1254: undefined left shift in gethexchrs()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
944 return (long)nr;
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
945 }
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
946
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
947 /*
4579
7a2be4a39423 updated for version 7.3.1037
Bram Moolenaar <bram@vim.org>
parents: 4505
diff changeset
948 * Get and return the value of the decimal string immediately after the
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
949 * current position. Return -1 for invalid. Consumes all digits.
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
950 */
12752
09c856605191 patch 8.0.1254: undefined left shift in gethexchrs()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
951 static long
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
952 getdecchrs(void)
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
953 {
12752
09c856605191 patch 8.0.1254: undefined left shift in gethexchrs()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
954 long_u nr = 0;
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
955 int c;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
956 int i;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
957
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
958 for (i = 0; ; ++i)
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
959 {
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
960 c = regparse[0];
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
961 if (c < '0' || c > '9')
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
962 break;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
963 nr *= 10;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
964 nr += c - '0';
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
965 ++regparse;
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
966 curchr = -1; // no longer valid
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
967 }
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
968
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
969 if (i == 0)
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
970 return -1;
12752
09c856605191 patch 8.0.1254: undefined left shift in gethexchrs()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
971 return (long)nr;
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
972 }
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
973
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
974 /*
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
975 * get and return the value of the octal string immediately after the current
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
976 * position. Return -1 for invalid, or 0-255 for valid. Smart enough to handle
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
977 * numbers > 377 correctly (for example, 400 is treated as 40) and doesn't
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
978 * treat 8 or 9 as recognised characters. Position is updated:
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
979 * blahblah\%o210asdf
856
8cd729851562 updated for version 7.0g
vimboss
parents: 840
diff changeset
980 * before-^ ^-after
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
981 */
12752
09c856605191 patch 8.0.1254: undefined left shift in gethexchrs()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
982 static long
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
983 getoctchrs(void)
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
984 {
12752
09c856605191 patch 8.0.1254: undefined left shift in gethexchrs()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
985 long_u nr = 0;
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
986 int c;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
987 int i;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
988
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
989 for (i = 0; i < 3 && nr < 040; ++i)
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
990 {
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
991 c = regparse[0];
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
992 if (c < '0' || c > '7')
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
993 break;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
994 nr <<= 3;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
995 nr |= hex2nr(c);
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
996 ++regparse;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
997 }
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
998
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
999 if (i == 0)
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1000 return -1;
12752
09c856605191 patch 8.0.1254: undefined left shift in gethexchrs()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
1001 return (long)nr;
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1002 }
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1003
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1004 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1005 * read_limits - Read two integers to be taken as a minimum and maximum.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1006 * If the first character is '-', then the range is reversed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1007 * Should end with 'end'. If minval is missing, zero is default, if maxval is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1008 * missing, a very big number is the default.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1009 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1010 static int
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1011 read_limits(long *minval, long *maxval)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1012 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1013 int reverse = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1014 char_u *first_char;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1015 long tmp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1016
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1017 if (*regparse == '-')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1018 {
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1019 // Starts with '-', so reverse the range later
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1020 regparse++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1021 reverse = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1022 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1023 first_char = regparse;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1024 *minval = getdigits(&regparse);
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1025 if (*regparse == ',') // There is a comma
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1026 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1027 if (vim_isdigit(*++regparse))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1028 *maxval = getdigits(&regparse);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1029 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1030 *maxval = MAX_LIMIT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1031 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1032 else if (VIM_ISDIGIT(*first_char))
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1033 *maxval = *minval; // It was \{n} or \{-n}
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1034 else
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1035 *maxval = MAX_LIMIT; // It was \{} or \{-}
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1036 if (*regparse == '\\')
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1037 regparse++; // Allow either \{...} or \{...\}
167
c93c9cad9618 updated for version 7.0051
vimboss
parents: 153
diff changeset
1038 if (*regparse != '}')
26917
d91aea2a612c patch 8.2.3987: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26913
diff changeset
1039 EMSG2_RET_FAIL(_(e_syntax_error_in_str_curlies),
15480
bd12ace1bab2 patch 8.1.0748: using sprintf() instead of semsg()
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1040 reg_magic == MAGIC_ALL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1041
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1042 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1043 * Reverse the range if there was a '-', or make sure it is in the right
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1044 * order otherwise.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1045 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1046 if ((!reverse && *minval > *maxval) || (reverse && *minval < *maxval))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1047 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1048 tmp = *minval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1049 *minval = *maxval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1050 *maxval = tmp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1051 }
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1052 skipchr(); // let's be friends with the lexer again
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1053 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1054 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1055
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1056 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1057 * vim_regexec and friends
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1058 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1059
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1060 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1061 * Global work variables for vim_regexec().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1062 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1063
7805
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7009
diff changeset
1064 static void cleanup_subexpr(void);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1065 #ifdef FEAT_SYN_HL
7805
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7009
diff changeset
1066 static void cleanup_zsubexpr(void);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7009
diff changeset
1067 #endif
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7009
diff changeset
1068 static void reg_nextline(void);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7009
diff changeset
1069 static int match_with_backref(linenr_T start_lnum, colnr_T start_col, linenr_T end_lnum, colnr_T end_col, int *bytelen);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1070
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1071 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1072 * Sometimes need to save a copy of a line. Since alloc()/free() is very
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1073 * slow, we keep one allocated piece of memory and only re-allocate it when
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
1074 * it's too small. It's freed in bt_regexec_both() when finished.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1075 */
1468
200b706675a5 updated for version 7.1-183
vimboss
parents: 1458
diff changeset
1076 static char_u *reg_tofree = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1077 static unsigned reg_tofreelen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1078
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1079 /*
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1080 * Structure used to store the execution state of the regex engine.
1209
070f2ac50cf8 updated for version 7.1b
vimboss
parents: 1148
diff changeset
1081 * Which ones are set depends on whether a single-line or multi-line match is
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1082 * done:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1083 * single-line multi-line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1084 * reg_match &regmatch_T NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1085 * reg_mmatch NULL &regmmatch_T
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1086 * reg_startp reg_match->startp <invalid>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1087 * reg_endp reg_match->endp <invalid>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1088 * reg_startpos <invalid> reg_mmatch->startpos
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1089 * reg_endpos <invalid> reg_mmatch->endpos
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1090 * reg_win NULL window in which to search
4061
be4baed0c933 updated for version 7.3.785
Bram Moolenaar <bram@vim.org>
parents: 4043
diff changeset
1091 * reg_buf curbuf buffer in which to search
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1092 * reg_firstlnum <invalid> first line in which to search
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1093 * reg_maxline 0 last line nr
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1094 * reg_line_lbr FALSE or TRUE FALSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1095 */
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1096 typedef struct {
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1097 regmatch_T *reg_match;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1098 regmmatch_T *reg_mmatch;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1099 char_u **reg_startp;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1100 char_u **reg_endp;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1101 lpos_T *reg_startpos;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1102 lpos_T *reg_endpos;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1103 win_T *reg_win;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1104 buf_T *reg_buf;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1105 linenr_T reg_firstlnum;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1106 linenr_T reg_maxline;
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1107 int reg_line_lbr; // "\n" in string is line break
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1108
14354
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1109 // The current match-position is stord in these variables:
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1110 linenr_T lnum; // line number, relative to first line
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1111 char_u *line; // start of current line
26161
9835f424bef5 patch 8.2.3612: using freed memory with regexp using a mark
Bram Moolenaar <Bram@vim.org>
parents: 25320
diff changeset
1112 char_u *input; // current input, points into "line"
14354
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1113
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1114 int need_clear_subexpr; // subexpressions still need to be cleared
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1115 #ifdef FEAT_SYN_HL
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1116 int need_clear_zsubexpr; // extmatch subexpressions still need to be
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1117 // cleared
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1118 #endif
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1119
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1120 // Internal copy of 'ignorecase'. It is set at each call to vim_regexec().
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1121 // Normally it gets the value of "rm_ic" or "rmm_ic", but when the pattern
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1122 // contains '\c' or '\C' the value is overruled.
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1123 int reg_ic;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1124
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1125 // Similar to "reg_ic", but only for 'combining' characters. Set with \Z
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1126 // flag in the regexp. Defaults to false, always.
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1127 int reg_icombine;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1128
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1129 // Copy of "rmm_maxcol": maximum column to search for a match. Zero when
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1130 // there is no maximum.
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1131 colnr_T reg_maxcol;
14354
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1132
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1133 // State for the NFA engine regexec.
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1134 int nfa_has_zend; // NFA regexp \ze operator encountered.
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1135 int nfa_has_backref; // NFA regexp \1 .. \9 encountered.
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1136 int nfa_nsubexpr; // Number of sub expressions actually being used
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1137 // during execution. 1 if only the whole match
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1138 // (subexpr 0) is used.
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1139 // listid is global, so that it increases on recursive calls to
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1140 // nfa_regmatch(), which means we don't have to clear the lastlist field of
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1141 // all the states.
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1142 int nfa_listid;
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1143 int nfa_alt_listid;
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1144
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1145 #ifdef FEAT_SYN_HL
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1146 int nfa_has_zsubexpr; // NFA regexp has \z( ), set zsubexpr.
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1147 #endif
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1148 } regexec_T;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1149
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1150 static regexec_T rex;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1151 static int rex_in_use = FALSE;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1152
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1153 /*
15709
2e2f07561f4b patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents: 15603
diff changeset
1154 * Return TRUE if character 'c' is included in 'iskeyword' option for
2e2f07561f4b patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents: 15603
diff changeset
1155 * "reg_buf" buffer.
2e2f07561f4b patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents: 15603
diff changeset
1156 */
2e2f07561f4b patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents: 15603
diff changeset
1157 static int
2e2f07561f4b patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents: 15603
diff changeset
1158 reg_iswordc(int c)
2e2f07561f4b patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents: 15603
diff changeset
1159 {
2e2f07561f4b patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents: 15603
diff changeset
1160 return vim_iswordc_buf(c, rex.reg_buf);
2e2f07561f4b patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents: 15603
diff changeset
1161 }
2e2f07561f4b patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents: 15603
diff changeset
1162
2e2f07561f4b patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents: 15603
diff changeset
1163 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1164 * Get pointer to the line "lnum", which is relative to "reg_firstlnum".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1165 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1166 static char_u *
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1167 reg_getline(linenr_T lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1168 {
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1169 // when looking behind for a match/no-match lnum is negative. But we
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1170 // can't go before line 1
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1171 if (rex.reg_firstlnum + lnum < 1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1172 return NULL;
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1173 if (lnum > rex.reg_maxline)
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1174 // Must have matched the "\n" in the last line.
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 474
diff changeset
1175 return (char_u *)"";
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1176 return ml_get_buf(rex.reg_buf, rex.reg_firstlnum + lnum, FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1177 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1178
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1179 #ifdef FEAT_SYN_HL
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1180 static char_u *reg_startzp[NSUBEXP]; // Workspace to mark beginning
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1181 static char_u *reg_endzp[NSUBEXP]; // and end of \z(...\) matches
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1182 static lpos_T reg_startzpos[NSUBEXP]; // idem, beginning pos
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1183 static lpos_T reg_endzpos[NSUBEXP]; // idem, end pos
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1184 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1185
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1186 // TRUE if using multi-line regexp.
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1187 #define REG_MULTI (rex.reg_match == NULL)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
1188
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1189 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1190 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1191 * Create a new extmatch and mark it as referenced once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1192 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1193 static reg_extmatch_T *
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1194 make_extmatch(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1195 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1196 reg_extmatch_T *em;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1197
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
1198 em = ALLOC_CLEAR_ONE(reg_extmatch_T);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1199 if (em != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1200 em->refcnt = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1201 return em;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1202 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1203
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1204 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1205 * Add a reference to an extmatch.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1206 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1207 reg_extmatch_T *
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1208 ref_extmatch(reg_extmatch_T *em)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1209 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1210 if (em != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1211 em->refcnt++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1212 return em;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1213 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1214
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1215 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1216 * Remove a reference to an extmatch. If there are no references left, free
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1217 * the info.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1218 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1219 void
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1220 unref_extmatch(reg_extmatch_T *em)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1221 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1222 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1223
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1224 if (em != NULL && --em->refcnt <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1225 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1226 for (i = 0; i < NSUBEXP; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1227 vim_free(em->matches[i]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1228 vim_free(em);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1229 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1230 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1231 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1232
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1233 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1234 * Get class of previous character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1235 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1236 static int
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1237 reg_prev_class(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1238 {
14354
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1239 if (rex.input > rex.line)
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1240 return mb_get_class_buf(rex.input - 1
15603
639b8318472c patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1241 - (*mb_head_off)(rex.line, rex.input - 1), rex.reg_buf);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1242 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1243 }
5735
50dbef5e774a updated for version 7.4.212
Bram Moolenaar <bram@vim.org>
parents: 5504
diff changeset
1244
4730
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1245 /*
14354
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1246 * Return TRUE if the current rex.input position matches the Visual area.
4730
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1247 */
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1248 static int
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1249 reg_match_visual(void)
4730
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1250 {
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1251 pos_T top, bot;
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1252 linenr_T lnum;
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1253 colnr_T col;
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1254 win_T *wp = rex.reg_win == NULL ? curwin : rex.reg_win;
4730
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1255 int mode;
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1256 colnr_T start, end;
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1257 colnr_T start2, end2;
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1258 colnr_T cols;
24745
b1fa3f005c93 patch 8.2.2911: pattern "%V" does not match all of block selection
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1259 colnr_T curswant;
4730
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1260
27466
8ed815f061af patch 8.2.4261: accessing invalid memory in a regular expression
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
1261 // Check if the buffer is the current buffer and not using a string.
27468
678ea52c15a0 patch 8.2.4262: some search tests fail
Bram Moolenaar <Bram@vim.org>
parents: 27466
diff changeset
1262 if (rex.reg_buf != curbuf || VIsual.lnum == 0 || !REG_MULTI)
4730
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1263 return FALSE;
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1264
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1265 if (VIsual_active)
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1266 {
11121
778c10516955 patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 10359
diff changeset
1267 if (LT_POS(VIsual, wp->w_cursor))
4730
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1268 {
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1269 top = VIsual;
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1270 bot = wp->w_cursor;
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1271 }
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1272 else
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1273 {
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1274 top = wp->w_cursor;
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1275 bot = VIsual;
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1276 }
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1277 mode = VIsual_mode;
24745
b1fa3f005c93 patch 8.2.2911: pattern "%V" does not match all of block selection
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1278 curswant = wp->w_curswant;
4730
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1279 }
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1280 else
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1281 {
11121
778c10516955 patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 10359
diff changeset
1282 if (LT_POS(curbuf->b_visual.vi_start, curbuf->b_visual.vi_end))
4730
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1283 {
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1284 top = curbuf->b_visual.vi_start;
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1285 bot = curbuf->b_visual.vi_end;
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1286 }
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1287 else
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1288 {
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1289 top = curbuf->b_visual.vi_end;
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1290 bot = curbuf->b_visual.vi_start;
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1291 }
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1292 mode = curbuf->b_visual.vi_mode;
24745
b1fa3f005c93 patch 8.2.2911: pattern "%V" does not match all of block selection
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1293 curswant = curbuf->b_visual.vi_curswant;
4730
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1294 }
14354
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1295 lnum = rex.lnum + rex.reg_firstlnum;
4730
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1296 if (lnum < top.lnum || lnum > bot.lnum)
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1297 return FALSE;
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1298
26841
48d6f187e9c0 patch 8.2.3949: using freed memory with /%V
Bram Moolenaar <Bram@vim.org>
parents: 26534
diff changeset
1299 col = (colnr_T)(rex.input - rex.line);
4730
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1300 if (mode == 'v')
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1301 {
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1302 if ((lnum == top.lnum && col < top.col)
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1303 || (lnum == bot.lnum && col >= bot.col + (*p_sel != 'e')))
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1304 return FALSE;
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1305 }
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1306 else if (mode == Ctrl_V)
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1307 {
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1308 getvvcol(wp, &top, &start, NULL, &end);
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1309 getvvcol(wp, &bot, &start2, NULL, &end2);
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1310 if (start2 < start)
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1311 start = start2;
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1312 if (end2 > end)
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1313 end = end2;
24745
b1fa3f005c93 patch 8.2.2911: pattern "%V" does not match all of block selection
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1314 if (top.col == MAXCOL || bot.col == MAXCOL || curswant == MAXCOL)
4730
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1315 end = MAXCOL;
26841
48d6f187e9c0 patch 8.2.3949: using freed memory with /%V
Bram Moolenaar <Bram@vim.org>
parents: 26534
diff changeset
1316
48d6f187e9c0 patch 8.2.3949: using freed memory with /%V
Bram Moolenaar <Bram@vim.org>
parents: 26534
diff changeset
1317 // getvvcol() flushes rex.line, need to get it again
48d6f187e9c0 patch 8.2.3949: using freed memory with /%V
Bram Moolenaar <Bram@vim.org>
parents: 26534
diff changeset
1318 rex.line = reg_getline(rex.lnum);
48d6f187e9c0 patch 8.2.3949: using freed memory with /%V
Bram Moolenaar <Bram@vim.org>
parents: 26534
diff changeset
1319 rex.input = rex.line + col;
48d6f187e9c0 patch 8.2.3949: using freed memory with /%V
Bram Moolenaar <Bram@vim.org>
parents: 26534
diff changeset
1320
29451
057c26b5c33a patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents: 29410
diff changeset
1321 cols = win_linetabsize(wp, rex.reg_firstlnum + rex.lnum, rex.line, col);
4730
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1322 if (cols < start || cols > end - (*p_sel == 'e'))
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1323 return FALSE;
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1324 }
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1325 return TRUE;
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1326 }
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
1327
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1328 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1329 * Check the regexp program for its magic number.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1330 * Return TRUE if it's wrong.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1331 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1332 static int
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1333 prog_magic_wrong(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1334 {
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
1335 regprog_T *prog;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
1336
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1337 prog = REG_MULTI ? rex.reg_mmatch->regprog : rex.reg_match->regprog;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
1338 if (prog->engine == &nfa_regengine)
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1339 // For NFA matcher we don't check the magic
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
1340 return FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
1341
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
1342 if (UCHARAT(((bt_regprog_T *)prog)->program) != REGMAGIC)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1343 {
25306
078edc1821bf patch 8.2.3190: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1344 emsg(_(e_corrupted_regexp_program));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1345 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1346 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1347 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1348 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1349
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1350 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1351 * Cleanup the subexpressions, if this wasn't done yet.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1352 * This construction is used to clear the subexpressions only when they are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1353 * used (to increase speed).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1354 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1355 static void
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1356 cleanup_subexpr(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1357 {
14354
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1358 if (rex.need_clear_subexpr)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1359 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1360 if (REG_MULTI)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1361 {
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1362 // Use 0xff to set lnum to -1
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1363 vim_memset(rex.reg_startpos, 0xff, sizeof(lpos_T) * NSUBEXP);
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1364 vim_memset(rex.reg_endpos, 0xff, sizeof(lpos_T) * NSUBEXP);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1365 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1366 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1367 {
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1368 vim_memset(rex.reg_startp, 0, sizeof(char_u *) * NSUBEXP);
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1369 vim_memset(rex.reg_endp, 0, sizeof(char_u *) * NSUBEXP);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1370 }
14354
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1371 rex.need_clear_subexpr = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1372 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1373 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1374
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1375 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1376 static void
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1377 cleanup_zsubexpr(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1378 {
14354
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1379 if (rex.need_clear_zsubexpr)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1380 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1381 if (REG_MULTI)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1382 {
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1383 // Use 0xff to set lnum to -1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1384 vim_memset(reg_startzpos, 0xff, sizeof(lpos_T) * NSUBEXP);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1385 vim_memset(reg_endzpos, 0xff, sizeof(lpos_T) * NSUBEXP);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1386 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1387 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1388 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1389 vim_memset(reg_startzp, 0, sizeof(char_u *) * NSUBEXP);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1390 vim_memset(reg_endzp, 0, sizeof(char_u *) * NSUBEXP);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1391 }
14354
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1392 rex.need_clear_zsubexpr = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1393 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1394 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1395 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1396
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1397 /*
14354
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1398 * Advance rex.lnum, rex.line and rex.input to the next line.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1399 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1400 static void
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1401 reg_nextline(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1402 {
14354
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1403 rex.line = reg_getline(++rex.lnum);
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1404 rex.input = rex.line;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1405 fast_breakcheck();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1406 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1407
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1408 /*
4891
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1409 * Check whether a backreference matches.
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1410 * Returns RA_FAIL, RA_NOMATCH or RA_MATCH.
5504
ec5d11403c19 updated for version 7.4.101
Bram Moolenaar <bram@vim.org>
parents: 5353
diff changeset
1411 * If "bytelen" is not NULL, it is set to the byte length of the match in the
ec5d11403c19 updated for version 7.4.101
Bram Moolenaar <bram@vim.org>
parents: 5353
diff changeset
1412 * last line.
4891
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1413 */
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1414 static int
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1415 match_with_backref(
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1416 linenr_T start_lnum,
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1417 colnr_T start_col,
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1418 linenr_T end_lnum,
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1419 colnr_T end_col,
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1420 int *bytelen)
4891
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1421 {
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1422 linenr_T clnum = start_lnum;
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1423 colnr_T ccol = start_col;
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1424 int len;
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1425 char_u *p;
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1426
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1427 if (bytelen != NULL)
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1428 *bytelen = 0;
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1429 for (;;)
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1430 {
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1431 // Since getting one line may invalidate the other, need to make copy.
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1432 // Slow!
14354
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1433 if (rex.line != reg_tofree)
4891
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1434 {
14354
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1435 len = (int)STRLEN(rex.line);
4891
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1436 if (reg_tofree == NULL || len >= (int)reg_tofreelen)
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1437 {
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1438 len += 50; // get some extra
4891
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1439 vim_free(reg_tofree);
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1440 reg_tofree = alloc(len);
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1441 if (reg_tofree == NULL)
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1442 return RA_FAIL; // out of memory!
4891
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1443 reg_tofreelen = len;
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1444 }
14354
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1445 STRCPY(reg_tofree, rex.line);
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1446 rex.input = reg_tofree + (rex.input - rex.line);
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1447 rex.line = reg_tofree;
4891
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1448 }
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1449
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1450 // Get the line to compare with.
4891
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1451 p = reg_getline(clnum);
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1452 if (clnum == end_lnum)
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1453 len = end_col - ccol;
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1454 else
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1455 len = (int)STRLEN(p + ccol);
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1456
14354
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1457 if (cstrncmp(p + ccol, rex.input, &len) != 0)
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1458 return RA_NOMATCH; // doesn't match
4891
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1459 if (bytelen != NULL)
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1460 *bytelen += len;
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1461 if (clnum == end_lnum)
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1462 break; // match and at end!
14354
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
1463 if (rex.lnum >= rex.reg_maxline)
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1464 return RA_NOMATCH; // text too short
4891
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1465
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1466 // Advance to next line.
4891
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1467 reg_nextline();
5504
ec5d11403c19 updated for version 7.4.101
Bram Moolenaar <bram@vim.org>
parents: 5353
diff changeset
1468 if (bytelen != NULL)
ec5d11403c19 updated for version 7.4.101
Bram Moolenaar <bram@vim.org>
parents: 5353
diff changeset
1469 *bytelen = 0;
4891
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1470 ++clnum;
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1471 ccol = 0;
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1472 if (got_int)
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1473 return RA_FAIL;
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1474 }
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1475
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1476 // found a match! Note that rex.line may now point to a copy of the line,
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1477 // that should not matter.
4891
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1478 return RA_MATCH;
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
1479 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1480
6203
8515b42f939c updated for version 7.4.437
Bram Moolenaar <bram@vim.org>
parents: 6041
diff changeset
1481 /*
8515b42f939c updated for version 7.4.437
Bram Moolenaar <bram@vim.org>
parents: 6041
diff changeset
1482 * Used in a place where no * or \+ can follow.
8515b42f939c updated for version 7.4.437
Bram Moolenaar <bram@vim.org>
parents: 6041
diff changeset
1483 */
8515b42f939c updated for version 7.4.437
Bram Moolenaar <bram@vim.org>
parents: 6041
diff changeset
1484 static int
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1485 re_mult_next(char *what)
6203
8515b42f939c updated for version 7.4.437
Bram Moolenaar <bram@vim.org>
parents: 6041
diff changeset
1486 {
8515b42f939c updated for version 7.4.437
Bram Moolenaar <bram@vim.org>
parents: 6041
diff changeset
1487 if (re_multi_type(peekchr()) == MULTI_MULT)
15480
bd12ace1bab2 patch 8.1.0748: using sprintf() instead of semsg()
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1488 {
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
1489 semsg(_(e_nfa_regexp_cannot_repeat_str), what);
15480
bd12ace1bab2 patch 8.1.0748: using sprintf() instead of semsg()
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1490 rc_did_emsg = TRUE;
bd12ace1bab2 patch 8.1.0748: using sprintf() instead of semsg()
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1491 return FAIL;
bd12ace1bab2 patch 8.1.0748: using sprintf() instead of semsg()
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1492 }
6203
8515b42f939c updated for version 7.4.437
Bram Moolenaar <bram@vim.org>
parents: 6041
diff changeset
1493 return OK;
8515b42f939c updated for version 7.4.437
Bram Moolenaar <bram@vim.org>
parents: 6041
diff changeset
1494 }
8515b42f939c updated for version 7.4.437
Bram Moolenaar <bram@vim.org>
parents: 6041
diff changeset
1495
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1496 typedef struct
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1497 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1498 int a, b, c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1499 } decomp_T;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1500
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1501
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1502 // 0xfb20 - 0xfb4f
297
9a1c2a8186b7 updated for version 7.0078
vimboss
parents: 270
diff changeset
1503 static decomp_T decomp_table[0xfb4f-0xfb20+1] =
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1504 {
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1505 {0x5e2,0,0}, // 0xfb20 alt ayin
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1506 {0x5d0,0,0}, // 0xfb21 alt alef
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1507 {0x5d3,0,0}, // 0xfb22 alt dalet
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1508 {0x5d4,0,0}, // 0xfb23 alt he
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1509 {0x5db,0,0}, // 0xfb24 alt kaf
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1510 {0x5dc,0,0}, // 0xfb25 alt lamed
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1511 {0x5dd,0,0}, // 0xfb26 alt mem-sofit
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1512 {0x5e8,0,0}, // 0xfb27 alt resh
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1513 {0x5ea,0,0}, // 0xfb28 alt tav
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1514 {'+', 0, 0}, // 0xfb29 alt plus
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1515 {0x5e9, 0x5c1, 0}, // 0xfb2a shin+shin-dot
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1516 {0x5e9, 0x5c2, 0}, // 0xfb2b shin+sin-dot
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1517 {0x5e9, 0x5c1, 0x5bc}, // 0xfb2c shin+shin-dot+dagesh
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1518 {0x5e9, 0x5c2, 0x5bc}, // 0xfb2d shin+sin-dot+dagesh
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1519 {0x5d0, 0x5b7, 0}, // 0xfb2e alef+patah
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1520 {0x5d0, 0x5b8, 0}, // 0xfb2f alef+qamats
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1521 {0x5d0, 0x5b4, 0}, // 0xfb30 alef+hiriq
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1522 {0x5d1, 0x5bc, 0}, // 0xfb31 bet+dagesh
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1523 {0x5d2, 0x5bc, 0}, // 0xfb32 gimel+dagesh
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1524 {0x5d3, 0x5bc, 0}, // 0xfb33 dalet+dagesh
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1525 {0x5d4, 0x5bc, 0}, // 0xfb34 he+dagesh
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1526 {0x5d5, 0x5bc, 0}, // 0xfb35 vav+dagesh
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1527 {0x5d6, 0x5bc, 0}, // 0xfb36 zayin+dagesh
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1528 {0xfb37, 0, 0}, // 0xfb37 -- UNUSED
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1529 {0x5d8, 0x5bc, 0}, // 0xfb38 tet+dagesh
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1530 {0x5d9, 0x5bc, 0}, // 0xfb39 yud+dagesh
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1531 {0x5da, 0x5bc, 0}, // 0xfb3a kaf sofit+dagesh
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1532 {0x5db, 0x5bc, 0}, // 0xfb3b kaf+dagesh
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1533 {0x5dc, 0x5bc, 0}, // 0xfb3c lamed+dagesh
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1534 {0xfb3d, 0, 0}, // 0xfb3d -- UNUSED
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1535 {0x5de, 0x5bc, 0}, // 0xfb3e mem+dagesh
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1536 {0xfb3f, 0, 0}, // 0xfb3f -- UNUSED
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1537 {0x5e0, 0x5bc, 0}, // 0xfb40 nun+dagesh
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1538 {0x5e1, 0x5bc, 0}, // 0xfb41 samech+dagesh
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1539 {0xfb42, 0, 0}, // 0xfb42 -- UNUSED
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1540 {0x5e3, 0x5bc, 0}, // 0xfb43 pe sofit+dagesh
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1541 {0x5e4, 0x5bc,0}, // 0xfb44 pe+dagesh
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1542 {0xfb45, 0, 0}, // 0xfb45 -- UNUSED
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1543 {0x5e6, 0x5bc, 0}, // 0xfb46 tsadi+dagesh
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1544 {0x5e7, 0x5bc, 0}, // 0xfb47 qof+dagesh
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1545 {0x5e8, 0x5bc, 0}, // 0xfb48 resh+dagesh
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1546 {0x5e9, 0x5bc, 0}, // 0xfb49 shin+dagesh
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1547 {0x5ea, 0x5bc, 0}, // 0xfb4a tav+dagesh
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1548 {0x5d5, 0x5b9, 0}, // 0xfb4b vav+holam
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1549 {0x5d1, 0x5bf, 0}, // 0xfb4c bet+rafe
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1550 {0x5db, 0x5bf, 0}, // 0xfb4d kaf+rafe
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1551 {0x5e4, 0x5bf, 0}, // 0xfb4e pe+rafe
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1552 {0x5d0, 0x5dc, 0} // 0xfb4f alef-lamed
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1553 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1554
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1555 static void
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1556 mb_decompose(int c, int *c1, int *c2, int *c3)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1557 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1558 decomp_T d;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1559
4505
d037b9cbdaaa updated for version 7.3.1000
Bram Moolenaar <bram@vim.org>
parents: 4466
diff changeset
1560 if (c >= 0xfb20 && c <= 0xfb4f)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1561 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1562 d = decomp_table[c - 0xfb20];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1563 *c1 = d.a;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1564 *c2 = d.b;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1565 *c3 = d.c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1566 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1567 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1568 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1569 *c1 = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1570 *c2 = *c3 = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1571 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1572 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1573
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1574 /*
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1575 * Compare two strings, ignore case if rex.reg_ic set.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1576 * Return 0 if strings match, non-zero otherwise.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1577 * Correct the length "*n" when composing characters are ignored.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1578 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1579 static int
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1580 cstrncmp(char_u *s1, char_u *s2, int *n)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1581 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1582 int result;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1583
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1584 if (!rex.reg_ic)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1585 result = STRNCMP(s1, s2, *n);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1586 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1587 result = MB_STRNICMP(s1, s2, *n);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1588
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1589 // if it failed and it's utf8 and we want to combineignore:
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1590 if (result != 0 && enc_utf8 && rex.reg_icombine)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1591 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1592 char_u *str1, *str2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1593 int c1, c2, c11, c12;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1594 int junk;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1595
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1596 // we have to handle the strcmp ourselves, since it is necessary to
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1597 // deal with the composing characters by ignoring them:
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1598 str1 = s1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1599 str2 = s2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1600 c1 = c2 = 0;
507
a1059cda45f2 updated for version 7.0142
vimboss
parents: 492
diff changeset
1601 while ((int)(str1 - s1) < *n)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1602 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1603 c1 = mb_ptr2char_adv(&str1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1604 c2 = mb_ptr2char_adv(&str2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1605
18019
68fd5296bf73 patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17966
diff changeset
1606 // Decompose the character if necessary, into 'base' characters.
68fd5296bf73 patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17966
diff changeset
1607 // Currently hard-coded for Hebrew, Arabic to be done...
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1608 if (c1 != c2 && (!rex.reg_ic || utf_fold(c1) != utf_fold(c2)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1609 {
18019
68fd5296bf73 patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17966
diff changeset
1610 // decomposition necessary?
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1611 mb_decompose(c1, &c11, &junk, &junk);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1612 mb_decompose(c2, &c12, &junk, &junk);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1613 c1 = c11;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1614 c2 = c12;
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1615 if (c11 != c12
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1616 && (!rex.reg_ic || utf_fold(c11) != utf_fold(c12)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1617 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1618 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1619 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1620 result = c2 - c1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1621 if (result == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1622 *n = (int)(str2 - s2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1623 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1624
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1625 return result;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1626 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1627
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1628 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1629 * cstrchr: This function is used a lot for simple searches, keep it fast!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1630 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1631 static char_u *
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1632 cstrchr(char_u *s, int c)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1633 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1634 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1635 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1636
15603
639b8318472c patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1637 if (!rex.reg_ic || (!enc_utf8 && mb_char2len(c) > 1))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1638 return vim_strchr(s, c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1639
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1640 // tolower() and toupper() can be slow, comparing twice should be a lot
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1641 // faster (esp. when using MS Visual C++!).
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1642 // For UTF-8 need to use folded case.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1643 if (enc_utf8 && c > 0x80)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1644 cc = utf_fold(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1645 else
1347
302a6aa7aca2 updated for version 7.1-061
vimboss
parents: 1341
diff changeset
1646 if (MB_ISUPPER(c))
302a6aa7aca2 updated for version 7.1-061
vimboss
parents: 1341
diff changeset
1647 cc = MB_TOLOWER(c);
302a6aa7aca2 updated for version 7.1-061
vimboss
parents: 1341
diff changeset
1648 else if (MB_ISLOWER(c))
302a6aa7aca2 updated for version 7.1-061
vimboss
parents: 1341
diff changeset
1649 cc = MB_TOUPPER(c);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1650 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1651 return vim_strchr(s, c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1652
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1653 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1654 {
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 418
diff changeset
1655 for (p = s; *p != NUL; p += (*mb_ptr2len)(p))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1656 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1657 if (enc_utf8 && c > 0x80)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1658 {
29527
e7158d889784 patch 9.0.0105: illegal memory access when pattern starts with illegal byte
Bram Moolenaar <Bram@vim.org>
parents: 29451
diff changeset
1659 int uc = utf_ptr2char(p);
e7158d889784 patch 9.0.0105: illegal memory access when pattern starts with illegal byte
Bram Moolenaar <Bram@vim.org>
parents: 29451
diff changeset
1660
e7158d889784 patch 9.0.0105: illegal memory access when pattern starts with illegal byte
Bram Moolenaar <Bram@vim.org>
parents: 29451
diff changeset
1661 // Do not match an illegal byte. E.g. 0xff matches 0xc3 0xbf,
e7158d889784 patch 9.0.0105: illegal memory access when pattern starts with illegal byte
Bram Moolenaar <Bram@vim.org>
parents: 29451
diff changeset
1662 // not 0xff.
e7158d889784 patch 9.0.0105: illegal memory access when pattern starts with illegal byte
Bram Moolenaar <Bram@vim.org>
parents: 29451
diff changeset
1663 if ((uc < 0x80 || uc != *p) && utf_fold(uc) == cc)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1664 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1665 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1666 else if (*p == c || *p == cc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1667 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1668 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1669 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1670 else
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1671 // Faster version for when there are no multi-byte characters.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1672 for (p = s; *p != NUL; ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1673 if (*p == c || *p == cc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1674 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1675
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1676 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1677 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1678
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1679 ////////////////////////////////////////////////////////////////
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1680 // regsub stuff //
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1681 ////////////////////////////////////////////////////////////////
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1682
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1683 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1684 * We should define ftpr as a pointer to a function returning a pointer to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1685 * a function returning a pointer to a function ...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1686 * This is impossible, so we declare a pointer to a function returning a
22151
01cab6232a9a patch 8.2.1625: compiler warning for use of fptr_T
Bram Moolenaar <Bram@vim.org>
parents: 22143
diff changeset
1687 * void pointer. This should work for all compilers.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1688 */
22151
01cab6232a9a patch 8.2.1625: compiler warning for use of fptr_T
Bram Moolenaar <Bram@vim.org>
parents: 22143
diff changeset
1689 typedef void (*(*fptr_T)(int *, int));
7805
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7009
diff changeset
1690
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
1691 static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, int destlen, int flags);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1692
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
1693 static fptr_T
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1694 do_upper(int *d, int c)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1695 {
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
1696 *d = MB_TOUPPER(c);
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
1697
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
1698 return (fptr_T)NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1699 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1700
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
1701 static fptr_T
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1702 do_Upper(int *d, int c)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1703 {
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
1704 *d = MB_TOUPPER(c);
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
1705
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
1706 return (fptr_T)do_Upper;
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
1707 }
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
1708
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
1709 static fptr_T
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1710 do_lower(int *d, int c)
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
1711 {
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
1712 *d = MB_TOLOWER(c);
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
1713
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
1714 return (fptr_T)NULL;
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
1715 }
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
1716
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
1717 static fptr_T
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1718 do_Lower(int *d, int c)
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
1719 {
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
1720 *d = MB_TOLOWER(c);
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
1721
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
1722 return (fptr_T)do_Lower;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1723 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1724
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1725 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1726 * regtilde(): Replace tildes in the pattern by the old pattern.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1727 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1728 * Short explanation of the tilde: It stands for the previous replacement
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1729 * pattern. If that previous pattern also contains a ~ we should go back a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1730 * step further... But we insert the previous pattern into the current one
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1731 * and remember that.
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
1732 * This still does not handle the case where "magic" changes. So require the
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
1733 * user to keep his hands off of "magic".
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1734 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1735 * The tildes are parsed once before the first call to vim_regsub().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1736 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1737 char_u *
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1738 regtilde(char_u *source, int magic)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1739 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1740 char_u *newsub = source;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1741 char_u *tmpsub;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1742 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1743 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1744 int prevlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1745
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1746 for (p = newsub; *p; ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1747 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1748 if ((*p == '~' && magic) || (*p == '\\' && *(p + 1) == '~' && !magic))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1749 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1750 if (reg_prev_sub != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1751 {
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1752 // length = len(newsub) - 1 + len(prev_sub) + 1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1753 prevlen = (int)STRLEN(reg_prev_sub);
16764
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
1754 tmpsub = alloc(STRLEN(newsub) + prevlen);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1755 if (tmpsub != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1756 {
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1757 // copy prefix
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1758 len = (int)(p - newsub); // not including ~
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1759 mch_memmove(tmpsub, newsub, (size_t)len);
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1760 // interpret tilde
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1761 mch_memmove(tmpsub + len, reg_prev_sub, (size_t)prevlen);
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1762 // copy postfix
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1763 if (!magic)
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1764 ++p; // back off backslash
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1765 STRCPY(tmpsub + len + prevlen, p + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1766
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1767 if (newsub != source) // already allocated newsub
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1768 vim_free(newsub);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1769 newsub = tmpsub;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1770 p = newsub + len + prevlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1771 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1772 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1773 else if (magic)
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1774 STRMOVE(p, p + 1); // remove '~'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1775 else
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1776 STRMOVE(p, p + 2); // remove '\~'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1777 --p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1778 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1779 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1780 {
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1781 if (*p == '\\' && p[1]) // skip escaped characters
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1782 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1783 if (has_mbyte)
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 418
diff changeset
1784 p += (*mb_ptr2len)(p) - 1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1785 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1786 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1787
29410
be069ab9d583 patch 9.0.0047: using freed memory with recursive substitute
Bram Moolenaar <Bram@vim.org>
parents: 29272
diff changeset
1788 // Store a copy of newsub in reg_prev_sub. It is always allocated,
be069ab9d583 patch 9.0.0047: using freed memory with recursive substitute
Bram Moolenaar <Bram@vim.org>
parents: 29272
diff changeset
1789 // because recursive calls may make the returned string invalid.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1790 vim_free(reg_prev_sub);
29410
be069ab9d583 patch 9.0.0047: using freed memory with recursive substitute
Bram Moolenaar <Bram@vim.org>
parents: 29272
diff changeset
1791 reg_prev_sub = vim_strsave(newsub);
be069ab9d583 patch 9.0.0047: using freed memory with recursive substitute
Bram Moolenaar <Bram@vim.org>
parents: 29272
diff changeset
1792
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1793 return newsub;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1794 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1795
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1796 #ifdef FEAT_EVAL
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1797 static int can_f_submatch = FALSE; // TRUE when submatch() can be used
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1798
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1799 // These pointers are used for reg_submatch(). Needed for when the
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1800 // substitution string is an expression that contains a call to substitute()
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1801 // and submatch().
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1802 typedef struct {
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1803 regmatch_T *sm_match;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1804 regmmatch_T *sm_mmatch;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1805 linenr_T sm_firstlnum;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1806 linenr_T sm_maxline;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1807 int sm_line_lbr;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1808 } regsubmatch_T;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1809
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1810 static regsubmatch_T rsm; // can only be used when can_f_submatch is TRUE
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1811 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1812
17966
46f95606b9ec patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1813 #ifdef FEAT_EVAL
9626
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1814
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1815 /*
18572
23fef64352a1 patch 8.1.2280: crash when passing partial to substitute()
Bram Moolenaar <Bram@vim.org>
parents: 18019
diff changeset
1816 * Put the submatches in "argv[argskip]" which is a list passed into
23fef64352a1 patch 8.1.2280: crash when passing partial to substitute()
Bram Moolenaar <Bram@vim.org>
parents: 18019
diff changeset
1817 * call_func() by vim_regsub_both().
9626
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1818 */
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1819 static int
30281
d3cfd12839ef patch 9.0.0476: varargs does not work for replacement function of substitute()
Bram Moolenaar <Bram@vim.org>
parents: 29888
diff changeset
1820 fill_submatch_list(int argc UNUSED, typval_T *argv, int argskip, ufunc_T *fp)
9626
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1821 {
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1822 listitem_T *li;
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1823 int i;
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1824 char_u *s;
18572
23fef64352a1 patch 8.1.2280: crash when passing partial to substitute()
Bram Moolenaar <Bram@vim.org>
parents: 18019
diff changeset
1825 typval_T *listarg = argv + argskip;
9626
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1826
30289
085406413994 patch 9.0.0480: cannot use a :def varargs function with substitute()
Bram Moolenaar <Bram@vim.org>
parents: 30281
diff changeset
1827 if (!has_varargs(fp) && fp->uf_args.ga_len <= argskip)
18572
23fef64352a1 patch 8.1.2280: crash when passing partial to substitute()
Bram Moolenaar <Bram@vim.org>
parents: 18019
diff changeset
1828 // called function doesn't take a submatches argument
23fef64352a1 patch 8.1.2280: crash when passing partial to substitute()
Bram Moolenaar <Bram@vim.org>
parents: 18019
diff changeset
1829 return argskip;
9626
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1830
18572
23fef64352a1 patch 8.1.2280: crash when passing partial to substitute()
Bram Moolenaar <Bram@vim.org>
parents: 18019
diff changeset
1831 // Relies on sl_list to be the first item in staticList10_T.
23fef64352a1 patch 8.1.2280: crash when passing partial to substitute()
Bram Moolenaar <Bram@vim.org>
parents: 18019
diff changeset
1832 init_static_list((staticList10_T *)(listarg->vval.v_list));
9626
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1833
18572
23fef64352a1 patch 8.1.2280: crash when passing partial to substitute()
Bram Moolenaar <Bram@vim.org>
parents: 18019
diff changeset
1834 // There are always 10 list items in staticList10_T.
23fef64352a1 patch 8.1.2280: crash when passing partial to substitute()
Bram Moolenaar <Bram@vim.org>
parents: 18019
diff changeset
1835 li = listarg->vval.v_list->lv_first;
9626
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1836 for (i = 0; i < 10; ++i)
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1837 {
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1838 s = rsm.sm_match->startp[i];
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1839 if (s == NULL || rsm.sm_match->endp[i] == NULL)
9626
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1840 s = NULL;
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1841 else
20830
9064044fd4f6 patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents: 20113
diff changeset
1842 s = vim_strnsave(s, rsm.sm_match->endp[i] - s);
9626
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1843 li->li_tv.v_type = VAR_STRING;
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1844 li->li_tv.vval.v_string = s;
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1845 li = li->li_next;
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1846 }
18572
23fef64352a1 patch 8.1.2280: crash when passing partial to substitute()
Bram Moolenaar <Bram@vim.org>
parents: 18019
diff changeset
1847 return argskip + 1;
9626
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1848 }
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1849
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1850 static void
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1851 clear_submatch_list(staticList10_T *sl)
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1852 {
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1853 int i;
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1854
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1855 for (i = 0; i < 10; ++i)
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1856 vim_free(sl->sl_items[i].li_tv.vval.v_string);
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1857 }
17966
46f95606b9ec patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1858 #endif
9626
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
1859
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1860 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1861 * vim_regsub() - perform substitutions after a vim_regexec() or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1862 * vim_regexec_multi() match.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1863 *
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
1864 * If "flags" has REGSUB_COPY really copy into "dest[destlen]".
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
1865 * Oterwise nothing is copied, only compue the length of the result.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1866 *
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
1867 * If "flags" has REGSUB_MAGIC then behave like 'magic' is set.
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
1868 *
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
1869 * If "flags" has REGSUB_BACKSLASH a backslash will be removed later, need to
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
1870 * double them to keep them, and insert a backslash before a CR to avoid it
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
1871 * being replaced with a line break later.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1872 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1873 * Note: The matched text must not change between the call of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1874 * vim_regexec()/vim_regexec_multi() and vim_regsub()! It would make the back
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1875 * references invalid!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1876 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1877 * Returns the size of the replacement, including terminating NUL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1878 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1879 int
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1880 vim_regsub(
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1881 regmatch_T *rmp,
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1882 char_u *source,
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9015
diff changeset
1883 typval_T *expr,
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1884 char_u *dest,
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
1885 int destlen,
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
1886 int flags)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1887 {
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1888 int result;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1889 regexec_T rex_save;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1890 int rex_in_use_save = rex_in_use;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1891
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1892 if (rex_in_use)
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1893 // Being called recursively, save the state.
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1894 rex_save = rex;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1895 rex_in_use = TRUE;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1896
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1897 rex.reg_match = rmp;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1898 rex.reg_mmatch = NULL;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1899 rex.reg_maxline = 0;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1900 rex.reg_buf = curbuf;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1901 rex.reg_line_lbr = TRUE;
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
1902 result = vim_regsub_both(source, expr, dest, destlen, flags);
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1903
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1904 rex_in_use = rex_in_use_save;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1905 if (rex_in_use)
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1906 rex = rex_save;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1907
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1908 return result;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1909 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1910
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1911 int
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1912 vim_regsub_multi(
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1913 regmmatch_T *rmp,
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1914 linenr_T lnum,
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1915 char_u *source,
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1916 char_u *dest,
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
1917 int destlen,
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
1918 int flags)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1919 {
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1920 int result;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1921 regexec_T rex_save;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1922 int rex_in_use_save = rex_in_use;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1923
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1924 if (rex_in_use)
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1925 // Being called recursively, save the state.
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1926 rex_save = rex;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1927 rex_in_use = TRUE;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1928
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1929 rex.reg_match = NULL;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1930 rex.reg_mmatch = rmp;
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1931 rex.reg_buf = curbuf; // always works on the current buffer!
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1932 rex.reg_firstlnum = lnum;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1933 rex.reg_maxline = curbuf->b_ml.ml_line_count - lnum;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1934 rex.reg_line_lbr = FALSE;
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
1935 result = vim_regsub_both(source, NULL, dest, destlen, flags);
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1936
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1937 rex_in_use = rex_in_use_save;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1938 if (rex_in_use)
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1939 rex = rex_save;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1940
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
1941 return result;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1942 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1943
29255
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
1944 #if defined(FEAT_EVAL) || defined(PROTO)
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
1945 // When nesting more than a couple levels it's probably a mistake.
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
1946 # define MAX_REGSUB_NESTING 4
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
1947 static char_u *eval_result[MAX_REGSUB_NESTING] = {NULL, NULL, NULL, NULL};
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
1948
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
1949 # if defined(EXITFREE) || defined(PROTO)
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
1950 void
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
1951 free_resub_eval_result(void)
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
1952 {
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
1953 int i;
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
1954
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
1955 for (i = 0; i < MAX_REGSUB_NESTING; ++i)
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
1956 VIM_CLEAR(eval_result[i]);
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
1957 }
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
1958 # endif
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
1959 #endif
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
1960
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1961 static int
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1962 vim_regsub_both(
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1963 char_u *source,
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9015
diff changeset
1964 typval_T *expr,
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
1965 char_u *dest,
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
1966 int destlen,
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
1967 int flags)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1968 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1969 char_u *src;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1970 char_u *dst;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1971 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1972 int c;
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
1973 int cc;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1974 int no = -1;
4244
7faeece39228 updated for version 7.3.873
Bram Moolenaar <bram@vim.org>
parents: 4176
diff changeset
1975 fptr_T func_all = (fptr_T)NULL;
7faeece39228 updated for version 7.3.873
Bram Moolenaar <bram@vim.org>
parents: 4176
diff changeset
1976 fptr_T func_one = (fptr_T)NULL;
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1977 linenr_T clnum = 0; // init for GCC
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1978 int len = 0; // init for GCC
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1979 #ifdef FEAT_EVAL
29255
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
1980 static int nesting = 0;
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
1981 int nested;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1982 #endif
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
1983 int copy = flags & REGSUB_COPY;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1984
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1985 // Be paranoid...
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9015
diff changeset
1986 if ((source == NULL && expr == NULL) || dest == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1987 {
25306
078edc1821bf patch 8.2.3190: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1988 emsg(_(e_null_argument));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1989 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1990 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1991 if (prog_magic_wrong())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1992 return 0;
29255
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
1993 #ifdef FEAT_EVAL
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
1994 if (nesting == MAX_REGSUB_NESTING)
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
1995 {
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
1996 emsg(_(e_substitute_nesting_too_deep));
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
1997 return 0;
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
1998 }
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
1999 nested = nesting;
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
2000 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2001 src = source;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2002 dst = dest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2003
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2004 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2005 * When the substitute part starts with "\=" evaluate it as an expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2006 */
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2007 if (expr != NULL || (source[0] == '\\' && source[1] == '='))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2008 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2009 #ifdef FEAT_EVAL
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2010 // To make sure that the length doesn't change between checking the
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2011 // length and copying the string, and to speed up things, the
29071
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 29048
diff changeset
2012 // resulting string is saved from the call with
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 29048
diff changeset
2013 // "flags & REGSUB_COPY" == 0 to the call with
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 29048
diff changeset
2014 // "flags & REGSUB_COPY" != 0.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2015 if (copy)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2016 {
29255
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
2017 if (eval_result[nested] != NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2018 {
29255
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
2019 STRCPY(dest, eval_result[nested]);
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
2020 dst += STRLEN(eval_result[nested]);
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
2021 VIM_CLEAR(eval_result[nested]);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2022 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2023 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2024 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2025 {
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2026 int prev_can_f_submatch = can_f_submatch;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2027 regsubmatch_T rsm_save;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2028
29255
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
2029 VIM_CLEAR(eval_result[nested]);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2030
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2031 // The expression may contain substitute(), which calls us
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2032 // recursively. Make sure submatch() gets the text from the first
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2033 // level.
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2034 if (can_f_submatch)
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2035 rsm_save = rsm;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2036 can_f_submatch = TRUE;
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2037 rsm.sm_match = rex.reg_match;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2038 rsm.sm_mmatch = rex.reg_mmatch;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2039 rsm.sm_firstlnum = rex.reg_firstlnum;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2040 rsm.sm_maxline = rex.reg_maxline;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2041 rsm.sm_line_lbr = rex.reg_line_lbr;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2042
29255
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
2043 // Although unlikely, it is possible that the expression invokes a
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
2044 // substitute command (it might fail, but still). Therefore keep
29272
8175cd4c8fdd patch 8.2.5154: still mentioning version8, some cosmetic issues
Bram Moolenaar <Bram@vim.org>
parents: 29255
diff changeset
2045 // an array of eval results.
29255
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
2046 ++nesting;
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
2047
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9015
diff changeset
2048 if (expr != NULL)
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9015
diff changeset
2049 {
9626
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
2050 typval_T argv[2];
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9015
diff changeset
2051 char_u buf[NUMBUFLEN];
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9015
diff changeset
2052 typval_T rettv;
9626
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
2053 staticList10_T matchList;
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17444
diff changeset
2054 funcexe_T funcexe;
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9015
diff changeset
2055
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9015
diff changeset
2056 rettv.v_type = VAR_STRING;
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9015
diff changeset
2057 rettv.vval.v_string = NULL;
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2058 argv[0].v_type = VAR_LIST;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2059 argv[0].vval.v_list = &matchList.sl_list;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2060 matchList.sl_list.lv_len = 0;
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
2061 CLEAR_FIELD(funcexe);
26534
28745eec1dda patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents: 26436
diff changeset
2062 funcexe.fe_argv_func = fill_submatch_list;
28745eec1dda patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents: 26436
diff changeset
2063 funcexe.fe_evaluate = TRUE;
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2064 if (expr->v_type == VAR_FUNC)
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9015
diff changeset
2065 {
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2066 s = expr->vval.v_string;
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17444
diff changeset
2067 call_func(s, -1, &rettv, 1, argv, &funcexe);
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9015
diff changeset
2068 }
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2069 else if (expr->v_type == VAR_PARTIAL)
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9015
diff changeset
2070 {
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2071 partial_T *partial = expr->vval.v_partial;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2072
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2073 s = partial_name(partial);
26534
28745eec1dda patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents: 26436
diff changeset
2074 funcexe.fe_partial = partial;
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17444
diff changeset
2075 call_func(s, -1, &rettv, 1, argv, &funcexe);
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9015
diff changeset
2076 }
28692
bfd8e25fa207 patch 8.2.4870: Vim9: expression in :substitute is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 28572
diff changeset
2077 else if (expr->v_type == VAR_INSTR)
bfd8e25fa207 patch 8.2.4870: Vim9: expression in :substitute is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 28572
diff changeset
2078 {
bfd8e25fa207 patch 8.2.4870: Vim9: expression in :substitute is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 28572
diff changeset
2079 exe_typval_instr(expr, &rettv);
bfd8e25fa207 patch 8.2.4870: Vim9: expression in :substitute is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 28572
diff changeset
2080 }
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2081 if (matchList.sl_list.lv_len > 0)
18576
e9675870c480 patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents: 18572
diff changeset
2082 // fill_submatch_list() was called
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2083 clear_submatch_list(&matchList);
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2084
18576
e9675870c480 patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents: 18572
diff changeset
2085 if (rettv.v_type == VAR_UNKNOWN)
e9675870c480 patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents: 18572
diff changeset
2086 // something failed, no need to report another error
29255
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
2087 eval_result[nested] = NULL;
18576
e9675870c480 patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents: 18572
diff changeset
2088 else
e9675870c480 patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents: 18572
diff changeset
2089 {
29255
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
2090 eval_result[nested] = tv_get_string_buf_chk(&rettv, buf);
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
2091 if (eval_result[nested] != NULL)
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
2092 eval_result[nested] = vim_strsave(eval_result[nested]);
18576
e9675870c480 patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents: 18572
diff changeset
2093 }
9626
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
2094 clear_tv(&rettv);
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9015
diff changeset
2095 }
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 23505
diff changeset
2096 else if (substitute_instr != NULL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 23505
diff changeset
2097 // Execute instructions from ISN_SUBSTITUTE.
29255
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
2098 eval_result[nested] = exe_substitute_instr();
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9015
diff changeset
2099 else
29255
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
2100 eval_result[nested] = eval_to_string(source + 2, TRUE);
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
2101 --nesting;
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9015
diff changeset
2102
29255
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
2103 if (eval_result[nested] != NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2104 {
2125
b8744d1982d1 updated for version 7.2.407
Bram Moolenaar <bram@zimbu.org>
parents: 2012
diff changeset
2105 int had_backslash = FALSE;
b8744d1982d1 updated for version 7.2.407
Bram Moolenaar <bram@zimbu.org>
parents: 2012
diff changeset
2106
29255
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
2107 for (s = eval_result[nested]; *s != NUL; MB_PTR_ADV(s))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2108 {
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2109 // Change NL to CR, so that it becomes a line break,
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2110 // unless called from vim_regexec_nl().
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2111 // Skip over a backslashed character.
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2112 if (*s == NL && !rsm.sm_line_lbr)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2113 *s = CAR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2114 else if (*s == '\\' && s[1] != NUL)
2125
b8744d1982d1 updated for version 7.2.407
Bram Moolenaar <bram@zimbu.org>
parents: 2012
diff changeset
2115 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2116 ++s;
2173
ecb9c2b70b0f updated for version 7.2.437
Bram Moolenaar <bram@vim.org>
parents: 2125
diff changeset
2117 /* Change NL to CR here too, so that this works:
ecb9c2b70b0f updated for version 7.2.437
Bram Moolenaar <bram@vim.org>
parents: 2125
diff changeset
2118 * :s/abc\\\ndef/\="aaa\\\nbbb"/ on text:
ecb9c2b70b0f updated for version 7.2.437
Bram Moolenaar <bram@vim.org>
parents: 2125
diff changeset
2119 * abc\
ecb9c2b70b0f updated for version 7.2.437
Bram Moolenaar <bram@vim.org>
parents: 2125
diff changeset
2120 * def
2904
c249d9aa60f7 updated for version 7.3.225
Bram Moolenaar <bram@vim.org>
parents: 2578
diff changeset
2121 * Not when called from vim_regexec_nl().
2173
ecb9c2b70b0f updated for version 7.2.437
Bram Moolenaar <bram@vim.org>
parents: 2125
diff changeset
2122 */
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2123 if (*s == NL && !rsm.sm_line_lbr)
2173
ecb9c2b70b0f updated for version 7.2.437
Bram Moolenaar <bram@vim.org>
parents: 2125
diff changeset
2124 *s = CAR;
2125
b8744d1982d1 updated for version 7.2.407
Bram Moolenaar <bram@zimbu.org>
parents: 2012
diff changeset
2125 had_backslash = TRUE;
b8744d1982d1 updated for version 7.2.407
Bram Moolenaar <bram@zimbu.org>
parents: 2012
diff changeset
2126 }
b8744d1982d1 updated for version 7.2.407
Bram Moolenaar <bram@zimbu.org>
parents: 2012
diff changeset
2127 }
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2128 if (had_backslash && (flags & REGSUB_BACKSLASH))
2125
b8744d1982d1 updated for version 7.2.407
Bram Moolenaar <bram@zimbu.org>
parents: 2012
diff changeset
2129 {
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2130 // Backslashes will be consumed, need to double them.
29255
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
2131 s = vim_strsave_escaped(eval_result[nested], (char_u *)"\\");
2125
b8744d1982d1 updated for version 7.2.407
Bram Moolenaar <bram@zimbu.org>
parents: 2012
diff changeset
2132 if (s != NULL)
b8744d1982d1 updated for version 7.2.407
Bram Moolenaar <bram@zimbu.org>
parents: 2012
diff changeset
2133 {
29255
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
2134 vim_free(eval_result[nested]);
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
2135 eval_result[nested] = s;
2125
b8744d1982d1 updated for version 7.2.407
Bram Moolenaar <bram@zimbu.org>
parents: 2012
diff changeset
2136 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2137 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2138
29255
5ebc561444fe patch 8.2.5146: memory leak when substitute expression nests
Bram Moolenaar <Bram@vim.org>
parents: 29245
diff changeset
2139 dst += STRLEN(eval_result[nested]);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2140 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2141
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2142 can_f_submatch = prev_can_f_submatch;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2143 if (can_f_submatch)
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2144 rsm = rsm_save;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2145 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2146 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2147 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2148 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2149 while ((c = *src++) != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2150 {
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2151 if (c == '&' && (flags & REGSUB_MAGIC))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2152 no = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2153 else if (c == '\\' && *src != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2154 {
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2155 if (*src == '&' && !(flags & REGSUB_MAGIC))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2156 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2157 ++src;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2158 no = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2159 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2160 else if ('0' <= *src && *src <= '9')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2161 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2162 no = *src++ - '0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2163 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2164 else if (vim_strchr((char_u *)"uUlLeE", *src))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2165 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2166 switch (*src++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2167 {
4244
7faeece39228 updated for version 7.3.873
Bram Moolenaar <bram@vim.org>
parents: 4176
diff changeset
2168 case 'u': func_one = (fptr_T)do_upper;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2169 continue;
4244
7faeece39228 updated for version 7.3.873
Bram Moolenaar <bram@vim.org>
parents: 4176
diff changeset
2170 case 'U': func_all = (fptr_T)do_Upper;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2171 continue;
4244
7faeece39228 updated for version 7.3.873
Bram Moolenaar <bram@vim.org>
parents: 4176
diff changeset
2172 case 'l': func_one = (fptr_T)do_lower;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2173 continue;
4244
7faeece39228 updated for version 7.3.873
Bram Moolenaar <bram@vim.org>
parents: 4176
diff changeset
2174 case 'L': func_all = (fptr_T)do_Lower;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2175 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2176 case 'e':
4244
7faeece39228 updated for version 7.3.873
Bram Moolenaar <bram@vim.org>
parents: 4176
diff changeset
2177 case 'E': func_one = func_all = (fptr_T)NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2178 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2179 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2180 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2181 }
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2182 if (no < 0) // Ordinary character.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2183 {
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 772
diff changeset
2184 if (c == K_SPECIAL && src[0] != NUL && src[1] != NUL)
95dac6af3b3a updated for version 7.0232
vimboss
parents: 772
diff changeset
2185 {
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2186 // Copy a special key as-is.
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 772
diff changeset
2187 if (copy)
95dac6af3b3a updated for version 7.0232
vimboss
parents: 772
diff changeset
2188 {
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2189 if (dst + 3 > dest + destlen)
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2190 {
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2191 iemsg("vim_regsub_both(): not enough space");
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2192 return 0;
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2193 }
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 772
diff changeset
2194 *dst++ = c;
95dac6af3b3a updated for version 7.0232
vimboss
parents: 772
diff changeset
2195 *dst++ = *src++;
95dac6af3b3a updated for version 7.0232
vimboss
parents: 772
diff changeset
2196 *dst++ = *src++;
95dac6af3b3a updated for version 7.0232
vimboss
parents: 772
diff changeset
2197 }
95dac6af3b3a updated for version 7.0232
vimboss
parents: 772
diff changeset
2198 else
95dac6af3b3a updated for version 7.0232
vimboss
parents: 772
diff changeset
2199 {
95dac6af3b3a updated for version 7.0232
vimboss
parents: 772
diff changeset
2200 dst += 3;
95dac6af3b3a updated for version 7.0232
vimboss
parents: 772
diff changeset
2201 src += 2;
95dac6af3b3a updated for version 7.0232
vimboss
parents: 772
diff changeset
2202 }
95dac6af3b3a updated for version 7.0232
vimboss
parents: 772
diff changeset
2203 continue;
95dac6af3b3a updated for version 7.0232
vimboss
parents: 772
diff changeset
2204 }
95dac6af3b3a updated for version 7.0232
vimboss
parents: 772
diff changeset
2205
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2206 if (c == '\\' && *src != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2207 {
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2208 // Check for abbreviations -- webb
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2209 switch (*src)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2210 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2211 case 'r': c = CAR; ++src; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2212 case 'n': c = NL; ++src; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2213 case 't': c = TAB; ++src; break;
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2214 // Oh no! \e already has meaning in subst pat :-(
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2215 // case 'e': c = ESC; ++src; break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2216 case 'b': c = Ctrl_H; ++src; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2217
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2218 // If "backslash" is TRUE the backslash will be removed
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2219 // later. Used to insert a literal CR.
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2220 default: if (flags & REGSUB_BACKSLASH)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2221 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2222 if (copy)
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2223 {
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2224 if (dst + 1 > dest + destlen)
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2225 {
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2226 iemsg("vim_regsub_both(): not enough space");
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2227 return 0;
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2228 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2229 *dst = '\\';
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2230 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2231 ++dst;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2232 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2233 c = *src++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2234 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2235 }
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 772
diff changeset
2236 else if (has_mbyte)
95dac6af3b3a updated for version 7.0232
vimboss
parents: 772
diff changeset
2237 c = mb_ptr2char(src - 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2238
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2239 // Write to buffer, if copy is set.
4244
7faeece39228 updated for version 7.3.873
Bram Moolenaar <bram@vim.org>
parents: 4176
diff changeset
2240 if (func_one != (fptr_T)NULL)
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2241 // Turbo C complains without the typecast
4244
7faeece39228 updated for version 7.3.873
Bram Moolenaar <bram@vim.org>
parents: 4176
diff changeset
2242 func_one = (fptr_T)(func_one(&cc, c));
7faeece39228 updated for version 7.3.873
Bram Moolenaar <bram@vim.org>
parents: 4176
diff changeset
2243 else if (func_all != (fptr_T)NULL)
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2244 // Turbo C complains without the typecast
4244
7faeece39228 updated for version 7.3.873
Bram Moolenaar <bram@vim.org>
parents: 4176
diff changeset
2245 func_all = (fptr_T)(func_all(&cc, c));
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2246 else // just copy
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
2247 cc = c;
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
2248
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
2249 if (has_mbyte)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2250 {
2307
81527f127fb1 Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents: 2247
diff changeset
2251 int totlen = mb_ptr2len(src - 1);
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2252 int charlen = mb_char2len(cc);
2307
81527f127fb1 Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents: 2247
diff changeset
2253
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2254 if (copy)
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2255 {
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2256 if (dst + charlen > dest + destlen)
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2257 {
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2258 iemsg("vim_regsub_both(): not enough space");
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2259 return 0;
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2260 }
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
2261 mb_char2bytes(cc, dst);
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2262 }
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2263 dst += charlen - 1;
2307
81527f127fb1 Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents: 2247
diff changeset
2264 if (enc_utf8)
81527f127fb1 Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents: 2247
diff changeset
2265 {
81527f127fb1 Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents: 2247
diff changeset
2266 int clen = utf_ptr2len(src - 1);
81527f127fb1 Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents: 2247
diff changeset
2267
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2268 // If the character length is shorter than "totlen", there
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2269 // are composing characters; copy them as-is.
2307
81527f127fb1 Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents: 2247
diff changeset
2270 if (clen < totlen)
81527f127fb1 Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents: 2247
diff changeset
2271 {
81527f127fb1 Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents: 2247
diff changeset
2272 if (copy)
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2273 {
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2274 if (dst + totlen - clen > dest + destlen)
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2275 {
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2276 iemsg("vim_regsub_both(): not enough space");
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2277 return 0;
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2278 }
2307
81527f127fb1 Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents: 2247
diff changeset
2279 mch_memmove(dst + 1, src - 1 + clen,
81527f127fb1 Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents: 2247
diff changeset
2280 (size_t)(totlen - clen));
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2281 }
2307
81527f127fb1 Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents: 2247
diff changeset
2282 dst += totlen - clen;
81527f127fb1 Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents: 2247
diff changeset
2283 }
81527f127fb1 Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents: 2247
diff changeset
2284 }
81527f127fb1 Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents: 2247
diff changeset
2285 src += totlen - 1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2286 }
15603
639b8318472c patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
2287 else if (copy)
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2288 {
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2289 if (dst + 1 > dest + destlen)
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2290 {
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2291 iemsg("vim_regsub_both(): not enough space");
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2292 return 0;
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2293 }
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2294 *dst = cc;
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2295 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2296 dst++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2297 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2298 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2299 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2300 if (REG_MULTI)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2301 {
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2302 clnum = rex.reg_mmatch->startpos[no].lnum;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2303 if (clnum < 0 || rex.reg_mmatch->endpos[no].lnum < 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2304 s = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2305 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2306 {
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2307 s = reg_getline(clnum) + rex.reg_mmatch->startpos[no].col;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2308 if (rex.reg_mmatch->endpos[no].lnum == clnum)
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2309 len = rex.reg_mmatch->endpos[no].col
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2310 - rex.reg_mmatch->startpos[no].col;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2311 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2312 len = (int)STRLEN(s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2313 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2314 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2315 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2316 {
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2317 s = rex.reg_match->startp[no];
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2318 if (rex.reg_match->endp[no] == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2319 s = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2320 else
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2321 len = (int)(rex.reg_match->endp[no] - s);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2322 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2323 if (s != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2324 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2325 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2326 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2327 if (len == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2328 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2329 if (REG_MULTI)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2330 {
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2331 if (rex.reg_mmatch->endpos[no].lnum == clnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2332 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2333 if (copy)
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2334 {
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2335 if (dst + 1 > dest + destlen)
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2336 {
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2337 iemsg("vim_regsub_both(): not enough space");
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2338 return 0;
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2339 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2340 *dst = CAR;
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2341 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2342 ++dst;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2343 s = reg_getline(++clnum);
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2344 if (rex.reg_mmatch->endpos[no].lnum == clnum)
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2345 len = rex.reg_mmatch->endpos[no].col;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2346 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2347 len = (int)STRLEN(s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2348 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2349 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2350 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2351 }
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2352 else if (*s == NUL) // we hit NUL.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2353 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2354 if (copy)
25306
078edc1821bf patch 8.2.3190: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
2355 iemsg(_(e_damaged_match_string));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2356 goto exit;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2357 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2358 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2359 {
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2360 if ((flags & REGSUB_BACKSLASH)
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2361 && (*s == CAR || *s == '\\'))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2362 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2363 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2364 * Insert a backslash in front of a CR, otherwise
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2365 * it will be replaced by a line break.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2366 * Number of backslashes will be halved later,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2367 * double them here.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2368 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2369 if (copy)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2370 {
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2371 if (dst + 2 > dest + destlen)
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2372 {
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2373 iemsg("vim_regsub_both(): not enough space");
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2374 return 0;
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2375 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2376 dst[0] = '\\';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2377 dst[1] = *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2378 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2379 dst += 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2380 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2381 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2382 {
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
2383 if (has_mbyte)
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
2384 c = mb_ptr2char(s);
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
2385 else
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
2386 c = *s;
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
2387
4244
7faeece39228 updated for version 7.3.873
Bram Moolenaar <bram@vim.org>
parents: 4176
diff changeset
2388 if (func_one != (fptr_T)NULL)
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2389 // Turbo C complains without the typecast
4244
7faeece39228 updated for version 7.3.873
Bram Moolenaar <bram@vim.org>
parents: 4176
diff changeset
2390 func_one = (fptr_T)(func_one(&cc, c));
7faeece39228 updated for version 7.3.873
Bram Moolenaar <bram@vim.org>
parents: 4176
diff changeset
2391 else if (func_all != (fptr_T)NULL)
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2392 // Turbo C complains without the typecast
4244
7faeece39228 updated for version 7.3.873
Bram Moolenaar <bram@vim.org>
parents: 4176
diff changeset
2393 func_all = (fptr_T)(func_all(&cc, c));
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2394 else // just copy
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
2395 cc = c;
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
2396
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
2397 if (has_mbyte)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2398 {
1332
6d421b3c485b updated for version 7.1-046
vimboss
parents: 1209
diff changeset
2399 int l;
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2400 int charlen;
1332
6d421b3c485b updated for version 7.1-046
vimboss
parents: 1209
diff changeset
2401
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2402 // Copy composing characters separately, one
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2403 // at a time.
1332
6d421b3c485b updated for version 7.1-046
vimboss
parents: 1209
diff changeset
2404 if (enc_utf8)
6d421b3c485b updated for version 7.1-046
vimboss
parents: 1209
diff changeset
2405 l = utf_ptr2len(s) - 1;
6d421b3c485b updated for version 7.1-046
vimboss
parents: 1209
diff changeset
2406 else
6d421b3c485b updated for version 7.1-046
vimboss
parents: 1209
diff changeset
2407 l = mb_ptr2len(s) - 1;
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
2408
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
2409 s += l;
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
2410 len -= l;
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2411 charlen = mb_char2len(cc);
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
2412 if (copy)
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2413 {
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2414 if (dst + charlen > dest + destlen)
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2415 {
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2416 iemsg("vim_regsub_both(): not enough space");
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2417 return 0;
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2418 }
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
2419 mb_char2bytes(cc, dst);
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2420 }
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2421 dst += charlen - 1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2422 }
15603
639b8318472c patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
2423 else if (copy)
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2424 {
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2425 if (dst + 1 > dest + destlen)
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2426 {
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2427 iemsg("vim_regsub_both(): not enough space");
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2428 return 0;
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2429 }
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2430 *dst = cc;
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2431 }
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
2432 dst++;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2433 }
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 741
diff changeset
2434
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2435 ++s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2436 --len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2437 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2438 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2439 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2440 no = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2441 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2442 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2443 if (copy)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2444 *dst = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2445
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2446 exit:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2447 return (int)((dst - dest) + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2448 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2449
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2450 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2451 /*
2011
a3a4be6bdcdd updated for version 7.2-308
vimboss
parents: 2010
diff changeset
2452 * Call reg_getline() with the line numbers from the submatch. If a
a3a4be6bdcdd updated for version 7.2-308
vimboss
parents: 2010
diff changeset
2453 * substitute() was used the reg_maxline and other values have been
a3a4be6bdcdd updated for version 7.2-308
vimboss
parents: 2010
diff changeset
2454 * overwritten.
a3a4be6bdcdd updated for version 7.2-308
vimboss
parents: 2010
diff changeset
2455 */
a3a4be6bdcdd updated for version 7.2-308
vimboss
parents: 2010
diff changeset
2456 static char_u *
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
2457 reg_getline_submatch(linenr_T lnum)
2011
a3a4be6bdcdd updated for version 7.2-308
vimboss
parents: 2010
diff changeset
2458 {
a3a4be6bdcdd updated for version 7.2-308
vimboss
parents: 2010
diff changeset
2459 char_u *s;
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2460 linenr_T save_first = rex.reg_firstlnum;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2461 linenr_T save_max = rex.reg_maxline;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2462
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2463 rex.reg_firstlnum = rsm.sm_firstlnum;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2464 rex.reg_maxline = rsm.sm_maxline;
2011
a3a4be6bdcdd updated for version 7.2-308
vimboss
parents: 2010
diff changeset
2465
a3a4be6bdcdd updated for version 7.2-308
vimboss
parents: 2010
diff changeset
2466 s = reg_getline(lnum);
a3a4be6bdcdd updated for version 7.2-308
vimboss
parents: 2010
diff changeset
2467
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2468 rex.reg_firstlnum = save_first;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2469 rex.reg_maxline = save_max;
2011
a3a4be6bdcdd updated for version 7.2-308
vimboss
parents: 2010
diff changeset
2470 return s;
a3a4be6bdcdd updated for version 7.2-308
vimboss
parents: 2010
diff changeset
2471 }
a3a4be6bdcdd updated for version 7.2-308
vimboss
parents: 2010
diff changeset
2472
a3a4be6bdcdd updated for version 7.2-308
vimboss
parents: 2010
diff changeset
2473 /*
1209
070f2ac50cf8 updated for version 7.1b
vimboss
parents: 1148
diff changeset
2474 * Used for the submatch() function: get the string from the n'th submatch in
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2475 * allocated memory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2476 * Returns NULL when not in a ":s" command and for a non-existing submatch.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2477 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2478 char_u *
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
2479 reg_submatch(int no)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2480 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2481 char_u *retval = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2482 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2483 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2484 int round;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2485 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2486
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 798
diff changeset
2487 if (!can_f_submatch || no < 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2488 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2489
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2490 if (rsm.sm_match == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2491 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2492 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2493 * First round: compute the length and allocate memory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2494 * Second round: copy the text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2495 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2496 for (round = 1; round <= 2; ++round)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2497 {
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2498 lnum = rsm.sm_mmatch->startpos[no].lnum;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2499 if (lnum < 0 || rsm.sm_mmatch->endpos[no].lnum < 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2500 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2501
16040
13ab270dd68d patch 8.1.1025: checking NULL pointer after addition
Bram Moolenaar <Bram@vim.org>
parents: 15967
diff changeset
2502 s = reg_getline_submatch(lnum);
13ab270dd68d patch 8.1.1025: checking NULL pointer after addition
Bram Moolenaar <Bram@vim.org>
parents: 15967
diff changeset
2503 if (s == NULL) // anti-crash check, cannot happen?
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2504 break;
16040
13ab270dd68d patch 8.1.1025: checking NULL pointer after addition
Bram Moolenaar <Bram@vim.org>
parents: 15967
diff changeset
2505 s += rsm.sm_mmatch->startpos[no].col;
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2506 if (rsm.sm_mmatch->endpos[no].lnum == lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2507 {
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2508 // Within one line: take form start to end col.
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2509 len = rsm.sm_mmatch->endpos[no].col
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2510 - rsm.sm_mmatch->startpos[no].col;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2511 if (round == 2)
418
84825cc6f049 updated for version 7.0109
vimboss
parents: 410
diff changeset
2512 vim_strncpy(retval, s, len);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2513 ++len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2514 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2515 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2516 {
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2517 // Multiple lines: take start line from start col, middle
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2518 // lines completely and end line up to end col.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2519 len = (int)STRLEN(s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2520 if (round == 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2521 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2522 STRCPY(retval, s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2523 retval[len] = '\n';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2524 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2525 ++len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2526 ++lnum;
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2527 while (lnum < rsm.sm_mmatch->endpos[no].lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2528 {
2011
a3a4be6bdcdd updated for version 7.2-308
vimboss
parents: 2010
diff changeset
2529 s = reg_getline_submatch(lnum++);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2530 if (round == 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2531 STRCPY(retval + len, s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2532 len += (int)STRLEN(s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2533 if (round == 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2534 retval[len] = '\n';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2535 ++len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2536 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2537 if (round == 2)
2011
a3a4be6bdcdd updated for version 7.2-308
vimboss
parents: 2010
diff changeset
2538 STRNCPY(retval + len, reg_getline_submatch(lnum),
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2539 rsm.sm_mmatch->endpos[no].col);
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2540 len += rsm.sm_mmatch->endpos[no].col;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2541 if (round == 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2542 retval[len] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2543 ++len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2544 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2545
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 798
diff changeset
2546 if (retval == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2547 {
16768
695d9ef00b03 patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents: 16764
diff changeset
2548 retval = alloc(len);
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 798
diff changeset
2549 if (retval == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2550 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2551 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2552 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2553 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2554 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2555 {
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2556 s = rsm.sm_match->startp[no];
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2557 if (s == NULL || rsm.sm_match->endp[no] == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2558 retval = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2559 else
20830
9064044fd4f6 patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents: 20113
diff changeset
2560 retval = vim_strnsave(s, rsm.sm_match->endp[no] - s);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2561 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2562
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2563 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2564 }
5794
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2565
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2566 /*
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2567 * Used for the submatch() function with the optional non-zero argument: get
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2568 * the list of strings from the n'th submatch in allocated memory with NULs
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2569 * represented in NLs.
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2570 * Returns a list of allocated strings. Returns NULL when not in a ":s"
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2571 * command, for a non-existing submatch and for any error.
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2572 */
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2573 list_T *
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
2574 reg_submatch_list(int no)
5794
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2575 {
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2576 char_u *s;
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2577 linenr_T slnum;
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2578 linenr_T elnum;
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2579 colnr_T scol;
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2580 colnr_T ecol;
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2581 int i;
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2582 list_T *list;
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2583 int error = FALSE;
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2584
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2585 if (!can_f_submatch || no < 0)
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2586 return NULL;
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2587
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2588 if (rsm.sm_match == NULL)
5794
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2589 {
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2590 slnum = rsm.sm_mmatch->startpos[no].lnum;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2591 elnum = rsm.sm_mmatch->endpos[no].lnum;
5794
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2592 if (slnum < 0 || elnum < 0)
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2593 return NULL;
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2594
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2595 scol = rsm.sm_mmatch->startpos[no].col;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2596 ecol = rsm.sm_mmatch->endpos[no].col;
5794
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2597
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2598 list = list_alloc();
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2599 if (list == NULL)
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2600 return NULL;
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2601
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2602 s = reg_getline_submatch(slnum) + scol;
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2603 if (slnum == elnum)
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2604 {
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2605 if (list_append_string(list, s, ecol - scol) == FAIL)
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2606 error = TRUE;
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2607 }
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2608 else
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2609 {
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2610 if (list_append_string(list, s, -1) == FAIL)
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2611 error = TRUE;
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2612 for (i = 1; i < elnum - slnum; i++)
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2613 {
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2614 s = reg_getline_submatch(slnum + i);
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2615 if (list_append_string(list, s, -1) == FAIL)
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2616 error = TRUE;
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2617 }
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2618 s = reg_getline_submatch(elnum);
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2619 if (list_append_string(list, s, ecol) == FAIL)
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2620 error = TRUE;
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2621 }
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2622 }
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2623 else
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2624 {
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2625 s = rsm.sm_match->startp[no];
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2626 if (s == NULL || rsm.sm_match->endp[no] == NULL)
5794
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2627 return NULL;
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2628 list = list_alloc();
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2629 if (list == NULL)
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2630 return NULL;
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2631 if (list_append_string(list, s,
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2632 (int)(rsm.sm_match->endp[no] - s)) == FAIL)
5794
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2633 error = TRUE;
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2634 }
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2635
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2636 if (error)
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2637 {
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8825
diff changeset
2638 list_free(list);
5794
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2639 return NULL;
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2640 }
22143
3ec9e302ec94 patch 8.2.1621: crash when using submatch(0, 1) in substitute()
Bram Moolenaar <Bram@vim.org>
parents: 20996
diff changeset
2641 ++list->lv_refcount;
5794
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2642 return list;
a63d0cd691dc updated for version 7.4.241
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2643 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2644 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2645
19405
08f4dc2ba716 patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents: 19384
diff changeset
2646 /*
08f4dc2ba716 patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents: 19384
diff changeset
2647 * Initialize the values used for matching against multiple lines
08f4dc2ba716 patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents: 19384
diff changeset
2648 */
08f4dc2ba716 patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents: 19384
diff changeset
2649 static void
08f4dc2ba716 patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents: 19384
diff changeset
2650 init_regexec_multi(
08f4dc2ba716 patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents: 19384
diff changeset
2651 regmmatch_T *rmp,
08f4dc2ba716 patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents: 19384
diff changeset
2652 win_T *win, // window in which to search or NULL
08f4dc2ba716 patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents: 19384
diff changeset
2653 buf_T *buf, // buffer in which to search
08f4dc2ba716 patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents: 19384
diff changeset
2654 linenr_T lnum) // nr of line to start looking for match
08f4dc2ba716 patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents: 19384
diff changeset
2655 {
08f4dc2ba716 patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents: 19384
diff changeset
2656 rex.reg_match = NULL;
08f4dc2ba716 patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents: 19384
diff changeset
2657 rex.reg_mmatch = rmp;
08f4dc2ba716 patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents: 19384
diff changeset
2658 rex.reg_buf = buf;
08f4dc2ba716 patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents: 19384
diff changeset
2659 rex.reg_win = win;
08f4dc2ba716 patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents: 19384
diff changeset
2660 rex.reg_firstlnum = lnum;
08f4dc2ba716 patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents: 19384
diff changeset
2661 rex.reg_maxline = rex.reg_buf->b_ml.ml_line_count - lnum;
08f4dc2ba716 patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents: 19384
diff changeset
2662 rex.reg_line_lbr = FALSE;
08f4dc2ba716 patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents: 19384
diff changeset
2663 rex.reg_ic = rmp->rmm_ic;
08f4dc2ba716 patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents: 19384
diff changeset
2664 rex.reg_icombine = FALSE;
08f4dc2ba716 patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents: 19384
diff changeset
2665 rex.reg_maxcol = rmp->rmm_maxcol;
08f4dc2ba716 patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents: 19384
diff changeset
2666 }
08f4dc2ba716 patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents: 19384
diff changeset
2667
18019
68fd5296bf73 patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17966
diff changeset
2668 #include "regexp_bt.c"
68fd5296bf73 patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17966
diff changeset
2669
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2670 static regengine_T bt_regengine =
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2671 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2672 bt_regcomp,
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
2673 bt_regfree,
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2674 bt_regexec_nl,
6328
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2675 bt_regexec_multi,
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2676 };
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2677
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2678 #include "regexp_nfa.c"
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2679
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2680 static regengine_T nfa_regengine =
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2681 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2682 nfa_regcomp,
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
2683 nfa_regfree,
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2684 nfa_regexec_nl,
6328
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2685 nfa_regexec_multi,
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2686 };
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2687
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2688 // Which regexp engine to use? Needed for vim_regcomp().
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2689 // Must match with 'regexpengine'.
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2690 static int regexp_engine = 0;
6328
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2691
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2692 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2693 static char_u regname[][30] = {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2694 "AUTOMATIC Regexp Engine",
4579
7a2be4a39423 updated for version 7.3.1037
Bram Moolenaar <bram@vim.org>
parents: 4505
diff changeset
2695 "BACKTRACKING Regexp Engine",
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2696 "NFA Regexp Engine"
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2697 };
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2698 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2699
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2700 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2701 * Compile a regular expression into internal code.
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
2702 * Returns the program in allocated memory.
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
2703 * Use vim_regfree() to free the memory.
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
2704 * Returns NULL for an error.
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2705 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2706 regprog_T *
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
2707 vim_regcomp(char_u *expr_arg, int re_flags)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2708 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2709 regprog_T *prog = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2710 char_u *expr = expr_arg;
18949
5c405689da3e patch 8.2.0035: saving and restoring called_emsg is clumsy
Bram Moolenaar <Bram@vim.org>
parents: 18812
diff changeset
2711 int called_emsg_before;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2712
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2713 regexp_engine = p_re;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2714
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2715 // Check for prefix "\%#=", that sets the regexp engine
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2716 if (STRNCMP(expr, "\\%#=", 4) == 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2717 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2718 int newengine = expr[4] - '0';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2719
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2720 if (newengine == AUTOMATIC_ENGINE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2721 || newengine == BACKTRACKING_ENGINE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2722 || newengine == NFA_ENGINE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2723 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2724 regexp_engine = expr[4] - '0';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2725 expr += 5;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2726 #ifdef DEBUG
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15339
diff changeset
2727 smsg("New regexp mode selected (%d): %s",
5897
b5972833add9 updated for version 7.4.291
Bram Moolenaar <bram@vim.org>
parents: 5838
diff changeset
2728 regexp_engine, regname[newengine]);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2729 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2730 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2731 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2732 {
26962
85866e069c24 patch 8.2.4010: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26958
diff changeset
2733 emsg(_(e_percent_hash_can_only_be_followed_by_zero_one_two_automatic_engine_will_be_used));
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2734 regexp_engine = AUTOMATIC_ENGINE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2735 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2736 }
14354
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
2737 #ifdef DEBUG
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2738 bt_regengine.expr = expr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2739 nfa_regengine.expr = expr;
14354
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
2740 #endif
15856
e44b7caaf373 patch 8.1.0935: old regexp engine may use invalid buffer
Bram Moolenaar <Bram@vim.org>
parents: 15854
diff changeset
2741 // reg_iswordc() uses rex.reg_buf
e44b7caaf373 patch 8.1.0935: old regexp engine may use invalid buffer
Bram Moolenaar <Bram@vim.org>
parents: 15854
diff changeset
2742 rex.reg_buf = curbuf;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2743
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2744 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2745 * First try the NFA engine, unless backtracking was requested.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2746 */
18949
5c405689da3e patch 8.2.0035: saving and restoring called_emsg is clumsy
Bram Moolenaar <Bram@vim.org>
parents: 18812
diff changeset
2747 called_emsg_before = called_emsg;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2748 if (regexp_engine != BACKTRACKING_ENGINE)
13244
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 12752
diff changeset
2749 prog = nfa_regengine.regcomp(expr,
6533
bdc8e71633e4 updated for version 7.4.593
Bram Moolenaar <bram@vim.org>
parents: 6390
diff changeset
2750 re_flags + (regexp_engine == AUTOMATIC_ENGINE ? RE_AUTO : 0));
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2751 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2752 prog = bt_regengine.regcomp(expr, re_flags);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2753
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2754 // Check for error compiling regexp with initial engine.
6328
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2755 if (prog == NULL)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2756 {
4460
fe8a0a6a1c2a updated for version 7.3.978
Bram Moolenaar <bram@vim.org>
parents: 4444
diff changeset
2757 #ifdef BT_REGEXP_DEBUG_LOG
23471
a7cdfc8e4b6e patch 8.2.2278: falling back to old regexp engine can some patterns
Bram Moolenaar <Bram@vim.org>
parents: 22167
diff changeset
2758 if (regexp_engine == BACKTRACKING_ENGINE) // debugging log for BT engine
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2759 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2760 FILE *f;
4460
fe8a0a6a1c2a updated for version 7.3.978
Bram Moolenaar <bram@vim.org>
parents: 4444
diff changeset
2761 f = fopen(BT_REGEXP_DEBUG_LOG_NAME, "a");
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2762 if (f)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2763 {
4762
47906f888725 updated for version 7.3.1128
Bram Moolenaar <bram@vim.org>
parents: 4760
diff changeset
2764 fprintf(f, "Syntax error in \"%s\"\n", expr);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2765 fclose(f);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2766 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2767 else
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15339
diff changeset
2768 semsg("(NFA) Could not open \"%s\" to write !!!",
13244
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 12752
diff changeset
2769 BT_REGEXP_DEBUG_LOG_NAME);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2770 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2771 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2772 /*
6328
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2773 * If the NFA engine failed, try the backtracking engine.
6533
bdc8e71633e4 updated for version 7.4.593
Bram Moolenaar <bram@vim.org>
parents: 6390
diff changeset
2774 * The NFA engine also fails for patterns that it can't handle well
bdc8e71633e4 updated for version 7.4.593
Bram Moolenaar <bram@vim.org>
parents: 6390
diff changeset
2775 * but are still valid patterns, thus a retry should work.
15935
ff00d207cc5e patch 8.1.0973: pattern with syntax error gives threee error messages
Bram Moolenaar <Bram@vim.org>
parents: 15860
diff changeset
2776 * But don't try if an error message was given.
6533
bdc8e71633e4 updated for version 7.4.593
Bram Moolenaar <bram@vim.org>
parents: 6390
diff changeset
2777 */
18949
5c405689da3e patch 8.2.0035: saving and restoring called_emsg is clumsy
Bram Moolenaar <Bram@vim.org>
parents: 18812
diff changeset
2778 if (regexp_engine == AUTOMATIC_ENGINE
5c405689da3e patch 8.2.0035: saving and restoring called_emsg is clumsy
Bram Moolenaar <Bram@vim.org>
parents: 18812
diff changeset
2779 && called_emsg == called_emsg_before)
6328
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2780 {
6533
bdc8e71633e4 updated for version 7.4.593
Bram Moolenaar <bram@vim.org>
parents: 6390
diff changeset
2781 regexp_engine = BACKTRACKING_ENGINE;
23471
a7cdfc8e4b6e patch 8.2.2278: falling back to old regexp engine can some patterns
Bram Moolenaar <Bram@vim.org>
parents: 22167
diff changeset
2782 #ifdef FEAT_EVAL
a7cdfc8e4b6e patch 8.2.2278: falling back to old regexp engine can some patterns
Bram Moolenaar <Bram@vim.org>
parents: 22167
diff changeset
2783 report_re_switch(expr);
a7cdfc8e4b6e patch 8.2.2278: falling back to old regexp engine can some patterns
Bram Moolenaar <Bram@vim.org>
parents: 22167
diff changeset
2784 #endif
4762
47906f888725 updated for version 7.3.1128
Bram Moolenaar <bram@vim.org>
parents: 4760
diff changeset
2785 prog = bt_regengine.regcomp(expr, re_flags);
6328
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2786 }
4762
47906f888725 updated for version 7.3.1128
Bram Moolenaar <bram@vim.org>
parents: 4760
diff changeset
2787 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2788
6328
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2789 if (prog != NULL)
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2790 {
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2791 // Store the info needed to call regcomp() again when the engine turns
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2792 // out to be very slow when executing it.
6328
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2793 prog->re_engine = regexp_engine;
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2794 prog->re_flags = re_flags;
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2795 }
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2796
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2797 return prog;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2798 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2799
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2800 /*
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
2801 * Free a compiled regexp program, returned by vim_regcomp().
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
2802 */
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
2803 void
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
2804 vim_regfree(regprog_T *prog)
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
2805 {
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
2806 if (prog != NULL)
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
2807 prog->engine->regfree(prog);
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
2808 }
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
2809
18019
68fd5296bf73 patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17966
diff changeset
2810 #if defined(EXITFREE) || defined(PROTO)
68fd5296bf73 patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17966
diff changeset
2811 void
68fd5296bf73 patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17966
diff changeset
2812 free_regexp_stuff(void)
68fd5296bf73 patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17966
diff changeset
2813 {
68fd5296bf73 patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17966
diff changeset
2814 ga_clear(&regstack);
68fd5296bf73 patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17966
diff changeset
2815 ga_clear(&backpos);
68fd5296bf73 patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17966
diff changeset
2816 vim_free(reg_tofree);
68fd5296bf73 patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17966
diff changeset
2817 vim_free(reg_prev_sub);
68fd5296bf73 patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17966
diff changeset
2818 }
68fd5296bf73 patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17966
diff changeset
2819 #endif
68fd5296bf73 patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17966
diff changeset
2820
6328
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2821 #ifdef FEAT_EVAL
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2822 static void
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
2823 report_re_switch(char_u *pat)
6328
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2824 {
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2825 if (p_verbose > 0)
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2826 {
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2827 verbose_enter();
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15480
diff changeset
2828 msg_puts(_("Switching to backtracking RE engine for pattern: "));
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15480
diff changeset
2829 msg_puts((char *)pat);
6328
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2830 verbose_leave();
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2831 }
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2832 }
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2833 #endif
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2834
26336
a2e6da79274d patch 8.2.3699: the +title feature adds a lot of #ifdef but little code
Bram Moolenaar <Bram@vim.org>
parents: 26161
diff changeset
2835 #if defined(FEAT_X11) || defined(PROTO)
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
2836 /*
15306
7fff2d18e191 patch 8.1.0661: clipboard regexp might be used recursively
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
2837 * Return whether "prog" is currently being executed.
7fff2d18e191 patch 8.1.0661: clipboard regexp might be used recursively
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
2838 */
7fff2d18e191 patch 8.1.0661: clipboard regexp might be used recursively
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
2839 int
7fff2d18e191 patch 8.1.0661: clipboard regexp might be used recursively
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
2840 regprog_in_use(regprog_T *prog)
7fff2d18e191 patch 8.1.0661: clipboard regexp might be used recursively
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
2841 {
7fff2d18e191 patch 8.1.0661: clipboard regexp might be used recursively
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
2842 return prog->re_in_use;
7fff2d18e191 patch 8.1.0661: clipboard regexp might be used recursively
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
2843 }
15555
d89c5b339c2a patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
2844 #endif
15306
7fff2d18e191 patch 8.1.0661: clipboard regexp might be used recursively
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
2845
7fff2d18e191 patch 8.1.0661: clipboard regexp might be used recursively
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
2846 /*
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2847 * Match a regexp against a string.
29048
c98fc7a4dde4 patch 8.2.5046: vim_regsub() can overwrite the destination
Bram Moolenaar <Bram@vim.org>
parents: 28692
diff changeset
2848 * "rmp->regprog" must be a compiled regexp as returned by vim_regcomp().
6375
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6328
diff changeset
2849 * Note: "rmp->regprog" may be freed and changed.
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2850 * Uses curbuf for line count and 'iskeyword'.
6328
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2851 * When "nl" is TRUE consider a "\n" in "line" to be a line break.
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2852 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2853 * Return TRUE if there is a match, FALSE if not.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2854 */
6328
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2855 static int
11529
998d2cf59caa patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents: 11527
diff changeset
2856 vim_regexec_string(
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
2857 regmatch_T *rmp,
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2858 char_u *line, // string to match against
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2859 colnr_T col, // column to start looking for match
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
2860 int nl)
6328
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2861 {
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2862 int result;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2863 regexec_T rex_save;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2864 int rex_in_use_save = rex_in_use;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2865
14354
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
2866 // Cannot use the same prog recursively, it contains state.
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
2867 if (rmp->regprog->re_in_use)
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
2868 {
26958
d92e0d85923f patch 8.2.4008: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26952
diff changeset
2869 emsg(_(e_cannot_use_pattern_recursively));
14354
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
2870 return FALSE;
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
2871 }
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
2872 rmp->regprog->re_in_use = TRUE;
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
2873
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2874 if (rex_in_use)
14354
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
2875 // Being called recursively, save the state.
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2876 rex_save = rex;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2877 rex_in_use = TRUE;
14354
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
2878
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2879 rex.reg_startp = NULL;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2880 rex.reg_endp = NULL;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2881 rex.reg_startpos = NULL;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2882 rex.reg_endpos = NULL;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2883
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2884 result = rmp->regprog->engine->regexec_nl(rmp, line, col, nl);
14358
72d506d94f3f patch 8.1.0194: possibly use of NULL pointer
Christian Brabandt <cb@256bit.org>
parents: 14354
diff changeset
2885 rmp->regprog->re_in_use = FALSE;
6328
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2886
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2887 // NFA engine aborted because it's very slow.
6328
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2888 if (rmp->regprog->re_engine == AUTOMATIC_ENGINE
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2889 && result == NFA_TOO_EXPENSIVE)
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2890 {
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2891 int save_p_re = p_re;
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2892 int re_flags = rmp->regprog->re_flags;
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2893 char_u *pat = vim_strsave(((nfa_regprog_T *)rmp->regprog)->pattern);
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2894
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2895 p_re = BACKTRACKING_ENGINE;
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2896 vim_regfree(rmp->regprog);
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2897 if (pat != NULL)
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2898 {
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2899 #ifdef FEAT_EVAL
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2900 report_re_switch(pat);
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2901 #endif
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2902 rmp->regprog = vim_regcomp(pat, re_flags);
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2903 if (rmp->regprog != NULL)
14358
72d506d94f3f patch 8.1.0194: possibly use of NULL pointer
Christian Brabandt <cb@256bit.org>
parents: 14354
diff changeset
2904 {
72d506d94f3f patch 8.1.0194: possibly use of NULL pointer
Christian Brabandt <cb@256bit.org>
parents: 14354
diff changeset
2905 rmp->regprog->re_in_use = TRUE;
6328
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2906 result = rmp->regprog->engine->regexec_nl(rmp, line, col, nl);
14358
72d506d94f3f patch 8.1.0194: possibly use of NULL pointer
Christian Brabandt <cb@256bit.org>
parents: 14354
diff changeset
2907 rmp->regprog->re_in_use = FALSE;
72d506d94f3f patch 8.1.0194: possibly use of NULL pointer
Christian Brabandt <cb@256bit.org>
parents: 14354
diff changeset
2908 }
6328
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2909 vim_free(pat);
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2910 }
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2911
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2912 p_re = save_p_re;
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2913 }
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2914
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2915 rex_in_use = rex_in_use_save;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2916 if (rex_in_use)
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2917 rex = rex_save;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2918
6390
230b52b9d35e updated for version 7.4.526
Bram Moolenaar <bram@vim.org>
parents: 6375
diff changeset
2919 return result > 0;
6328
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2920 }
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
2921
6375
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6328
diff changeset
2922 /*
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6328
diff changeset
2923 * Note: "*prog" may be freed and changed.
6390
230b52b9d35e updated for version 7.4.526
Bram Moolenaar <bram@vim.org>
parents: 6375
diff changeset
2924 * Return TRUE if there is a match, FALSE if not.
6375
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6328
diff changeset
2925 */
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6328
diff changeset
2926 int
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
2927 vim_regexec_prog(
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
2928 regprog_T **prog,
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
2929 int ignore_case,
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
2930 char_u *line,
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
2931 colnr_T col)
6375
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6328
diff changeset
2932 {
11529
998d2cf59caa patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents: 11527
diff changeset
2933 int r;
998d2cf59caa patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents: 11527
diff changeset
2934 regmatch_T regmatch;
6375
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6328
diff changeset
2935
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6328
diff changeset
2936 regmatch.regprog = *prog;
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6328
diff changeset
2937 regmatch.rm_ic = ignore_case;
11529
998d2cf59caa patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents: 11527
diff changeset
2938 r = vim_regexec_string(&regmatch, line, col, FALSE);
6375
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6328
diff changeset
2939 *prog = regmatch.regprog;
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6328
diff changeset
2940 return r;
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6328
diff changeset
2941 }
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6328
diff changeset
2942
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6328
diff changeset
2943 /*
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6328
diff changeset
2944 * Note: "rmp->regprog" may be freed and changed.
6390
230b52b9d35e updated for version 7.4.526
Bram Moolenaar <bram@vim.org>
parents: 6375
diff changeset
2945 * Return TRUE if there is a match, FALSE if not.
6375
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6328
diff changeset
2946 */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2947 int
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
2948 vim_regexec(regmatch_T *rmp, char_u *line, colnr_T col)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2949 {
11529
998d2cf59caa patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents: 11527
diff changeset
2950 return vim_regexec_string(rmp, line, col, FALSE);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2951 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2952
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2953 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2954 * Like vim_regexec(), but consider a "\n" in "line" to be a line break.
6375
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6328
diff changeset
2955 * Note: "rmp->regprog" may be freed and changed.
6390
230b52b9d35e updated for version 7.4.526
Bram Moolenaar <bram@vim.org>
parents: 6375
diff changeset
2956 * Return TRUE if there is a match, FALSE if not.
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2957 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2958 int
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
2959 vim_regexec_nl(regmatch_T *rmp, char_u *line, colnr_T col)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2960 {
11529
998d2cf59caa patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents: 11527
diff changeset
2961 return vim_regexec_string(rmp, line, col, TRUE);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2962 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2963
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2964 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2965 * Match a regexp against multiple lines.
14161
7cac4646c552 patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents: 13286
diff changeset
2966 * "rmp->regprog" must be a compiled regexp as returned by vim_regcomp().
7cac4646c552 patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents: 13286
diff changeset
2967 * Note: "rmp->regprog" may be freed and changed, even set to NULL.
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2968 * Uses curbuf for line count and 'iskeyword'.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2969 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2970 * Return zero if there is no match. Return number of lines contained in the
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2971 * match otherwise.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2972 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2973 long
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
2974 vim_regexec_multi(
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7807
diff changeset
2975 regmmatch_T *rmp,
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2976 win_T *win, // window in which to search or NULL
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2977 buf_T *buf, // buffer in which to search
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2978 linenr_T lnum, // nr of line to start looking for match
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2979 colnr_T col, // column to start looking for match
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2980 int *timed_out) // flag is set when timeout limit reached
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
2981 {
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2982 int result;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2983 regexec_T rex_save;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2984 int rex_in_use_save = rex_in_use;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2985
14354
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
2986 // Cannot use the same prog recursively, it contains state.
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
2987 if (rmp->regprog->re_in_use)
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
2988 {
26958
d92e0d85923f patch 8.2.4008: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26952
diff changeset
2989 emsg(_(e_cannot_use_pattern_recursively));
14354
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
2990 return FALSE;
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
2991 }
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
2992 rmp->regprog->re_in_use = TRUE;
ffd834f893aa patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents: 14169
diff changeset
2993
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2994 if (rex_in_use)
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2995 // Being called recursively, save the state.
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2996 rex_save = rex;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2997 rex_in_use = TRUE;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
2998
11521
578df034735d patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents: 11482
diff changeset
2999 result = rmp->regprog->engine->regexec_multi(
29071
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 29048
diff changeset
3000 rmp, win, buf, lnum, col, timed_out);
14358
72d506d94f3f patch 8.1.0194: possibly use of NULL pointer
Christian Brabandt <cb@256bit.org>
parents: 14354
diff changeset
3001 rmp->regprog->re_in_use = FALSE;
6328
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
3002
18812
d34ec6fe207d patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3003 // NFA engine aborted because it's very slow.
6328
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
3004 if (rmp->regprog->re_engine == AUTOMATIC_ENGINE
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
3005 && result == NFA_TOO_EXPENSIVE)
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
3006 {
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
3007 int save_p_re = p_re;
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
3008 int re_flags = rmp->regprog->re_flags;
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
3009 char_u *pat = vim_strsave(((nfa_regprog_T *)rmp->regprog)->pattern);
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
3010
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
3011 p_re = BACKTRACKING_ENGINE;
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
3012 if (pat != NULL)
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
3013 {
28323
82f34ca7b3b7 patch 8.2.4687: "vimgrep /%v/ *" may cause a crash
Bram Moolenaar <Bram@vim.org>
parents: 27752
diff changeset
3014 regprog_T *prev_prog = rmp->regprog;
82f34ca7b3b7 patch 8.2.4687: "vimgrep /%v/ *" may cause a crash
Bram Moolenaar <Bram@vim.org>
parents: 27752
diff changeset
3015
6328
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
3016 #ifdef FEAT_EVAL
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
3017 report_re_switch(pat);
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
3018 #endif
14169
42a9178374d1 patch 8.1.0102: cannot build without syntax highlighting
Christian Brabandt <cb@256bit.org>
parents: 14161
diff changeset
3019 #ifdef FEAT_SYN_HL
14161
7cac4646c552 patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents: 13286
diff changeset
3020 // checking for \z misuse was already done when compiling for NFA,
7cac4646c552 patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents: 13286
diff changeset
3021 // allow all here
7cac4646c552 patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents: 13286
diff changeset
3022 reg_do_extmatch = REX_ALL;
14169
42a9178374d1 patch 8.1.0102: cannot build without syntax highlighting
Christian Brabandt <cb@256bit.org>
parents: 14161
diff changeset
3023 #endif
6328
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
3024 rmp->regprog = vim_regcomp(pat, re_flags);
14169
42a9178374d1 patch 8.1.0102: cannot build without syntax highlighting
Christian Brabandt <cb@256bit.org>
parents: 14161
diff changeset
3025 #ifdef FEAT_SYN_HL
14161
7cac4646c552 patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents: 13286
diff changeset
3026 reg_do_extmatch = 0;
14169
42a9178374d1 patch 8.1.0102: cannot build without syntax highlighting
Christian Brabandt <cb@256bit.org>
parents: 14161
diff changeset
3027 #endif
28323
82f34ca7b3b7 patch 8.2.4687: "vimgrep /%v/ *" may cause a crash
Bram Moolenaar <Bram@vim.org>
parents: 27752
diff changeset
3028 if (rmp->regprog == NULL)
82f34ca7b3b7 patch 8.2.4687: "vimgrep /%v/ *" may cause a crash
Bram Moolenaar <Bram@vim.org>
parents: 27752
diff changeset
3029 {
82f34ca7b3b7 patch 8.2.4687: "vimgrep /%v/ *" may cause a crash
Bram Moolenaar <Bram@vim.org>
parents: 27752
diff changeset
3030 // Somehow compiling the pattern failed now, put back the
82f34ca7b3b7 patch 8.2.4687: "vimgrep /%v/ *" may cause a crash
Bram Moolenaar <Bram@vim.org>
parents: 27752
diff changeset
3031 // previous one to avoid "regprog" becoming NULL.
82f34ca7b3b7 patch 8.2.4687: "vimgrep /%v/ *" may cause a crash
Bram Moolenaar <Bram@vim.org>
parents: 27752
diff changeset
3032 rmp->regprog = prev_prog;
82f34ca7b3b7 patch 8.2.4687: "vimgrep /%v/ *" may cause a crash
Bram Moolenaar <Bram@vim.org>
parents: 27752
diff changeset
3033 }
82f34ca7b3b7 patch 8.2.4687: "vimgrep /%v/ *" may cause a crash
Bram Moolenaar <Bram@vim.org>
parents: 27752
diff changeset
3034 else
82f34ca7b3b7 patch 8.2.4687: "vimgrep /%v/ *" may cause a crash
Bram Moolenaar <Bram@vim.org>
parents: 27752
diff changeset
3035 {
82f34ca7b3b7 patch 8.2.4687: "vimgrep /%v/ *" may cause a crash
Bram Moolenaar <Bram@vim.org>
parents: 27752
diff changeset
3036 vim_regfree(prev_prog);
14161
7cac4646c552 patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents: 13286
diff changeset
3037
14358
72d506d94f3f patch 8.1.0194: possibly use of NULL pointer
Christian Brabandt <cb@256bit.org>
parents: 14354
diff changeset
3038 rmp->regprog->re_in_use = TRUE;
6328
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
3039 result = rmp->regprog->engine->regexec_multi(
29071
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 29048
diff changeset
3040 rmp, win, buf, lnum, col, timed_out);
14358
72d506d94f3f patch 8.1.0194: possibly use of NULL pointer
Christian Brabandt <cb@256bit.org>
parents: 14354
diff changeset
3041 rmp->regprog->re_in_use = FALSE;
72d506d94f3f patch 8.1.0194: possibly use of NULL pointer
Christian Brabandt <cb@256bit.org>
parents: 14354
diff changeset
3042 }
6328
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
3043 vim_free(pat);
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
3044 }
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
3045 p_re = save_p_re;
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
3046 }
adfbffe1e642 updated for version 7.4.497
Bram Moolenaar <bram@vim.org>
parents: 6203
diff changeset
3047
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
3048 rex_in_use = rex_in_use_save;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
3049 if (rex_in_use)
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
3050 rex = rex_save;
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10187
diff changeset
3051
6390
230b52b9d35e updated for version 7.4.526
Bram Moolenaar <bram@vim.org>
parents: 6375
diff changeset
3052 return result <= 0 ? 0 : result;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 4244
diff changeset
3053 }