annotate src/regexp.c @ 39:410fa1a31baf v7.0023

updated for version 7.0023
author vimboss
date Sun, 19 Dec 2004 22:46:22 +0000
parents ac33b7c03fac
children f529edb9bab3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * Handling of regular expressions: vim_regcomp(), vim_regexec(), vim_regsub()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 * NOTICE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 * This is NOT the original regular expression code as written by Henry
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 * Spencer. This code has been modified specifically for use with the VIM
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 * editor, and should not be used separately from Vim. If you want a good
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 * regular expression library, get the original code. The copyright notice
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 * that follows is from the original.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 * END NOTICE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 * Copyright (c) 1986 by University of Toronto.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 * Written by Henry Spencer. Not derived from licensed software.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 * Permission is granted to anyone to use this software for any
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 * purpose on any computer system, and to redistribute it freely,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 * subject to the following restrictions:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 * 1. The author is not responsible for the consequences of use of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 * this software, no matter how awful, even if they arise
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 * from defects in it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 * 2. The origin of this software must not be misrepresented, either
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 * by explicit claim or by omission.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 * 3. Altered versions must be plainly marked as such, and must not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 * be misrepresented as being the original software.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 * Beware that some of this code is subtly aware of the way operator
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 * precedence is structured in regular expressions. Serious changes in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 * regular-expression syntax might require a total rethink.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 *
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
36 * Changes have been made by Tony Andrews, Olaf 'Rhialto' Seibert, Robert
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
37 * Webb, Ciaran McCreesh and Bram Moolenaar.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 * Named character class support added by Walter Briscoe (1998 Jul 01)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 #include "vim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 #undef DEBUG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 * The "internal use only" fields in regexp.h are present to pass info from
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 * compile to execute that permits the execute phase to run lots faster on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 * simple cases. They are:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 * regstart char that must begin a match; NUL if none obvious; Can be a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 * multi-byte character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 * reganch is the match anchored (at beginning-of-line only)?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 * regmust string (pointer into program) that match must include, or NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 * regmlen length of regmust string
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 * regflags RF_ values or'ed together
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 * Regstart and reganch permit very fast decisions on suitable starting points
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 * for a match, cutting down the work a lot. Regmust permits fast rejection
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 * of lines that cannot possibly match. The regmust tests are costly enough
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 * that vim_regcomp() supplies a regmust only if the r.e. contains something
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 * potentially expensive (at present, the only such thing detected is * or +
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 * at the start of the r.e., which can involve a lot of backup). Regmlen is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 * supplied because the test in vim_regexec() needs it and vim_regcomp() is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 * computing it anyway.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 * Structure for regexp "program". This is essentially a linear encoding
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 * of a nondeterministic finite-state machine (aka syntax charts or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 * "railroad normal form" in parsing technology). Each node is an opcode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 * plus a "next" pointer, possibly plus an operand. "Next" pointers of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 * all nodes except BRANCH and BRACES_COMPLEX implement concatenation; a "next"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 * pointer with a BRANCH on both ends of it is connecting two alternatives.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 * (Here we have one of the subtle syntax dependencies: an individual BRANCH
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 * (as opposed to a collection of them) is never concatenated with anything
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 * because of operator precedence). The "next" pointer of a BRACES_COMPLEX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 * node points to the node after the stuff to be repeated. The operand of some
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 * types of node is a literal string; for others, it is a node leading into a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 * sub-FSM. In particular, the operand of a BRANCH node is the first node of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 * the branch. (NB this is *not* a tree structure: the tail of the branch
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 * connects to the thing following the set of BRANCHes.)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 * pattern is coded like:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 * +-----------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 * | V
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 * <aa>\|<bb> BRANCH <aa> BRANCH <bb> --> END
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 * | ^ | ^
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 * +------+ +----------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 * +------------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 * V |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 * <aa>* BRANCH BRANCH <aa> --> BACK BRANCH --> NOTHING --> END
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 * | | ^ ^
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 * | +---------------+ |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 * +---------------------------------------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 * +-------------------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 * V |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 * <aa>\{} BRANCH BRACE_LIMITS --> BRACE_COMPLEX <aa> --> BACK END
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 * | | ^
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 * | +----------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 * +-----------------------------------------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 * <aa>\@!<bb> BRANCH NOMATCH <aa> --> END <bb> --> END
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 * | | ^ ^
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 * | +----------------+ |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 * +--------------------------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 * +---------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 * | V
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 * \z[abc] BRANCH BRANCH a BRANCH b BRANCH c BRANCH NOTHING --> END
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 * | | | | ^ ^
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 * | | | +-----+ |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 * | | +----------------+ |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 * | +---------------------------+ |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 * +------------------------------------------------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 * They all start with a BRANCH for "\|" alternaties, even when there is only
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 * one alternative.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 * The opcodes are:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 /* definition number opnd? meaning */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 #define END 0 /* End of program or NOMATCH operand. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 #define BOL 1 /* Match "" at beginning of line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 #define EOL 2 /* Match "" at end of line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 #define BRANCH 3 /* node Match this alternative, or the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 * next... */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 #define BACK 4 /* Match "", "next" ptr points backward. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 #define EXACTLY 5 /* str Match this string. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 #define NOTHING 6 /* Match empty string. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 #define STAR 7 /* node Match this (simple) thing 0 or more
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 * times. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 #define PLUS 8 /* node Match this (simple) thing 1 or more
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 * times. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 #define MATCH 9 /* node match the operand zero-width */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 #define NOMATCH 10 /* node check for no match with operand */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 #define BEHIND 11 /* node look behind for a match with operand */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 #define NOBEHIND 12 /* node look behind for no match with operand */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 #define SUBPAT 13 /* node match the operand here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 #define BRACE_SIMPLE 14 /* node Match this (simple) thing between m and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 * n times (\{m,n\}). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 #define BOW 15 /* Match "" after [^a-zA-Z0-9_] */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 #define EOW 16 /* Match "" at [^a-zA-Z0-9_] */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 #define BRACE_LIMITS 17 /* nr nr define the min & max for BRACE_SIMPLE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 * and BRACE_COMPLEX. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 #define NEWL 18 /* Match line-break */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 #define BHPOS 19 /* End position for BEHIND or NOBEHIND */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 /* character classes: 20-48 normal, 50-78 include a line-break */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 #define ADD_NL 30
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 #define FIRST_NL ANY + ADD_NL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 #define ANY 20 /* Match any one character. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 #define ANYOF 21 /* str Match any character in this string. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 #define ANYBUT 22 /* str Match any character not in this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 * string. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 #define IDENT 23 /* Match identifier char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 #define SIDENT 24 /* Match identifier char but no digit */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 #define KWORD 25 /* Match keyword char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 #define SKWORD 26 /* Match word char but no digit */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 #define FNAME 27 /* Match file name char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 #define SFNAME 28 /* Match file name char but no digit */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 #define PRINT 29 /* Match printable char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 #define SPRINT 30 /* Match printable char but no digit */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 #define WHITE 31 /* Match whitespace char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 #define NWHITE 32 /* Match non-whitespace char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 #define DIGIT 33 /* Match digit char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 #define NDIGIT 34 /* Match non-digit char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 #define HEX 35 /* Match hex char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 #define NHEX 36 /* Match non-hex char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 #define OCTAL 37 /* Match octal char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 #define NOCTAL 38 /* Match non-octal char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 #define WORD 39 /* Match word char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 #define NWORD 40 /* Match non-word char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 #define HEAD 41 /* Match head char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 #define NHEAD 42 /* Match non-head char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 #define ALPHA 43 /* Match alpha char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 #define NALPHA 44 /* Match non-alpha char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 #define LOWER 45 /* Match lowercase char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 #define NLOWER 46 /* Match non-lowercase char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 #define UPPER 47 /* Match uppercase char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 #define NUPPER 48 /* Match non-uppercase char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 #define LAST_NL NUPPER + ADD_NL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 #define WITH_NL(op) ((op) >= FIRST_NL && (op) <= LAST_NL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 #define MOPEN 80 /* -89 Mark this point in input as start of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 * \( subexpr. MOPEN + 0 marks start of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 * match. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 #define MCLOSE 90 /* -99 Analogous to MOPEN. MCLOSE + 0 marks
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 * end of match. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 #define BACKREF 100 /* -109 node Match same string again \1-\9 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 # define ZOPEN 110 /* -119 Mark this point in input as start of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 * \z( subexpr. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 # define ZCLOSE 120 /* -129 Analogous to ZOPEN. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 # define ZREF 130 /* -139 node Match external submatch \z1-\z9 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 #define BRACE_COMPLEX 140 /* -149 node Match nodes between m & n times */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 #define NOPEN 150 /* Mark this point in input as start of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 \%( subexpr. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 #define NCLOSE 151 /* Analogous to NOPEN. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 #define MULTIBYTECODE 200 /* mbc Match one multi-byte character */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 #define RE_BOF 201 /* Match "" at beginning of file. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 #define RE_EOF 202 /* Match "" at end of file. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 #define CURSOR 203 /* Match location of cursor. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 #define RE_LNUM 204 /* nr cmp Match line number */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 #define RE_COL 205 /* nr cmp Match column number */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 #define RE_VCOL 206 /* nr cmp Match virtual column number */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224 * Magic characters have a special meaning, they don't match literally.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 * Magic characters are negative. This separates them from literal characters
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226 * (possibly multi-byte). Only ASCII characters can be Magic.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 #define Magic(x) ((int)(x) - 256)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 #define un_Magic(x) ((x) + 256)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 #define is_Magic(x) ((x) < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 static int no_Magic __ARGS((int x));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 static int toggle_Magic __ARGS((int x));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 no_Magic(x)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 int x;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 if (is_Magic(x))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 return un_Magic(x);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 return x;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 toggle_Magic(x)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 int x;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 if (is_Magic(x))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 return un_Magic(x);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 return Magic(x);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254 * The first byte of the regexp internal "program" is actually this magic
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 * number; the start node begins in the second byte. It's used to catch the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 * most severe mutilation of the program by the caller.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 #define REGMAGIC 0234
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 * Opcode notes:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 * BRANCH The set of branches constituting a single choice are hooked
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 * together with their "next" pointers, since precedence prevents
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 * anything being concatenated to any individual branch. The
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 * "next" pointer of the last BRANCH in a choice points to the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 * thing following the whole choice. This is also where the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 * final "next" pointer of each individual branch points; each
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 * branch starts with the operand node of a BRANCH node.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 * BACK Normal "next" pointers all implicitly point forward; BACK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 * exists to make loop structures possible.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 * STAR,PLUS '=', and complex '*' and '+', are implemented as circular
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 * BRANCH structures using BACK. Simple cases (one character
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 * per match) are implemented with STAR and PLUS for speed
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 * and to minimize recursive plunges.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 * BRACE_LIMITS This is always followed by a BRACE_SIMPLE or BRACE_COMPLEX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 * node, and defines the min and max limits to be used for that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 * node.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 * MOPEN,MCLOSE ...are numbered at compile time.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 * ZOPEN,ZCLOSE ...ditto
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 * A node is one char of opcode followed by two chars of "next" pointer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 * "Next" pointers are stored as two 8-bit bytes, high order first. The
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 * value is a positive offset from the opcode of the node containing it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292 * An operand, if any, simply follows the node. (Note that much of the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 * code generation knows about this implicit relationship.)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 * Using two bytes for the "next" pointer is vast overkill for most things,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296 * but allows patterns to get big without disasters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 #define OP(p) ((int)*(p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299 #define NEXT(p) (((*((p) + 1) & 0377) << 8) + (*((p) + 2) & 0377))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300 #define OPERAND(p) ((p) + 3)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301 /* Obtain an operand that was stored as four bytes, MSB first. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302 #define OPERAND_MIN(p) (((long)(p)[3] << 24) + ((long)(p)[4] << 16) \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 + ((long)(p)[5] << 8) + (long)(p)[6])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 /* Obtain a second operand stored as four bytes. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 #define OPERAND_MAX(p) OPERAND_MIN((p) + 4)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 /* Obtain a second single-byte operand stored after a four bytes operand. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307 #define OPERAND_CMP(p) (p)[7]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310 * Utility definitions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 #define UCHARAT(p) ((int)*(char_u *)(p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314 /* Used for an error (down from) vim_regcomp(): give the error message, set
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 * rc_did_emsg and return NULL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 #define EMSG_RET_NULL(m) { EMSG(m); rc_did_emsg = TRUE; return NULL; }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 #define EMSG_M_RET_NULL(m, c) { EMSG2(m, c ? "" : "\\"); rc_did_emsg = TRUE; return NULL; }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 #define EMSG_RET_FAIL(m) { EMSG(m); rc_did_emsg = TRUE; return FAIL; }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319 #define EMSG_ONE_RET_NULL EMSG_M_RET_NULL(_("E369: invalid item in %s%%[]"), reg_magic == MAGIC_ALL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 #define MAX_LIMIT (32767L << 16L)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323 static int re_multi_type __ARGS((int));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 static int cstrncmp __ARGS((char_u *s1, char_u *s2, int *n));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325 static char_u *cstrchr __ARGS((char_u *, int));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 #ifdef DEBUG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 static void regdump __ARGS((char_u *, regprog_T *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 static char_u *regprop __ARGS((char_u *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332 #define NOT_MULTI 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 #define MULTI_ONE 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 #define MULTI_MULT 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 * Return NOT_MULTI if c is not a "multi" operator.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 * Return MULTI_ONE if c is a single "multi" operator.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338 * Return MULTI_MULT if c is a multi "multi" operator.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 re_multi_type(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 if (c == Magic('@') || c == Magic('=') || c == Magic('?'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345 return MULTI_ONE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346 if (c == Magic('*') || c == Magic('+') || c == Magic('{'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347 return MULTI_MULT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 return NOT_MULTI;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352 * Flags to be passed up and down.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354 #define HASWIDTH 0x1 /* Known never to match null string. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 #define SIMPLE 0x2 /* Simple enough to be STAR/PLUS operand. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 #define SPSTART 0x4 /* Starts with * or +. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357 #define HASNL 0x8 /* Contains some \n. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 #define HASLOOKBH 0x10 /* Contains "\@<=" or "\@<!". */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359 #define WORST 0 /* Worst case. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 * When regcode is set to this value, code is not emitted and size is computed
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 * instead.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 #define JUST_CALC_SIZE ((char_u *) -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
367 static char_u *reg_prev_sub;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 * REGEXP_INRANGE contains all characters which are always special in a []
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371 * range after '\'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372 * REGEXP_ABBR contains all characters which act as abbreviations after '\'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373 * These are:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374 * \n - New line (NL).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375 * \r - Carriage Return (CR).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376 * \t - Tab (TAB).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 * \e - Escape (ESC).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 * \b - Backspace (Ctrl_H).
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
379 * \d - Character code in decimal, eg \d123
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
380 * \o - Character code in octal, eg \o80
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
381 * \x - Character code in hex, eg \x4a
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
382 * \u - Multibyte character code, eg \u20ac
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
383 * \U - Long multibyte character code, eg \U12345678
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385 static char_u REGEXP_INRANGE[] = "]^-n\\";
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
386 static char_u REGEXP_ABBR[] = "nrtebdoxuU";
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388 static int backslash_trans __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389 static int skip_class_name __ARGS((char_u **pp));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 static char_u *skip_anyof __ARGS((char_u *p));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391 static void init_class_tab __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394 * Translate '\x' to its control character, except "\n", which is Magic.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 backslash_trans(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 case 'r': return CAR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403 case 't': return TAB;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404 case 'e': return ESC;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 case 'b': return BS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407 return c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411 * Check for a character class name. "pp" points to the '['.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412 * Returns one of the CLASS_ items. CLASS_NONE means that no item was
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 * recognized. Otherwise "pp" is advanced to after the item.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 skip_class_name(pp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417 char_u **pp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 static const char *(class_names[]) =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 "alnum:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 #define CLASS_ALNUM 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423 "alpha:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
424 #define CLASS_ALPHA 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425 "blank:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426 #define CLASS_BLANK 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427 "cntrl:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428 #define CLASS_CNTRL 3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429 "digit:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
430 #define CLASS_DIGIT 4
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431 "graph:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
432 #define CLASS_GRAPH 5
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433 "lower:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
434 #define CLASS_LOWER 6
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
435 "print:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
436 #define CLASS_PRINT 7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437 "punct:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
438 #define CLASS_PUNCT 8
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439 "space:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440 #define CLASS_SPACE 9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441 "upper:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442 #define CLASS_UPPER 10
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
443 "xdigit:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
444 #define CLASS_XDIGIT 11
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
445 "tab:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
446 #define CLASS_TAB 12
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447 "return:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448 #define CLASS_RETURN 13
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449 "backspace:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
450 #define CLASS_BACKSPACE 14
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
451 "escape:]",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452 #define CLASS_ESCAPE 15
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 #define CLASS_NONE 99
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457 if ((*pp)[1] == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 for (i = 0; i < sizeof(class_names) / sizeof(*class_names); ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460 if (STRNCMP(*pp + 2, class_names[i], STRLEN(class_names[i])) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462 *pp += STRLEN(class_names[i]) + 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 return i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466 return CLASS_NONE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
468
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470 * Skip over a "[]" range.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471 * "p" must point to the character after the '['.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472 * The returned pointer is on the matching ']', or the terminating NUL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474 static char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475 skip_anyof(p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
477 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
478 int cpo_lit; /* 'cpoptions' contains 'l' flag */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 int l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
483 cpo_lit = (!reg_syn && vim_strchr(p_cpo, CPO_LITERAL) != NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
485 if (*p == '^') /* Complement of range. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487 if (*p == ']' || *p == '-')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
488 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 while (*p != NUL && *p != ']')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492 if (has_mbyte && (l = (*mb_ptr2len_check)(p)) > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
493 p += l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496 if (*p == '-')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499 if (*p != ']' && *p != NUL)
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
500 mb_ptr_adv(p);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502 else if (*p == '\\'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
503 && (vim_strchr(REGEXP_INRANGE, p[1]) != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
504 || (!cpo_lit && vim_strchr(REGEXP_ABBR, p[1]) != NULL)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505 p += 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
506 else if (*p == '[')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
507 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
508 if (skip_class_name(&p) == CLASS_NONE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
509 ++p; /* It was not a class name */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
512 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
513 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
514
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
515 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
516 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
517
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
518 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
519 * Specific version of character class functions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
520 * Using a table to keep this fast.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
521 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522 static short class_tab[256];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
523
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
524 #define RI_DIGIT 0x01
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
525 #define RI_HEX 0x02
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
526 #define RI_OCTAL 0x04
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
527 #define RI_WORD 0x08
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
528 #define RI_HEAD 0x10
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
529 #define RI_ALPHA 0x20
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
530 #define RI_LOWER 0x40
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
531 #define RI_UPPER 0x80
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532 #define RI_WHITE 0x100
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
534 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
535 init_class_tab()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
536 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
537 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
538 static int done = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
539
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
540 if (done)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
541 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
542
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
543 for (i = 0; i < 256; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
544 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
545 if (i >= '0' && i <= '7')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
546 class_tab[i] = RI_DIGIT + RI_HEX + RI_OCTAL + RI_WORD;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
547 else if (i >= '8' && i <= '9')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
548 class_tab[i] = RI_DIGIT + RI_HEX + RI_WORD;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
549 else if (i >= 'a' && i <= 'f')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
550 class_tab[i] = RI_HEX + RI_WORD + RI_HEAD + RI_ALPHA + RI_LOWER;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
551 #ifdef EBCDIC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
552 else if ((i >= 'g' && i <= 'i') || (i >= 'j' && i <= 'r')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
553 || (i >= 's' && i <= 'z'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
554 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
555 else if (i >= 'g' && i <= 'z')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
556 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
557 class_tab[i] = RI_WORD + RI_HEAD + RI_ALPHA + RI_LOWER;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
558 else if (i >= 'A' && i <= 'F')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
559 class_tab[i] = RI_HEX + RI_WORD + RI_HEAD + RI_ALPHA + RI_UPPER;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
560 #ifdef EBCDIC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
561 else if ((i >= 'G' && i <= 'I') || ( i >= 'J' && i <= 'R')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
562 || (i >= 'S' && i <= 'Z'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
563 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
564 else if (i >= 'G' && i <= 'Z')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
565 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
566 class_tab[i] = RI_WORD + RI_HEAD + RI_ALPHA + RI_UPPER;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
567 else if (i == '_')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
568 class_tab[i] = RI_WORD + RI_HEAD;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
569 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
570 class_tab[i] = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
571 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
572 class_tab[' '] |= RI_WHITE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573 class_tab['\t'] |= RI_WHITE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574 done = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578 # define ri_digit(c) (c < 0x100 && (class_tab[c] & RI_DIGIT))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
579 # define ri_hex(c) (c < 0x100 && (class_tab[c] & RI_HEX))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580 # define ri_octal(c) (c < 0x100 && (class_tab[c] & RI_OCTAL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581 # define ri_word(c) (c < 0x100 && (class_tab[c] & RI_WORD))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582 # define ri_head(c) (c < 0x100 && (class_tab[c] & RI_HEAD))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
583 # define ri_alpha(c) (c < 0x100 && (class_tab[c] & RI_ALPHA))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
584 # define ri_lower(c) (c < 0x100 && (class_tab[c] & RI_LOWER))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
585 # define ri_upper(c) (c < 0x100 && (class_tab[c] & RI_UPPER))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
586 # define ri_white(c) (c < 0x100 && (class_tab[c] & RI_WHITE))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
587 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588 # define ri_digit(c) (class_tab[c] & RI_DIGIT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589 # define ri_hex(c) (class_tab[c] & RI_HEX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590 # define ri_octal(c) (class_tab[c] & RI_OCTAL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
591 # define ri_word(c) (class_tab[c] & RI_WORD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
592 # define ri_head(c) (class_tab[c] & RI_HEAD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
593 # define ri_alpha(c) (class_tab[c] & RI_ALPHA)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
594 # define ri_lower(c) (class_tab[c] & RI_LOWER)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595 # define ri_upper(c) (class_tab[c] & RI_UPPER)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596 # define ri_white(c) (class_tab[c] & RI_WHITE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
598
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
599 /* flags for regflags */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600 #define RF_ICASE 1 /* ignore case */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
601 #define RF_NOICASE 2 /* don't ignore case */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602 #define RF_HASNL 4 /* can match a NL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603 #define RF_ICOMBINE 8 /* ignore combining characters */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
604 #define RF_LOOKBH 16 /* uses "\@<=" or "\@<!" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
605
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
606 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
607 * Global work variables for vim_regcomp().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
608 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
610 static char_u *regparse; /* Input-scan pointer. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
611 static int prevchr_len; /* byte length of previous char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
612 static int num_complex_braces; /* Complex \{...} count */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
613 static int regnpar; /* () count. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
614 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
615 static int regnzpar; /* \z() count. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
616 static int re_has_z; /* \z item detected */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
617 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
618 static char_u *regcode; /* Code-emit pointer, or JUST_CALC_SIZE */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
619 static long regsize; /* Code size. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
620 static char_u had_endbrace[NSUBEXP]; /* flags, TRUE if end of () found */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
621 static unsigned regflags; /* RF_ flags for prog */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
622 static long brace_min[10]; /* Minimums for complex brace repeats */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
623 static long brace_max[10]; /* Maximums for complex brace repeats */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
624 static int brace_count[10]; /* Current counts for complex brace repeats */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
625 #if defined(FEAT_SYN_HL) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
626 static int had_eol; /* TRUE when EOL found by vim_regcomp() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
627 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
628 static int one_exactly = FALSE; /* only do one char for EXACTLY */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
629
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
630 static int reg_magic; /* magicness of the pattern: */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
631 #define MAGIC_NONE 1 /* "\V" very unmagic */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
632 #define MAGIC_OFF 2 /* "\M" or 'magic' off */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
633 #define MAGIC_ON 3 /* "\m" or 'magic' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
634 #define MAGIC_ALL 4 /* "\v" very magic */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
635
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
636 static int reg_string; /* matching with a string instead of a buffer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
637 line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
638
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
639 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
640 * META contains all characters that may be magic, except '^' and '$'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
641 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
642
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
643 #ifdef EBCDIC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
644 static char_u META[] = "%&()*+.123456789<=>?@ACDFHIKLMOPSUVWX[_acdfhiklmnopsuvwxz{|~";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
645 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
646 /* META[] is used often enough to justify turning it into a table. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
647 static char_u META_flags[] = {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
648 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
649 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
650 /* % & ( ) * + . */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
651 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
652 /* 1 2 3 4 5 6 7 8 9 < = > ? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
653 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
654 /* @ A C D F H I K L M O */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
655 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
656 /* P S U V W X Z [ _ */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
657 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
658 /* a c d f h i k l m n o */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
659 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
660 /* p s u v w x z { | ~ */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
661 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
662 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
663 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
664
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
665 static int curchr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
666
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
667 /* arguments for reg() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
668 #define REG_NOPAREN 0 /* toplevel reg() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
669 #define REG_PAREN 1 /* \(\) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
670 #define REG_ZPAREN 2 /* \z(\) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
671 #define REG_NPAREN 3 /* \%(\) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
672
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
673 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
674 * Forward declarations for vim_regcomp()'s friends.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
675 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
676 static void initchr __ARGS((char_u *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
677 static int getchr __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
678 static void skipchr_keepstart __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
679 static int peekchr __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
680 static void skipchr __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
681 static void ungetchr __ARGS((void));
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
682 static int gethexchrs __ARGS((int maxinputlen));
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
683 static int getoctchrs __ARGS((void));
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
684 static int getdecchrs __ARGS((void));
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
685 static int coll_get_char __ARGS((void));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
686 static void regcomp_start __ARGS((char_u *expr, int flags));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
687 static char_u *reg __ARGS((int, int *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
688 static char_u *regbranch __ARGS((int *flagp));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
689 static char_u *regconcat __ARGS((int *flagp));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
690 static char_u *regpiece __ARGS((int *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
691 static char_u *regatom __ARGS((int *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
692 static char_u *regnode __ARGS((int));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
693 static int prog_magic_wrong __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
694 static char_u *regnext __ARGS((char_u *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
695 static void regc __ARGS((int b));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
696 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
697 static void regmbc __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
698 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
699 static void reginsert __ARGS((int, char_u *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
700 static void reginsert_limits __ARGS((int, long, long, char_u *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
701 static char_u *re_put_long __ARGS((char_u *pr, long_u val));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
702 static int read_limits __ARGS((long *, long *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
703 static void regtail __ARGS((char_u *, char_u *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
704 static void regoptail __ARGS((char_u *, char_u *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
705
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
706 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
707 * Return TRUE if compiled regular expression "prog" can match a line break.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
708 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
709 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
710 re_multiline(prog)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
711 regprog_T *prog;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
712 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
713 return (prog->regflags & RF_HASNL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
714 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
715
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
716 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
717 * Return TRUE if compiled regular expression "prog" looks before the start
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
718 * position (pattern contains "\@<=" or "\@<!").
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
719 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
720 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
721 re_lookbehind(prog)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
722 regprog_T *prog;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
723 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
724 return (prog->regflags & RF_LOOKBH);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
725 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
726
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
727 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
728 * Skip past regular expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
729 * Stop at end of 'p' of where 'dirc' is found ('/', '?', etc).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
730 * Take care of characters with a backslash in front of it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
731 * Skip strings inside [ and ].
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
732 * When "newp" is not NULL and "dirc" is '?', make an allocated copy of the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
733 * expression and change "\?" to "?". If "*newp" is not NULL the expression
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
734 * is changed in-place.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
735 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
736 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
737 skip_regexp(startp, dirc, magic, newp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
738 char_u *startp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
739 int dirc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
740 int magic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
741 char_u **newp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
742 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
743 int mymagic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
744 char_u *p = startp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
745
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
746 if (magic)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
747 mymagic = MAGIC_ON;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
748 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
749 mymagic = MAGIC_OFF;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
750
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
751 for (; p[0] != NUL; mb_ptr_adv(p))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
752 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
753 if (p[0] == dirc) /* found end of regexp */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
754 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
755 if ((p[0] == '[' && mymagic >= MAGIC_ON)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
756 || (p[0] == '\\' && p[1] == '[' && mymagic <= MAGIC_OFF))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
757 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
758 p = skip_anyof(p + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
759 if (p[0] == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
760 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
761 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
762 else if (p[0] == '\\' && p[1] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
763 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
764 if (dirc == '?' && newp != NULL && p[1] == '?')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
765 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
766 /* change "\?" to "?", make a copy first. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
767 if (*newp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
768 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
769 *newp = vim_strsave(startp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
770 if (*newp != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
771 p = *newp + (p - startp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
772 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
773 if (*newp != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
774 mch_memmove(p, p + 1, STRLEN(p));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
775 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
776 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
777 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
778 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
779 ++p; /* skip next character */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
780 if (*p == 'v')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
781 mymagic = MAGIC_ALL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
782 else if (*p == 'V')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
783 mymagic = MAGIC_NONE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
784 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
785 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
786 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
787 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
788
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
789 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
790 * vim_regcomp - compile a regular expression into internal code
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
791 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
792 * We can't allocate space until we know how big the compiled form will be,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
793 * but we can't compile it (and thus know how big it is) until we've got a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
794 * place to put the code. So we cheat: we compile it twice, once with code
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
795 * generation turned off and size counting turned on, and once "for real".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
796 * This also means that we don't allocate space until we are sure that the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
797 * thing really will compile successfully, and we never have to move the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
798 * code and thus invalidate pointers into it. (Note that it has to be in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
799 * one piece because vim_free() must be able to free it all.)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
800 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
801 * Whether upper/lower case is to be ignored is decided when executing the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
802 * program, it does not matter here.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
803 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
804 * Beware that the optimization-preparation code in here knows about some
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
805 * of the structure of the compiled regexp.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
806 * "re_flags": RE_MAGIC and/or RE_STRING.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
807 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
808 regprog_T *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
809 vim_regcomp(expr, re_flags)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
810 char_u *expr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
811 int re_flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
812 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
813 regprog_T *r;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
814 char_u *scan;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
815 char_u *longest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
816 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
817 int flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
818
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
819 if (expr == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
820 EMSG_RET_NULL(_(e_null));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
821
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
822 init_class_tab();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
823
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
824 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
825 * First pass: determine size, legality.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
826 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
827 regcomp_start(expr, re_flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
828 regcode = JUST_CALC_SIZE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
829 regc(REGMAGIC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
830 if (reg(REG_NOPAREN, &flags) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
831 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
832
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
833 /* Small enough for pointer-storage convention? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
834 #ifdef SMALL_MALLOC /* 16 bit storage allocation */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
835 if (regsize >= 65536L - 256L)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
836 EMSG_RET_NULL(_("E339: Pattern too long"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
837 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
838
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
839 /* Allocate space. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
840 r = (regprog_T *)lalloc(sizeof(regprog_T) + regsize, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
841 if (r == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
842 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
843
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
844 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
845 * Second pass: emit code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
846 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
847 regcomp_start(expr, re_flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
848 regcode = r->program;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
849 regc(REGMAGIC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
850 if (reg(REG_NOPAREN, &flags) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
851 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
852 vim_free(r);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
853 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
854 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
855
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
856 /* Dig out information for optimizations. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
857 r->regstart = NUL; /* Worst-case defaults. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
858 r->reganch = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
859 r->regmust = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
860 r->regmlen = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
861 r->regflags = regflags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
862 if (flags & HASNL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
863 r->regflags |= RF_HASNL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
864 if (flags & HASLOOKBH)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
865 r->regflags |= RF_LOOKBH;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
866 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
867 /* Remember whether this pattern has any \z specials in it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
868 r->reghasz = re_has_z;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
869 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
870 scan = r->program + 1; /* First BRANCH. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
871 if (OP(regnext(scan)) == END) /* Only one top-level choice. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
872 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
873 scan = OPERAND(scan);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
874
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
875 /* Starting-point info. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
876 if (OP(scan) == BOL || OP(scan) == RE_BOF)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
877 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
878 r->reganch++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
879 scan = regnext(scan);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
880 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
881
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
882 if (OP(scan) == EXACTLY)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
883 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
884 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
885 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
886 r->regstart = (*mb_ptr2char)(OPERAND(scan));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
887 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
888 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
889 r->regstart = *OPERAND(scan);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
890 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
891 else if ((OP(scan) == BOW
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
892 || OP(scan) == EOW
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
893 || OP(scan) == NOTHING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
894 || OP(scan) == MOPEN + 0 || OP(scan) == NOPEN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
895 || OP(scan) == MCLOSE + 0 || OP(scan) == NCLOSE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
896 && OP(regnext(scan)) == EXACTLY)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
897 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
898 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
899 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
900 r->regstart = (*mb_ptr2char)(OPERAND(regnext(scan)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
901 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
902 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
903 r->regstart = *OPERAND(regnext(scan));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
904 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
905
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
906 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
907 * If there's something expensive in the r.e., find the longest
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
908 * literal string that must appear and make it the regmust. Resolve
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
909 * ties in favor of later strings, since the regstart check works
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
910 * with the beginning of the r.e. and avoiding duplication
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
911 * strengthens checking. Not a strong reason, but sufficient in the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
912 * absence of others.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
913 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
914 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
915 * When the r.e. starts with BOW, it is faster to look for a regmust
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
916 * first. Used a lot for "#" and "*" commands. (Added by mool).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
917 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
918 if ((flags & SPSTART || OP(scan) == BOW || OP(scan) == EOW)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
919 && !(flags & HASNL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
920 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
921 longest = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
922 len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
923 for (; scan != NULL; scan = regnext(scan))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
924 if (OP(scan) == EXACTLY && STRLEN(OPERAND(scan)) >= (size_t)len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
925 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
926 longest = OPERAND(scan);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
927 len = (int)STRLEN(OPERAND(scan));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
928 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
929 r->regmust = longest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
930 r->regmlen = len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
931 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
932 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
933 #ifdef DEBUG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
934 regdump(expr, r);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
935 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
936 return r;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
937 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
938
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
939 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
940 * Setup to parse the regexp. Used once to get the length and once to do it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
941 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
942 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
943 regcomp_start(expr, re_flags)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
944 char_u *expr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
945 int re_flags; /* see vim_regcomp() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
946 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
947 initchr(expr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
948 if (re_flags & RE_MAGIC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
949 reg_magic = MAGIC_ON;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
950 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
951 reg_magic = MAGIC_OFF;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
952 reg_string = (re_flags & RE_STRING);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
953
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
954 num_complex_braces = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
955 regnpar = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
956 vim_memset(had_endbrace, 0, sizeof(had_endbrace));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
957 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
958 regnzpar = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
959 re_has_z = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
960 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
961 regsize = 0L;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
962 regflags = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
963 #if defined(FEAT_SYN_HL) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
964 had_eol = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
965 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
966 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
967
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
968 #if defined(FEAT_SYN_HL) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
969 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
970 * Check if during the previous call to vim_regcomp the EOL item "$" has been
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
971 * found. This is messy, but it works fine.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
972 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
973 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
974 vim_regcomp_had_eol()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
975 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
976 return had_eol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
977 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
978 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
979
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
980 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
981 * reg - regular expression, i.e. main body or parenthesized thing
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
982 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
983 * Caller must absorb opening parenthesis.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
984 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
985 * Combining parenthesis handling with the base level of regular expression
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
986 * is a trifle forced, but the need to tie the tails of the branches to what
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
987 * follows makes it hard to avoid.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
988 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
989 static char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
990 reg(paren, flagp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
991 int paren; /* REG_NOPAREN, REG_PAREN, REG_NPAREN or REG_ZPAREN */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
992 int *flagp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
993 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
994 char_u *ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
995 char_u *br;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
996 char_u *ender;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
997 int parno = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
998 int flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
999
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1000 *flagp = HASWIDTH; /* Tentatively. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1001
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1002 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1003 if (paren == REG_ZPAREN)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1004 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1005 /* Make a ZOPEN node. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1006 if (regnzpar >= NSUBEXP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1007 EMSG_RET_NULL(_("E50: Too many \\z("));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1008 parno = regnzpar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1009 regnzpar++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1010 ret = regnode(ZOPEN + parno);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1011 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1012 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1013 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1014 if (paren == REG_PAREN)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1015 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1016 /* Make a MOPEN node. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1017 if (regnpar >= NSUBEXP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1018 EMSG_M_RET_NULL(_("E51: Too many %s("), reg_magic == MAGIC_ALL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1019 parno = regnpar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1020 ++regnpar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1021 ret = regnode(MOPEN + parno);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1022 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1023 else if (paren == REG_NPAREN)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1024 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1025 /* Make a NOPEN node. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1026 ret = regnode(NOPEN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1027 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1028 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1029 ret = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1030
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1031 /* Pick up the branches, linking them together. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1032 br = regbranch(&flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1033 if (br == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1034 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1035 if (ret != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1036 regtail(ret, br); /* [MZ]OPEN -> first. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1037 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1038 ret = br;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1039 /* If one of the branches can be zero-width, the whole thing can.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1040 * If one of the branches has * at start or matches a line-break, the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1041 * whole thing can. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1042 if (!(flags & HASWIDTH))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1043 *flagp &= ~HASWIDTH;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1044 *flagp |= flags & (SPSTART | HASNL | HASLOOKBH);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1045 while (peekchr() == Magic('|'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1046 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1047 skipchr();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1048 br = regbranch(&flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1049 if (br == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1050 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1051 regtail(ret, br); /* BRANCH -> BRANCH. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1052 if (!(flags & HASWIDTH))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1053 *flagp &= ~HASWIDTH;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1054 *flagp |= flags & (SPSTART | HASNL | HASLOOKBH);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1055 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1056
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1057 /* Make a closing node, and hook it on the end. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1058 ender = regnode(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1059 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1060 paren == REG_ZPAREN ? ZCLOSE + parno :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1061 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1062 paren == REG_PAREN ? MCLOSE + parno :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1063 paren == REG_NPAREN ? NCLOSE : END);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1064 regtail(ret, ender);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1065
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1066 /* Hook the tails of the branches to the closing node. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1067 for (br = ret; br != NULL; br = regnext(br))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1068 regoptail(br, ender);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1069
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1070 /* Check for proper termination. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1071 if (paren != REG_NOPAREN && getchr() != Magic(')'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1072 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1073 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1074 if (paren == REG_ZPAREN)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1075 EMSG_RET_NULL(_("E52: Unmatched \\z("))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1076 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1077 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1078 if (paren == REG_NPAREN)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1079 EMSG_M_RET_NULL(_("E53: Unmatched %s%%("), reg_magic == MAGIC_ALL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1080 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1081 EMSG_M_RET_NULL(_("E54: Unmatched %s("), reg_magic == MAGIC_ALL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1082 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1083 else if (paren == REG_NOPAREN && peekchr() != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1084 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1085 if (curchr == Magic(')'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1086 EMSG_M_RET_NULL(_("E55: Unmatched %s)"), reg_magic == MAGIC_ALL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1087 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1088 EMSG_RET_NULL(_(e_trailing)) /* "Can't happen". */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1089 /* NOTREACHED */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1090 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1091 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1092 * Here we set the flag allowing back references to this set of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1093 * parentheses.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1094 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1095 if (paren == REG_PAREN)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1096 had_endbrace[parno] = TRUE; /* have seen the close paren */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1097 return ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1098 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1099
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1100 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1101 * regbranch - one alternative of an | operator
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1102 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1103 * Implements the & operator.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1104 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1105 static char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1106 regbranch(flagp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1107 int *flagp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1108 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1109 char_u *ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1110 char_u *chain = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1111 char_u *latest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1112 int flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1113
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1114 *flagp = WORST | HASNL; /* Tentatively. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1115
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1116 ret = regnode(BRANCH);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1117 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1118 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1119 latest = regconcat(&flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1120 if (latest == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1121 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1122 /* If one of the branches has width, the whole thing has. If one of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1123 * the branches anchors at start-of-line, the whole thing does.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1124 * If one of the branches uses look-behind, the whole thing does. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1125 *flagp |= flags & (HASWIDTH | SPSTART | HASLOOKBH);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1126 /* If one of the branches doesn't match a line-break, the whole thing
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1127 * doesn't. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1128 *flagp &= ~HASNL | (flags & HASNL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1129 if (chain != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1130 regtail(chain, latest);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1131 if (peekchr() != Magic('&'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1132 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1133 skipchr();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1134 regtail(latest, regnode(END)); /* operand ends */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1135 reginsert(MATCH, latest);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1136 chain = latest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1137 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1138
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1139 return ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1140 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1141
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1142 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1143 * regbranch - one alternative of an | or & operator
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1144 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1145 * Implements the concatenation operator.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1146 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1147 static char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1148 regconcat(flagp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1149 int *flagp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1150 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1151 char_u *first = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1152 char_u *chain = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1153 char_u *latest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1154 int flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1155 int cont = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1156
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1157 *flagp = WORST; /* Tentatively. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1158
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1159 while (cont)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1160 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1161 switch (peekchr())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1162 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1163 case NUL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1164 case Magic('|'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1165 case Magic('&'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1166 case Magic(')'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1167 cont = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1168 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1169 case Magic('Z'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1170 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1171 regflags |= RF_ICOMBINE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1172 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1173 skipchr_keepstart();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1174 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1175 case Magic('c'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1176 regflags |= RF_ICASE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1177 skipchr_keepstart();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1178 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1179 case Magic('C'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1180 regflags |= RF_NOICASE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1181 skipchr_keepstart();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1182 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1183 case Magic('v'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1184 reg_magic = MAGIC_ALL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1185 skipchr_keepstart();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1186 curchr = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1187 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1188 case Magic('m'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1189 reg_magic = MAGIC_ON;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1190 skipchr_keepstart();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1191 curchr = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1192 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1193 case Magic('M'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1194 reg_magic = MAGIC_OFF;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1195 skipchr_keepstart();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1196 curchr = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1197 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1198 case Magic('V'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1199 reg_magic = MAGIC_NONE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1200 skipchr_keepstart();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1201 curchr = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1202 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1203 default:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1204 latest = regpiece(&flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1205 if (latest == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1206 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1207 *flagp |= flags & (HASWIDTH | HASNL | HASLOOKBH);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1208 if (chain == NULL) /* First piece. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1209 *flagp |= flags & SPSTART;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1210 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1211 regtail(chain, latest);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1212 chain = latest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1213 if (first == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1214 first = latest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1215 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1216 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1217 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1218 if (first == NULL) /* Loop ran zero times. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1219 first = regnode(NOTHING);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1220 return first;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1221 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1222
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1223 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1224 * regpiece - something followed by possible [*+=]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1225 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1226 * Note that the branching code sequences used for = and the general cases
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1227 * of * and + are somewhat optimized: they use the same NOTHING node as
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1228 * both the endmarker for their branch list and the body of the last branch.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1229 * It might seem that this node could be dispensed with entirely, but the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1230 * endmarker role is not redundant.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1231 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1232 static char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1233 regpiece(flagp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1234 int *flagp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1235 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1236 char_u *ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1237 int op;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1238 char_u *next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1239 int flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1240 long minval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1241 long maxval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1242
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1243 ret = regatom(&flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1244 if (ret == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1245 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1246
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1247 op = peekchr();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1248 if (re_multi_type(op) == NOT_MULTI)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1249 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1250 *flagp = flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1251 return ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1252 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1253 if (!(flags & HASWIDTH) && re_multi_type(op) == MULTI_MULT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1254 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1255 if (op == Magic('*'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1256 EMSG_M_RET_NULL(_("E56: %s* operand could be empty"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1257 reg_magic >= MAGIC_ON);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1258 if (op == Magic('+'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1259 EMSG_M_RET_NULL(_("E57: %s+ operand could be empty"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1260 reg_magic == MAGIC_ALL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1261 /* "\{}" is checked below, it's allowed when there is an upper limit */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1262 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1263 /* default flags */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1264 *flagp = (WORST | SPSTART | (flags & (HASNL | HASLOOKBH)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1265
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1266 skipchr();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1267 switch (op)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1268 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1269 case Magic('*'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1270 if (flags & SIMPLE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1271 reginsert(STAR, ret);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1272 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1273 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1274 /* Emit x* as (x&|), where & means "self". */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1275 reginsert(BRANCH, ret); /* Either x */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1276 regoptail(ret, regnode(BACK)); /* and loop */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1277 regoptail(ret, ret); /* back */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1278 regtail(ret, regnode(BRANCH)); /* or */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1279 regtail(ret, regnode(NOTHING)); /* null. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1280 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1281 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1282
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1283 case Magic('+'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1284 if (flags & SIMPLE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1285 reginsert(PLUS, ret);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1286 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1287 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1288 /* Emit x+ as x(&|), where & means "self". */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1289 next = regnode(BRANCH); /* Either */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1290 regtail(ret, next);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1291 regtail(regnode(BACK), ret); /* loop back */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1292 regtail(next, regnode(BRANCH)); /* or */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1293 regtail(ret, regnode(NOTHING)); /* null. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1294 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1295 *flagp = (WORST | HASWIDTH | (flags & (HASNL | HASLOOKBH)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1296 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1297
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1298 case Magic('@'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1299 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1300 int lop = END;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1301
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1302 switch (no_Magic(getchr()))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1303 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1304 case '=': lop = MATCH; break; /* \@= */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1305 case '!': lop = NOMATCH; break; /* \@! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1306 case '>': lop = SUBPAT; break; /* \@> */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1307 case '<': switch (no_Magic(getchr()))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1308 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1309 case '=': lop = BEHIND; break; /* \@<= */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1310 case '!': lop = NOBEHIND; break; /* \@<! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1311 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1312 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1313 if (lop == END)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1314 EMSG_M_RET_NULL(_("E59: invalid character after %s@"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1315 reg_magic == MAGIC_ALL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1316 /* Look behind must match with behind_pos. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1317 if (lop == BEHIND || lop == NOBEHIND)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1318 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1319 regtail(ret, regnode(BHPOS));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1320 *flagp |= HASLOOKBH;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1321 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1322 regtail(ret, regnode(END)); /* operand ends */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1323 reginsert(lop, ret);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1324 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1325 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1326
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1327 case Magic('?'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1328 case Magic('='):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1329 /* Emit x= as (x|) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1330 reginsert(BRANCH, ret); /* Either x */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1331 regtail(ret, regnode(BRANCH)); /* or */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1332 next = regnode(NOTHING); /* null. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1333 regtail(ret, next);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1334 regoptail(ret, next);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1335 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1336
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1337 case Magic('{'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1338 if (!read_limits(&minval, &maxval))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1339 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1340 if (!(flags & HASWIDTH) && (maxval > minval
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1341 ? maxval >= MAX_LIMIT : minval >= MAX_LIMIT))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1342 EMSG_M_RET_NULL(_("E58: %s{ operand could be empty"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1343 reg_magic == MAGIC_ALL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1344 if (flags & SIMPLE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1345 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1346 reginsert(BRACE_SIMPLE, ret);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1347 reginsert_limits(BRACE_LIMITS, minval, maxval, ret);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1348 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1349 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1350 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1351 if (num_complex_braces >= 10)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1352 EMSG_M_RET_NULL(_("E60: Too many complex %s{...}s"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1353 reg_magic == MAGIC_ALL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1354 reginsert(BRACE_COMPLEX + num_complex_braces, ret);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1355 regoptail(ret, regnode(BACK));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1356 regoptail(ret, ret);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1357 reginsert_limits(BRACE_LIMITS, minval, maxval, ret);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1358 ++num_complex_braces;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1359 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1360 if (minval > 0 && maxval > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1361 *flagp = (HASWIDTH | (flags & (HASNL | HASLOOKBH)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1362 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1363 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1364 if (re_multi_type(peekchr()) != NOT_MULTI)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1365 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1366 /* Can't have a multi follow a multi. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1367 if (peekchr() == Magic('*'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1368 sprintf((char *)IObuff, _("E61: Nested %s*"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1369 reg_magic >= MAGIC_ON ? "" : "\\");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1370 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1371 sprintf((char *)IObuff, _("E62: Nested %s%c"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1372 reg_magic == MAGIC_ALL ? "" : "\\", no_Magic(peekchr()));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1373 EMSG_RET_NULL(IObuff);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1374 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1375
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1376 return ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1377 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1378
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1379 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1380 * regatom - the lowest level
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1381 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1382 * Optimization: gobbles an entire sequence of ordinary characters so that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1383 * it can turn them into a single node, which is smaller to store and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1384 * faster to run. Don't do this when one_exactly is set.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1385 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1386 static char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1387 regatom(flagp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1388 int *flagp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1389 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1390 char_u *ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1391 int flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1392 int cpo_lit; /* 'cpoptions' contains 'l' flag */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1393 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1394 static char_u *classchars = (char_u *)".iIkKfFpPsSdDxXoOwWhHaAlLuU";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1395 static int classcodes[] = {ANY, IDENT, SIDENT, KWORD, SKWORD,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1396 FNAME, SFNAME, PRINT, SPRINT,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1397 WHITE, NWHITE, DIGIT, NDIGIT,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1398 HEX, NHEX, OCTAL, NOCTAL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1399 WORD, NWORD, HEAD, NHEAD,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1400 ALPHA, NALPHA, LOWER, NLOWER,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1401 UPPER, NUPPER
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1402 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1403 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1404 int extra = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1405
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1406 *flagp = WORST; /* Tentatively. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1407 cpo_lit = (!reg_syn && vim_strchr(p_cpo, CPO_LITERAL) != NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1408
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1409 c = getchr();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1410 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1411 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1412 case Magic('^'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1413 ret = regnode(BOL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1414 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1415
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1416 case Magic('$'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1417 ret = regnode(EOL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1418 #if defined(FEAT_SYN_HL) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1419 had_eol = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1420 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1421 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1422
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1423 case Magic('<'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1424 ret = regnode(BOW);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1425 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1426
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1427 case Magic('>'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1428 ret = regnode(EOW);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1429 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1430
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1431 case Magic('_'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1432 c = no_Magic(getchr());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1433 if (c == '^') /* "\_^" is start-of-line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1434 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1435 ret = regnode(BOL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1436 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1437 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1438 if (c == '$') /* "\_$" is end-of-line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1439 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1440 ret = regnode(EOL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1441 #if defined(FEAT_SYN_HL) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1442 had_eol = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1443 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1444 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1445 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1446
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1447 extra = ADD_NL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1448 *flagp |= HASNL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1449
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1450 /* "\_[" is character range plus newline */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1451 if (c == '[')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1452 goto collection;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1453
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1454 /* "\_x" is character class plus newline */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1455 /*FALLTHROUGH*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1456
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1457 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1458 * Character classes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1459 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1460 case Magic('.'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1461 case Magic('i'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1462 case Magic('I'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1463 case Magic('k'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1464 case Magic('K'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1465 case Magic('f'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1466 case Magic('F'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1467 case Magic('p'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1468 case Magic('P'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1469 case Magic('s'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1470 case Magic('S'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1471 case Magic('d'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1472 case Magic('D'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1473 case Magic('x'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1474 case Magic('X'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1475 case Magic('o'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1476 case Magic('O'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1477 case Magic('w'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1478 case Magic('W'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1479 case Magic('h'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1480 case Magic('H'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1481 case Magic('a'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1482 case Magic('A'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1483 case Magic('l'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1484 case Magic('L'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1485 case Magic('u'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1486 case Magic('U'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1487 p = vim_strchr(classchars, no_Magic(c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1488 if (p == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1489 EMSG_RET_NULL(_("E63: invalid use of \\_"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1490 ret = regnode(classcodes[p - classchars] + extra);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1491 *flagp |= HASWIDTH | SIMPLE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1492 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1493
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1494 case Magic('n'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1495 if (reg_string)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1496 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1497 /* In a string "\n" matches a newline character. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1498 ret = regnode(EXACTLY);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1499 regc(NL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1500 regc(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1501 *flagp |= HASWIDTH | SIMPLE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1502 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1503 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1504 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1505 /* In buffer text "\n" matches the end of a line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1506 ret = regnode(NEWL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1507 *flagp |= HASWIDTH | HASNL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1508 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1509 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1510
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1511 case Magic('('):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1512 if (one_exactly)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1513 EMSG_ONE_RET_NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1514 ret = reg(REG_PAREN, &flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1515 if (ret == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1516 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1517 *flagp |= flags & (HASWIDTH | SPSTART | HASNL | HASLOOKBH);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1518 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1519
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1520 case NUL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1521 case Magic('|'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1522 case Magic('&'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1523 case Magic(')'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1524 EMSG_RET_NULL(_(e_internal)); /* Supposed to be caught earlier. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1525 /* NOTREACHED */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1526
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1527 case Magic('='):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1528 case Magic('?'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1529 case Magic('+'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1530 case Magic('@'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1531 case Magic('{'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1532 case Magic('*'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1533 c = no_Magic(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1534 sprintf((char *)IObuff, _("E64: %s%c follows nothing"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1535 (c == '*' ? reg_magic >= MAGIC_ON : reg_magic == MAGIC_ALL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1536 ? "" : "\\", c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1537 EMSG_RET_NULL(IObuff);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1538 /* NOTREACHED */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1539
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1540 case Magic('~'): /* previous substitute pattern */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1541 if (reg_prev_sub)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1542 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1543 char_u *lp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1544
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1545 ret = regnode(EXACTLY);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1546 lp = reg_prev_sub;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1547 while (*lp != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1548 regc(*lp++);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1549 regc(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1550 if (*reg_prev_sub != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1551 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1552 *flagp |= HASWIDTH;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1553 if ((lp - reg_prev_sub) == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1554 *flagp |= SIMPLE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1555 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1556 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1557 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1558 EMSG_RET_NULL(_(e_nopresub));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1559 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1560
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1561 case Magic('1'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1562 case Magic('2'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1563 case Magic('3'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1564 case Magic('4'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1565 case Magic('5'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1566 case Magic('6'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1567 case Magic('7'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1568 case Magic('8'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1569 case Magic('9'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1570 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1571 int refnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1572
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1573 refnum = c - Magic('0');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1574 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1575 * Check if the back reference is legal. We must have seen the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1576 * close brace.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1577 * TODO: Should also check that we don't refer to something
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1578 * that is repeated (+*=): what instance of the repetition
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1579 * should we match?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1580 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1581 if (!had_endbrace[refnum])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1582 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1583 /* Trick: check if "@<=" or "@<!" follows, in which case
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1584 * the \1 can appear before the referenced match. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1585 for (p = regparse; *p != NUL; ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1586 if (p[0] == '@' && p[1] == '<'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1587 && (p[2] == '!' || p[2] == '='))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1588 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1589 if (*p == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1590 EMSG_RET_NULL(_("E65: Illegal back reference"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1591 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1592 ret = regnode(BACKREF + refnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1593 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1594 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1595
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1596 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1597 case Magic('z'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1598 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1599 c = no_Magic(getchr());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1600 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1601 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1602 case '(': if (reg_do_extmatch != REX_SET)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1603 EMSG_RET_NULL(_("E66: \\z( not allowed here"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1604 if (one_exactly)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1605 EMSG_ONE_RET_NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1606 ret = reg(REG_ZPAREN, &flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1607 if (ret == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1608 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1609 *flagp |= flags & (HASWIDTH|SPSTART|HASNL|HASLOOKBH);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1610 re_has_z = REX_SET;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1611 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1612
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1613 case '1':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1614 case '2':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1615 case '3':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1616 case '4':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1617 case '5':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1618 case '6':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1619 case '7':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1620 case '8':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1621 case '9': if (reg_do_extmatch != REX_USE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1622 EMSG_RET_NULL(_("E67: \\z1 et al. not allowed here"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1623 ret = regnode(ZREF + c - '0');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1624 re_has_z = REX_USE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1625 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1626
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1627 case 's': ret = regnode(MOPEN + 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1628 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1629
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1630 case 'e': ret = regnode(MCLOSE + 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1631 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1632
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1633 default: EMSG_RET_NULL(_("E68: Invalid character after \\z"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1634 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1635 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1636 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1637 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1638
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1639 case Magic('%'):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1640 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1641 c = no_Magic(getchr());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1642 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1643 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1644 /* () without a back reference */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1645 case '(':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1646 if (one_exactly)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1647 EMSG_ONE_RET_NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1648 ret = reg(REG_NPAREN, &flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1649 if (ret == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1650 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1651 *flagp |= flags & (HASWIDTH | SPSTART | HASNL | HASLOOKBH);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1652 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1653
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1654 /* Catch \%^ and \%$ regardless of where they appear in the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1655 * pattern -- regardless of whether or not it makes sense. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1656 case '^':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1657 ret = regnode(RE_BOF);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1658 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1659
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1660 case '$':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1661 ret = regnode(RE_EOF);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1662 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1663
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1664 case '#':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1665 ret = regnode(CURSOR);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1666 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1667
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1668 /* \%[abc]: Emit as a list of branches, all ending at the last
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1669 * branch which matches nothing. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1670 case '[':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1671 if (one_exactly) /* doesn't nest */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1672 EMSG_ONE_RET_NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1673 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1674 char_u *lastbranch;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1675 char_u *lastnode = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1676 char_u *br;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1677
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1678 ret = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1679 while ((c = getchr()) != ']')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1680 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1681 if (c == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1682 EMSG_M_RET_NULL(_("E69: Missing ] after %s%%["),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1683 reg_magic == MAGIC_ALL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1684 br = regnode(BRANCH);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1685 if (ret == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1686 ret = br;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1687 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1688 regtail(lastnode, br);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1689
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1690 ungetchr();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1691 one_exactly = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1692 lastnode = regatom(flagp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1693 one_exactly = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1694 if (lastnode == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1695 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1696 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1697 if (ret == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1698 EMSG_M_RET_NULL(_("E70: Empty %s%%[]"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1699 reg_magic == MAGIC_ALL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1700 lastbranch = regnode(BRANCH);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1701 br = regnode(NOTHING);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1702 if (ret != JUST_CALC_SIZE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1703 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1704 regtail(lastnode, br);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1705 regtail(lastbranch, br);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1706 /* connect all branches to the NOTHING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1707 * branch at the end */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1708 for (br = ret; br != lastnode; )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1709 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1710 if (OP(br) == BRANCH)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1711 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1712 regtail(br, lastbranch);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1713 br = OPERAND(br);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1714 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1715 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1716 br = regnext(br);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1717 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1718 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1719 *flagp &= ~HASWIDTH;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1720 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1721 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1722
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1723 case 'd': /* %d123 decimal */
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1724 case 'o': /* %o123 octal */
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1725 case 'x': /* %xab hex 2 */
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1726 case 'u': /* %uabcd hex 4 */
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1727 case 'U': /* %U1234abcd hex 8 */
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1728 {
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1729 int i;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1730
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1731 switch (c)
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1732 {
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1733 case 'd': i = getdecchrs(); break;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1734 case 'o': i = getoctchrs(); break;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1735 case 'x': i = gethexchrs(2); break;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1736 case 'u': i = gethexchrs(4); break;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1737 case 'U': i = gethexchrs(8); break;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1738 default: i = -1; break;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1739 }
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1740
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1741 if (i < 0)
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1742 EMSG_M_RET_NULL(
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1743 _("E678: Invalid character after %s%%[dxouU]"),
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1744 reg_magic == MAGIC_ALL);
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1745 ret = regnode(EXACTLY);
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1746 if (i == 0)
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1747 regc(0x0a);
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1748 else
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1749 #ifdef FEAT_MBYTE
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1750 regmbc(i);
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1751 #else
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1752 regc(i);
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1753 #endif
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1754 regc(NUL);
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1755 *flagp |= HASWIDTH;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1756 break;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1757 }
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1758
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1759 default:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1760 if (VIM_ISDIGIT(c) || c == '<' || c == '>')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1761 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1762 long_u n = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1763 int cmp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1764
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1765 cmp = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1766 if (cmp == '<' || cmp == '>')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1767 c = getchr();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1768 while (VIM_ISDIGIT(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1769 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1770 n = n * 10 + (c - '0');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1771 c = getchr();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1772 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1773 if (c == 'l' || c == 'c' || c == 'v')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1774 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1775 if (c == 'l')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1776 ret = regnode(RE_LNUM);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1777 else if (c == 'c')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1778 ret = regnode(RE_COL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1779 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1780 ret = regnode(RE_VCOL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1781 if (ret == JUST_CALC_SIZE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1782 regsize += 5;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1783 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1784 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1785 /* put the number and the optional
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1786 * comparator after the opcode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1787 regcode = re_put_long(regcode, n);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1788 *regcode++ = cmp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1789 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1790 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1791 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1792 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1793
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1794 EMSG_M_RET_NULL(_("E71: Invalid character after %s%%"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1795 reg_magic == MAGIC_ALL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1796 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1797 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1798 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1799
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1800 case Magic('['):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1801 collection:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1802 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1803 char_u *lp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1804
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1805 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1806 * If there is no matching ']', we assume the '[' is a normal
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1807 * character. This makes 'incsearch' and ":help [" work.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1808 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1809 lp = skip_anyof(regparse);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1810 if (*lp == ']') /* there is a matching ']' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1811 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1812 int startc = -1; /* > 0 when next '-' is a range */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1813 int endc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1814
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1815 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1816 * In a character class, different parsing rules apply.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1817 * Not even \ is special anymore, nothing is.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1818 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1819 if (*regparse == '^') /* Complement of range. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1820 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1821 ret = regnode(ANYBUT + extra);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1822 regparse++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1823 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1824 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1825 ret = regnode(ANYOF + extra);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1826
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1827 /* At the start ']' and '-' mean the literal character. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1828 if (*regparse == ']' || *regparse == '-')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1829 regc(*regparse++);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1830
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1831 while (*regparse != NUL && *regparse != ']')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1832 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1833 if (*regparse == '-')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1834 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1835 ++regparse;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1836 /* The '-' is not used for a range at the end and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1837 * after or before a '\n'. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1838 if (*regparse == ']' || *regparse == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1839 || startc == -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1840 || (regparse[0] == '\\' && regparse[1] == 'n'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1841 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1842 regc('-');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1843 startc = '-'; /* [--x] is a range */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1844 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1845 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1846 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1847 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1848 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1849 endc = mb_ptr2char_adv(&regparse);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1850 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1851 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1852 endc = *regparse++;
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1853
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1854 /* Handle \o40, \x20 and \u20AC style sequences */
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1855 if (endc == '\\' && !cpo_lit)
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1856 endc = coll_get_char();
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1857
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1858 if (startc > endc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1859 EMSG_RET_NULL(_(e_invrange));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1860 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1861 if (has_mbyte && ((*mb_char2len)(startc) > 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1862 || (*mb_char2len)(endc) > 1))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1863 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1864 /* Limit to a range of 256 chars */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1865 if (endc > startc + 256)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1866 EMSG_RET_NULL(_(e_invrange));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1867 while (++startc <= endc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1868 regmbc(startc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1869 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1870 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1871 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1872 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1873 #ifdef EBCDIC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1874 int alpha_only = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1875
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1876 /* for alphabetical range skip the gaps
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1877 * 'i'-'j', 'r'-'s', 'I'-'J' and 'R'-'S'. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1878 if (isalpha(startc) && isalpha(endc))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1879 alpha_only = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1880 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1881 while (++startc <= endc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1882 #ifdef EBCDIC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1883 if (!alpha_only || isalpha(startc))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1884 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1885 regc(startc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1886 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1887 startc = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1888 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1889 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1890 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1891 * Only "\]", "\^", "\]" and "\\" are special in Vi. Vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1892 * accepts "\t", "\e", etc., but only when the 'l' flag in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1893 * 'cpoptions' is not included.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1894 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1895 else if (*regparse == '\\'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1896 && (vim_strchr(REGEXP_INRANGE, regparse[1]) != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1897 || (!cpo_lit
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1898 && vim_strchr(REGEXP_ABBR,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1899 regparse[1]) != NULL)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1900 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1901 regparse++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1902 if (*regparse == 'n')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1903 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1904 /* '\n' in range: also match NL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1905 if (ret != JUST_CALC_SIZE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1906 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1907 if (*ret == ANYBUT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1908 *ret = ANYBUT + ADD_NL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1909 else if (*ret == ANYOF)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1910 *ret = ANYOF + ADD_NL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1911 /* else: must have had a \n already */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1912 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1913 *flagp |= HASNL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1914 regparse++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1915 startc = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1916 }
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1917 else if (*regparse == 'd'
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1918 || *regparse == 'o'
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1919 || *regparse == 'x'
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1920 || *regparse == 'u'
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1921 || *regparse == 'U')
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1922 {
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1923 startc = coll_get_char();
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1924 if (startc == 0)
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1925 regc(0x0a);
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1926 else
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1927 #ifdef FEAT_MBYTE
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1928 regmbc(startc);
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1929 #else
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1930 regc(startc);
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1931 #endif
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
1932 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1933 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1934 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1935 startc = backslash_trans(*regparse++);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1936 regc(startc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1937 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1938 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1939 else if (*regparse == '[')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1940 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1941 int c_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1942 int cu;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1943
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1944 c_class = skip_class_name(&regparse);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1945 startc = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1946 /* Characters assumed to be 8 bits! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1947 switch (c_class)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1948 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1949 case CLASS_NONE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1950 /* literal '[', allow [[-x] as a range */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1951 startc = *regparse++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1952 regc(startc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1953 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1954 case CLASS_ALNUM:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1955 for (cu = 1; cu <= 255; cu++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1956 if (isalnum(cu))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1957 regc(cu);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1958 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1959 case CLASS_ALPHA:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1960 for (cu = 1; cu <= 255; cu++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1961 if (isalpha(cu))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1962 regc(cu);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1963 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1964 case CLASS_BLANK:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1965 regc(' ');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1966 regc('\t');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1967 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1968 case CLASS_CNTRL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1969 for (cu = 1; cu <= 255; cu++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1970 if (iscntrl(cu))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1971 regc(cu);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1972 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1973 case CLASS_DIGIT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1974 for (cu = 1; cu <= 255; cu++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1975 if (VIM_ISDIGIT(cu))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1976 regc(cu);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1977 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1978 case CLASS_GRAPH:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1979 for (cu = 1; cu <= 255; cu++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1980 if (isgraph(cu))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1981 regc(cu);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1982 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1983 case CLASS_LOWER:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1984 for (cu = 1; cu <= 255; cu++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1985 if (islower(cu))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1986 regc(cu);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1987 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1988 case CLASS_PRINT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1989 for (cu = 1; cu <= 255; cu++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1990 if (vim_isprintc(cu))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1991 regc(cu);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1992 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1993 case CLASS_PUNCT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1994 for (cu = 1; cu <= 255; cu++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1995 if (ispunct(cu))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1996 regc(cu);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1997 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1998 case CLASS_SPACE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1999 for (cu = 9; cu <= 13; cu++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2000 regc(cu);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2001 regc(' ');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2002 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2003 case CLASS_UPPER:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2004 for (cu = 1; cu <= 255; cu++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2005 if (isupper(cu))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2006 regc(cu);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2007 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2008 case CLASS_XDIGIT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2009 for (cu = 1; cu <= 255; cu++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2010 if (vim_isxdigit(cu))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2011 regc(cu);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2012 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2013 case CLASS_TAB:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2014 regc('\t');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2015 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2016 case CLASS_RETURN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2017 regc('\r');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2018 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2019 case CLASS_BACKSPACE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2020 regc('\b');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2021 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2022 case CLASS_ESCAPE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2023 regc('\033');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2024 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2025 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2026 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2027 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2028 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2029 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2030 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2031 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2032 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2033
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2034 /* produce a multibyte character, including any
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2035 * following composing characters */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2036 startc = mb_ptr2char(regparse);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2037 len = (*mb_ptr2len_check)(regparse);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2038 if (enc_utf8 && utf_char2len(startc) != len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2039 startc = -1; /* composing chars */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2040 while (--len >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2041 regc(*regparse++);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2042 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2043 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2044 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2045 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2046 startc = *regparse++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2047 regc(startc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2048 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2049 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2050 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2051 regc(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2052 prevchr_len = 1; /* last char was the ']' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2053 if (*regparse != ']')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2054 EMSG_RET_NULL(_(e_toomsbra)); /* Cannot happen? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2055 skipchr(); /* let's be friends with the lexer again */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2056 *flagp |= HASWIDTH | SIMPLE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2057 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2058 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2059 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2060 /* FALLTHROUGH */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2061
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2062 default:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2063 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2064 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2065
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2066 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2067 /* A multi-byte character is handled as a separate atom if it's
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2068 * before a multi. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2069 if (has_mbyte && (*mb_char2len)(c) > 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2070 && re_multi_type(peekchr()) != NOT_MULTI)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2071 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2072 ret = regnode(MULTIBYTECODE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2073 regmbc(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2074 *flagp |= HASWIDTH | SIMPLE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2075 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2076 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2077 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2078
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2079 ret = regnode(EXACTLY);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2080
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2081 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2082 * Append characters as long as:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2083 * - there is no following multi, we then need the character in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2084 * front of it as a single character operand
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2085 * - not running into a Magic character
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2086 * - "one_exactly" is not set
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2087 * But always emit at least one character. Might be a Multi,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2088 * e.g., a "[" without matching "]".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2089 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2090 for (len = 0; c != NUL && (len == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2091 || (re_multi_type(peekchr()) == NOT_MULTI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2092 && !one_exactly
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2093 && !is_Magic(c))); ++len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2094 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2095 c = no_Magic(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2096 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2097 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2098 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2099 regmbc(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2100 if (enc_utf8)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2101 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2102 int off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2103 int l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2104
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2105 /* Need to get composing character too, directly
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2106 * access regparse for that, because skipchr() skips
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2107 * over composing chars. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2108 ungetchr();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2109 if (*regparse == '\\' && regparse[1] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2110 off = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2111 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2112 off = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2113 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2114 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2115 l = utf_ptr2len_check(regparse + off);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2116 if (!UTF_COMPOSINGLIKE(regparse + off,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2117 regparse + off + l))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2118 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2119 off += l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2120 regmbc(utf_ptr2char(regparse + off));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2121 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2122 skipchr();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2123 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2124 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2125 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2126 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2127 regc(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2128 c = getchr();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2129 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2130 ungetchr();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2131
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2132 regc(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2133 *flagp |= HASWIDTH;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2134 if (len == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2135 *flagp |= SIMPLE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2136 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2137 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2138 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2139
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2140 return ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2141 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2142
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2143 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2144 * emit a node
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2145 * Return pointer to generated code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2146 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2147 static char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2148 regnode(op)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2149 int op;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2150 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2151 char_u *ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2152
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2153 ret = regcode;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2154 if (ret == JUST_CALC_SIZE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2155 regsize += 3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2156 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2157 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2158 *regcode++ = op;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2159 *regcode++ = NUL; /* Null "next" pointer. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2160 *regcode++ = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2161 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2162 return ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2163 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2164
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2165 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2166 * Emit (if appropriate) a byte of code
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2167 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2168 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2169 regc(b)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2170 int b;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2171 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2172 if (regcode == JUST_CALC_SIZE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2173 regsize++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2174 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2175 *regcode++ = b;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2176 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2177
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2178 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2179 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2180 * Emit (if appropriate) a multi-byte character of code
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2181 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2182 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2183 regmbc(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2184 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2185 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2186 if (regcode == JUST_CALC_SIZE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2187 regsize += (*mb_char2len)(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2188 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2189 regcode += (*mb_char2bytes)(c, regcode);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2190 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2191 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2192
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2193 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2194 * reginsert - insert an operator in front of already-emitted operand
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2195 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2196 * Means relocating the operand.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2197 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2198 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2199 reginsert(op, opnd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2200 int op;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2201 char_u *opnd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2202 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2203 char_u *src;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2204 char_u *dst;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2205 char_u *place;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2206
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2207 if (regcode == JUST_CALC_SIZE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2208 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2209 regsize += 3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2210 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2211 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2212 src = regcode;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2213 regcode += 3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2214 dst = regcode;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2215 while (src > opnd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2216 *--dst = *--src;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2217
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2218 place = opnd; /* Op node, where operand used to be. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2219 *place++ = op;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2220 *place++ = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2221 *place = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2222 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2223
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2224 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2225 * reginsert_limits - insert an operator in front of already-emitted operand.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2226 * The operator has the given limit values as operands. Also set next pointer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2227 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2228 * Means relocating the operand.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2229 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2230 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2231 reginsert_limits(op, minval, maxval, opnd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2232 int op;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2233 long minval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2234 long maxval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2235 char_u *opnd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2236 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2237 char_u *src;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2238 char_u *dst;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2239 char_u *place;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2240
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2241 if (regcode == JUST_CALC_SIZE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2242 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2243 regsize += 11;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2244 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2245 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2246 src = regcode;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2247 regcode += 11;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2248 dst = regcode;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2249 while (src > opnd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2250 *--dst = *--src;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2251
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2252 place = opnd; /* Op node, where operand used to be. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2253 *place++ = op;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2254 *place++ = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2255 *place++ = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2256 place = re_put_long(place, (long_u)minval);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2257 place = re_put_long(place, (long_u)maxval);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2258 regtail(opnd, place);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2259 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2260
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2261 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2262 * Write a long as four bytes at "p" and return pointer to the next char.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2263 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2264 static char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2265 re_put_long(p, val)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2266 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2267 long_u val;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2268 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2269 *p++ = (char_u) ((val >> 24) & 0377);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2270 *p++ = (char_u) ((val >> 16) & 0377);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2271 *p++ = (char_u) ((val >> 8) & 0377);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2272 *p++ = (char_u) (val & 0377);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2273 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2274 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2275
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2276 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2277 * regtail - set the next-pointer at the end of a node chain
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2278 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2279 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2280 regtail(p, val)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2281 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2282 char_u *val;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2283 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2284 char_u *scan;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2285 char_u *temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2286 int offset;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2287
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2288 if (p == JUST_CALC_SIZE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2289 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2290
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2291 /* Find last node. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2292 scan = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2293 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2294 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2295 temp = regnext(scan);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2296 if (temp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2297 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2298 scan = temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2299 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2300
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2301 if (OP(scan) == BACK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2302 offset = (int)(scan - val);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2303 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2304 offset = (int)(val - scan);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2305 *(scan + 1) = (char_u) (((unsigned)offset >> 8) & 0377);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2306 *(scan + 2) = (char_u) (offset & 0377);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2307 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2308
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2309 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2310 * regoptail - regtail on item after a BRANCH; nop if none
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2311 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2312 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2313 regoptail(p, val)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2314 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2315 char_u *val;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2316 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2317 /* When op is neither BRANCH nor BRACE_COMPLEX0-9, it is "operandless" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2318 if (p == NULL || p == JUST_CALC_SIZE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2319 || (OP(p) != BRANCH
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2320 && (OP(p) < BRACE_COMPLEX || OP(p) > BRACE_COMPLEX + 9)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2321 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2322 regtail(OPERAND(p), val);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2323 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2324
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2325 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2326 * getchr() - get the next character from the pattern. We know about
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2327 * magic and such, so therefore we need a lexical analyzer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2328 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2329
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2330 /* static int curchr; */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2331 static int prevprevchr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2332 static int prevchr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2333 static int nextchr; /* used for ungetchr() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2334 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2335 * Note: prevchr is sometimes -1 when we are not at the start,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2336 * eg in /[ ^I]^ the pattern was never found even if it existed, because ^ was
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2337 * taken to be magic -- webb
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2338 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2339 static int at_start; /* True when on the first character */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2340 static int prev_at_start; /* True when on the second character */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2341
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2342 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2343 initchr(str)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2344 char_u *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2345 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2346 regparse = str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2347 prevchr_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2348 curchr = prevprevchr = prevchr = nextchr = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2349 at_start = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2350 prev_at_start = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2351 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2352
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2353 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2354 peekchr()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2355 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2356 if (curchr == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2357 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2358 switch (curchr = regparse[0])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2359 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2360 case '.':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2361 case '[':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2362 case '~':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2363 /* magic when 'magic' is on */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2364 if (reg_magic >= MAGIC_ON)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2365 curchr = Magic(curchr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2366 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2367 case '(':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2368 case ')':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2369 case '{':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2370 case '%':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2371 case '+':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2372 case '=':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2373 case '?':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2374 case '@':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2375 case '!':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2376 case '&':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2377 case '|':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2378 case '<':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2379 case '>':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2380 case '#': /* future ext. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2381 case '"': /* future ext. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2382 case '\'': /* future ext. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2383 case ',': /* future ext. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2384 case '-': /* future ext. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2385 case ':': /* future ext. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2386 case ';': /* future ext. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2387 case '`': /* future ext. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2388 case '/': /* Can't be used in / command */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2389 /* magic only after "\v" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2390 if (reg_magic == MAGIC_ALL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2391 curchr = Magic(curchr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2392 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2393 case '*':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2394 /* * is not magic as the very first character, eg "?*ptr" and when
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2395 * after '^', eg "/^*ptr" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2396 if (reg_magic >= MAGIC_ON && !at_start
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2397 && !(prev_at_start && prevchr == Magic('^')))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2398 curchr = Magic('*');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2399 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2400 case '^':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2401 /* '^' is only magic as the very first character and if it's after
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2402 * "\(", "\|", "\&' or "\n" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2403 if (reg_magic >= MAGIC_OFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2404 && (at_start
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2405 || reg_magic == MAGIC_ALL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2406 || prevchr == Magic('(')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2407 || prevchr == Magic('|')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2408 || prevchr == Magic('&')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2409 || prevchr == Magic('n')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2410 || (no_Magic(prevchr) == '('
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2411 && prevprevchr == Magic('%'))))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2412 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2413 curchr = Magic('^');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2414 at_start = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2415 prev_at_start = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2416 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2417 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2418 case '$':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2419 /* '$' is only magic as the very last char and if it's in front of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2420 * either "\|", "\)", "\&", or "\n" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2421 if (reg_magic >= MAGIC_OFF)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2422 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2423 char_u *p = regparse + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2424
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2425 /* ignore \c \C \m and \M after '$' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2426 while (p[0] == '\\' && (p[1] == 'c' || p[1] == 'C'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2427 || p[1] == 'm' || p[1] == 'M' || p[1] == 'Z'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2428 p += 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2429 if (p[0] == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2430 || (p[0] == '\\'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2431 && (p[1] == '|' || p[1] == '&' || p[1] == ')'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2432 || p[1] == 'n'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2433 || reg_magic == MAGIC_ALL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2434 curchr = Magic('$');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2435 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2436 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2437 case '\\':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2438 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2439 int c = regparse[1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2440
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2441 if (c == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2442 curchr = '\\'; /* trailing '\' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2443 else if (
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2444 #ifdef EBCDIC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2445 vim_strchr(META, c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2446 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2447 c <= '~' && META_flags[c]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2448 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2449 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2450 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2451 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2452 * META contains everything that may be magic sometimes,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2453 * except ^ and $ ("\^" and "\$" are only magic after
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2454 * "\v"). We now fetch the next character and toggle its
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2455 * magicness. Therefore, \ is so meta-magic that it is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2456 * not in META.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2457 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2458 curchr = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2459 prev_at_start = at_start;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2460 at_start = FALSE; /* be able to say "/\*ptr" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2461 ++regparse;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2462 peekchr();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2463 --regparse;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2464 curchr = toggle_Magic(curchr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2465 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2466 else if (vim_strchr(REGEXP_ABBR, c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2467 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2468 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2469 * Handle abbreviations, like "\t" for TAB -- webb
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2470 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2471 curchr = backslash_trans(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2472 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2473 else if (reg_magic == MAGIC_NONE && (c == '$' || c == '^'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2474 curchr = toggle_Magic(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2475 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2476 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2477 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2478 * Next character can never be (made) magic?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2479 * Then backslashing it won't do anything.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2480 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2481 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2482 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2483 curchr = (*mb_ptr2char)(regparse + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2484 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2485 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2486 curchr = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2487 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2488 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2489 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2490
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2491 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2492 default:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2493 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2494 curchr = (*mb_ptr2char)(regparse);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2495 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2496 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2497 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2498
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2499 return curchr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2500 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2501
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2502 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2503 * Eat one lexed character. Do this in a way that we can undo it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2504 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2505 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2506 skipchr()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2507 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2508 /* peekchr() eats a backslash, do the same here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2509 if (*regparse == '\\')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2510 prevchr_len = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2511 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2512 prevchr_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2513 if (regparse[prevchr_len] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2514 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2515 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2516 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2517 prevchr_len += (*mb_ptr2len_check)(regparse + prevchr_len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2518 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2519 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2520 ++prevchr_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2521 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2522 regparse += prevchr_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2523 prev_at_start = at_start;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2524 at_start = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2525 prevprevchr = prevchr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2526 prevchr = curchr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2527 curchr = nextchr; /* use previously unget char, or -1 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2528 nextchr = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2529 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2530
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2531 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2532 * Skip a character while keeping the value of prev_at_start for at_start.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2533 * prevchr and prevprevchr are also kept.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2534 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2535 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2536 skipchr_keepstart()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2537 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2538 int as = prev_at_start;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2539 int pr = prevchr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2540 int prpr = prevprevchr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2541
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2542 skipchr();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2543 at_start = as;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2544 prevchr = pr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2545 prevprevchr = prpr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2546 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2547
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2548 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2549 getchr()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2550 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2551 int chr = peekchr();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2552
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2553 skipchr();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2554 return chr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2555 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2556
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2557 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2558 * put character back. Works only once!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2559 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2560 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2561 ungetchr()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2562 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2563 nextchr = curchr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2564 curchr = prevchr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2565 prevchr = prevprevchr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2566 at_start = prev_at_start;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2567 prev_at_start = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2568
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2569 /* Backup regparse, so that it's at the same position as before the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2570 * getchr(). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2571 regparse -= prevchr_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2572 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2573
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2574 /*
29
ac33b7c03fac updated for version 7.0018
vimboss
parents: 24
diff changeset
2575 * Get and return the value of the hex string at the current position.
ac33b7c03fac updated for version 7.0018
vimboss
parents: 24
diff changeset
2576 * Return -1 if there is no valid hex number.
ac33b7c03fac updated for version 7.0018
vimboss
parents: 24
diff changeset
2577 * The position is updated:
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2578 * blahblah\%x20asdf
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2579 * before-^ ^-after
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2580 * The parameter controls the maximum number of input characters. This will be
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2581 * 2 when reading a \%x20 sequence and 4 when reading a \%u20AC sequence.
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2582 */
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2583 static int
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2584 gethexchrs(maxinputlen)
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2585 int maxinputlen;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2586 {
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2587 int nr = 0;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2588 int c;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2589 int i;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2590
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2591 for (i = 0; i < maxinputlen; ++i)
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2592 {
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2593 c = regparse[0];
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2594 if (!vim_isxdigit(c))
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2595 break;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2596 nr <<= 4;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2597 nr |= hex2nr(c);
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2598 ++regparse;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2599 }
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2600
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2601 if (i == 0)
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2602 return -1;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2603 return nr;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2604 }
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2605
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2606 /*
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2607 * get and return the value of the decimal string immediately after the
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2608 * current position. Return -1 for invalid. Consumes all digits.
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2609 */
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2610 static int
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2611 getdecchrs()
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2612 {
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2613 int nr = 0;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2614 int c;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2615 int i;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2616
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2617 for (i = 0; ; ++i)
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2618 {
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2619 c = regparse[0];
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2620 if (c < '0' || c > '9')
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2621 break;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2622 nr *= 10;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2623 nr += c - '0';
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2624 ++regparse;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2625 }
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2626
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2627 if (i == 0)
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2628 return -1;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2629 return nr;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2630 }
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2631
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2632 /*
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2633 * get and return the value of the octal string immediately after the current
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2634 * position. Return -1 for invalid, or 0-255 for valid. Smart enough to handle
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2635 * numbers > 377 correctly (for example, 400 is treated as 40) and doesn't
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2636 * treat 8 or 9 as recognised characters. Position is updated:
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2637 * blahblah\%o210asdf
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2638 * before-^ ^-after
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2639 */
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2640 static int
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2641 getoctchrs()
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2642 {
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2643 int nr = 0;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2644 int c;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2645 int i;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2646
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2647 for (i = 0; i < 3 && nr < 040; ++i)
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2648 {
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2649 c = regparse[0];
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2650 if (c < '0' || c > '7')
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2651 break;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2652 nr <<= 3;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2653 nr |= hex2nr(c);
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2654 ++regparse;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2655 }
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2656
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2657 if (i == 0)
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2658 return -1;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2659 return nr;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2660 }
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2661
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2662 /*
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2663 * Get a number after a backslash that is inside [].
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2664 * When nothing is recognized return a backslash.
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2665 */
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2666 static int
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2667 coll_get_char()
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2668 {
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2669 int nr = -1;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2670
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2671 switch (*regparse++)
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2672 {
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2673 case 'd': nr = getdecchrs(); break;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2674 case 'o': nr = getoctchrs(); break;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2675 case 'x': nr = gethexchrs(2); break;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2676 case 'u': nr = gethexchrs(4); break;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2677 case 'U': nr = gethexchrs(8); break;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2678 }
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2679 if (nr < 0)
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2680 {
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2681 /* If getting the number fails be backwards compatible: the character
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2682 * is a backslash. */
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2683 --regparse;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2684 nr = '\\';
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2685 }
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2686 return nr;
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2687 }
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2688
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
2689 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2690 * read_limits - Read two integers to be taken as a minimum and maximum.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2691 * If the first character is '-', then the range is reversed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2692 * Should end with 'end'. If minval is missing, zero is default, if maxval is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2693 * missing, a very big number is the default.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2694 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2695 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2696 read_limits(minval, maxval)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2697 long *minval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2698 long *maxval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2699 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2700 int reverse = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2701 char_u *first_char;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2702 long tmp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2703
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2704 if (*regparse == '-')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2705 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2706 /* Starts with '-', so reverse the range later */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2707 regparse++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2708 reverse = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2709 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2710 first_char = regparse;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2711 *minval = getdigits(&regparse);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2712 if (*regparse == ',') /* There is a comma */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2713 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2714 if (vim_isdigit(*++regparse))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2715 *maxval = getdigits(&regparse);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2716 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2717 *maxval = MAX_LIMIT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2718 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2719 else if (VIM_ISDIGIT(*first_char))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2720 *maxval = *minval; /* It was \{n} or \{-n} */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2721 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2722 *maxval = MAX_LIMIT; /* It was \{} or \{-} */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2723 if (*regparse == '\\')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2724 regparse++; /* Allow either \{...} or \{...\} */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2725 if (*regparse != '}' || (*maxval == 0 && *minval == 0))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2726 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2727 sprintf((char *)IObuff, _("E554: Syntax error in %s{...}"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2728 reg_magic == MAGIC_ALL ? "" : "\\");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2729 EMSG_RET_FAIL(IObuff);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2730 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2731
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2732 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2733 * Reverse the range if there was a '-', or make sure it is in the right
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2734 * order otherwise.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2735 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2736 if ((!reverse && *minval > *maxval) || (reverse && *minval < *maxval))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2737 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2738 tmp = *minval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2739 *minval = *maxval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2740 *maxval = tmp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2741 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2742 skipchr(); /* let's be friends with the lexer again */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2743 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2744 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2745
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2746 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2747 * vim_regexec and friends
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2748 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2749
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2750 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2751 * Global work variables for vim_regexec().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2752 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2753
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2754 /* The current match-position is remembered with these variables: */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2755 static linenr_T reglnum; /* line number, relative to first line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2756 static char_u *regline; /* start of current line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2757 static char_u *reginput; /* current input, points into "regline" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2758
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2759 static int need_clear_subexpr; /* subexpressions still need to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2760 * cleared */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2761 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2762 static int need_clear_zsubexpr = FALSE; /* extmatch subexpressions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2763 * still need to be cleared */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2764 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2765
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2766 static int out_of_stack; /* TRUE when ran out of stack space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2767
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2768 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2769 * Structure used to save the current input state, when it needs to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2770 * restored after trying a match. Used by reg_save() and reg_restore().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2771 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2772 typedef struct
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2773 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2774 union
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2775 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2776 char_u *ptr; /* reginput pointer, for single-line regexp */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2777 lpos_T pos; /* reginput pos, for multi-line regexp */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2778 } rs_u;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2779 } regsave_T;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2780
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2781 /* struct to save start/end pointer/position in for \(\) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2782 typedef struct
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2783 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2784 union
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2785 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2786 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2787 lpos_T pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2788 } se_u;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2789 } save_se_T;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2790
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2791 static char_u *reg_getline __ARGS((linenr_T lnum));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2792 static long vim_regexec_both __ARGS((char_u *line, colnr_T col));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2793 static long regtry __ARGS((regprog_T *prog, colnr_T col));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2794 static void cleanup_subexpr __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2795 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2796 static void cleanup_zsubexpr __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2797 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2798 static void reg_nextline __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2799 static void reg_save __ARGS((regsave_T *save));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2800 static void reg_restore __ARGS((regsave_T *save));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2801 static int reg_save_equal __ARGS((regsave_T *save));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2802 static void save_se_multi __ARGS((save_se_T *savep, lpos_T *posp));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2803 static void save_se_one __ARGS((save_se_T *savep, char_u **pp));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2804
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2805 /* Save the sub-expressions before attempting a match. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2806 #define save_se(savep, posp, pp) \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2807 REG_MULTI ? save_se_multi((savep), (posp)) : save_se_one((savep), (pp))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2808
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2809 /* After a failed match restore the sub-expressions. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2810 #define restore_se(savep, posp, pp) { \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2811 if (REG_MULTI) \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2812 *(posp) = (savep)->se_u.pos; \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2813 else \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2814 *(pp) = (savep)->se_u.ptr; }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2815
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2816 static int re_num_cmp __ARGS((long_u val, char_u *scan));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2817 static int regmatch __ARGS((char_u *prog));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2818 static int regrepeat __ARGS((char_u *p, long maxcount));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2819
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2820 #ifdef DEBUG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2821 int regnarrate = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2822 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2823
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2824 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2825 * Internal copy of 'ignorecase'. It is set at each call to vim_regexec().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2826 * Normally it gets the value of "rm_ic" or "rmm_ic", but when the pattern
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2827 * contains '\c' or '\C' the value is overruled.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2828 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2829 static int ireg_ic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2830
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2831 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2832 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2833 * Similar to ireg_ic, but only for 'combining' characters. Set with \Z flag
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2834 * in the regexp. Defaults to false, always.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2835 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2836 static int ireg_icombine;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2837 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2838
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2839 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2840 * Sometimes need to save a copy of a line. Since alloc()/free() is very
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2841 * slow, we keep one allocated piece of memory and only re-allocate it when
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2842 * it's too small. It's freed in vim_regexec_both() when finished.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2843 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2844 static char_u *reg_tofree;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2845 static unsigned reg_tofreelen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2846
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2847 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2848 * These variables are set when executing a regexp to speed up the execution.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2849 * Which ones are set depends on whethere a single-line or multi-line match is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2850 * done:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2851 * single-line multi-line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2852 * reg_match &regmatch_T NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2853 * reg_mmatch NULL &regmmatch_T
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2854 * reg_startp reg_match->startp <invalid>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2855 * reg_endp reg_match->endp <invalid>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2856 * reg_startpos <invalid> reg_mmatch->startpos
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2857 * reg_endpos <invalid> reg_mmatch->endpos
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2858 * reg_win NULL window in which to search
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2859 * reg_buf <invalid> buffer in which to search
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2860 * reg_firstlnum <invalid> first line in which to search
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2861 * reg_maxline 0 last line nr
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2862 * reg_line_lbr FALSE or TRUE FALSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2863 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2864 static regmatch_T *reg_match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2865 static regmmatch_T *reg_mmatch;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2866 static char_u **reg_startp = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2867 static char_u **reg_endp = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2868 static lpos_T *reg_startpos = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2869 static lpos_T *reg_endpos = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2870 static win_T *reg_win;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2871 static buf_T *reg_buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2872 static linenr_T reg_firstlnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2873 static linenr_T reg_maxline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2874 static int reg_line_lbr; /* "\n" in string is line break */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2875
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2876 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2877 * Get pointer to the line "lnum", which is relative to "reg_firstlnum".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2878 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2879 static char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2880 reg_getline(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2881 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2882 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2883 /* when looking behind for a match/no-match lnum is negative. But we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2884 * can't go before line 1 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2885 if (reg_firstlnum + lnum < 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2886 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2887 return ml_get_buf(reg_buf, reg_firstlnum + lnum, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2888 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2889
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2890 static regsave_T behind_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2891
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2892 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2893 static char_u *reg_startzp[NSUBEXP]; /* Workspace to mark beginning */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2894 static char_u *reg_endzp[NSUBEXP]; /* and end of \z(...\) matches */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2895 static lpos_T reg_startzpos[NSUBEXP]; /* idem, beginning pos */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2896 static lpos_T reg_endzpos[NSUBEXP]; /* idem, end pos */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2897 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2898
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2899 /* TRUE if using multi-line regexp. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2900 #define REG_MULTI (reg_match == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2901
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2902 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2903 * Match a regexp against a string.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2904 * "rmp->regprog" is a compiled regexp as returned by vim_regcomp().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2905 * Uses curbuf for line count and 'iskeyword'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2906 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2907 * Return TRUE if there is a match, FALSE if not.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2908 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2909 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2910 vim_regexec(rmp, line, col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2911 regmatch_T *rmp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2912 char_u *line; /* string to match against */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2913 colnr_T col; /* column to start looking for match */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2914 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2915 reg_match = rmp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2916 reg_mmatch = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2917 reg_maxline = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2918 reg_line_lbr = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2919 reg_win = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2920 ireg_ic = rmp->rm_ic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2921 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2922 ireg_icombine = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2923 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2924 return (vim_regexec_both(line, col) != 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2925 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2926
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
2927 #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) \
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
2928 || defined(FIND_REPLACE_DIALOG) || defined(PROTO)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2929 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2930 * Like vim_regexec(), but consider a "\n" in "line" to be a line break.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2931 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2932 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2933 vim_regexec_nl(rmp, line, col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2934 regmatch_T *rmp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2935 char_u *line; /* string to match against */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2936 colnr_T col; /* column to start looking for match */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2937 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2938 reg_match = rmp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2939 reg_mmatch = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2940 reg_maxline = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2941 reg_line_lbr = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2942 reg_win = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2943 ireg_ic = rmp->rm_ic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2944 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2945 ireg_icombine = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2946 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2947 return (vim_regexec_both(line, col) != 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2948 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2949 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2950
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2951 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2952 * Match a regexp against multiple lines.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2953 * "rmp->regprog" is a compiled regexp as returned by vim_regcomp().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2954 * Uses curbuf for line count and 'iskeyword'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2955 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2956 * Return zero if there is no match. Return number of lines contained in the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2957 * match otherwise.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2958 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2959 long
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2960 vim_regexec_multi(rmp, win, buf, lnum, col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2961 regmmatch_T *rmp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2962 win_T *win; /* window in which to search or NULL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2963 buf_T *buf; /* buffer in which to search */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2964 linenr_T lnum; /* nr of line to start looking for match */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2965 colnr_T col; /* column to start looking for match */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2966 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2967 long r;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2968 buf_T *save_curbuf = curbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2969
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2970 reg_match = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2971 reg_mmatch = rmp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2972 reg_buf = buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2973 reg_win = win;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2974 reg_firstlnum = lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2975 reg_maxline = reg_buf->b_ml.ml_line_count - lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2976 reg_line_lbr = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2977 ireg_ic = rmp->rmm_ic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2978 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2979 ireg_icombine = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2980 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2981
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2982 /* Need to switch to buffer "buf" to make vim_iswordc() work. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2983 curbuf = buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2984 r = vim_regexec_both(NULL, col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2985 curbuf = save_curbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2986
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2987 return r;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2988 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2989
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2990 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2991 * Match a regexp against a string ("line" points to the string) or multiple
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2992 * lines ("line" is NULL, use reg_getline()).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2993 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2994 #ifdef HAVE_SETJMP_H
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2995 static long
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2996 vim_regexec_both(line_arg, col_arg)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2997 char_u *line_arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2998 colnr_T col_arg; /* column to start looking for match */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2999 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3000 static long
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3001 vim_regexec_both(line, col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3002 char_u *line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3003 colnr_T col; /* column to start looking for match */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3004 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3005 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3006 regprog_T *prog;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3007 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3008 long retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3009 #ifdef HAVE_SETJMP_H
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3010 char_u *line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3011 colnr_T col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3012 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3013
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3014 reg_tofree = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3015
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3016 #ifdef HAVE_TRY_EXCEPT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3017 __try
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3018 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3019 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3020
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3021 #ifdef HAVE_SETJMP_H
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3022 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3023 * Matching with a regexp may cause a very deep recursive call of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3024 * regmatch(). Vim will crash when running out of stack space. Catch
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3025 * this here if the system supports it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3026 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3027 mch_startjmp();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3028 if (SETJMP(lc_jump_env) != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3029 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3030 mch_didjmp();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3031 # ifdef SIGHASARG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3032 if (lc_signal != SIGINT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3033 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3034 EMSG(_("E361: Crash intercepted; regexp too complex?"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3035 retval = 0L;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3036 goto theend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3037 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3038
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3039 /* Trick to avoid "might be clobbered by `longjmp'" warning from gcc. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3040 line = line_arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3041 col = col_arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3042 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3043 retval = 0L;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3044
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3045 if (REG_MULTI)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3046 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3047 prog = reg_mmatch->regprog;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3048 line = reg_getline((linenr_T)0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3049 reg_startpos = reg_mmatch->startpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3050 reg_endpos = reg_mmatch->endpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3051 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3052 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3053 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3054 prog = reg_match->regprog;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3055 reg_startp = reg_match->startp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3056 reg_endp = reg_match->endp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3057 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3058
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3059 /* Be paranoid... */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3060 if (prog == NULL || line == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3061 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3062 EMSG(_(e_null));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3063 goto theend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3064 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3065
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3066 /* Check validity of program. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3067 if (prog_magic_wrong())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3068 goto theend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3069
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3070 /* If pattern contains "\c" or "\C": overrule value of ireg_ic */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3071 if (prog->regflags & RF_ICASE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3072 ireg_ic = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3073 else if (prog->regflags & RF_NOICASE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3074 ireg_ic = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3075
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3076 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3077 /* If pattern contains "\Z" overrule value of ireg_icombine */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3078 if (prog->regflags & RF_ICOMBINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3079 ireg_icombine = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3080 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3081
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3082 /* If there is a "must appear" string, look for it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3083 if (prog->regmust != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3084 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3085 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3086
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3087 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3088 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3089 c = (*mb_ptr2char)(prog->regmust);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3090 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3091 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3092 c = *prog->regmust;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3093 s = line + col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3094 while ((s = cstrchr(s, c)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3095 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3096 if (cstrncmp(s, prog->regmust, &prog->regmlen) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3097 break; /* Found it. */
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
3098 mb_ptr_adv(s);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3099 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3100 if (s == NULL) /* Not present. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3101 goto theend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3102 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3103
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3104 regline = line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3105 reglnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3106 out_of_stack = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3107
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3108 /* Simplest case: Anchored match need be tried only once. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3109 if (prog->reganch)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3110 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3111 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3112
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3113 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3114 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3115 c = (*mb_ptr2char)(regline + col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3116 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3117 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3118 c = regline[col];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3119 if (prog->regstart == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3120 || prog->regstart == c
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3121 || (ireg_ic && ((
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3122 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3123 (enc_utf8 && utf_fold(prog->regstart) == utf_fold(c)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3124 || (c < 255 && prog->regstart < 255 &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3125 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3126 TOLOWER_LOC(prog->regstart) == TOLOWER_LOC(c)))))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3127 retval = regtry(prog, col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3128 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3129 retval = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3130 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3131 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3132 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3133 /* Messy cases: unanchored match. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3134 while (!got_int && !out_of_stack)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3135 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3136 if (prog->regstart != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3137 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3138 /* Skip until the char we know it must start with. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3139 s = cstrchr(regline + col, prog->regstart);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3140 if (s == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3141 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3142 retval = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3143 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3144 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3145 col = (int)(s - regline);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3146 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3147
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3148 retval = regtry(prog, col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3149 if (retval > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3150 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3151
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3152 /* if not currently on the first line, get it again */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3153 if (reglnum != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3154 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3155 regline = reg_getline((linenr_T)0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3156 reglnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3157 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3158 if (regline[col] == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3159 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3160 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3161 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3162 col += (*mb_ptr2len_check)(regline + col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3163 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3164 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3165 ++col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3166 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3167 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3168
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3169 if (out_of_stack)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3170 EMSG(_("E363: pattern caused out-of-stack error"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3171
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3172 #ifdef HAVE_TRY_EXCEPT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3173 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3174 __except(EXCEPTION_EXECUTE_HANDLER)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3175 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3176 if (GetExceptionCode() == EXCEPTION_STACK_OVERFLOW)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3177 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3178 RESETSTKOFLW();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3179 EMSG(_("E363: pattern caused out-of-stack error"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3180 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3181 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3182 EMSG(_("E361: Crash intercepted; regexp too complex?"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3183 retval = 0L;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3184 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3185 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3186
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3187 theend:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3188 /* Didn't find a match. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3189 vim_free(reg_tofree);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3190 #ifdef HAVE_SETJMP_H
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3191 mch_endjmp();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3192 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3193 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3194 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3195
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3196 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3197 static reg_extmatch_T *make_extmatch __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3198
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3199 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3200 * Create a new extmatch and mark it as referenced once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3201 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3202 static reg_extmatch_T *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3203 make_extmatch()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3204 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3205 reg_extmatch_T *em;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3206
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3207 em = (reg_extmatch_T *)alloc_clear((unsigned)sizeof(reg_extmatch_T));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3208 if (em != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3209 em->refcnt = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3210 return em;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3211 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3212
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3213 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3214 * Add a reference to an extmatch.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3215 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3216 reg_extmatch_T *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3217 ref_extmatch(em)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3218 reg_extmatch_T *em;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3219 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3220 if (em != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3221 em->refcnt++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3222 return em;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3223 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3224
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3225 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3226 * Remove a reference to an extmatch. If there are no references left, free
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3227 * the info.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3228 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3229 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3230 unref_extmatch(em)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3231 reg_extmatch_T *em;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3232 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3233 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3234
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3235 if (em != NULL && --em->refcnt <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3236 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3237 for (i = 0; i < NSUBEXP; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3238 vim_free(em->matches[i]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3239 vim_free(em);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3240 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3241 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3242 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3243
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3244 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3245 * regtry - try match of "prog" with at regline["col"].
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3246 * Returns 0 for failure, number of lines contained in the match otherwise.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3247 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3248 static long
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3249 regtry(prog, col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3250 regprog_T *prog;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3251 colnr_T col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3252 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3253 reginput = regline + col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3254 need_clear_subexpr = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3255 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3256 /* Clear the external match subpointers if necessary. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3257 if (prog->reghasz == REX_SET)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3258 need_clear_zsubexpr = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3259 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3260
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3261 if (regmatch(prog->program + 1))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3262 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3263 cleanup_subexpr();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3264 if (REG_MULTI)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3265 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3266 if (reg_startpos[0].lnum < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3267 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3268 reg_startpos[0].lnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3269 reg_startpos[0].col = col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3270 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3271 if (reg_endpos[0].lnum < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3272 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3273 reg_endpos[0].lnum = reglnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3274 reg_endpos[0].col = (int)(reginput - regline);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3275 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3276 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3277 /* Use line number of "\ze". */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3278 reglnum = reg_endpos[0].lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3279 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3280 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3281 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3282 if (reg_startp[0] == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3283 reg_startp[0] = regline + col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3284 if (reg_endp[0] == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3285 reg_endp[0] = reginput;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3286 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3287 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3288 /* Package any found \z(...\) matches for export. Default is none. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3289 unref_extmatch(re_extmatch_out);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3290 re_extmatch_out = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3291
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3292 if (prog->reghasz == REX_SET)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3293 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3294 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3295
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3296 cleanup_zsubexpr();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3297 re_extmatch_out = make_extmatch();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3298 for (i = 0; i < NSUBEXP; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3299 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3300 if (REG_MULTI)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3301 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3302 /* Only accept single line matches. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3303 if (reg_startzpos[i].lnum >= 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3304 && reg_endzpos[i].lnum == reg_startzpos[i].lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3305 re_extmatch_out->matches[i] =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3306 vim_strnsave(reg_getline(reg_startzpos[i].lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3307 + reg_startzpos[i].col,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3308 reg_endzpos[i].col - reg_startzpos[i].col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3309 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3310 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3311 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3312 if (reg_startzp[i] != NULL && reg_endzp[i] != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3313 re_extmatch_out->matches[i] =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3314 vim_strnsave(reg_startzp[i],
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3315 (int)(reg_endzp[i] - reg_startzp[i]));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3316 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3317 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3318 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3319 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3320 return 1 + reglnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3321 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3322 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3323 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3324
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3325 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3326 static int reg_prev_class __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3327
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3328 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3329 * Get class of previous character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3330 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3331 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3332 reg_prev_class()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3333 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3334 if (reginput > regline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3335 return mb_get_class(reginput - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3336 - (*mb_head_off)(regline, reginput - 1));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3337 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3338 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3339
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3340 #endif
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
3341 #define ADVANCE_REGINPUT() mb_ptr_adv(reginput)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3342
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3343 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3344 * The arguments from BRACE_LIMITS are stored here. They are actually local
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3345 * to regmatch(), but they are here to reduce the amount of stack space used
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3346 * (it can be called recursively many times).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3347 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3348 static long bl_minval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3349 static long bl_maxval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3350
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3351 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3352 * regmatch - main matching routine
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3353 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3354 * Conceptually the strategy is simple: Check to see whether the current
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3355 * node matches, call self recursively to see whether the rest matches,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3356 * and then act accordingly. In practice we make some effort to avoid
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3357 * recursion, in particular by going through "ordinary" nodes (that don't
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3358 * need to know whether the rest of the match failed) by a loop instead of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3359 * by recursion.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3360 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3361 * Returns TRUE when there is a match. Leaves reginput and reglnum just after
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3362 * the last matched character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3363 * Returns FALSE when there is no match. Leaves reginput and reglnum in an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3364 * undefined state!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3365 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3366 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3367 regmatch(scan)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3368 char_u *scan; /* Current node. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3369 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3370 char_u *next; /* Next node. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3371 int op;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3372 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3373
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3374 #ifdef HAVE_GETRLIMIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3375 /* Check if we are running out of stack space. Could be caused by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3376 * recursively calling ourselves. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3377 if (out_of_stack || mch_stackcheck((char *)&op) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3378 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3379 out_of_stack = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3380 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3381 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3382 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3383
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3384 /* Some patterns my cause a long time to match, even though they are not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3385 * illegal. E.g., "\([a-z]\+\)\+Q". Allow breaking them with CTRL-C. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3386 fast_breakcheck();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3387
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3388 #ifdef DEBUG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3389 if (scan != NULL && regnarrate)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3390 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3391 mch_errmsg(regprop(scan));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3392 mch_errmsg("(\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3393 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3394 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3395 while (scan != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3396 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3397 if (got_int || out_of_stack)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3398 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3399 #ifdef DEBUG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3400 if (regnarrate)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3401 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3402 mch_errmsg(regprop(scan));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3403 mch_errmsg("...\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3404 # ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3405 if (re_extmatch_in != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3406 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3407 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3408
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3409 mch_errmsg(_("External submatches:\n"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3410 for (i = 0; i < NSUBEXP; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3411 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3412 mch_errmsg(" \"");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3413 if (re_extmatch_in->matches[i] != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3414 mch_errmsg(re_extmatch_in->matches[i]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3415 mch_errmsg("\"\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3416 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3417 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3418 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3419 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3420 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3421 next = regnext(scan);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3422
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3423 op = OP(scan);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3424 /* Check for character class with NL added. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3425 if (WITH_NL(op) && *reginput == NUL && reglnum < reg_maxline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3426 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3427 reg_nextline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3428 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3429 else if (reg_line_lbr && WITH_NL(op) && *reginput == '\n')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3430 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3431 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3432 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3433 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3434 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3435 if (WITH_NL(op))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3436 op -= ADD_NL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3437 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3438 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3439 c = (*mb_ptr2char)(reginput);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3440 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3441 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3442 c = *reginput;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3443 switch (op)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3444 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3445 case BOL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3446 if (reginput != regline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3447 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3448 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3449
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3450 case EOL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3451 if (c != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3452 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3453 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3454
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3455 case RE_BOF:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3456 /* Passing -1 to the getline() function provided for the search
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3457 * should always return NULL if the current line is the first
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3458 * line of the file. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3459 if (reglnum != 0 || reginput != regline
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3460 || (REG_MULTI && reg_getline((linenr_T)-1) != NULL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3461 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3462 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3463
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3464 case RE_EOF:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3465 if (reglnum != reg_maxline || c != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3466 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3467 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3468
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3469 case CURSOR:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3470 /* Check if the buffer is in a window and compare the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3471 * reg_win->w_cursor position to the match position. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3472 if (reg_win == NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3473 || (reglnum + reg_firstlnum != reg_win->w_cursor.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3474 || ((colnr_T)(reginput - regline) != reg_win->w_cursor.col))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3475 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3476 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3477
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3478 case RE_LNUM:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3479 if (!REG_MULTI || !re_num_cmp((long_u)(reglnum + reg_firstlnum),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3480 scan))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3481 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3482 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3483
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3484 case RE_COL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3485 if (!re_num_cmp((long_u)(reginput - regline) + 1, scan))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3486 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3487 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3488
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3489 case RE_VCOL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3490 if (!re_num_cmp((long_u)win_linetabsize(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3491 reg_win == NULL ? curwin : reg_win,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3492 regline, (colnr_T)(reginput - regline)) + 1, scan))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3493 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3494 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3495
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3496 case BOW: /* \<word; reginput points to w */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3497 if (c == NUL) /* Can't match at end of line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3498 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3499 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3500 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3501 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3502 int this_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3503
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3504 /* Get class of current and previous char (if it exists). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3505 this_class = mb_get_class(reginput);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3506 if (this_class <= 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3507 return FALSE; /* not on a word at all */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3508 if (reg_prev_class() == this_class)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3509 return FALSE; /* previous char is in same word */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3510 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3511 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3512 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3513 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3514 if (!vim_iswordc(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3515 || (reginput > regline && vim_iswordc(reginput[-1])))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3516 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3517 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3518 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3519
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3520 case EOW: /* word\>; reginput points after d */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3521 if (reginput == regline) /* Can't match at start of line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3522 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3523 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3524 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3525 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3526 int this_class, prev_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3527
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3528 /* Get class of current and previous char (if it exists). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3529 this_class = mb_get_class(reginput);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3530 prev_class = reg_prev_class();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3531 if (this_class == prev_class)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3532 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3533 if (prev_class == 0 || prev_class == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3534 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3535 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3536 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3537 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3538 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3539 if (!vim_iswordc(reginput[-1]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3540 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3541 if (reginput[0] != NUL && vim_iswordc(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3542 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3543 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3544 break; /* Matched with EOW */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3545
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3546 case ANY:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3547 if (c == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3548 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3549 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3550 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3551
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3552 case IDENT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3553 if (!vim_isIDc(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3554 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3555 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3556 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3557
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3558 case SIDENT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3559 if (VIM_ISDIGIT(*reginput) || !vim_isIDc(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3560 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3561 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3562 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3563
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3564 case KWORD:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3565 if (!vim_iswordp(reginput))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3566 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3567 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3568 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3569
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3570 case SKWORD:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3571 if (VIM_ISDIGIT(*reginput) || !vim_iswordp(reginput))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3572 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3573 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3574 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3575
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3576 case FNAME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3577 if (!vim_isfilec(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3578 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3579 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3580 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3581
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3582 case SFNAME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3583 if (VIM_ISDIGIT(*reginput) || !vim_isfilec(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3584 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3585 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3586 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3587
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3588 case PRINT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3589 if (ptr2cells(reginput) != 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3590 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3591 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3592 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3593
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3594 case SPRINT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3595 if (VIM_ISDIGIT(*reginput) || ptr2cells(reginput) != 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3596 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3597 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3598 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3599
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3600 case WHITE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3601 if (!vim_iswhite(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3602 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3603 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3604 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3605
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3606 case NWHITE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3607 if (c == NUL || vim_iswhite(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3608 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3609 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3610 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3611
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3612 case DIGIT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3613 if (!ri_digit(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3614 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3615 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3616 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3617
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3618 case NDIGIT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3619 if (c == NUL || ri_digit(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3620 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3621 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3622 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3623
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3624 case HEX:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3625 if (!ri_hex(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3626 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3627 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3628 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3629
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3630 case NHEX:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3631 if (c == NUL || ri_hex(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3632 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3633 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3634 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3635
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3636 case OCTAL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3637 if (!ri_octal(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3638 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3639 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3640 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3641
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3642 case NOCTAL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3643 if (c == NUL || ri_octal(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3644 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3645 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3646 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3647
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3648 case WORD:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3649 if (!ri_word(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3650 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3651 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3652 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3653
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3654 case NWORD:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3655 if (c == NUL || ri_word(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3656 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3657 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3658 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3659
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3660 case HEAD:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3661 if (!ri_head(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3662 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3663 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3664 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3665
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3666 case NHEAD:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3667 if (c == NUL || ri_head(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3668 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3669 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3670 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3671
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3672 case ALPHA:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3673 if (!ri_alpha(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3674 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3675 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3676 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3677
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3678 case NALPHA:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3679 if (c == NUL || ri_alpha(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3680 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3681 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3682 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3683
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3684 case LOWER:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3685 if (!ri_lower(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3686 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3687 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3688 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3689
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3690 case NLOWER:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3691 if (c == NUL || ri_lower(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3692 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3693 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3694 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3695
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3696 case UPPER:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3697 if (!ri_upper(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3698 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3699 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3700 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3701
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3702 case NUPPER:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3703 if (c == NUL || ri_upper(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3704 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3705 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3706 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3707
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3708 case EXACTLY:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3709 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3710 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3711 char_u *opnd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3712
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3713 opnd = OPERAND(scan);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3714 /* Inline the first byte, for speed. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3715 if (*opnd != *reginput
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3716 && (!ireg_ic || (
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3717 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3718 !enc_utf8 &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3719 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3720 TOLOWER_LOC(*opnd) != TOLOWER_LOC(*reginput))))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3721 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3722 if (*opnd == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3723 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3724 /* match empty string always works; happens when "~" is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3725 * empty. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3726 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3727 else if (opnd[1] == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3728 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3729 && !(enc_utf8 && ireg_ic)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3730 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3731 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3732 ++reginput; /* matched a single char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3733 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3734 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3735 len = (int)STRLEN(opnd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3736 /* Need to match first byte again for multi-byte. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3737 if (cstrncmp(opnd, reginput, &len) != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3738 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3739 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3740 /* Check for following composing character. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3741 if (enc_utf8 && UTF_COMPOSINGLIKE(reginput, reginput + len))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3742 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3743 /* raaron: This code makes a composing character get
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3744 * ignored, which is the correct behavior (sometimes)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3745 * for voweled Hebrew texts. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3746 if (!ireg_icombine)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3747 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3748 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3749 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3750 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3751 reginput += len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3752 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3753 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3754 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3755
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3756 case ANYOF:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3757 case ANYBUT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3758 if (c == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3759 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3760 if ((cstrchr(OPERAND(scan), c) == NULL) == (op == ANYOF))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3761 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3762 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3763 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3764
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3765 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3766 case MULTIBYTECODE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3767 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3768 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3769 int i, len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3770 char_u *opnd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3771
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3772 opnd = OPERAND(scan);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3773 /* Safety check (just in case 'encoding' was changed since
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3774 * compiling the program). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3775 if ((len = (*mb_ptr2len_check)(opnd)) < 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3776 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3777 for (i = 0; i < len; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3778 if (opnd[i] != reginput[i])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3779 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3780 reginput += len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3781 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3782 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3783 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3784 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3785 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3786
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3787 case NOTHING:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3788 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3789
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3790 case BACK:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3791 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3792
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3793 case MOPEN + 0: /* Match start: \zs */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3794 case MOPEN + 1: /* \( */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3795 case MOPEN + 2:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3796 case MOPEN + 3:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3797 case MOPEN + 4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3798 case MOPEN + 5:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3799 case MOPEN + 6:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3800 case MOPEN + 7:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3801 case MOPEN + 8:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3802 case MOPEN + 9:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3803 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3804 int no;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3805 save_se_T save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3806
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3807 no = op - MOPEN;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3808 cleanup_subexpr();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3809 save_se(&save, &reg_startpos[no], &reg_startp[no]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3810
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3811 if (regmatch(next))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3812 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3813
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3814 restore_se(&save, &reg_startpos[no], &reg_startp[no]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3815 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3816 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3817 /* break; Not Reached */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3818
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3819 case NOPEN: /* \%( */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3820 case NCLOSE: /* \) after \%( */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3821 if (regmatch(next))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3822 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3823 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3824 /* break; Not Reached */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3825
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3826 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3827 case ZOPEN + 1:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3828 case ZOPEN + 2:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3829 case ZOPEN + 3:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3830 case ZOPEN + 4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3831 case ZOPEN + 5:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3832 case ZOPEN + 6:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3833 case ZOPEN + 7:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3834 case ZOPEN + 8:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3835 case ZOPEN + 9:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3836 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3837 int no;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3838 save_se_T save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3839
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3840 no = op - ZOPEN;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3841 cleanup_zsubexpr();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3842 save_se(&save, &reg_startzpos[no], &reg_startzp[no]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3843
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3844 if (regmatch(next))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3845 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3846
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3847 restore_se(&save, &reg_startzpos[no], &reg_startzp[no]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3848 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3849 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3850 /* break; Not Reached */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3851 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3852
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3853 case MCLOSE + 0: /* Match end: \ze */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3854 case MCLOSE + 1: /* \) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3855 case MCLOSE + 2:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3856 case MCLOSE + 3:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3857 case MCLOSE + 4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3858 case MCLOSE + 5:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3859 case MCLOSE + 6:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3860 case MCLOSE + 7:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3861 case MCLOSE + 8:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3862 case MCLOSE + 9:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3863 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3864 int no;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3865 save_se_T save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3866
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3867 no = op - MCLOSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3868 cleanup_subexpr();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3869 save_se(&save, &reg_endpos[no], &reg_endp[no]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3870
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3871 if (regmatch(next))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3872 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3873
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3874 restore_se(&save, &reg_endpos[no], &reg_endp[no]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3875 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3876 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3877 /* break; Not Reached */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3878
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3879 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3880 case ZCLOSE + 1: /* \) after \z( */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3881 case ZCLOSE + 2:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3882 case ZCLOSE + 3:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3883 case ZCLOSE + 4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3884 case ZCLOSE + 5:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3885 case ZCLOSE + 6:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3886 case ZCLOSE + 7:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3887 case ZCLOSE + 8:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3888 case ZCLOSE + 9:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3889 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3890 int no;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3891 save_se_T save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3892
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3893 no = op - ZCLOSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3894 cleanup_zsubexpr();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3895 save_se(&save, &reg_endzpos[no], &reg_endzp[no]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3896
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3897 if (regmatch(next))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3898 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3899
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3900 restore_se(&save, &reg_endzpos[no], &reg_endzp[no]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3901 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3902 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3903 /* break; Not Reached */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3904 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3905
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3906 case BACKREF + 1:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3907 case BACKREF + 2:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3908 case BACKREF + 3:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3909 case BACKREF + 4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3910 case BACKREF + 5:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3911 case BACKREF + 6:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3912 case BACKREF + 7:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3913 case BACKREF + 8:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3914 case BACKREF + 9:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3915 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3916 int no;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3917 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3918 linenr_T clnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3919 colnr_T ccol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3920 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3921
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3922 no = op - BACKREF;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3923 cleanup_subexpr();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3924 if (!REG_MULTI) /* Single-line regexp */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3925 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3926 if (reg_endp[no] == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3927 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3928 /* Backref was not set: Match an empty string. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3929 len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3930 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3931 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3932 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3933 /* Compare current input with back-ref in the same
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3934 * line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3935 len = (int)(reg_endp[no] - reg_startp[no]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3936 if (cstrncmp(reg_startp[no], reginput, &len) != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3937 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3938 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3939 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3940 else /* Multi-line regexp */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3941 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3942 if (reg_endpos[no].lnum < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3943 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3944 /* Backref was not set: Match an empty string. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3945 len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3946 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3947 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3948 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3949 if (reg_startpos[no].lnum == reglnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3950 && reg_endpos[no].lnum == reglnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3951 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3952 /* Compare back-ref within the current line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3953 len = reg_endpos[no].col - reg_startpos[no].col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3954 if (cstrncmp(regline + reg_startpos[no].col,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3955 reginput, &len) != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3956 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3957 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3958 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3959 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3960 /* Messy situation: Need to compare between two
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3961 * lines. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3962 ccol = reg_startpos[no].col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3963 clnum = reg_startpos[no].lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3964 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3965 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3966 /* Since getting one line may invalidate
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3967 * the other, need to make copy. Slow! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3968 if (regline != reg_tofree)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3969 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3970 len = (int)STRLEN(regline);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3971 if (reg_tofree == NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3972 || len >= (int)reg_tofreelen)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3973 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3974 len += 50; /* get some extra */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3975 vim_free(reg_tofree);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3976 reg_tofree = alloc(len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3977 if (reg_tofree == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3978 return FALSE; /* out of memory! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3979 reg_tofreelen = len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3980 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3981 STRCPY(reg_tofree, regline);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3982 reginput = reg_tofree
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3983 + (reginput - regline);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3984 regline = reg_tofree;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3985 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3986
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3987 /* Get the line to compare with. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3988 p = reg_getline(clnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3989 if (clnum == reg_endpos[no].lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3990 len = reg_endpos[no].col - ccol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3991 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3992 len = (int)STRLEN(p + ccol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3993
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3994 if (cstrncmp(p + ccol, reginput, &len) != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3995 return FALSE; /* doesn't match */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3996 if (clnum == reg_endpos[no].lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3997 break; /* match and at end! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3998 if (reglnum == reg_maxline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3999 return FALSE; /* text too short */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4000
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4001 /* Advance to next line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4002 reg_nextline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4003 ++clnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4004 ccol = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4005 if (got_int || out_of_stack)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4006 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4007 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4008
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4009 /* found a match! Note that regline may now point
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4010 * to a copy of the line, that should not matter. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4011 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4012 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4013 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4014
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4015 /* Matched the backref, skip over it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4016 reginput += len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4017 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4018 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4019
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4020 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4021 case ZREF + 1:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4022 case ZREF + 2:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4023 case ZREF + 3:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4024 case ZREF + 4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4025 case ZREF + 5:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4026 case ZREF + 6:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4027 case ZREF + 7:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4028 case ZREF + 8:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4029 case ZREF + 9:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4030 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4031 int no;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4032 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4033
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4034 cleanup_zsubexpr();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4035 no = op - ZREF;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4036 if (re_extmatch_in != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4037 && re_extmatch_in->matches[no] != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4038 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4039 len = (int)STRLEN(re_extmatch_in->matches[no]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4040 if (cstrncmp(re_extmatch_in->matches[no],
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4041 reginput, &len) != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4042 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4043 reginput += len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4044 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4045 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4046 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4047 /* Backref was not set: Match an empty string. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4048 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4049 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4050 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4051 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4052
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4053 case BRANCH:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4054 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4055 if (OP(next) != BRANCH) /* No choice. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4056 next = OPERAND(scan); /* Avoid recursion. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4057 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4058 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4059 regsave_T save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4060
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4061 do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4062 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4063 reg_save(&save);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4064 if (regmatch(OPERAND(scan)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4065 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4066 reg_restore(&save);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4067 scan = regnext(scan);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4068 } while (scan != NULL && OP(scan) == BRANCH);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4069 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4070 /* NOTREACHED */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4071 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4072 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4073 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4074
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4075 case BRACE_LIMITS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4076 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4077 int no;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4078
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4079 if (OP(next) == BRACE_SIMPLE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4080 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4081 bl_minval = OPERAND_MIN(scan);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4082 bl_maxval = OPERAND_MAX(scan);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4083 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4084 else if (OP(next) >= BRACE_COMPLEX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4085 && OP(next) < BRACE_COMPLEX + 10)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4086 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4087 no = OP(next) - BRACE_COMPLEX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4088 brace_min[no] = OPERAND_MIN(scan);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4089 brace_max[no] = OPERAND_MAX(scan);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4090 brace_count[no] = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4091 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4092 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4093 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4094 EMSG(_(e_internal)); /* Shouldn't happen */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4095 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4096 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4097 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4098 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4099
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4100 case BRACE_COMPLEX + 0:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4101 case BRACE_COMPLEX + 1:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4102 case BRACE_COMPLEX + 2:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4103 case BRACE_COMPLEX + 3:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4104 case BRACE_COMPLEX + 4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4105 case BRACE_COMPLEX + 5:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4106 case BRACE_COMPLEX + 6:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4107 case BRACE_COMPLEX + 7:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4108 case BRACE_COMPLEX + 8:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4109 case BRACE_COMPLEX + 9:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4110 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4111 int no;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4112 regsave_T save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4113
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4114 no = op - BRACE_COMPLEX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4115 ++brace_count[no];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4116
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4117 /* If not matched enough times yet, try one more */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4118 if (brace_count[no] <= (brace_min[no] <= brace_max[no]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4119 ? brace_min[no] : brace_max[no]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4120 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4121 reg_save(&save);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4122 if (regmatch(OPERAND(scan)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4123 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4124 reg_restore(&save);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4125 --brace_count[no]; /* failed, decrement match count */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4126 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4127 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4128
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4129 /* If matched enough times, may try matching some more */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4130 if (brace_min[no] <= brace_max[no])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4131 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4132 /* Range is the normal way around, use longest match */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4133 if (brace_count[no] <= brace_max[no])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4134 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4135 reg_save(&save);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4136 if (regmatch(OPERAND(scan)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4137 return TRUE; /* matched some more times */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4138 reg_restore(&save);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4139 --brace_count[no]; /* matched just enough times */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4140 /* continue with the items after \{} */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4141 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4142 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4143 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4144 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4145 /* Range is backwards, use shortest match first */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4146 if (brace_count[no] <= brace_min[no])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4147 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4148 reg_save(&save);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4149 if (regmatch(next))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4150 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4151 reg_restore(&save);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4152 next = OPERAND(scan);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4153 /* must try to match one more item */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4154 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4155 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4156 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4157 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4158
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4159 case BRACE_SIMPLE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4160 case STAR:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4161 case PLUS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4162 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4163 int nextb; /* next byte */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4164 int nextb_ic; /* next byte reverse case */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4165 long count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4166 regsave_T save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4167 long minval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4168 long maxval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4169
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4170 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4171 * Lookahead to avoid useless match attempts when we know
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4172 * what character comes next.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4173 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4174 if (OP(next) == EXACTLY)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4175 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4176 nextb = *OPERAND(next);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4177 if (ireg_ic)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4178 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4179 if (isupper(nextb))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4180 nextb_ic = TOLOWER_LOC(nextb);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4181 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4182 nextb_ic = TOUPPER_LOC(nextb);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4183 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4184 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4185 nextb_ic = nextb;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4186 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4187 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4188 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4189 nextb = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4190 nextb_ic = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4191 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4192 if (op != BRACE_SIMPLE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4193 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4194 minval = (op == STAR) ? 0 : 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4195 maxval = MAX_LIMIT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4196 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4197 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4198 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4199 minval = bl_minval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4200 maxval = bl_maxval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4201 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4202
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4203 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4204 * When maxval > minval, try matching as much as possible, up
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4205 * to maxval. When maxval < minval, try matching at least the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4206 * minimal number (since the range is backwards, that's also
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4207 * maxval!).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4208 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4209 count = regrepeat(OPERAND(scan), maxval);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4210 if (got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4211 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4212 if (minval <= maxval)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4213 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4214 /* Range is the normal way around, use longest match */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4215 while (count >= minval)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4216 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4217 /* If it could match, try it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4218 if (nextb == NUL || *reginput == nextb
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4219 || *reginput == nextb_ic)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4220 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4221 reg_save(&save);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4222 if (regmatch(next))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4223 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4224 reg_restore(&save);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4225 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4226 /* Couldn't or didn't match -- back up one char. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4227 if (--count < minval)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4228 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4229 if (reginput == regline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4230 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4231 /* backup to last char of previous line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4232 --reglnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4233 regline = reg_getline(reglnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4234 /* Just in case regrepeat() didn't count right. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4235 if (regline == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4236 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4237 reginput = regline + STRLEN(regline);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4238 fast_breakcheck();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4239 if (got_int || out_of_stack)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4240 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4241 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4242 else
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
4243 mb_ptr_back(regline, reginput);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4244 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4245 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4246 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4247 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4248 /* Range is backwards, use shortest match first.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4249 * Careful: maxval and minval are exchanged! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4250 if (count < maxval)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4251 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4252 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4253 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4254 /* If it could work, try it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4255 if (nextb == NUL || *reginput == nextb
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4256 || *reginput == nextb_ic)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4257 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4258 reg_save(&save);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4259 if (regmatch(next))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4260 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4261 reg_restore(&save);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4262 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4263 /* Couldn't or didn't match: try advancing one char. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4264 if (count == minval
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4265 || regrepeat(OPERAND(scan), 1L) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4266 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4267 ++count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4268 if (got_int || out_of_stack)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4269 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4270 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4271 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4272 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4273 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4274 /* break; Not Reached */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4275
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4276 case NOMATCH:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4277 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4278 regsave_T save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4279
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4280 /* If the operand matches, we fail. Otherwise backup and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4281 * continue with the next item. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4282 reg_save(&save);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4283 if (regmatch(OPERAND(scan)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4284 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4285 reg_restore(&save);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4286 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4287 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4288
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4289 case MATCH:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4290 case SUBPAT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4291 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4292 regsave_T save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4293
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4294 /* If the operand doesn't match, we fail. Otherwise backup
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4295 * and continue with the next item. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4296 reg_save(&save);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4297 if (!regmatch(OPERAND(scan)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4298 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4299 if (op == MATCH) /* zero-width */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4300 reg_restore(&save);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4301 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4302 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4303
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4304 case BEHIND:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4305 case NOBEHIND:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4306 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4307 regsave_T save_after, save_start;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4308 regsave_T save_behind_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4309 int needmatch = (op == BEHIND);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4310
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4311 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4312 * Look back in the input of the operand matches or not. This
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4313 * must be done at every position in the input and checking if
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4314 * the match ends at the current position.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4315 * First check if the next item matches, that's probably
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4316 * faster.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4317 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4318 reg_save(&save_start);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4319 if (regmatch(next))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4320 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4321 /* save the position after the found match for next */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4322 reg_save(&save_after);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4323
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4324 /* start looking for a match with operand at the current
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4325 * postion. Go back one character until we find the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4326 * result, hitting the start of the line or the previous
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4327 * line (for multi-line matching).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4328 * Set behind_pos to where the match should end, BHPOS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4329 * will match it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4330 save_behind_pos = behind_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4331 behind_pos = save_start;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4332 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4333 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4334 reg_restore(&save_start);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4335 if (regmatch(OPERAND(scan))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4336 && reg_save_equal(&behind_pos))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4337 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4338 behind_pos = save_behind_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4339 /* found a match that ends where "next" started */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4340 if (needmatch)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4341 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4342 reg_restore(&save_after);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4343 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4344 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4345 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4346 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4347 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4348 * No match: Go back one character. May go to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4349 * previous line once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4350 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4351 if (REG_MULTI)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4352 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4353 if (save_start.rs_u.pos.col == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4354 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4355 if (save_start.rs_u.pos.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4356 < behind_pos.rs_u.pos.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4357 || reg_getline(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4358 --save_start.rs_u.pos.lnum) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4359 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4360 reg_restore(&save_start);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4361 save_start.rs_u.pos.col =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4362 (colnr_T)STRLEN(regline);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4363 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4364 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4365 --save_start.rs_u.pos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4366 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4367 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4368 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4369 if (save_start.rs_u.ptr == regline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4370 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4371 --save_start.rs_u.ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4372 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4373 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4374
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4375 /* NOBEHIND succeeds when no match was found */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4376 behind_pos = save_behind_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4377 if (!needmatch)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4378 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4379 reg_restore(&save_after);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4380 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4381 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4382 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4383 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4384 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4385
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4386 case BHPOS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4387 if (REG_MULTI)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4388 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4389 if (behind_pos.rs_u.pos.col != (colnr_T)(reginput - regline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4390 || behind_pos.rs_u.pos.lnum != reglnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4391 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4392 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4393 else if (behind_pos.rs_u.ptr != reginput)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4394 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4395 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4396
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4397 case NEWL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4398 if ((c != NUL || reglnum == reg_maxline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4399 && (c != '\n' || !reg_line_lbr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4400 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4401 if (reg_line_lbr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4402 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4403 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4404 reg_nextline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4405 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4406
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4407 case END:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4408 return TRUE; /* Success! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4409
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4410 default:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4411 EMSG(_(e_re_corr));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4412 #ifdef DEBUG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4413 printf("Illegal op code %d\n", op);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4414 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4415 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4416 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4417 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4418
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4419 scan = next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4420 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4421
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4422 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4423 * We get here only if there's trouble -- normally "case END" is the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4424 * terminating point.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4425 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4426 EMSG(_(e_re_corr));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4427 #ifdef DEBUG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4428 printf("Premature EOL\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4429 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4430 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4431 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4432
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4433 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4434 * regrepeat - repeatedly match something simple, return how many.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4435 * Advances reginput (and reglnum) to just after the matched chars.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4436 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4437 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4438 regrepeat(p, maxcount)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4439 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4440 long maxcount; /* maximum number of matches allowed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4441 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4442 long count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4443 char_u *scan;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4444 char_u *opnd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4445 int mask;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4446 int testval = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4447
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4448 scan = reginput; /* Make local copy of reginput for speed. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4449 opnd = OPERAND(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4450 switch (OP(p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4451 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4452 case ANY:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4453 case ANY + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4454 while (count < maxcount)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4455 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4456 /* Matching anything means we continue until end-of-line (or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4457 * end-of-file for ANY + ADD_NL), only limited by maxcount. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4458 while (*scan != NUL && count < maxcount)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4459 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4460 ++count;
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
4461 mb_ptr_adv(scan);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4462 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4463 if (!WITH_NL(OP(p)) || reglnum == reg_maxline || count == maxcount)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4464 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4465 ++count; /* count the line-break */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4466 reg_nextline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4467 scan = reginput;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4468 if (got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4469 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4470 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4471 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4472
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4473 case IDENT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4474 case IDENT + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4475 testval = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4476 /*FALLTHROUGH*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4477 case SIDENT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4478 case SIDENT + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4479 while (count < maxcount)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4480 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4481 if (vim_isIDc(*scan) && (testval || !VIM_ISDIGIT(*scan)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4482 {
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
4483 mb_ptr_adv(scan);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4484 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4485 else if (*scan == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4486 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4487 if (!WITH_NL(OP(p)) || reglnum == reg_maxline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4488 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4489 reg_nextline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4490 scan = reginput;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4491 if (got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4492 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4493 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4494 else if (reg_line_lbr && *scan == '\n' && WITH_NL(OP(p)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4495 ++scan;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4496 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4497 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4498 ++count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4499 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4500 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4501
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4502 case KWORD:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4503 case KWORD + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4504 testval = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4505 /*FALLTHROUGH*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4506 case SKWORD:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4507 case SKWORD + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4508 while (count < maxcount)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4509 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4510 if (vim_iswordp(scan) && (testval || !VIM_ISDIGIT(*scan)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4511 {
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
4512 mb_ptr_adv(scan);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4513 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4514 else if (*scan == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4515 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4516 if (!WITH_NL(OP(p)) || reglnum == reg_maxline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4517 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4518 reg_nextline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4519 scan = reginput;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4520 if (got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4521 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4522 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4523 else if (reg_line_lbr && *scan == '\n' && WITH_NL(OP(p)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4524 ++scan;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4525 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4526 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4527 ++count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4528 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4529 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4530
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4531 case FNAME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4532 case FNAME + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4533 testval = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4534 /*FALLTHROUGH*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4535 case SFNAME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4536 case SFNAME + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4537 while (count < maxcount)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4538 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4539 if (vim_isfilec(*scan) && (testval || !VIM_ISDIGIT(*scan)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4540 {
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
4541 mb_ptr_adv(scan);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4542 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4543 else if (*scan == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4544 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4545 if (!WITH_NL(OP(p)) || reglnum == reg_maxline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4546 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4547 reg_nextline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4548 scan = reginput;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4549 if (got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4550 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4551 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4552 else if (reg_line_lbr && *scan == '\n' && WITH_NL(OP(p)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4553 ++scan;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4554 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4555 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4556 ++count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4557 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4558 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4559
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4560 case PRINT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4561 case PRINT + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4562 testval = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4563 /*FALLTHROUGH*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4564 case SPRINT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4565 case SPRINT + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4566 while (count < maxcount)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4567 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4568 if (*scan == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4569 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4570 if (!WITH_NL(OP(p)) || reglnum == reg_maxline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4571 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4572 reg_nextline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4573 scan = reginput;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4574 if (got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4575 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4576 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4577 else if (ptr2cells(scan) == 1 && (testval || !VIM_ISDIGIT(*scan)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4578 {
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
4579 mb_ptr_adv(scan);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4580 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4581 else if (reg_line_lbr && *scan == '\n' && WITH_NL(OP(p)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4582 ++scan;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4583 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4584 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4585 ++count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4586 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4587 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4588
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4589 case WHITE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4590 case WHITE + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4591 testval = mask = RI_WHITE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4592 do_class:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4593 while (count < maxcount)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4594 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4595 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4596 int l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4597 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4598 if (*scan == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4599 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4600 if (!WITH_NL(OP(p)) || reglnum == reg_maxline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4601 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4602 reg_nextline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4603 scan = reginput;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4604 if (got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4605 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4606 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4607 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4608 else if (has_mbyte && (l = (*mb_ptr2len_check)(scan)) > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4609 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4610 if (testval != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4611 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4612 scan += l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4613 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4614 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4615 else if ((class_tab[*scan] & mask) == testval)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4616 ++scan;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4617 else if (reg_line_lbr && *scan == '\n' && WITH_NL(OP(p)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4618 ++scan;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4619 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4620 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4621 ++count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4622 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4623 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4624
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4625 case NWHITE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4626 case NWHITE + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4627 mask = RI_WHITE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4628 goto do_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4629 case DIGIT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4630 case DIGIT + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4631 testval = mask = RI_DIGIT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4632 goto do_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4633 case NDIGIT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4634 case NDIGIT + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4635 mask = RI_DIGIT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4636 goto do_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4637 case HEX:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4638 case HEX + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4639 testval = mask = RI_HEX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4640 goto do_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4641 case NHEX:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4642 case NHEX + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4643 mask = RI_HEX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4644 goto do_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4645 case OCTAL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4646 case OCTAL + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4647 testval = mask = RI_OCTAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4648 goto do_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4649 case NOCTAL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4650 case NOCTAL + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4651 mask = RI_OCTAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4652 goto do_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4653 case WORD:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4654 case WORD + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4655 testval = mask = RI_WORD;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4656 goto do_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4657 case NWORD:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4658 case NWORD + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4659 mask = RI_WORD;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4660 goto do_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4661 case HEAD:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4662 case HEAD + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4663 testval = mask = RI_HEAD;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4664 goto do_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4665 case NHEAD:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4666 case NHEAD + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4667 mask = RI_HEAD;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4668 goto do_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4669 case ALPHA:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4670 case ALPHA + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4671 testval = mask = RI_ALPHA;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4672 goto do_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4673 case NALPHA:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4674 case NALPHA + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4675 mask = RI_ALPHA;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4676 goto do_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4677 case LOWER:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4678 case LOWER + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4679 testval = mask = RI_LOWER;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4680 goto do_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4681 case NLOWER:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4682 case NLOWER + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4683 mask = RI_LOWER;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4684 goto do_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4685 case UPPER:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4686 case UPPER + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4687 testval = mask = RI_UPPER;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4688 goto do_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4689 case NUPPER:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4690 case NUPPER + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4691 mask = RI_UPPER;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4692 goto do_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4693
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4694 case EXACTLY:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4695 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4696 int cu, cl;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4697
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4698 /* This doesn't do a multi-byte character, because a MULTIBYTECODE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4699 * would have been used for it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4700 if (ireg_ic)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4701 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4702 cu = TOUPPER_LOC(*opnd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4703 cl = TOLOWER_LOC(*opnd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4704 while (count < maxcount && (*scan == cu || *scan == cl))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4705 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4706 count++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4707 scan++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4708 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4709 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4710 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4711 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4712 cu = *opnd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4713 while (count < maxcount && *scan == cu)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4714 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4715 count++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4716 scan++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4717 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4718 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4719 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4720 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4721
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4722 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4723 case MULTIBYTECODE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4724 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4725 int i, len, cf = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4726
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4727 /* Safety check (just in case 'encoding' was changed since
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4728 * compiling the program). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4729 if ((len = (*mb_ptr2len_check)(opnd)) > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4730 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4731 if (ireg_ic && enc_utf8)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4732 cf = utf_fold(utf_ptr2char(opnd));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4733 while (count < maxcount)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4734 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4735 for (i = 0; i < len; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4736 if (opnd[i] != scan[i])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4737 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4738 if (i < len && (!ireg_ic || !enc_utf8
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4739 || utf_fold(utf_ptr2char(scan)) != cf))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4740 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4741 scan += len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4742 ++count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4743 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4744 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4745 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4746 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4747 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4748
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4749 case ANYOF:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4750 case ANYOF + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4751 testval = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4752 /*FALLTHROUGH*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4753
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4754 case ANYBUT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4755 case ANYBUT + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4756 while (count < maxcount)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4757 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4758 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4759 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4760 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4761 if (*scan == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4762 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4763 if (!WITH_NL(OP(p)) || reglnum == reg_maxline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4764 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4765 reg_nextline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4766 scan = reginput;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4767 if (got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4768 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4769 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4770 else if (reg_line_lbr && *scan == '\n' && WITH_NL(OP(p)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4771 ++scan;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4772 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4773 else if (has_mbyte && (len = (*mb_ptr2len_check)(scan)) > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4774 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4775 if ((cstrchr(opnd, (*mb_ptr2char)(scan)) == NULL) == testval)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4776 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4777 scan += len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4778 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4779 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4780 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4781 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4782 if ((cstrchr(opnd, *scan) == NULL) == testval)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4783 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4784 ++scan;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4785 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4786 ++count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4787 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4788 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4789
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4790 case NEWL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4791 while (count < maxcount
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4792 && ((*scan == NUL && reglnum < reg_maxline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4793 || (*scan == '\n' && reg_line_lbr)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4794 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4795 count++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4796 if (reg_line_lbr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4797 ADVANCE_REGINPUT();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4798 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4799 reg_nextline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4800 scan = reginput;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4801 if (got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4802 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4803 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4804 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4805
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4806 default: /* Oh dear. Called inappropriately. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4807 EMSG(_(e_re_corr));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4808 #ifdef DEBUG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4809 printf("Called regrepeat with op code %d\n", OP(p));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4810 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4811 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4812 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4813
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4814 reginput = scan;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4815
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4816 return (int)count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4817 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4818
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4819 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4820 * regnext - dig the "next" pointer out of a node
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4821 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4822 static char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4823 regnext(p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4824 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4825 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4826 int offset;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4827
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4828 if (p == JUST_CALC_SIZE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4829 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4830
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4831 offset = NEXT(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4832 if (offset == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4833 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4834
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4835 if (OP(p) == BACK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4836 return p - offset;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4837 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4838 return p + offset;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4839 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4840
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4841 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4842 * Check the regexp program for its magic number.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4843 * Return TRUE if it's wrong.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4844 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4845 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4846 prog_magic_wrong()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4847 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4848 if (UCHARAT(REG_MULTI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4849 ? reg_mmatch->regprog->program
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4850 : reg_match->regprog->program) != REGMAGIC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4851 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4852 EMSG(_(e_re_corr));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4853 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4854 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4855 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4856 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4857
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4858 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4859 * Cleanup the subexpressions, if this wasn't done yet.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4860 * This construction is used to clear the subexpressions only when they are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4861 * used (to increase speed).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4862 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4863 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4864 cleanup_subexpr()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4865 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4866 if (need_clear_subexpr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4867 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4868 if (REG_MULTI)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4869 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4870 /* Use 0xff to set lnum to -1 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4871 vim_memset(reg_startpos, 0xff, sizeof(lpos_T) * NSUBEXP);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4872 vim_memset(reg_endpos, 0xff, sizeof(lpos_T) * NSUBEXP);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4873 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4874 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4875 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4876 vim_memset(reg_startp, 0, sizeof(char_u *) * NSUBEXP);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4877 vim_memset(reg_endp, 0, sizeof(char_u *) * NSUBEXP);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4878 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4879 need_clear_subexpr = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4880 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4881 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4882
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4883 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4884 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4885 cleanup_zsubexpr()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4886 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4887 if (need_clear_zsubexpr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4888 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4889 if (REG_MULTI)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4890 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4891 /* Use 0xff to set lnum to -1 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4892 vim_memset(reg_startzpos, 0xff, sizeof(lpos_T) * NSUBEXP);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4893 vim_memset(reg_endzpos, 0xff, sizeof(lpos_T) * NSUBEXP);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4894 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4895 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4896 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4897 vim_memset(reg_startzp, 0, sizeof(char_u *) * NSUBEXP);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4898 vim_memset(reg_endzp, 0, sizeof(char_u *) * NSUBEXP);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4899 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4900 need_clear_zsubexpr = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4901 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4902 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4903 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4904
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4905 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4906 * Advance reglnum, regline and reginput to the next line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4907 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4908 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4909 reg_nextline()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4910 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4911 regline = reg_getline(++reglnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4912 reginput = regline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4913 fast_breakcheck();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4914 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4915
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4916 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4917 * Save the input line and position in a regsave_T.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4918 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4919 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4920 reg_save(save)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4921 regsave_T *save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4922 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4923 if (REG_MULTI)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4924 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4925 save->rs_u.pos.col = (colnr_T)(reginput - regline);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4926 save->rs_u.pos.lnum = reglnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4927 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4928 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4929 save->rs_u.ptr = reginput;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4930 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4931
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4932 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4933 * Restore the input line and position from a regsave_T.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4934 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4935 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4936 reg_restore(save)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4937 regsave_T *save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4938 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4939 if (REG_MULTI)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4940 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4941 if (reglnum != save->rs_u.pos.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4942 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4943 /* only call reg_getline() when the line number changed to save
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4944 * a bit of time */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4945 reglnum = save->rs_u.pos.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4946 regline = reg_getline(reglnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4947 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4948 reginput = regline + save->rs_u.pos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4949 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4950 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4951 reginput = save->rs_u.ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4952 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4953
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4954 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4955 * Return TRUE if current position is equal to saved position.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4956 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4957 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4958 reg_save_equal(save)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4959 regsave_T *save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4960 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4961 if (REG_MULTI)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4962 return reglnum == save->rs_u.pos.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4963 && reginput == regline + save->rs_u.pos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4964 return reginput == save->rs_u.ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4965 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4966
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4967 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4968 * Tentatively set the sub-expression start to the current position (after
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4969 * calling regmatch() they will have changed). Need to save the existing
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4970 * values for when there is no match.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4971 * Use se_save() to use pointer (save_se_multi()) or position (save_se_one()),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4972 * depending on REG_MULTI.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4973 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4974 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4975 save_se_multi(savep, posp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4976 save_se_T *savep;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4977 lpos_T *posp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4978 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4979 savep->se_u.pos = *posp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4980 posp->lnum = reglnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4981 posp->col = (colnr_T)(reginput - regline);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4982 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4983
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4984 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4985 save_se_one(savep, pp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4986 save_se_T *savep;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4987 char_u **pp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4988 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4989 savep->se_u.ptr = *pp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4990 *pp = reginput;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4991 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4992
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4993 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4994 * Compare a number with the operand of RE_LNUM, RE_COL or RE_VCOL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4995 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4996 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4997 re_num_cmp(val, scan)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4998 long_u val;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4999 char_u *scan;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5000 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5001 long_u n = OPERAND_MIN(scan);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5002
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5003 if (OPERAND_CMP(scan) == '>')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5004 return val > n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5005 if (OPERAND_CMP(scan) == '<')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5006 return val < n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5007 return val == n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5008 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5009
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5010
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5011 #ifdef DEBUG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5012
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5013 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5014 * regdump - dump a regexp onto stdout in vaguely comprehensible form
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5015 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5016 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5017 regdump(pattern, r)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5018 char_u *pattern;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5019 regprog_T *r;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5020 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5021 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5022 int op = EXACTLY; /* Arbitrary non-END op. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5023 char_u *next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5024 char_u *end = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5025
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5026 printf("\r\nregcomp(%s):\r\n", pattern);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5027
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5028 s = r->program + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5029 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5030 * Loop until we find the END that isn't before a referred next (an END
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5031 * can also appear in a NOMATCH operand).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5032 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5033 while (op != END || s <= end)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5034 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5035 op = OP(s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5036 printf("%2d%s", (int)(s - r->program), regprop(s)); /* Where, what. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5037 next = regnext(s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5038 if (next == NULL) /* Next ptr. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5039 printf("(0)");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5040 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5041 printf("(%d)", (int)((s - r->program) + (next - s)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5042 if (end < next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5043 end = next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5044 if (op == BRACE_LIMITS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5045 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5046 /* Two short ints */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5047 printf(" minval %ld, maxval %ld", OPERAND_MIN(s), OPERAND_MAX(s));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5048 s += 8;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5049 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5050 s += 3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5051 if (op == ANYOF || op == ANYOF + ADD_NL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5052 || op == ANYBUT || op == ANYBUT + ADD_NL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5053 || op == EXACTLY)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5054 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5055 /* Literal string, where present. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5056 while (*s != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5057 printf("%c", *s++);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5058 s++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5059 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5060 printf("\r\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5061 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5062
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5063 /* Header fields of interest. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5064 if (r->regstart != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5065 printf("start `%s' 0x%x; ", r->regstart < 256
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5066 ? (char *)transchar(r->regstart)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5067 : "multibyte", r->regstart);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5068 if (r->reganch)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5069 printf("anchored; ");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5070 if (r->regmust != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5071 printf("must have \"%s\"", r->regmust);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5072 printf("\r\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5073 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5074
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5075 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5076 * regprop - printable representation of opcode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5077 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5078 static char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5079 regprop(op)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5080 char_u *op;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5081 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5082 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5083 static char_u buf[50];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5084
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5085 (void) strcpy(buf, ":");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5086
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5087 switch (OP(op))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5088 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5089 case BOL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5090 p = "BOL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5091 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5092 case EOL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5093 p = "EOL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5094 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5095 case RE_BOF:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5096 p = "BOF";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5097 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5098 case RE_EOF:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5099 p = "EOF";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5100 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5101 case CURSOR:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5102 p = "CURSOR";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5103 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5104 case RE_LNUM:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5105 p = "RE_LNUM";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5106 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5107 case RE_COL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5108 p = "RE_COL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5109 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5110 case RE_VCOL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5111 p = "RE_VCOL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5112 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5113 case BOW:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5114 p = "BOW";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5115 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5116 case EOW:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5117 p = "EOW";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5118 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5119 case ANY:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5120 p = "ANY";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5121 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5122 case ANY + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5123 p = "ANY+NL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5124 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5125 case ANYOF:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5126 p = "ANYOF";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5127 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5128 case ANYOF + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5129 p = "ANYOF+NL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5130 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5131 case ANYBUT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5132 p = "ANYBUT";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5133 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5134 case ANYBUT + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5135 p = "ANYBUT+NL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5136 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5137 case IDENT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5138 p = "IDENT";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5139 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5140 case IDENT + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5141 p = "IDENT+NL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5142 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5143 case SIDENT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5144 p = "SIDENT";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5145 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5146 case SIDENT + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5147 p = "SIDENT+NL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5148 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5149 case KWORD:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5150 p = "KWORD";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5151 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5152 case KWORD + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5153 p = "KWORD+NL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5154 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5155 case SKWORD:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5156 p = "SKWORD";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5157 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5158 case SKWORD + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5159 p = "SKWORD+NL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5160 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5161 case FNAME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5162 p = "FNAME";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5163 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5164 case FNAME + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5165 p = "FNAME+NL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5166 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5167 case SFNAME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5168 p = "SFNAME";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5169 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5170 case SFNAME + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5171 p = "SFNAME+NL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5172 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5173 case PRINT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5174 p = "PRINT";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5175 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5176 case PRINT + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5177 p = "PRINT+NL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5178 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5179 case SPRINT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5180 p = "SPRINT";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5181 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5182 case SPRINT + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5183 p = "SPRINT+NL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5184 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5185 case WHITE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5186 p = "WHITE";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5187 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5188 case WHITE + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5189 p = "WHITE+NL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5190 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5191 case NWHITE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5192 p = "NWHITE";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5193 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5194 case NWHITE + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5195 p = "NWHITE+NL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5196 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5197 case DIGIT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5198 p = "DIGIT";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5199 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5200 case DIGIT + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5201 p = "DIGIT+NL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5202 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5203 case NDIGIT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5204 p = "NDIGIT";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5205 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5206 case NDIGIT + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5207 p = "NDIGIT+NL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5208 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5209 case HEX:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5210 p = "HEX";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5211 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5212 case HEX + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5213 p = "HEX+NL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5214 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5215 case NHEX:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5216 p = "NHEX";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5217 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5218 case NHEX + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5219 p = "NHEX+NL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5220 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5221 case OCTAL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5222 p = "OCTAL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5223 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5224 case OCTAL + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5225 p = "OCTAL+NL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5226 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5227 case NOCTAL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5228 p = "NOCTAL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5229 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5230 case NOCTAL + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5231 p = "NOCTAL+NL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5232 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5233 case WORD:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5234 p = "WORD";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5235 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5236 case WORD + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5237 p = "WORD+NL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5238 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5239 case NWORD:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5240 p = "NWORD";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5241 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5242 case NWORD + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5243 p = "NWORD+NL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5244 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5245 case HEAD:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5246 p = "HEAD";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5247 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5248 case HEAD + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5249 p = "HEAD+NL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5250 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5251 case NHEAD:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5252 p = "NHEAD";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5253 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5254 case NHEAD + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5255 p = "NHEAD+NL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5256 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5257 case ALPHA:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5258 p = "ALPHA";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5259 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5260 case ALPHA + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5261 p = "ALPHA+NL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5262 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5263 case NALPHA:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5264 p = "NALPHA";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5265 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5266 case NALPHA + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5267 p = "NALPHA+NL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5268 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5269 case LOWER:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5270 p = "LOWER";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5271 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5272 case LOWER + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5273 p = "LOWER+NL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5274 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5275 case NLOWER:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5276 p = "NLOWER";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5277 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5278 case NLOWER + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5279 p = "NLOWER+NL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5280 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5281 case UPPER:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5282 p = "UPPER";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5283 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5284 case UPPER + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5285 p = "UPPER+NL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5286 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5287 case NUPPER:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5288 p = "NUPPER";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5289 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5290 case NUPPER + ADD_NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5291 p = "NUPPER+NL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5292 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5293 case BRANCH:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5294 p = "BRANCH";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5295 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5296 case EXACTLY:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5297 p = "EXACTLY";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5298 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5299 case NOTHING:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5300 p = "NOTHING";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5301 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5302 case BACK:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5303 p = "BACK";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5304 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5305 case END:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5306 p = "END";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5307 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5308 case MOPEN + 0:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5309 p = "MATCH START";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5310 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5311 case MOPEN + 1:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5312 case MOPEN + 2:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5313 case MOPEN + 3:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5314 case MOPEN + 4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5315 case MOPEN + 5:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5316 case MOPEN + 6:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5317 case MOPEN + 7:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5318 case MOPEN + 8:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5319 case MOPEN + 9:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5320 sprintf(buf + STRLEN(buf), "MOPEN%d", OP(op) - MOPEN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5321 p = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5322 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5323 case MCLOSE + 0:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5324 p = "MATCH END";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5325 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5326 case MCLOSE + 1:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5327 case MCLOSE + 2:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5328 case MCLOSE + 3:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5329 case MCLOSE + 4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5330 case MCLOSE + 5:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5331 case MCLOSE + 6:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5332 case MCLOSE + 7:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5333 case MCLOSE + 8:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5334 case MCLOSE + 9:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5335 sprintf(buf + STRLEN(buf), "MCLOSE%d", OP(op) - MCLOSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5336 p = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5337 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5338 case BACKREF + 1:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5339 case BACKREF + 2:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5340 case BACKREF + 3:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5341 case BACKREF + 4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5342 case BACKREF + 5:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5343 case BACKREF + 6:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5344 case BACKREF + 7:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5345 case BACKREF + 8:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5346 case BACKREF + 9:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5347 sprintf(buf + STRLEN(buf), "BACKREF%d", OP(op) - BACKREF);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5348 p = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5349 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5350 case NOPEN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5351 p = "NOPEN";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5352 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5353 case NCLOSE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5354 p = "NCLOSE";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5355 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5356 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5357 case ZOPEN + 1:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5358 case ZOPEN + 2:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5359 case ZOPEN + 3:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5360 case ZOPEN + 4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5361 case ZOPEN + 5:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5362 case ZOPEN + 6:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5363 case ZOPEN + 7:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5364 case ZOPEN + 8:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5365 case ZOPEN + 9:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5366 sprintf(buf + STRLEN(buf), "ZOPEN%d", OP(op) - ZOPEN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5367 p = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5368 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5369 case ZCLOSE + 1:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5370 case ZCLOSE + 2:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5371 case ZCLOSE + 3:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5372 case ZCLOSE + 4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5373 case ZCLOSE + 5:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5374 case ZCLOSE + 6:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5375 case ZCLOSE + 7:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5376 case ZCLOSE + 8:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5377 case ZCLOSE + 9:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5378 sprintf(buf + STRLEN(buf), "ZCLOSE%d", OP(op) - ZCLOSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5379 p = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5380 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5381 case ZREF + 1:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5382 case ZREF + 2:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5383 case ZREF + 3:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5384 case ZREF + 4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5385 case ZREF + 5:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5386 case ZREF + 6:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5387 case ZREF + 7:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5388 case ZREF + 8:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5389 case ZREF + 9:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5390 sprintf(buf + STRLEN(buf), "ZREF%d", OP(op) - ZREF);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5391 p = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5392 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5393 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5394 case STAR:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5395 p = "STAR";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5396 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5397 case PLUS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5398 p = "PLUS";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5399 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5400 case NOMATCH:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5401 p = "NOMATCH";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5402 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5403 case MATCH:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5404 p = "MATCH";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5405 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5406 case BEHIND:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5407 p = "BEHIND";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5408 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5409 case NOBEHIND:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5410 p = "NOBEHIND";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5411 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5412 case SUBPAT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5413 p = "SUBPAT";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5414 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5415 case BRACE_LIMITS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5416 p = "BRACE_LIMITS";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5417 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5418 case BRACE_SIMPLE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5419 p = "BRACE_SIMPLE";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5420 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5421 case BRACE_COMPLEX + 0:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5422 case BRACE_COMPLEX + 1:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5423 case BRACE_COMPLEX + 2:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5424 case BRACE_COMPLEX + 3:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5425 case BRACE_COMPLEX + 4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5426 case BRACE_COMPLEX + 5:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5427 case BRACE_COMPLEX + 6:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5428 case BRACE_COMPLEX + 7:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5429 case BRACE_COMPLEX + 8:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5430 case BRACE_COMPLEX + 9:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5431 sprintf(buf + STRLEN(buf), "BRACE_COMPLEX%d", OP(op) - BRACE_COMPLEX);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5432 p = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5433 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5434 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5435 case MULTIBYTECODE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5436 p = "MULTIBYTECODE";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5437 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5438 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5439 case NEWL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5440 p = "NEWL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5441 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5442 default:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5443 sprintf(buf + STRLEN(buf), "corrupt %d", OP(op));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5444 p = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5445 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5446 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5447 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5448 (void) strcat(buf, p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5449 return buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5450 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5451 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5452
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5453 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5454 static void mb_decompose __ARGS((int c, int *c1, int *c2, int *c3));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5455
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5456 typedef struct
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5457 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5458 int a, b, c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5459 } decomp_T;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5460
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5461
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5462 /* 0xfb20 - 0xfb4f */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5463 decomp_T decomp_table[0xfb4f-0xfb20+1] =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5464 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5465 {0x5e2,0,0}, /* 0xfb20 alt ayin */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5466 {0x5d0,0,0}, /* 0xfb21 alt alef */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5467 {0x5d3,0,0}, /* 0xfb22 alt dalet */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5468 {0x5d4,0,0}, /* 0xfb23 alt he */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5469 {0x5db,0,0}, /* 0xfb24 alt kaf */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5470 {0x5dc,0,0}, /* 0xfb25 alt lamed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5471 {0x5dd,0,0}, /* 0xfb26 alt mem-sofit */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5472 {0x5e8,0,0}, /* 0xfb27 alt resh */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5473 {0x5ea,0,0}, /* 0xfb28 alt tav */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5474 {'+', 0, 0}, /* 0xfb29 alt plus */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5475 {0x5e9, 0x5c1, 0}, /* 0xfb2a shin+shin-dot */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5476 {0x5e9, 0x5c2, 0}, /* 0xfb2b shin+sin-dot */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5477 {0x5e9, 0x5c1, 0x5bc}, /* 0xfb2c shin+shin-dot+dagesh */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5478 {0x5e9, 0x5c2, 0x5bc}, /* 0xfb2d shin+sin-dot+dagesh */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5479 {0x5d0, 0x5b7, 0}, /* 0xfb2e alef+patah */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5480 {0x5d0, 0x5b8, 0}, /* 0xfb2f alef+qamats */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5481 {0x5d0, 0x5b4, 0}, /* 0xfb30 alef+hiriq */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5482 {0x5d1, 0x5bc, 0}, /* 0xfb31 bet+dagesh */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5483 {0x5d2, 0x5bc, 0}, /* 0xfb32 gimel+dagesh */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5484 {0x5d3, 0x5bc, 0}, /* 0xfb33 dalet+dagesh */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5485 {0x5d4, 0x5bc, 0}, /* 0xfb34 he+dagesh */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5486 {0x5d5, 0x5bc, 0}, /* 0xfb35 vav+dagesh */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5487 {0x5d6, 0x5bc, 0}, /* 0xfb36 zayin+dagesh */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5488 {0xfb37, 0, 0}, /* 0xfb37 -- UNUSED */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5489 {0x5d8, 0x5bc, 0}, /* 0xfb38 tet+dagesh */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5490 {0x5d9, 0x5bc, 0}, /* 0xfb39 yud+dagesh */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5491 {0x5da, 0x5bc, 0}, /* 0xfb3a kaf sofit+dagesh */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5492 {0x5db, 0x5bc, 0}, /* 0xfb3b kaf+dagesh */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5493 {0x5dc, 0x5bc, 0}, /* 0xfb3c lamed+dagesh */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5494 {0xfb3d, 0, 0}, /* 0xfb3d -- UNUSED */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5495 {0x5de, 0x5bc, 0}, /* 0xfb3e mem+dagesh */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5496 {0xfb3f, 0, 0}, /* 0xfb3f -- UNUSED */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5497 {0x5e0, 0x5bc, 0}, /* 0xfb40 nun+dagesh */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5498 {0x5e1, 0x5bc, 0}, /* 0xfb41 samech+dagesh */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5499 {0xfb42, 0, 0}, /* 0xfb42 -- UNUSED */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5500 {0x5e3, 0x5bc, 0}, /* 0xfb43 pe sofit+dagesh */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5501 {0x5e4, 0x5bc,0}, /* 0xfb44 pe+dagesh */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5502 {0xfb45, 0, 0}, /* 0xfb45 -- UNUSED */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5503 {0x5e6, 0x5bc, 0}, /* 0xfb46 tsadi+dagesh */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5504 {0x5e7, 0x5bc, 0}, /* 0xfb47 qof+dagesh */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5505 {0x5e8, 0x5bc, 0}, /* 0xfb48 resh+dagesh */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5506 {0x5e9, 0x5bc, 0}, /* 0xfb49 shin+dagesh */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5507 {0x5ea, 0x5bc, 0}, /* 0xfb4a tav+dagesh */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5508 {0x5d5, 0x5b9, 0}, /* 0xfb4b vav+holam */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5509 {0x5d1, 0x5bf, 0}, /* 0xfb4c bet+rafe */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5510 {0x5db, 0x5bf, 0}, /* 0xfb4d kaf+rafe */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5511 {0x5e4, 0x5bf, 0}, /* 0xfb4e pe+rafe */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5512 {0x5d0, 0x5dc, 0} /* 0xfb4f alef-lamed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5513 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5514
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5515 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5516 mb_decompose(c, c1, c2, c3)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5517 int c, *c1, *c2, *c3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5518 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5519 decomp_T d;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5520
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5521 if (c >= 0x4b20 && c <= 0xfb4f)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5522 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5523 d = decomp_table[c - 0xfb20];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5524 *c1 = d.a;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5525 *c2 = d.b;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5526 *c3 = d.c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5527 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5528 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5529 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5530 *c1 = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5531 *c2 = *c3 = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5532 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5533 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5534 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5535
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5536 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5537 * Compare two strings, ignore case if ireg_ic set.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5538 * Return 0 if strings match, non-zero otherwise.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5539 * Correct the length "*n" when composing characters are ignored.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5540 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5541 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5542 cstrncmp(s1, s2, n)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5543 char_u *s1, *s2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5544 int *n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5545 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5546 int result;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5547
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5548 if (!ireg_ic)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5549 result = STRNCMP(s1, s2, *n);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5550 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5551 result = MB_STRNICMP(s1, s2, *n);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5552
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5553 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5554 /* if it failed and it's utf8 and we want to combineignore: */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5555 if (result != 0 && enc_utf8 && ireg_icombine)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5556 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5557 char_u *str1, *str2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5558 int c1, c2, c11, c12;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5559 int ix;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5560 int junk;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5561
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5562 /* we have to handle the strcmp ourselves, since it is necessary to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5563 * deal with the composing characters by ignoring them: */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5564 str1 = s1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5565 str2 = s2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5566 c1 = c2 = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5567 for (ix = 0; ix < *n; )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5568 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5569 c1 = mb_ptr2char_adv(&str1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5570 c2 = mb_ptr2char_adv(&str2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5571 ix += utf_char2len(c1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5572
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5573 /* decompose the character if necessary, into 'base' characters
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5574 * because I don't care about Arabic, I will hard-code the Hebrew
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5575 * which I *do* care about! So sue me... */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5576 if (c1 != c2 && (!ireg_ic || utf_fold(c1) != utf_fold(c2)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5577 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5578 /* decomposition necessary? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5579 mb_decompose(c1, &c11, &junk, &junk);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5580 mb_decompose(c2, &c12, &junk, &junk);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5581 c1 = c11;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5582 c2 = c12;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5583 if (c11 != c12 && (!ireg_ic || utf_fold(c11) != utf_fold(c12)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5584 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5585 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5586 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5587 result = c2 - c1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5588 if (result == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5589 *n = (int)(str2 - s2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5590 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5591 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5592
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5593 return result;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5594 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5595
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5596 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5597 * cstrchr: This function is used a lot for simple searches, keep it fast!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5598 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5599 static char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5600 cstrchr(s, c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5601 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5602 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5603 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5604 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5605 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5606
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5607 if (!ireg_ic
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5608 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5609 || (!enc_utf8 && mb_char2len(c) > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5610 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5611 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5612 return vim_strchr(s, c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5613
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5614 /* tolower() and toupper() can be slow, comparing twice should be a lot
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5615 * faster (esp. when using MS Visual C++!).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5616 * For UTF-8 need to use folded case. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5617 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5618 if (enc_utf8 && c > 0x80)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5619 cc = utf_fold(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5620 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5621 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5622 if (isupper(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5623 cc = TOLOWER_LOC(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5624 else if (islower(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5625 cc = TOUPPER_LOC(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5626 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5627 return vim_strchr(s, c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5628
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5629 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5630 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5631 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5632 for (p = s; *p != NUL; p += (*mb_ptr2len_check)(p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5633 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5634 if (enc_utf8 && c > 0x80)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5635 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5636 if (utf_fold(utf_ptr2char(p)) == cc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5637 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5638 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5639 else if (*p == c || *p == cc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5640 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5641 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5642 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5643 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5644 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5645 /* Faster version for when there are no multi-byte characters. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5646 for (p = s; *p != NUL; ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5647 if (*p == c || *p == cc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5648 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5649
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5650 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5651 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5652
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5653 /***************************************************************
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5654 * regsub stuff *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5655 ***************************************************************/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5656
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5657 /* This stuff below really confuses cc on an SGI -- webb */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5658 #ifdef __sgi
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5659 # undef __ARGS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5660 # define __ARGS(x) ()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5661 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5662
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5663 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5664 * We should define ftpr as a pointer to a function returning a pointer to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5665 * a function returning a pointer to a function ...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5666 * This is impossible, so we declare a pointer to a function returning a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5667 * pointer to a function returning void. This should work for all compilers.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5668 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5669 typedef void (*(*fptr) __ARGS((char_u *, int)))();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5670
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5671 static fptr do_upper __ARGS((char_u *, int));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5672 static fptr do_Upper __ARGS((char_u *, int));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5673 static fptr do_lower __ARGS((char_u *, int));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5674 static fptr do_Lower __ARGS((char_u *, int));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5675
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5676 static int vim_regsub_both __ARGS((char_u *source, char_u *dest, int copy, int magic, int backslash));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5677
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5678 static fptr
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5679 do_upper(d, c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5680 char_u *d;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5681 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5682 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5683 *d = TOUPPER_LOC(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5684
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5685 return (fptr)NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5686 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5687
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5688 static fptr
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5689 do_Upper(d, c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5690 char_u *d;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5691 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5692 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5693 *d = TOUPPER_LOC(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5694
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5695 return (fptr)do_Upper;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5696 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5697
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5698 static fptr
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5699 do_lower(d, c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5700 char_u *d;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5701 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5702 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5703 *d = TOLOWER_LOC(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5704
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5705 return (fptr)NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5706 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5707
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5708 static fptr
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5709 do_Lower(d, c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5710 char_u *d;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5711 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5712 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5713 *d = TOLOWER_LOC(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5714
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5715 return (fptr)do_Lower;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5716 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5717
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5718 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5719 * regtilde(): Replace tildes in the pattern by the old pattern.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5720 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5721 * Short explanation of the tilde: It stands for the previous replacement
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5722 * pattern. If that previous pattern also contains a ~ we should go back a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5723 * step further... But we insert the previous pattern into the current one
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5724 * and remember that.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5725 * This still does not handle the case where "magic" changes. TODO?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5726 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5727 * The tildes are parsed once before the first call to vim_regsub().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5728 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5729 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5730 regtilde(source, magic)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5731 char_u *source;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5732 int magic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5733 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5734 char_u *newsub = source;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5735 char_u *tmpsub;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5736 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5737 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5738 int prevlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5739
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5740 for (p = newsub; *p; ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5741 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5742 if ((*p == '~' && magic) || (*p == '\\' && *(p + 1) == '~' && !magic))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5743 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5744 if (reg_prev_sub != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5745 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5746 /* length = len(newsub) - 1 + len(prev_sub) + 1 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5747 prevlen = (int)STRLEN(reg_prev_sub);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5748 tmpsub = alloc((unsigned)(STRLEN(newsub) + prevlen));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5749 if (tmpsub != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5750 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5751 /* copy prefix */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5752 len = (int)(p - newsub); /* not including ~ */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5753 mch_memmove(tmpsub, newsub, (size_t)len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5754 /* interpretate tilde */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5755 mch_memmove(tmpsub + len, reg_prev_sub, (size_t)prevlen);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5756 /* copy postfix */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5757 if (!magic)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5758 ++p; /* back off \ */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5759 STRCPY(tmpsub + len + prevlen, p + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5760
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5761 if (newsub != source) /* already allocated newsub */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5762 vim_free(newsub);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5763 newsub = tmpsub;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5764 p = newsub + len + prevlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5765 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5766 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5767 else if (magic)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5768 STRCPY(p, p + 1); /* remove '~' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5769 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5770 STRCPY(p, p + 2); /* remove '\~' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5771 --p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5772 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5773 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5774 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5775 if (*p == '\\' && p[1]) /* skip escaped characters */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5776 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5777 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5778 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5779 p += (*mb_ptr2len_check)(p) - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5780 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5781 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5782 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5783
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5784 vim_free(reg_prev_sub);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5785 if (newsub != source) /* newsub was allocated, just keep it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5786 reg_prev_sub = newsub;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5787 else /* no ~ found, need to save newsub */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5788 reg_prev_sub = vim_strsave(newsub);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5789 return newsub;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5790 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5791
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5792 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5793 static int can_f_submatch = FALSE; /* TRUE when submatch() can be used */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5794
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5795 /* These pointers are used instead of reg_match and reg_mmatch for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5796 * reg_submatch(). Needed for when the substitution string is an expression
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5797 * that contains a call to substitute() and submatch(). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5798 static regmatch_T *submatch_match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5799 static regmmatch_T *submatch_mmatch;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5800 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5801
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5802 #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5803 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5804 * vim_regsub() - perform substitutions after a vim_regexec() or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5805 * vim_regexec_multi() match.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5806 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5807 * If "copy" is TRUE really copy into "dest".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5808 * If "copy" is FALSE nothing is copied, this is just to find out the length
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5809 * of the result.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5810 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5811 * If "backslash" is TRUE, a backslash will be removed later, need to double
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5812 * them to keep them, and insert a backslash before a CR to avoid it being
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5813 * replaced with a line break later.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5814 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5815 * Note: The matched text must not change between the call of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5816 * vim_regexec()/vim_regexec_multi() and vim_regsub()! It would make the back
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5817 * references invalid!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5818 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5819 * Returns the size of the replacement, including terminating NUL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5820 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5821 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5822 vim_regsub(rmp, source, dest, copy, magic, backslash)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5823 regmatch_T *rmp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5824 char_u *source;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5825 char_u *dest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5826 int copy;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5827 int magic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5828 int backslash;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5829 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5830 reg_match = rmp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5831 reg_mmatch = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5832 reg_maxline = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5833 return vim_regsub_both(source, dest, copy, magic, backslash);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5834 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5835 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5836
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5837 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5838 vim_regsub_multi(rmp, lnum, source, dest, copy, magic, backslash)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5839 regmmatch_T *rmp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5840 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5841 char_u *source;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5842 char_u *dest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5843 int copy;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5844 int magic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5845 int backslash;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5846 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5847 reg_match = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5848 reg_mmatch = rmp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5849 reg_buf = curbuf; /* always works on the current buffer! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5850 reg_firstlnum = lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5851 reg_maxline = curbuf->b_ml.ml_line_count - lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5852 return vim_regsub_both(source, dest, copy, magic, backslash);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5853 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5854
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5855 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5856 vim_regsub_both(source, dest, copy, magic, backslash)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5857 char_u *source;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5858 char_u *dest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5859 int copy;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5860 int magic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5861 int backslash;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5862 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5863 char_u *src;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5864 char_u *dst;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5865 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5866 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5867 int no = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5868 fptr func = (fptr)NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5869 linenr_T clnum = 0; /* init for GCC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5870 int len = 0; /* init for GCC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5871 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5872 static char_u *eval_result = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5873 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5874 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5875 int l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5876 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5877
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5878
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5879 /* Be paranoid... */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5880 if (source == NULL || dest == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5881 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5882 EMSG(_(e_null));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5883 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5884 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5885 if (prog_magic_wrong())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5886 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5887 src = source;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5888 dst = dest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5889
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5890 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5891 * When the substitute part starts with "\=" evaluate it as an expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5892 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5893 if (source[0] == '\\' && source[1] == '='
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5894 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5895 && !can_f_submatch /* can't do this recursively */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5896 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5897 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5898 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5899 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5900 /* To make sure that the length doesn't change between checking the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5901 * length and copying the string, and to speed up things, the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5902 * resulting string is saved from the call with "copy" == FALSE to the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5903 * call with "copy" == TRUE. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5904 if (copy)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5905 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5906 if (eval_result != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5907 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5908 STRCPY(dest, eval_result);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5909 dst += STRLEN(eval_result);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5910 vim_free(eval_result);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5911 eval_result = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5912 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5913 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5914 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5915 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5916 linenr_T save_reg_maxline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5917 win_T *save_reg_win;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5918 int save_ireg_ic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5919
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5920 vim_free(eval_result);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5921
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5922 /* The expression may contain substitute(), which calls us
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5923 * recursively. Make sure submatch() gets the text from the first
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5924 * level. Don't need to save "reg_buf", because
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5925 * vim_regexec_multi() can't be called recursively. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5926 submatch_match = reg_match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5927 submatch_mmatch = reg_mmatch;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5928 save_reg_maxline = reg_maxline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5929 save_reg_win = reg_win;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5930 save_ireg_ic = ireg_ic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5931 can_f_submatch = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5932
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5933 eval_result = eval_to_string(source + 2, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5934 if (eval_result != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5935 {
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
5936 for (s = eval_result; *s != NUL; mb_ptr_adv(s))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5937 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5938 /* Change NL to CR, so that it becomes a line break.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5939 * Skip over a backslashed character. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5940 if (*s == NL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5941 *s = CAR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5942 else if (*s == '\\' && s[1] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5943 ++s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5944 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5945
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5946 dst += STRLEN(eval_result);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5947 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5948
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5949 reg_match = submatch_match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5950 reg_mmatch = submatch_mmatch;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5951 reg_maxline = save_reg_maxline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5952 reg_win = save_reg_win;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5953 ireg_ic = save_ireg_ic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5954 can_f_submatch = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5955 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5956 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5957 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5958 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5959 while ((c = *src++) != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5960 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5961 if (c == '&' && magic)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5962 no = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5963 else if (c == '\\' && *src != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5964 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5965 if (*src == '&' && !magic)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5966 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5967 ++src;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5968 no = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5969 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5970 else if ('0' <= *src && *src <= '9')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5971 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5972 no = *src++ - '0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5973 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5974 else if (vim_strchr((char_u *)"uUlLeE", *src))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5975 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5976 switch (*src++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5977 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5978 case 'u': func = (fptr)do_upper;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5979 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5980 case 'U': func = (fptr)do_Upper;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5981 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5982 case 'l': func = (fptr)do_lower;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5983 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5984 case 'L': func = (fptr)do_Lower;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5985 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5986 case 'e':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5987 case 'E': func = (fptr)NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5988 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5989 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5990 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5991 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5992 if (no < 0) /* Ordinary character. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5993 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5994 if (c == '\\' && *src != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5995 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5996 /* Check for abbreviations -- webb */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5997 switch (*src)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5998 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5999 case 'r': c = CAR; ++src; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6000 case 'n': c = NL; ++src; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6001 case 't': c = TAB; ++src; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6002 /* Oh no! \e already has meaning in subst pat :-( */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6003 /* case 'e': c = ESC; ++src; break; */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6004 case 'b': c = Ctrl_H; ++src; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6005
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6006 /* If "backslash" is TRUE the backslash will be removed
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6007 * later. Used to insert a literal CR. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6008 default: if (backslash)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6009 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6010 if (copy)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6011 *dst = '\\';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6012 ++dst;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6013 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6014 c = *src++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6015 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6016 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6017
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6018 /* Write to buffer, if copy is set. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6019 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6020 if (has_mbyte && (l = (*mb_ptr2len_check)(src - 1)) > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6021 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6022 /* TODO: should use "func" here. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6023 if (copy)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6024 mch_memmove(dst, src - 1, l);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6025 dst += l - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6026 src += l - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6027 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6028 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6029 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6030 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6031 if (copy)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6032 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6033 if (func == (fptr)NULL) /* just copy */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6034 *dst = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6035 else /* change case */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6036 func = (fptr)(func(dst, c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6037 /* Turbo C complains without the typecast */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6038 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6039 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6040 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6041 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6042 dst++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6043 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6044 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6045 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6046 if (REG_MULTI)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6047 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6048 clnum = reg_mmatch->startpos[no].lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6049 if (clnum < 0 || reg_mmatch->endpos[no].lnum < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6050 s = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6051 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6052 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6053 s = reg_getline(clnum) + reg_mmatch->startpos[no].col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6054 if (reg_mmatch->endpos[no].lnum == clnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6055 len = reg_mmatch->endpos[no].col
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6056 - reg_mmatch->startpos[no].col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6057 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6058 len = (int)STRLEN(s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6059 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6060 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6061 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6062 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6063 s = reg_match->startp[no];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6064 if (reg_match->endp[no] == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6065 s = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6066 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6067 len = (int)(reg_match->endp[no] - s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6068 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6069 if (s != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6070 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6071 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6072 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6073 if (len == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6074 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6075 if (REG_MULTI)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6076 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6077 if (reg_mmatch->endpos[no].lnum == clnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6078 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6079 if (copy)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6080 *dst = CAR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6081 ++dst;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6082 s = reg_getline(++clnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6083 if (reg_mmatch->endpos[no].lnum == clnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6084 len = reg_mmatch->endpos[no].col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6085 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6086 len = (int)STRLEN(s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6087 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6088 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6089 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6090 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6091 else if (*s == NUL) /* we hit NUL. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6092 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6093 if (copy)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6094 EMSG(_(e_re_damg));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6095 goto exit;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6096 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6097 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6098 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6099 if (backslash && (*s == CAR || *s == '\\'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6100 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6101 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6102 * Insert a backslash in front of a CR, otherwise
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6103 * it will be replaced by a line break.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6104 * Number of backslashes will be halved later,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6105 * double them here.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6106 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6107 if (copy)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6108 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6109 dst[0] = '\\';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6110 dst[1] = *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6111 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6112 dst += 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6113 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6114 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6115 else if (has_mbyte && (l = (*mb_ptr2len_check)(s)) > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6116 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6117 /* TODO: should use "func" here. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6118 if (copy)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6119 mch_memmove(dst, s, l);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6120 dst += l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6121 s += l - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6122 len -= l - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6123 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6124 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6125 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6126 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6127 if (copy)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6128 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6129 if (func == (fptr)NULL) /* just copy */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6130 *dst = *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6131 else /* change case */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6132 func = (fptr)(func(dst, *s));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6133 /* Turbo C complains without the typecast */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6134 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6135 ++dst;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6136 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6137 ++s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6138 --len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6139 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6140 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6141 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6142 no = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6143 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6144 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6145 if (copy)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6146 *dst = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6147
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6148 exit:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6149 return (int)((dst - dest) + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6150 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6151
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6152 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6153 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6154 * Used for the submatch() function: get the string from tne n'th submatch in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6155 * allocated memory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6156 * Returns NULL when not in a ":s" command and for a non-existing submatch.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6157 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6158 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6159 reg_submatch(no)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6160 int no;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6161 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6162 char_u *retval = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6163 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6164 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6165 int round;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6166 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6167
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6168 if (!can_f_submatch)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6169 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6170
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6171 if (submatch_match == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6172 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6173 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6174 * First round: compute the length and allocate memory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6175 * Second round: copy the text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6176 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6177 for (round = 1; round <= 2; ++round)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6178 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6179 lnum = submatch_mmatch->startpos[no].lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6180 if (lnum < 0 || submatch_mmatch->endpos[no].lnum < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6181 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6182
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6183 s = reg_getline(lnum) + submatch_mmatch->startpos[no].col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6184 if (s == NULL) /* anti-crash check, cannot happen? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6185 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6186 if (submatch_mmatch->endpos[no].lnum == lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6187 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6188 /* Within one line: take form start to end col. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6189 len = submatch_mmatch->endpos[no].col
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6190 - submatch_mmatch->startpos[no].col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6191 if (round == 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6192 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6193 STRNCPY(retval, s, len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6194 retval[len] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6195 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6196 ++len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6197 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6198 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6199 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6200 /* Multiple lines: take start line from start col, middle
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6201 * lines completely and end line up to end col. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6202 len = (int)STRLEN(s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6203 if (round == 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6204 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6205 STRCPY(retval, s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6206 retval[len] = '\n';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6207 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6208 ++len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6209 ++lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6210 while (lnum < submatch_mmatch->endpos[no].lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6211 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6212 s = reg_getline(lnum++);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6213 if (round == 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6214 STRCPY(retval + len, s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6215 len += (int)STRLEN(s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6216 if (round == 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6217 retval[len] = '\n';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6218 ++len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6219 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6220 if (round == 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6221 STRNCPY(retval + len, reg_getline(lnum),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6222 submatch_mmatch->endpos[no].col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6223 len += submatch_mmatch->endpos[no].col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6224 if (round == 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6225 retval[len] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6226 ++len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6227 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6228
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6229 if (round == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6230 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6231 retval = lalloc((long_u)len, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6232 if (s == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6233 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6234 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6235 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6236 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6237 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6238 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6239 if (submatch_match->endp[no] == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6240 retval = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6241 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6242 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6243 s = submatch_match->startp[no];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6244 retval = vim_strnsave(s, (int)(submatch_match->endp[no] - s));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6245 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6246 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6247
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6248 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6249 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6250 #endif