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