comparison src/syntax.c @ 18814:7e7ec935e7c8 v8.1.2395

patch 8.1.2395: using old C style comments Commit: https://github.com/vim/vim/commit/0d6f5d9740dbad1b0207f3ab257de806169dd905 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Dec 5 21:33:15 2019 +0100 patch 8.1.2395: using old C style comments Problem: Using old C style comments. Solution: Use // comments where appropriate.
author Bram Moolenaar <Bram@vim.org>
date Thu, 05 Dec 2019 21:45:04 +0100
parents 4cf69f8d1ec6
children 94eda51ba9ba
comparison
equal deleted inserted replaced
18813:89d78230790e 18814:7e7ec935e7c8
13 13
14 #include "vim.h" 14 #include "vim.h"
15 15
16 #if defined(FEAT_SYN_HL) || defined(PROTO) 16 #if defined(FEAT_SYN_HL) || defined(PROTO)
17 17
18 #define SYN_NAMELEN 50 /* maximum length of a syntax name */ 18 #define SYN_NAMELEN 50 // maximum length of a syntax name
19 19
20 /* different types of offsets that are possible */ 20 // different types of offsets that are possible
21 #define SPO_MS_OFF 0 /* match start offset */ 21 #define SPO_MS_OFF 0 // match start offset
22 #define SPO_ME_OFF 1 /* match end offset */ 22 #define SPO_ME_OFF 1 // match end offset
23 #define SPO_HS_OFF 2 /* highl. start offset */ 23 #define SPO_HS_OFF 2 // highl. start offset
24 #define SPO_HE_OFF 3 /* highl. end offset */ 24 #define SPO_HE_OFF 3 // highl. end offset
25 #define SPO_RS_OFF 4 /* region start offset */ 25 #define SPO_RS_OFF 4 // region start offset
26 #define SPO_RE_OFF 5 /* region end offset */ 26 #define SPO_RE_OFF 5 // region end offset
27 #define SPO_LC_OFF 6 /* leading context offset */ 27 #define SPO_LC_OFF 6 // leading context offset
28 #define SPO_COUNT 7 28 #define SPO_COUNT 7
29 29
30 static char *(spo_name_tab[SPO_COUNT]) = 30 static char *(spo_name_tab[SPO_COUNT]) =
31 {"ms=", "me=", "hs=", "he=", "rs=", "re=", "lc="}; 31 {"ms=", "me=", "hs=", "he=", "rs=", "re=", "lc="};
32 32
43 * 43 *
44 * Note that ordering of members is optimized to reduce padding. 44 * Note that ordering of members is optimized to reduce padding.
45 */ 45 */
46 typedef struct syn_pattern 46 typedef struct syn_pattern
47 { 47 {
48 char sp_type; /* see SPTYPE_ defines below */ 48 char sp_type; // see SPTYPE_ defines below
49 char sp_syncing; /* this item used for syncing */ 49 char sp_syncing; // this item used for syncing
50 short sp_syn_match_id; /* highlight group ID of pattern */ 50 short sp_syn_match_id; // highlight group ID of pattern
51 short sp_off_flags; /* see below */ 51 short sp_off_flags; // see below
52 int sp_offsets[SPO_COUNT]; /* offsets */ 52 int sp_offsets[SPO_COUNT]; // offsets
53 int sp_flags; /* see HL_ defines below */ 53 int sp_flags; // see HL_ defines below
54 #ifdef FEAT_CONCEAL 54 #ifdef FEAT_CONCEAL
55 int sp_cchar; /* conceal substitute character */ 55 int sp_cchar; // conceal substitute character
56 #endif 56 #endif
57 int sp_ic; /* ignore-case flag for sp_prog */ 57 int sp_ic; // ignore-case flag for sp_prog
58 int sp_sync_idx; /* sync item index (syncing only) */ 58 int sp_sync_idx; // sync item index (syncing only)
59 int sp_line_id; /* ID of last line where tried */ 59 int sp_line_id; // ID of last line where tried
60 int sp_startcol; /* next match in sp_line_id line */ 60 int sp_startcol; // next match in sp_line_id line
61 short *sp_cont_list; /* cont. group IDs, if non-zero */ 61 short *sp_cont_list; // cont. group IDs, if non-zero
62 short *sp_next_list; /* next group IDs, if non-zero */ 62 short *sp_next_list; // next group IDs, if non-zero
63 struct sp_syn sp_syn; /* struct passed to in_id_list() */ 63 struct sp_syn sp_syn; // struct passed to in_id_list()
64 char_u *sp_pattern; /* regexp to match, pattern */ 64 char_u *sp_pattern; // regexp to match, pattern
65 regprog_T *sp_prog; /* regexp to match, program */ 65 regprog_T *sp_prog; // regexp to match, program
66 #ifdef FEAT_PROFILE 66 #ifdef FEAT_PROFILE
67 syn_time_T sp_time; 67 syn_time_T sp_time;
68 #endif 68 #endif
69 } synpat_T; 69 } synpat_T;
70 70
71 /* The sp_off_flags are computed like this: 71 // The sp_off_flags are computed like this:
72 * offset from the start of the matched text: (1 << SPO_XX_OFF) 72 // offset from the start of the matched text: (1 << SPO_XX_OFF)
73 * offset from the end of the matched text: (1 << (SPO_XX_OFF + SPO_COUNT)) 73 // offset from the end of the matched text: (1 << (SPO_XX_OFF + SPO_COUNT))
74 * When both are present, only one is used. 74 // When both are present, only one is used.
75 */ 75
76 76 #define SPTYPE_MATCH 1 // match keyword with this group ID
77 #define SPTYPE_MATCH 1 /* match keyword with this group ID */ 77 #define SPTYPE_START 2 // match a regexp, start of item
78 #define SPTYPE_START 2 /* match a regexp, start of item */ 78 #define SPTYPE_END 3 // match a regexp, end of item
79 #define SPTYPE_END 3 /* match a regexp, end of item */ 79 #define SPTYPE_SKIP 4 // match a regexp, skip within item
80 #define SPTYPE_SKIP 4 /* match a regexp, skip within item */
81 80
82 81
83 #define SYN_ITEMS(buf) ((synpat_T *)((buf)->b_syn_patterns.ga_data)) 82 #define SYN_ITEMS(buf) ((synpat_T *)((buf)->b_syn_patterns.ga_data))
84 83
85 #define NONE_IDX -2 /* value of sp_sync_idx for "NONE" */ 84 #define NONE_IDX -2 // value of sp_sync_idx for "NONE"
86 85
87 /* 86 /*
88 * Flags for b_syn_sync_flags: 87 * Flags for b_syn_sync_flags:
89 */ 88 */
90 #define SF_CCOMMENT 0x01 /* sync on a C-style comment */ 89 #define SF_CCOMMENT 0x01 // sync on a C-style comment
91 #define SF_MATCH 0x02 /* sync by matching a pattern */ 90 #define SF_MATCH 0x02 // sync by matching a pattern
92 91
93 #define SYN_STATE_P(ssp) ((bufstate_T *)((ssp)->ga_data)) 92 #define SYN_STATE_P(ssp) ((bufstate_T *)((ssp)->ga_data))
94 93
95 #define MAXKEYWLEN 80 /* maximum length of a keyword */ 94 #define MAXKEYWLEN 80 // maximum length of a keyword
96 95
97 /* 96 /*
98 * The attributes of the syntax item that has been recognized. 97 * The attributes of the syntax item that has been recognized.
99 */ 98 */
100 static int current_attr = 0; /* attr of current syntax word */ 99 static int current_attr = 0; // attr of current syntax word
101 #ifdef FEAT_EVAL 100 #ifdef FEAT_EVAL
102 static int current_id = 0; /* ID of current char for syn_get_id() */ 101 static int current_id = 0; // ID of current char for syn_get_id()
103 static int current_trans_id = 0; /* idem, transparency removed */ 102 static int current_trans_id = 0; // idem, transparency removed
104 #endif 103 #endif
105 #ifdef FEAT_CONCEAL 104 #ifdef FEAT_CONCEAL
106 static int current_flags = 0; 105 static int current_flags = 0;
107 static int current_seqnr = 0; 106 static int current_seqnr = 0;
108 static int current_sub_char = 0; 107 static int current_sub_char = 0;
109 #endif 108 #endif
110 109
111 typedef struct syn_cluster_S 110 typedef struct syn_cluster_S
112 { 111 {
113 char_u *scl_name; /* syntax cluster name */ 112 char_u *scl_name; // syntax cluster name
114 char_u *scl_name_u; /* uppercase of scl_name */ 113 char_u *scl_name_u; // uppercase of scl_name
115 short *scl_list; /* IDs in this syntax cluster */ 114 short *scl_list; // IDs in this syntax cluster
116 } syn_cluster_T; 115 } syn_cluster_T;
117 116
118 /* 117 /*
119 * Methods of combining two clusters 118 * Methods of combining two clusters
120 */ 119 */
121 #define CLUSTER_REPLACE 1 /* replace first list with second */ 120 #define CLUSTER_REPLACE 1 // replace first list with second
122 #define CLUSTER_ADD 2 /* add second list to first */ 121 #define CLUSTER_ADD 2 // add second list to first
123 #define CLUSTER_SUBTRACT 3 /* subtract second list from first */ 122 #define CLUSTER_SUBTRACT 3 // subtract second list from first
124 123
125 #define SYN_CLSTR(buf) ((syn_cluster_T *)((buf)->b_syn_clusters.ga_data)) 124 #define SYN_CLSTR(buf) ((syn_cluster_T *)((buf)->b_syn_clusters.ga_data))
126 125
127 /* 126 /*
128 * Syntax group IDs have different types: 127 * Syntax group IDs have different types:
130 * 20000 - 20999 ALLBUT indicator (current_syn_inc_tag added) 129 * 20000 - 20999 ALLBUT indicator (current_syn_inc_tag added)
131 * 21000 - 21999 TOP indicator (current_syn_inc_tag added) 130 * 21000 - 21999 TOP indicator (current_syn_inc_tag added)
132 * 22000 - 22999 CONTAINED indicator (current_syn_inc_tag added) 131 * 22000 - 22999 CONTAINED indicator (current_syn_inc_tag added)
133 * 23000 - 32767 cluster IDs (subtract SYNID_CLUSTER for the cluster ID) 132 * 23000 - 32767 cluster IDs (subtract SYNID_CLUSTER for the cluster ID)
134 */ 133 */
135 #define SYNID_ALLBUT MAX_HL_ID /* syntax group ID for contains=ALLBUT */ 134 #define SYNID_ALLBUT MAX_HL_ID // syntax group ID for contains=ALLBUT
136 #define SYNID_TOP 21000 /* syntax group ID for contains=TOP */ 135 #define SYNID_TOP 21000 // syntax group ID for contains=TOP
137 #define SYNID_CONTAINED 22000 /* syntax group ID for contains=CONTAINED */ 136 #define SYNID_CONTAINED 22000 // syntax group ID for contains=CONTAINED
138 #define SYNID_CLUSTER 23000 /* first syntax group ID for clusters */ 137 #define SYNID_CLUSTER 23000 // first syntax group ID for clusters
139 138
140 #define MAX_SYN_INC_TAG 999 /* maximum before the above overflow */ 139 #define MAX_SYN_INC_TAG 999 // maximum before the above overflow
141 #define MAX_CLUSTER_ID (32767 - SYNID_CLUSTER) 140 #define MAX_CLUSTER_ID (32767 - SYNID_CLUSTER)
142 141
143 /* 142 /*
144 * Annoying Hack(TM): ":syn include" needs this pointer to pass to 143 * Annoying Hack(TM): ":syn include" needs this pointer to pass to
145 * expand_filename(). Most of the other syntax commands don't need it, so 144 * expand_filename(). Most of the other syntax commands don't need it, so
181 * When si_m_endpos.lnum is 0, the items other than si_idx are unknown. 180 * When si_m_endpos.lnum is 0, the items other than si_idx are unknown.
182 * (The end positions have the column number of the next char) 181 * (The end positions have the column number of the next char)
183 */ 182 */
184 typedef struct state_item 183 typedef struct state_item
185 { 184 {
186 int si_idx; /* index of syntax pattern or 185 int si_idx; // index of syntax pattern or
187 KEYWORD_IDX */ 186 // KEYWORD_IDX
188 int si_id; /* highlight group ID for keywords */ 187 int si_id; // highlight group ID for keywords
189 int si_trans_id; /* idem, transparency removed */ 188 int si_trans_id; // idem, transparency removed
190 int si_m_lnum; /* lnum of the match */ 189 int si_m_lnum; // lnum of the match
191 int si_m_startcol; /* starting column of the match */ 190 int si_m_startcol; // starting column of the match
192 lpos_T si_m_endpos; /* just after end posn of the match */ 191 lpos_T si_m_endpos; // just after end posn of the match
193 lpos_T si_h_startpos; /* start position of the highlighting */ 192 lpos_T si_h_startpos; // start position of the highlighting
194 lpos_T si_h_endpos; /* end position of the highlighting */ 193 lpos_T si_h_endpos; // end position of the highlighting
195 lpos_T si_eoe_pos; /* end position of end pattern */ 194 lpos_T si_eoe_pos; // end position of end pattern
196 int si_end_idx; /* group ID for end pattern or zero */ 195 int si_end_idx; // group ID for end pattern or zero
197 int si_ends; /* if match ends before si_m_endpos */ 196 int si_ends; // if match ends before si_m_endpos
198 int si_attr; /* attributes in this state */ 197 int si_attr; // attributes in this state
199 long si_flags; /* HL_HAS_EOL flag in this state, and 198 long si_flags; // HL_HAS_EOL flag in this state, and
200 * HL_SKIP* for si_next_list */ 199 // HL_SKIP* for si_next_list
201 #ifdef FEAT_CONCEAL 200 #ifdef FEAT_CONCEAL
202 int si_seqnr; /* sequence number */ 201 int si_seqnr; // sequence number
203 int si_cchar; /* substitution character for conceal */ 202 int si_cchar; // substitution character for conceal
204 #endif 203 #endif
205 short *si_cont_list; /* list of contained groups */ 204 short *si_cont_list; // list of contained groups
206 short *si_next_list; /* nextgroup IDs after this item ends */ 205 short *si_next_list; // nextgroup IDs after this item ends
207 reg_extmatch_T *si_extmatch; /* \z(...\) matches from start 206 reg_extmatch_T *si_extmatch; // \z(...\) matches from start
208 * pattern */ 207 // pattern
209 } stateitem_T; 208 } stateitem_T;
210 209
211 #define KEYWORD_IDX -1 /* value of si_idx for keywords */ 210 #define KEYWORD_IDX -1 // value of si_idx for keywords
212 #define ID_LIST_ALL (short *)-1 /* valid of si_cont_list for containing all 211 #define ID_LIST_ALL (short *)-1 // valid of si_cont_list for containing all
213 but contained groups */ 212 // but contained groups
214 213
215 #ifdef FEAT_CONCEAL 214 #ifdef FEAT_CONCEAL
216 static int next_seqnr = 1; /* value to use for si_seqnr */ 215 static int next_seqnr = 1; // value to use for si_seqnr
217 #endif 216 #endif
218 217
219 /* 218 /*
220 * Struct to reduce the number of arguments to get_syn_options(), it's used 219 * Struct to reduce the number of arguments to get_syn_options(), it's used
221 * very often. 220 * very often.
222 */ 221 */
223 typedef struct 222 typedef struct
224 { 223 {
225 int flags; /* flags for contained and transparent */ 224 int flags; // flags for contained and transparent
226 int keyword; /* TRUE for ":syn keyword" */ 225 int keyword; // TRUE for ":syn keyword"
227 int *sync_idx; /* syntax item for "grouphere" argument, NULL 226 int *sync_idx; // syntax item for "grouphere" argument, NULL
228 if not allowed */ 227 // if not allowed
229 char has_cont_list; /* TRUE if "cont_list" can be used */ 228 char has_cont_list; // TRUE if "cont_list" can be used
230 short *cont_list; /* group IDs for "contains" argument */ 229 short *cont_list; // group IDs for "contains" argument
231 short *cont_in_list; /* group IDs for "containedin" argument */ 230 short *cont_in_list; // group IDs for "containedin" argument
232 short *next_list; /* group IDs for "nextgroup" argument */ 231 short *next_list; // group IDs for "nextgroup" argument
233 } syn_opt_arg_T; 232 } syn_opt_arg_T;
234 233
235 /* 234 /*
236 * The next possible match in the current line for any pattern is remembered, 235 * The next possible match in the current line for any pattern is remembered,
237 * to avoid having to try for a match in each column. 236 * to avoid having to try for a match in each column.
238 * If next_match_idx == -1, not tried (in this line) yet. 237 * If next_match_idx == -1, not tried (in this line) yet.
239 * If next_match_col == MAXCOL, no match found in this line. 238 * If next_match_col == MAXCOL, no match found in this line.
240 * (All end positions have the column of the char after the end) 239 * (All end positions have the column of the char after the end)
241 */ 240 */
242 static int next_match_col; /* column for start of next match */ 241 static int next_match_col; // column for start of next match
243 static lpos_T next_match_m_endpos; /* position for end of next match */ 242 static lpos_T next_match_m_endpos; // position for end of next match
244 static lpos_T next_match_h_startpos; /* pos. for highl. start of next match */ 243 static lpos_T next_match_h_startpos; // pos. for highl. start of next match
245 static lpos_T next_match_h_endpos; /* pos. for highl. end of next match */ 244 static lpos_T next_match_h_endpos; // pos. for highl. end of next match
246 static int next_match_idx; /* index of matched item */ 245 static int next_match_idx; // index of matched item
247 static long next_match_flags; /* flags for next match */ 246 static long next_match_flags; // flags for next match
248 static lpos_T next_match_eos_pos; /* end of start pattn (start region) */ 247 static lpos_T next_match_eos_pos; // end of start pattn (start region)
249 static lpos_T next_match_eoe_pos; /* pos. for end of end pattern */ 248 static lpos_T next_match_eoe_pos; // pos. for end of end pattern
250 static int next_match_end_idx; /* ID of group for end pattn or zero */ 249 static int next_match_end_idx; // ID of group for end pattn or zero
251 static reg_extmatch_T *next_match_extmatch = NULL; 250 static reg_extmatch_T *next_match_extmatch = NULL;
252 251
253 /* 252 /*
254 * A state stack is an array of integers or stateitem_T, stored in a 253 * A state stack is an array of integers or stateitem_T, stored in a
255 * garray_T. A state stack is invalid if its itemsize entry is zero. 254 * garray_T. A state stack is invalid if its itemsize entry is zero.
259 258
260 /* 259 /*
261 * The current state (within the line) of the recognition engine. 260 * The current state (within the line) of the recognition engine.
262 * When current_state.ga_itemsize is 0 the current state is invalid. 261 * When current_state.ga_itemsize is 0 the current state is invalid.
263 */ 262 */
264 static win_T *syn_win; /* current window for highlighting */ 263 static win_T *syn_win; // current window for highlighting
265 static buf_T *syn_buf; /* current buffer for highlighting */ 264 static buf_T *syn_buf; // current buffer for highlighting
266 static synblock_T *syn_block; /* current buffer for highlighting */ 265 static synblock_T *syn_block; // current buffer for highlighting
267 #ifdef FEAT_RELTIME 266 #ifdef FEAT_RELTIME
268 static proftime_T *syn_tm; /* timeout limit */ 267 static proftime_T *syn_tm; // timeout limit
269 #endif 268 #endif
270 static linenr_T current_lnum = 0; /* lnum of current state */ 269 static linenr_T current_lnum = 0; // lnum of current state
271 static colnr_T current_col = 0; /* column of current state */ 270 static colnr_T current_col = 0; // column of current state
272 static int current_state_stored = 0; /* TRUE if stored current state 271 static int current_state_stored = 0; // TRUE if stored current state
273 * after setting current_finished */ 272 // after setting current_finished
274 static int current_finished = 0; /* current line has been finished */ 273 static int current_finished = 0; // current line has been finished
275 static garray_T current_state /* current stack of state_items */ 274 static garray_T current_state // current stack of state_items
276 = {0, 0, 0, 0, NULL}; 275 = {0, 0, 0, 0, NULL};
277 static short *current_next_list = NULL; /* when non-zero, nextgroup list */ 276 static short *current_next_list = NULL; // when non-zero, nextgroup list
278 static int current_next_flags = 0; /* flags for current_next_list */ 277 static int current_next_flags = 0; // flags for current_next_list
279 static int current_line_id = 0; /* unique number for current line */ 278 static int current_line_id = 0; // unique number for current line
280 279
281 #define CUR_STATE(idx) ((stateitem_T *)(current_state.ga_data))[idx] 280 #define CUR_STATE(idx) ((stateitem_T *)(current_state.ga_data))[idx]
282 281
283 static void syn_sync(win_T *wp, linenr_T lnum, synstate_T *last_valid); 282 static void syn_sync(win_T *wp, linenr_T lnum, synstate_T *last_valid);
284 static int syn_match_linecont(linenr_T lnum); 283 static int syn_match_linecont(linenr_T lnum);
375 synstate_T *last_min_valid = NULL; 374 synstate_T *last_min_valid = NULL;
376 synstate_T *sp, *prev = NULL; 375 synstate_T *sp, *prev = NULL;
377 linenr_T parsed_lnum; 376 linenr_T parsed_lnum;
378 linenr_T first_stored; 377 linenr_T first_stored;
379 int dist; 378 int dist;
380 static varnumber_T changedtick = 0; /* remember the last change ID */ 379 static varnumber_T changedtick = 0; // remember the last change ID
381 380
382 #ifdef FEAT_CONCEAL 381 #ifdef FEAT_CONCEAL
383 current_sub_char = NUL; 382 current_sub_char = NUL;
384 #endif 383 #endif
385 384
402 /* 401 /*
403 * Allocate syntax stack when needed. 402 * Allocate syntax stack when needed.
404 */ 403 */
405 syn_stack_alloc(); 404 syn_stack_alloc();
406 if (syn_block->b_sst_array == NULL) 405 if (syn_block->b_sst_array == NULL)
407 return; /* out of memory */ 406 return; // out of memory
408 syn_block->b_sst_lasttick = display_tick; 407 syn_block->b_sst_lasttick = display_tick;
409 408
410 /* 409 /*
411 * If the state of the end of the previous line is useful, store it. 410 * If the state of the end of the previous line is useful, store it.
412 */ 411 */
436 * Try to synchronize from a saved state in b_sst_array[]. 435 * Try to synchronize from a saved state in b_sst_array[].
437 * Only do this if lnum is not before and not to far beyond a saved state. 436 * Only do this if lnum is not before and not to far beyond a saved state.
438 */ 437 */
439 if (INVALID_STATE(&current_state) && syn_block->b_sst_array != NULL) 438 if (INVALID_STATE(&current_state) && syn_block->b_sst_array != NULL)
440 { 439 {
441 /* Find last valid saved state before start_lnum. */ 440 // Find last valid saved state before start_lnum.
442 for (p = syn_block->b_sst_first; p != NULL; p = p->sst_next) 441 for (p = syn_block->b_sst_first; p != NULL; p = p->sst_next)
443 { 442 {
444 if (p->sst_lnum > lnum) 443 if (p->sst_lnum > lnum)
445 break; 444 break;
446 if (p->sst_lnum <= lnum && p->sst_change_lnum == 0) 445 if (p->sst_lnum <= lnum && p->sst_change_lnum == 0)
460 */ 459 */
461 if (INVALID_STATE(&current_state)) 460 if (INVALID_STATE(&current_state))
462 { 461 {
463 syn_sync(wp, lnum, last_valid); 462 syn_sync(wp, lnum, last_valid);
464 if (current_lnum == 1) 463 if (current_lnum == 1)
465 /* First line is always valid, no matter "minlines". */ 464 // First line is always valid, no matter "minlines".
466 first_stored = 1; 465 first_stored = 1;
467 else 466 else
468 /* Need to parse "minlines" lines before state can be considered 467 // Need to parse "minlines" lines before state can be considered
469 * valid to store. */ 468 // valid to store.
470 first_stored = current_lnum + syn_block->b_syn_sync_minlines; 469 first_stored = current_lnum + syn_block->b_syn_sync_minlines;
471 } 470 }
472 else 471 else
473 first_stored = current_lnum; 472 first_stored = current_lnum;
474 473
484 { 483 {
485 syn_start_line(); 484 syn_start_line();
486 (void)syn_finish_line(FALSE); 485 (void)syn_finish_line(FALSE);
487 ++current_lnum; 486 ++current_lnum;
488 487
489 /* If we parsed at least "minlines" lines or started at a valid 488 // If we parsed at least "minlines" lines or started at a valid
490 * state, the current state is considered valid. */ 489 // state, the current state is considered valid.
491 if (current_lnum >= first_stored) 490 if (current_lnum >= first_stored)
492 { 491 {
493 /* Check if the saved state entry is for the current line and is 492 // Check if the saved state entry is for the current line and is
494 * equal to the current state. If so, then validate all saved 493 // equal to the current state. If so, then validate all saved
495 * states that depended on a change before the parsed line. */ 494 // states that depended on a change before the parsed line.
496 if (prev == NULL) 495 if (prev == NULL)
497 prev = syn_stack_find_entry(current_lnum - 1); 496 prev = syn_stack_find_entry(current_lnum - 1);
498 if (prev == NULL) 497 if (prev == NULL)
499 sp = syn_block->b_sst_first; 498 sp = syn_block->b_sst_first;
500 else 499 else
508 parsed_lnum = current_lnum; 507 parsed_lnum = current_lnum;
509 prev = sp; 508 prev = sp;
510 while (sp != NULL && sp->sst_change_lnum <= parsed_lnum) 509 while (sp != NULL && sp->sst_change_lnum <= parsed_lnum)
511 { 510 {
512 if (sp->sst_lnum <= lnum) 511 if (sp->sst_lnum <= lnum)
513 /* valid state before desired line, use this one */ 512 // valid state before desired line, use this one
514 prev = sp; 513 prev = sp;
515 else if (sp->sst_change_lnum == 0) 514 else if (sp->sst_change_lnum == 0)
516 /* past saved states depending on change, break here. */ 515 // past saved states depending on change, break here.
517 break; 516 break;
518 sp->sst_change_lnum = 0; 517 sp->sst_change_lnum = 0;
519 sp = sp->sst_next; 518 sp = sp->sst_next;
520 } 519 }
521 load_current_state(prev); 520 load_current_state(prev);
522 } 521 }
523 /* Store the state at this line when it's the first one, the line 522 // Store the state at this line when it's the first one, the line
524 * where we start parsing, or some distance from the previously 523 // where we start parsing, or some distance from the previously
525 * saved state. But only when parsed at least 'minlines'. */ 524 // saved state. But only when parsed at least 'minlines'.
526 else if (prev == NULL 525 else if (prev == NULL
527 || current_lnum == lnum 526 || current_lnum == lnum
528 || current_lnum >= prev->sst_lnum + dist) 527 || current_lnum >= prev->sst_lnum + dist)
529 prev = store_current_state(); 528 prev = store_current_state();
530 } 529 }
531 530
532 /* This can take a long time: break when CTRL-C pressed. The current 531 // This can take a long time: break when CTRL-C pressed. The current
533 * state will be wrong then. */ 532 // state will be wrong then.
534 line_breakcheck(); 533 line_breakcheck();
535 if (got_int) 534 if (got_int)
536 { 535 {
537 current_lnum = lnum; 536 current_lnum = lnum;
538 break; 537 break;
650 /* 649 /*
651 * 1. Search backwards for the end of a C-style comment. 650 * 1. Search backwards for the end of a C-style comment.
652 */ 651 */
653 if (syn_block->b_syn_sync_flags & SF_CCOMMENT) 652 if (syn_block->b_syn_sync_flags & SF_CCOMMENT)
654 { 653 {
655 /* Need to make syn_buf the current buffer for a moment, to be able to 654 // Need to make syn_buf the current buffer for a moment, to be able to
656 * use find_start_comment(). */ 655 // use find_start_comment().
657 curwin_save = curwin; 656 curwin_save = curwin;
658 curwin = wp; 657 curwin = wp;
659 curbuf_save = curbuf; 658 curbuf_save = curbuf;
660 curbuf = syn_buf; 659 curbuf = syn_buf;
661 660
668 if (*line == NUL || *(line + STRLEN(line) - 1) != '\\') 667 if (*line == NUL || *(line + STRLEN(line) - 1) != '\\')
669 break; 668 break;
670 } 669 }
671 current_lnum = start_lnum; 670 current_lnum = start_lnum;
672 671
673 /* set cursor to start of search */ 672 // set cursor to start of search
674 cursor_save = wp->w_cursor; 673 cursor_save = wp->w_cursor;
675 wp->w_cursor.lnum = start_lnum; 674 wp->w_cursor.lnum = start_lnum;
676 wp->w_cursor.col = 0; 675 wp->w_cursor.col = 0;
677 676
678 /* 677 /*
692 update_si_attr(current_state.ga_len - 1); 691 update_si_attr(current_state.ga_len - 1);
693 break; 692 break;
694 } 693 }
695 } 694 }
696 695
697 /* restore cursor and buffer */ 696 // restore cursor and buffer
698 wp->w_cursor = cursor_save; 697 wp->w_cursor = cursor_save;
699 curwin = curwin_save; 698 curwin = curwin_save;
700 curbuf = curbuf_save; 699 curbuf = curbuf_save;
701 } 700 }
702 701
715 found_m_endpos.col = 0; 714 found_m_endpos.col = 0;
716 end_lnum = start_lnum; 715 end_lnum = start_lnum;
717 lnum = start_lnum; 716 lnum = start_lnum;
718 while (--lnum > break_lnum) 717 while (--lnum > break_lnum)
719 { 718 {
720 /* This can take a long time: break when CTRL-C pressed. */ 719 // This can take a long time: break when CTRL-C pressed.
721 line_breakcheck(); 720 line_breakcheck();
722 if (got_int) 721 if (got_int)
723 { 722 {
724 invalidate_current_state(); 723 invalidate_current_state();
725 current_lnum = start_lnum; 724 current_lnum = start_lnum;
726 break; 725 break;
727 } 726 }
728 727
729 /* Check if we have run into a valid saved state stack now. */ 728 // Check if we have run into a valid saved state stack now.
730 if (last_valid != NULL && lnum == last_valid->sst_lnum) 729 if (last_valid != NULL && lnum == last_valid->sst_lnum)
731 { 730 {
732 load_current_state(last_valid); 731 load_current_state(last_valid);
733 break; 732 break;
734 } 733 }
757 if (had_sync_point && current_state.ga_len) 756 if (had_sync_point && current_state.ga_len)
758 { 757 {
759 cur_si = &CUR_STATE(current_state.ga_len - 1); 758 cur_si = &CUR_STATE(current_state.ga_len - 1);
760 if (cur_si->si_m_endpos.lnum > start_lnum) 759 if (cur_si->si_m_endpos.lnum > start_lnum)
761 { 760 {
762 /* ignore match that goes to after where started */ 761 // ignore match that goes to after where started
763 current_lnum = end_lnum; 762 current_lnum = end_lnum;
764 break; 763 break;
765 } 764 }
766 if (cur_si->si_idx < 0) 765 if (cur_si->si_idx < 0)
767 { 766 {
768 /* Cannot happen? */ 767 // Cannot happen?
769 found_flags = 0; 768 found_flags = 0;
770 found_match_idx = KEYWORD_IDX; 769 found_match_idx = KEYWORD_IDX;
771 } 770 }
772 else 771 else
773 { 772 {
792 else if (found_m_endpos.col > current_col) 791 else if (found_m_endpos.col > current_col)
793 current_col = found_m_endpos.col; 792 current_col = found_m_endpos.col;
794 else 793 else
795 ++current_col; 794 ++current_col;
796 795
797 /* syn_current_attr() will have skipped the check for 796 // syn_current_attr() will have skipped the check for
798 * an item that ends here, need to do that now. Be 797 // an item that ends here, need to do that now. Be
799 * careful not to go past the NUL. */ 798 // careful not to go past the NUL.
800 prev_current_col = current_col; 799 prev_current_col = current_col;
801 if (syn_getcurline()[current_col] != NUL) 800 if (syn_getcurline()[current_col] != NUL)
802 ++current_col; 801 ++current_col;
803 check_state_ends(); 802 check_state_ends();
804 current_col = prev_current_col; 803 current_col = prev_current_col;
852 851
853 end_lnum = lnum; 852 end_lnum = lnum;
854 invalidate_current_state(); 853 invalidate_current_state();
855 } 854 }
856 855
857 /* Ran into start of the file or exceeded maximum number of lines */ 856 // Ran into start of the file or exceeded maximum number of lines
858 if (lnum <= break_lnum) 857 if (lnum <= break_lnum)
859 { 858 {
860 invalidate_current_state(); 859 invalidate_current_state();
861 current_lnum = break_lnum + 1; 860 current_lnum = break_lnum + 1;
862 } 861 }
889 static int 888 static int
890 syn_match_linecont(linenr_T lnum) 889 syn_match_linecont(linenr_T lnum)
891 { 890 {
892 regmmatch_T regmatch; 891 regmmatch_T regmatch;
893 int r; 892 int r;
894 char_u buf_chartab[32]; /* chartab array for syn iskyeyword */ 893 char_u buf_chartab[32]; // chartab array for syn iskyeyword
895 894
896 if (syn_block->b_syn_linecont_prog != NULL) 895 if (syn_block->b_syn_linecont_prog != NULL)
897 { 896 {
898 /* use syntax iskeyword option */ 897 // use syntax iskeyword option
899 save_chartab(buf_chartab); 898 save_chartab(buf_chartab);
900 regmatch.rmm_ic = syn_block->b_syn_linecont_ic; 899 regmatch.rmm_ic = syn_block->b_syn_linecont_ic;
901 regmatch.regprog = syn_block->b_syn_linecont_prog; 900 regmatch.regprog = syn_block->b_syn_linecont_prog;
902 r = syn_regexec(&regmatch, lnum, (colnr_T)0, 901 r = syn_regexec(&regmatch, lnum, (colnr_T)0,
903 IF_SYN_TIME(&syn_block->b_syn_linecont_time)); 902 IF_SYN_TIME(&syn_block->b_syn_linecont_time));
946 int i; 945 int i;
947 int seen_keepend; 946 int seen_keepend;
948 947
949 if (startofline) 948 if (startofline)
950 { 949 {
951 /* Check for a match carried over from a previous line with a 950 // Check for a match carried over from a previous line with a
952 * contained region. The match ends as soon as the region ends. */ 951 // contained region. The match ends as soon as the region ends.
953 for (i = 0; i < current_state.ga_len; ++i) 952 for (i = 0; i < current_state.ga_len; ++i)
954 { 953 {
955 cur_si = &CUR_STATE(i); 954 cur_si = &CUR_STATE(i);
956 if (cur_si->si_idx >= 0 955 if (cur_si->si_idx >= 0
957 && (SYN_ITEMS(syn_block)[cur_si->si_idx]).sp_type 956 && (SYN_ITEMS(syn_block)[cur_si->si_idx]).sp_type
988 cur_si = &CUR_STATE(i); 987 cur_si = &CUR_STATE(i);
989 if ((cur_si->si_flags & HL_KEEPEND) 988 if ((cur_si->si_flags & HL_KEEPEND)
990 || (seen_keepend && !startofline) 989 || (seen_keepend && !startofline)
991 || (i == current_state.ga_len - 1 && startofline)) 990 || (i == current_state.ga_len - 1 && startofline))
992 { 991 {
993 cur_si->si_h_startpos.col = 0; /* start highl. in col 0 */ 992 cur_si->si_h_startpos.col = 0; // start highl. in col 0
994 cur_si->si_h_startpos.lnum = current_lnum; 993 cur_si->si_h_startpos.lnum = current_lnum;
995 994
996 if (!(cur_si->si_flags & HL_MATCHCONT)) 995 if (!(cur_si->si_flags & HL_MATCHCONT))
997 update_si_end(cur_si, (int)current_col, !startofline); 996 update_si_end(cur_si, (int)current_col, !startofline);
998 997
1001 } 1000 }
1002 } 1001 }
1003 check_keepend(); 1002 check_keepend();
1004 } 1003 }
1005 1004
1006 /**************************************** 1005 /////////////////////////////////////////
1007 * Handling of the state stack cache. 1006 // Handling of the state stack cache.
1008 */
1009 1007
1010 /* 1008 /*
1011 * EXPLANATION OF THE SYNTAX STATE STACK CACHE 1009 * EXPLANATION OF THE SYNTAX STATE STACK CACHE
1012 * 1010 *
1013 * To speed up syntax highlighting, the state stack for the start of some 1011 * To speed up syntax highlighting, the state stack for the start of some
1065 #endif 1063 #endif
1066 1064
1067 syn_stack_free_block(block); 1065 syn_stack_free_block(block);
1068 1066
1069 #ifdef FEAT_FOLDING 1067 #ifdef FEAT_FOLDING
1070 /* When using "syntax" fold method, must update all folds. */ 1068 // When using "syntax" fold method, must update all folds.
1071 FOR_ALL_WINDOWS(wp) 1069 FOR_ALL_WINDOWS(wp)
1072 { 1070 {
1073 if (wp->w_s == block && foldmethodIsSyntax(wp)) 1071 if (wp->w_s == block && foldmethodIsSyntax(wp))
1074 foldUpdateAll(wp); 1072 foldUpdateAll(wp);
1075 } 1073 }
1094 len = SST_MIN_ENTRIES; 1092 len = SST_MIN_ENTRIES;
1095 else if (len > SST_MAX_ENTRIES) 1093 else if (len > SST_MAX_ENTRIES)
1096 len = SST_MAX_ENTRIES; 1094 len = SST_MAX_ENTRIES;
1097 if (syn_block->b_sst_len > len * 2 || syn_block->b_sst_len < len) 1095 if (syn_block->b_sst_len > len * 2 || syn_block->b_sst_len < len)
1098 { 1096 {
1099 /* Allocate 50% too much, to avoid reallocating too often. */ 1097 // Allocate 50% too much, to avoid reallocating too often.
1100 len = syn_buf->b_ml.ml_line_count; 1098 len = syn_buf->b_ml.ml_line_count;
1101 len = (len + len / 2) / SST_DIST + Rows * 2; 1099 len = (len + len / 2) / SST_DIST + Rows * 2;
1102 if (len < SST_MIN_ENTRIES) 1100 if (len < SST_MIN_ENTRIES)
1103 len = SST_MIN_ENTRIES; 1101 len = SST_MIN_ENTRIES;
1104 else if (len > SST_MAX_ENTRIES) 1102 else if (len > SST_MAX_ENTRIES)
1105 len = SST_MAX_ENTRIES; 1103 len = SST_MAX_ENTRIES;
1106 1104
1107 if (syn_block->b_sst_array != NULL) 1105 if (syn_block->b_sst_array != NULL)
1108 { 1106 {
1109 /* When shrinking the array, cleanup the existing stack. 1107 // When shrinking the array, cleanup the existing stack.
1110 * Make sure that all valid entries fit in the new array. */ 1108 // Make sure that all valid entries fit in the new array.
1111 while (syn_block->b_sst_len - syn_block->b_sst_freecount + 2 > len 1109 while (syn_block->b_sst_len - syn_block->b_sst_freecount + 2 > len
1112 && syn_stack_cleanup()) 1110 && syn_stack_cleanup())
1113 ; 1111 ;
1114 if (len < syn_block->b_sst_len - syn_block->b_sst_freecount + 2) 1112 if (len < syn_block->b_sst_len - syn_block->b_sst_freecount + 2)
1115 len = syn_block->b_sst_len - syn_block->b_sst_freecount + 2; 1113 len = syn_block->b_sst_len - syn_block->b_sst_freecount + 2;
1116 } 1114 }
1117 1115
1118 sstp = ALLOC_CLEAR_MULT(synstate_T, len); 1116 sstp = ALLOC_CLEAR_MULT(synstate_T, len);
1119 if (sstp == NULL) /* out of memory! */ 1117 if (sstp == NULL) // out of memory!
1120 return; 1118 return;
1121 1119
1122 to = sstp - 1; 1120 to = sstp - 1;
1123 if (syn_block->b_sst_array != NULL) 1121 if (syn_block->b_sst_array != NULL)
1124 { 1122 {
1125 /* Move the states from the old array to the new one. */ 1123 // Move the states from the old array to the new one.
1126 for (from = syn_block->b_sst_first; from != NULL; 1124 for (from = syn_block->b_sst_first; from != NULL;
1127 from = from->sst_next) 1125 from = from->sst_next)
1128 { 1126 {
1129 ++to; 1127 ++to;
1130 *to = *from; 1128 *to = *from;
1141 { 1139 {
1142 syn_block->b_sst_first = NULL; 1140 syn_block->b_sst_first = NULL;
1143 syn_block->b_sst_freecount = len; 1141 syn_block->b_sst_freecount = len;
1144 } 1142 }
1145 1143
1146 /* Create the list of free entries. */ 1144 // Create the list of free entries.
1147 syn_block->b_sst_firstfree = to + 1; 1145 syn_block->b_sst_firstfree = to + 1;
1148 while (++to < sstp + len) 1146 while (++to < sstp + len)
1149 to->sst_next = to + 1; 1147 to->sst_next = to + 1;
1150 (sstp + len - 1)->sst_next = NULL; 1148 (sstp + len - 1)->sst_next = NULL;
1151 1149
1187 if (p->sst_lnum + block->b_syn_sync_linebreaks > buf->b_mod_top) 1185 if (p->sst_lnum + block->b_syn_sync_linebreaks > buf->b_mod_top)
1188 { 1186 {
1189 n = p->sst_lnum + buf->b_mod_xlines; 1187 n = p->sst_lnum + buf->b_mod_xlines;
1190 if (n <= buf->b_mod_bot) 1188 if (n <= buf->b_mod_bot)
1191 { 1189 {
1192 /* this state is inside the changed area, remove it */ 1190 // this state is inside the changed area, remove it
1193 np = p->sst_next; 1191 np = p->sst_next;
1194 if (prev == NULL) 1192 if (prev == NULL)
1195 block->b_sst_first = np; 1193 block->b_sst_first = np;
1196 else 1194 else
1197 prev->sst_next = np; 1195 prev->sst_next = np;
1198 syn_stack_free_entry(block, p); 1196 syn_stack_free_entry(block, p);
1199 p = np; 1197 p = np;
1200 continue; 1198 continue;
1201 } 1199 }
1202 /* This state is below the changed area. Remember the line 1200 // This state is below the changed area. Remember the line
1203 * that needs to be parsed before this entry can be made valid 1201 // that needs to be parsed before this entry can be made valid
1204 * again. */ 1202 // again.
1205 if (p->sst_change_lnum != 0 && p->sst_change_lnum > buf->b_mod_top) 1203 if (p->sst_change_lnum != 0 && p->sst_change_lnum > buf->b_mod_top)
1206 { 1204 {
1207 if (p->sst_change_lnum + buf->b_mod_xlines > buf->b_mod_top) 1205 if (p->sst_change_lnum + buf->b_mod_xlines > buf->b_mod_top)
1208 p->sst_change_lnum += buf->b_mod_xlines; 1206 p->sst_change_lnum += buf->b_mod_xlines;
1209 else 1207 else
1234 int retval = FALSE; 1232 int retval = FALSE;
1235 1233
1236 if (syn_block->b_sst_first == NULL) 1234 if (syn_block->b_sst_first == NULL)
1237 return retval; 1235 return retval;
1238 1236
1239 /* Compute normal distance between non-displayed entries. */ 1237 // Compute normal distance between non-displayed entries.
1240 if (syn_block->b_sst_len <= Rows) 1238 if (syn_block->b_sst_len <= Rows)
1241 dist = 999999; 1239 dist = 999999;
1242 else 1240 else
1243 dist = syn_buf->b_ml.ml_line_count / (syn_block->b_sst_len - Rows) + 1; 1241 dist = syn_buf->b_ml.ml_line_count / (syn_block->b_sst_len - Rows) + 1;
1244 1242
1272 prev = syn_block->b_sst_first; 1270 prev = syn_block->b_sst_first;
1273 for (p = prev->sst_next; p != NULL; prev = p, p = p->sst_next) 1271 for (p = prev->sst_next; p != NULL; prev = p, p = p->sst_next)
1274 { 1272 {
1275 if (p->sst_tick == tick && prev->sst_lnum + dist > p->sst_lnum) 1273 if (p->sst_tick == tick && prev->sst_lnum + dist > p->sst_lnum)
1276 { 1274 {
1277 /* Move this entry from used list to free list */ 1275 // Move this entry from used list to free list
1278 prev->sst_next = p->sst_next; 1276 prev->sst_next = p->sst_next;
1279 syn_stack_free_entry(syn_block, p); 1277 syn_stack_free_entry(syn_block, p);
1280 p = prev; 1278 p = prev;
1281 retval = TRUE; 1279 retval = TRUE;
1282 } 1280 }
1346 } 1344 }
1347 if (i >= 0) 1345 if (i >= 0)
1348 { 1346 {
1349 if (sp != NULL) 1347 if (sp != NULL)
1350 { 1348 {
1351 /* find "sp" in the list and remove it */ 1349 // find "sp" in the list and remove it
1352 if (syn_block->b_sst_first == sp) 1350 if (syn_block->b_sst_first == sp)
1353 /* it's the first entry */ 1351 // it's the first entry
1354 syn_block->b_sst_first = sp->sst_next; 1352 syn_block->b_sst_first = sp->sst_next;
1355 else 1353 else
1356 { 1354 {
1357 /* find the entry just before this one to adjust sst_next */ 1355 // find the entry just before this one to adjust sst_next
1358 for (p = syn_block->b_sst_first; p != NULL; p = p->sst_next) 1356 for (p = syn_block->b_sst_first; p != NULL; p = p->sst_next)
1359 if (p->sst_next == sp) 1357 if (p->sst_next == sp)
1360 break; 1358 break;
1361 if (p != NULL) /* just in case */ 1359 if (p != NULL) // just in case
1362 p->sst_next = sp->sst_next; 1360 p->sst_next = sp->sst_next;
1363 } 1361 }
1364 syn_stack_free_entry(syn_block, sp); 1362 syn_stack_free_entry(syn_block, sp);
1365 sp = NULL; 1363 sp = NULL;
1366 } 1364 }
1368 else if (sp == NULL || sp->sst_lnum != current_lnum) 1366 else if (sp == NULL || sp->sst_lnum != current_lnum)
1369 { 1367 {
1370 /* 1368 /*
1371 * Add a new entry 1369 * Add a new entry
1372 */ 1370 */
1373 /* If no free items, cleanup the array first. */ 1371 // If no free items, cleanup the array first.
1374 if (syn_block->b_sst_freecount == 0) 1372 if (syn_block->b_sst_freecount == 0)
1375 { 1373 {
1376 (void)syn_stack_cleanup(); 1374 (void)syn_stack_cleanup();
1377 /* "sp" may have been moved to the freelist now */ 1375 // "sp" may have been moved to the freelist now
1378 sp = syn_stack_find_entry(current_lnum); 1376 sp = syn_stack_find_entry(current_lnum);
1379 } 1377 }
1380 /* Still no free items? Must be a strange problem... */ 1378 // Still no free items? Must be a strange problem...
1381 if (syn_block->b_sst_freecount == 0) 1379 if (syn_block->b_sst_freecount == 0)
1382 sp = NULL; 1380 sp = NULL;
1383 else 1381 else
1384 { 1382 {
1385 /* Take the first item from the free list and put it in the used 1383 // Take the first item from the free list and put it in the used
1386 * list, after *sp */ 1384 // list, after *sp
1387 p = syn_block->b_sst_firstfree; 1385 p = syn_block->b_sst_firstfree;
1388 syn_block->b_sst_firstfree = p->sst_next; 1386 syn_block->b_sst_firstfree = p->sst_next;
1389 --syn_block->b_sst_freecount; 1387 --syn_block->b_sst_freecount;
1390 if (sp == NULL) 1388 if (sp == NULL)
1391 { 1389 {
1392 /* Insert in front of the list */ 1390 // Insert in front of the list
1393 p->sst_next = syn_block->b_sst_first; 1391 p->sst_next = syn_block->b_sst_first;
1394 syn_block->b_sst_first = p; 1392 syn_block->b_sst_first = p;
1395 } 1393 }
1396 else 1394 else
1397 { 1395 {
1398 /* insert in list after *sp */ 1396 // insert in list after *sp
1399 p->sst_next = sp->sst_next; 1397 p->sst_next = sp->sst_next;
1400 sp->sst_next = p; 1398 sp->sst_next = p;
1401 } 1399 }
1402 sp = p; 1400 sp = p;
1403 sp->sst_stacksize = 0; 1401 sp->sst_stacksize = 0;
1404 sp->sst_lnum = current_lnum; 1402 sp->sst_lnum = current_lnum;
1405 } 1403 }
1406 } 1404 }
1407 if (sp != NULL) 1405 if (sp != NULL)
1408 { 1406 {
1409 /* When overwriting an existing state stack, clear it first */ 1407 // When overwriting an existing state stack, clear it first
1410 clear_syn_state(sp); 1408 clear_syn_state(sp);
1411 sp->sst_stacksize = current_state.ga_len; 1409 sp->sst_stacksize = current_state.ga_len;
1412 if (current_state.ga_len > SST_FIX_STATES) 1410 if (current_state.ga_len > SST_FIX_STATES)
1413 { 1411 {
1414 /* Need to clear it, might be something remaining from when the 1412 // Need to clear it, might be something remaining from when the
1415 * length was less than SST_FIX_STATES. */ 1413 // length was less than SST_FIX_STATES.
1416 ga_init2(&sp->sst_union.sst_ga, (int)sizeof(bufstate_T), 1); 1414 ga_init2(&sp->sst_union.sst_ga, (int)sizeof(bufstate_T), 1);
1417 if (ga_grow(&sp->sst_union.sst_ga, current_state.ga_len) == FAIL) 1415 if (ga_grow(&sp->sst_union.sst_ga, current_state.ga_len) == FAIL)
1418 sp->sst_stacksize = 0; 1416 sp->sst_stacksize = 0;
1419 else 1417 else
1420 sp->sst_union.sst_ga.ga_len = current_state.ga_len; 1418 sp->sst_union.sst_ga.ga_len = current_state.ga_len;
1496 { 1494 {
1497 int i, j; 1495 int i, j;
1498 bufstate_T *bp; 1496 bufstate_T *bp;
1499 reg_extmatch_T *six, *bsx; 1497 reg_extmatch_T *six, *bsx;
1500 1498
1501 /* First a quick check if the stacks have the same size end nextlist. */ 1499 // First a quick check if the stacks have the same size end nextlist.
1502 if (sp->sst_stacksize == current_state.ga_len 1500 if (sp->sst_stacksize == current_state.ga_len
1503 && sp->sst_next_list == current_next_list) 1501 && sp->sst_next_list == current_next_list)
1504 { 1502 {
1505 /* Need to compare all states on both stacks. */ 1503 // Need to compare all states on both stacks.
1506 if (sp->sst_stacksize > SST_FIX_STATES) 1504 if (sp->sst_stacksize > SST_FIX_STATES)
1507 bp = SYN_STATE_P(&(sp->sst_union.sst_ga)); 1505 bp = SYN_STATE_P(&(sp->sst_union.sst_ga));
1508 else 1506 else
1509 bp = sp->sst_union.sst_stack; 1507 bp = sp->sst_union.sst_stack;
1510 1508
1511 for (i = current_state.ga_len; --i >= 0; ) 1509 for (i = current_state.ga_len; --i >= 0; )
1512 { 1510 {
1513 /* If the item has another index the state is different. */ 1511 // If the item has another index the state is different.
1514 if (bp[i].bs_idx != CUR_STATE(i).si_idx) 1512 if (bp[i].bs_idx != CUR_STATE(i).si_idx)
1515 break; 1513 break;
1516 if (bp[i].bs_extmatch != CUR_STATE(i).si_extmatch) 1514 if (bp[i].bs_extmatch != CUR_STATE(i).si_extmatch)
1517 { 1515 {
1518 /* When the extmatch pointers are different, the strings in 1516 // When the extmatch pointers are different, the strings in
1519 * them can still be the same. Check if the extmatch 1517 // them can still be the same. Check if the extmatch
1520 * references are equal. */ 1518 // references are equal.
1521 bsx = bp[i].bs_extmatch; 1519 bsx = bp[i].bs_extmatch;
1522 six = CUR_STATE(i).si_extmatch; 1520 six = CUR_STATE(i).si_extmatch;
1523 /* If one of the extmatch pointers is NULL the states are 1521 // If one of the extmatch pointers is NULL the states are
1524 * different. */ 1522 // different.
1525 if (bsx == NULL || six == NULL) 1523 if (bsx == NULL || six == NULL)
1526 break; 1524 break;
1527 for (j = 0; j < NSUBEXP; ++j) 1525 for (j = 0; j < NSUBEXP; ++j)
1528 { 1526 {
1529 /* Check each referenced match string. They must all be 1527 // Check each referenced match string. They must all be
1530 * equal. */ 1528 // equal.
1531 if (bsx->matches[j] != six->matches[j]) 1529 if (bsx->matches[j] != six->matches[j])
1532 { 1530 {
1533 /* If the pointer is different it can still be the 1531 // If the pointer is different it can still be the
1534 * same text. Compare the strings, ignore case when 1532 // same text. Compare the strings, ignore case when
1535 * the start item has the sp_ic flag set. */ 1533 // the start item has the sp_ic flag set.
1536 if (bsx->matches[j] == NULL 1534 if (bsx->matches[j] == NULL
1537 || six->matches[j] == NULL) 1535 || six->matches[j] == NULL)
1538 break; 1536 break;
1539 if ((SYN_ITEMS(syn_block)[CUR_STATE(i).si_idx]).sp_ic 1537 if ((SYN_ITEMS(syn_block)[CUR_STATE(i).si_idx]).sp_ic
1540 ? MB_STRICMP(bsx->matches[j], 1538 ? MB_STRICMP(bsx->matches[j],
1582 1580
1583 static void 1581 static void
1584 invalidate_current_state(void) 1582 invalidate_current_state(void)
1585 { 1583 {
1586 clear_current_state(); 1584 clear_current_state();
1587 current_state.ga_itemsize = 0; /* mark current_state invalid */ 1585 current_state.ga_itemsize = 0; // mark current_state invalid
1588 current_next_list = NULL; 1586 current_next_list = NULL;
1589 keepend_level = -1; 1587 keepend_level = -1;
1590 } 1588 }
1591 1589
1592 static void 1590 static void
1649 * the line. It can start anywhere in the line, as long as the current state 1647 * the line. It can start anywhere in the line, as long as the current state
1650 * is valid. 1648 * is valid.
1651 */ 1649 */
1652 static int 1650 static int
1653 syn_finish_line( 1651 syn_finish_line(
1654 int syncing) /* called for syncing */ 1652 int syncing) // called for syncing
1655 { 1653 {
1656 stateitem_T *cur_si; 1654 stateitem_T *cur_si;
1657 colnr_T prev_current_col; 1655 colnr_T prev_current_col;
1658 1656
1659 while (!current_finished) 1657 while (!current_finished)
1671 if (cur_si->si_idx >= 0 1669 if (cur_si->si_idx >= 0
1672 && (SYN_ITEMS(syn_block)[cur_si->si_idx].sp_flags 1670 && (SYN_ITEMS(syn_block)[cur_si->si_idx].sp_flags
1673 & (HL_SYNC_HERE|HL_SYNC_THERE))) 1671 & (HL_SYNC_HERE|HL_SYNC_THERE)))
1674 return TRUE; 1672 return TRUE;
1675 1673
1676 /* syn_current_attr() will have skipped the check for an item 1674 // syn_current_attr() will have skipped the check for an item
1677 * that ends here, need to do that now. Be careful not to go 1675 // that ends here, need to do that now. Be careful not to go
1678 * past the NUL. */ 1676 // past the NUL.
1679 prev_current_col = current_col; 1677 prev_current_col = current_col;
1680 if (syn_getcurline()[current_col] != NUL) 1678 if (syn_getcurline()[current_col] != NUL)
1681 ++current_col; 1679 ++current_col;
1682 check_state_ends(); 1680 check_state_ends();
1683 current_col = prev_current_col; 1681 current_col = prev_current_col;
1698 */ 1696 */
1699 int 1697 int
1700 get_syntax_attr( 1698 get_syntax_attr(
1701 colnr_T col, 1699 colnr_T col,
1702 int *can_spell, 1700 int *can_spell,
1703 int keep_state) /* keep state of char at "col" */ 1701 int keep_state) // keep state of char at "col"
1704 { 1702 {
1705 int attr = 0; 1703 int attr = 0;
1706 1704
1707 if (can_spell != NULL) 1705 if (can_spell != NULL)
1708 /* Default: Only do spelling when there is no @Spell cluster or when 1706 // Default: Only do spelling when there is no @Spell cluster or when
1709 * ":syn spell toplevel" was used. */ 1707 // ":syn spell toplevel" was used.
1710 *can_spell = syn_block->b_syn_spell == SYNSPL_DEFAULT 1708 *can_spell = syn_block->b_syn_spell == SYNSPL_DEFAULT
1711 ? (syn_block->b_spell_cluster_id == 0) 1709 ? (syn_block->b_spell_cluster_id == 0)
1712 : (syn_block->b_syn_spell == SYNSPL_TOP); 1710 : (syn_block->b_syn_spell == SYNSPL_TOP);
1713 1711
1714 /* check for out of memory situation */ 1712 // check for out of memory situation
1715 if (syn_block->b_sst_array == NULL) 1713 if (syn_block->b_sst_array == NULL)
1716 return 0; 1714 return 0;
1717 1715
1718 /* After 'synmaxcol' the attribute is always zero. */ 1716 // After 'synmaxcol' the attribute is always zero.
1719 if (syn_buf->b_p_smc > 0 && col >= (colnr_T)syn_buf->b_p_smc) 1717 if (syn_buf->b_p_smc > 0 && col >= (colnr_T)syn_buf->b_p_smc)
1720 { 1718 {
1721 clear_current_state(); 1719 clear_current_state();
1722 #ifdef FEAT_EVAL 1720 #ifdef FEAT_EVAL
1723 current_id = 0; 1721 current_id = 0;
1728 current_seqnr = 0; 1726 current_seqnr = 0;
1729 #endif 1727 #endif
1730 return 0; 1728 return 0;
1731 } 1729 }
1732 1730
1733 /* Make sure current_state is valid */ 1731 // Make sure current_state is valid
1734 if (INVALID_STATE(&current_state)) 1732 if (INVALID_STATE(&current_state))
1735 validate_current_state(); 1733 validate_current_state();
1736 1734
1737 /* 1735 /*
1738 * Skip from the current column to "col", get the attributes for "col". 1736 * Skip from the current column to "col", get the attributes for "col".
1750 /* 1748 /*
1751 * Get syntax attributes for current_lnum, current_col. 1749 * Get syntax attributes for current_lnum, current_col.
1752 */ 1750 */
1753 static int 1751 static int
1754 syn_current_attr( 1752 syn_current_attr(
1755 int syncing, /* When 1: called for syncing */ 1753 int syncing, // When 1: called for syncing
1756 int displaying, /* result will be displayed */ 1754 int displaying, // result will be displayed
1757 int *can_spell, /* return: do spell checking */ 1755 int *can_spell, // return: do spell checking
1758 int keep_state) /* keep syntax stack afterwards */ 1756 int keep_state) // keep syntax stack afterwards
1759 { 1757 {
1760 int syn_id; 1758 int syn_id;
1761 lpos_T endpos; /* was: char_u *endp; */ 1759 lpos_T endpos; // was: char_u *endp;
1762 lpos_T hl_startpos; /* was: int hl_startcol; */ 1760 lpos_T hl_startpos; // was: int hl_startcol;
1763 lpos_T hl_endpos; 1761 lpos_T hl_endpos;
1764 lpos_T eos_pos; /* end-of-start match (start region) */ 1762 lpos_T eos_pos; // end-of-start match (start region)
1765 lpos_T eoe_pos; /* end-of-end pattern */ 1763 lpos_T eoe_pos; // end-of-end pattern
1766 int end_idx; /* group ID for end pattern */ 1764 int end_idx; // group ID for end pattern
1767 int idx; 1765 int idx;
1768 synpat_T *spp; 1766 synpat_T *spp;
1769 stateitem_T *cur_si, *sip = NULL; 1767 stateitem_T *cur_si, *sip = NULL;
1770 int startcol; 1768 int startcol;
1771 int endcol; 1769 int endcol;
1772 long flags; 1770 long flags;
1773 int cchar; 1771 int cchar;
1774 short *next_list; 1772 short *next_list;
1775 int found_match; /* found usable match */ 1773 int found_match; // found usable match
1776 static int try_next_column = FALSE; /* must try in next col */ 1774 static int try_next_column = FALSE; // must try in next col
1777 int do_keywords; 1775 int do_keywords;
1778 regmmatch_T regmatch; 1776 regmmatch_T regmatch;
1779 lpos_T pos; 1777 lpos_T pos;
1780 int lc_col; 1778 int lc_col;
1781 reg_extmatch_T *cur_extmatch = NULL; 1779 reg_extmatch_T *cur_extmatch = NULL;
1782 char_u buf_chartab[32]; /* chartab array for syn iskyeyword */ 1780 char_u buf_chartab[32]; // chartab array for syn iskyeyword
1783 char_u *line; /* current line. NOTE: becomes invalid after 1781 char_u *line; // current line. NOTE: becomes invalid after
1784 looking for a pattern match! */ 1782 // looking for a pattern match!
1785 1783
1786 /* variables for zero-width matches that have a "nextgroup" argument */ 1784 // variables for zero-width matches that have a "nextgroup" argument
1787 int keep_next_list; 1785 int keep_next_list;
1788 int zero_width_next_list = FALSE; 1786 int zero_width_next_list = FALSE;
1789 garray_T zero_width_next_ga; 1787 garray_T zero_width_next_ga;
1790 1788
1791 /* 1789 /*
1805 current_finished = TRUE; 1803 current_finished = TRUE;
1806 current_state_stored = FALSE; 1804 current_state_stored = FALSE;
1807 return 0; 1805 return 0;
1808 } 1806 }
1809 1807
1810 /* if the current or next character is NUL, we will finish the line now */ 1808 // if the current or next character is NUL, we will finish the line now
1811 if (line[current_col] == NUL || line[current_col + 1] == NUL) 1809 if (line[current_col] == NUL || line[current_col + 1] == NUL)
1812 { 1810 {
1813 current_finished = TRUE; 1811 current_finished = TRUE;
1814 current_state_stored = FALSE; 1812 current_state_stored = FALSE;
1815 } 1813 }
1823 { 1821 {
1824 next_match_idx = -1; 1822 next_match_idx = -1;
1825 try_next_column = FALSE; 1823 try_next_column = FALSE;
1826 } 1824 }
1827 1825
1828 /* Only check for keywords when not syncing and there are some. */ 1826 // Only check for keywords when not syncing and there are some.
1829 do_keywords = !syncing 1827 do_keywords = !syncing
1830 && (syn_block->b_keywtab.ht_used > 0 1828 && (syn_block->b_keywtab.ht_used > 0
1831 || syn_block->b_keywtab_ic.ht_used > 0); 1829 || syn_block->b_keywtab_ic.ht_used > 0);
1832 1830
1833 /* Init the list of zero-width matches with a nextlist. This is used to 1831 // Init the list of zero-width matches with a nextlist. This is used to
1834 * avoid matching the same item in the same position twice. */ 1832 // avoid matching the same item in the same position twice.
1835 ga_init2(&zero_width_next_ga, (int)sizeof(int), 10); 1833 ga_init2(&zero_width_next_ga, (int)sizeof(int), 10);
1836 1834
1837 /* use syntax iskeyword option */ 1835 // use syntax iskeyword option
1838 save_chartab(buf_chartab); 1836 save_chartab(buf_chartab);
1839 1837
1840 /* 1838 /*
1841 * Repeat matching keywords and patterns, to find contained items at the 1839 * Repeat matching keywords and patterns, to find contained items at the
1842 * same column. This stops when there are no extra matches at the current 1840 * same column. This stops when there are no extra matches at the current
1886 if (push_current_state(KEYWORD_IDX) == OK) 1884 if (push_current_state(KEYWORD_IDX) == OK)
1887 { 1885 {
1888 cur_si = &CUR_STATE(current_state.ga_len - 1); 1886 cur_si = &CUR_STATE(current_state.ga_len - 1);
1889 cur_si->si_m_startcol = current_col; 1887 cur_si->si_m_startcol = current_col;
1890 cur_si->si_h_startpos.lnum = current_lnum; 1888 cur_si->si_h_startpos.lnum = current_lnum;
1891 cur_si->si_h_startpos.col = 0; /* starts right away */ 1889 cur_si->si_h_startpos.col = 0; // starts right away
1892 cur_si->si_m_endpos.lnum = current_lnum; 1890 cur_si->si_m_endpos.lnum = current_lnum;
1893 cur_si->si_m_endpos.col = endcol; 1891 cur_si->si_m_endpos.col = endcol;
1894 cur_si->si_h_endpos.lnum = current_lnum; 1892 cur_si->si_h_endpos.lnum = current_lnum;
1895 cur_si->si_h_endpos.col = endcol; 1893 cur_si->si_h_endpos.col = endcol;
1896 cur_si->si_ends = TRUE; 1894 cur_si->si_ends = TRUE;
1948 * Check all relevant patterns for a match at this 1946 * Check all relevant patterns for a match at this
1949 * position. This is complicated, because matching with a 1947 * position. This is complicated, because matching with a
1950 * pattern takes quite a bit of time, thus we want to 1948 * pattern takes quite a bit of time, thus we want to
1951 * avoid doing it when it's not needed. 1949 * avoid doing it when it's not needed.
1952 */ 1950 */
1953 next_match_idx = 0; /* no match in this line yet */ 1951 next_match_idx = 0; // no match in this line yet
1954 next_match_col = MAXCOL; 1952 next_match_col = MAXCOL;
1955 for (idx = syn_block->b_syn_patterns.ga_len; --idx >= 0; ) 1953 for (idx = syn_block->b_syn_patterns.ga_len; --idx >= 0; )
1956 { 1954 {
1957 spp = &(SYN_ITEMS(syn_block)[idx]); 1955 spp = &(SYN_ITEMS(syn_block)[idx]);
1958 if ( spp->sp_syncing == syncing 1956 if ( spp->sp_syncing == syncing
1968 cur_si->si_cont_list, &spp->sp_syn, 1966 cur_si->si_cont_list, &spp->sp_syn,
1969 spp->sp_flags & HL_CONTAINED)))) 1967 spp->sp_flags & HL_CONTAINED))))
1970 { 1968 {
1971 int r; 1969 int r;
1972 1970
1973 /* If we already tried matching in this line, and 1971 // If we already tried matching in this line, and
1974 * there isn't a match before next_match_col, skip 1972 // there isn't a match before next_match_col, skip
1975 * this item. */ 1973 // this item.
1976 if (spp->sp_line_id == current_line_id 1974 if (spp->sp_line_id == current_line_id
1977 && spp->sp_startcol >= next_match_col) 1975 && spp->sp_startcol >= next_match_col)
1978 continue; 1976 continue;
1979 spp->sp_line_id = current_line_id; 1977 spp->sp_line_id = current_line_id;
1980 1978
1989 (colnr_T)lc_col, 1987 (colnr_T)lc_col,
1990 IF_SYN_TIME(&spp->sp_time)); 1988 IF_SYN_TIME(&spp->sp_time));
1991 spp->sp_prog = regmatch.regprog; 1989 spp->sp_prog = regmatch.regprog;
1992 if (!r) 1990 if (!r)
1993 { 1991 {
1994 /* no match in this line, try another one */ 1992 // no match in this line, try another one
1995 spp->sp_startcol = MAXCOL; 1993 spp->sp_startcol = MAXCOL;
1996 continue; 1994 continue;
1997 } 1995 }
1998 1996
1999 /* 1997 /*
2001 */ 1999 */
2002 syn_add_start_off(&pos, &regmatch, 2000 syn_add_start_off(&pos, &regmatch,
2003 spp, SPO_MS_OFF, -1); 2001 spp, SPO_MS_OFF, -1);
2004 if (pos.lnum > current_lnum) 2002 if (pos.lnum > current_lnum)
2005 { 2003 {
2006 /* must have used end of match in a next line, 2004 // must have used end of match in a next line,
2007 * we can't handle that */ 2005 // we can't handle that
2008 spp->sp_startcol = MAXCOL; 2006 spp->sp_startcol = MAXCOL;
2009 continue; 2007 continue;
2010 } 2008 }
2011 startcol = pos.col; 2009 startcol = pos.col;
2012 2010
2013 /* remember the next column where this pattern 2011 // remember the next column where this pattern
2014 * matches in the current line */ 2012 // matches in the current line
2015 spp->sp_startcol = startcol; 2013 spp->sp_startcol = startcol;
2016 2014
2017 /* 2015 /*
2018 * If a previously found match starts at a lower 2016 * If a previously found match starts at a lower
2019 * column number, don't use this one. 2017 * column number, don't use this one.
2033 } 2031 }
2034 2032
2035 endpos.lnum = regmatch.endpos[0].lnum; 2033 endpos.lnum = regmatch.endpos[0].lnum;
2036 endpos.col = regmatch.endpos[0].col; 2034 endpos.col = regmatch.endpos[0].col;
2037 2035
2038 /* Compute the highlight start. */ 2036 // Compute the highlight start.
2039 syn_add_start_off(&hl_startpos, &regmatch, 2037 syn_add_start_off(&hl_startpos, &regmatch,
2040 spp, SPO_HS_OFF, -1); 2038 spp, SPO_HS_OFF, -1);
2041 2039
2042 /* Compute the region start. */ 2040 // Compute the region start.
2043 /* Default is to use the end of the match. */ 2041 // Default is to use the end of the match.
2044 syn_add_end_off(&eos_pos, &regmatch, 2042 syn_add_end_off(&eos_pos, &regmatch,
2045 spp, SPO_RS_OFF, 0); 2043 spp, SPO_RS_OFF, 0);
2046 2044
2047 /* 2045 /*
2048 * Grab the external submatches before they get 2046 * Grab the external submatches before they get
2051 unref_extmatch(cur_extmatch); 2049 unref_extmatch(cur_extmatch);
2052 cur_extmatch = re_extmatch_out; 2050 cur_extmatch = re_extmatch_out;
2053 re_extmatch_out = NULL; 2051 re_extmatch_out = NULL;
2054 2052
2055 flags = 0; 2053 flags = 0;
2056 eoe_pos.lnum = 0; /* avoid warning */ 2054 eoe_pos.lnum = 0; // avoid warning
2057 eoe_pos.col = 0; 2055 eoe_pos.col = 0;
2058 end_idx = 0; 2056 end_idx = 0;
2059 hl_endpos.lnum = 0; 2057 hl_endpos.lnum = 0;
2060 2058
2061 /* 2059 /*
2071 2069
2072 startpos = endpos; 2070 startpos = endpos;
2073 find_endpos(idx, &startpos, &endpos, &hl_endpos, 2071 find_endpos(idx, &startpos, &endpos, &hl_endpos,
2074 &flags, &eoe_pos, &end_idx, cur_extmatch); 2072 &flags, &eoe_pos, &end_idx, cur_extmatch);
2075 if (endpos.lnum == 0) 2073 if (endpos.lnum == 0)
2076 continue; /* not found */ 2074 continue; // not found
2077 } 2075 }
2078 2076
2079 /* 2077 /*
2080 * For a "match" the size must be > 0 after the 2078 * For a "match" the size must be > 0 after the
2081 * end offset needs has been added. Except when 2079 * end offset needs has been added. Except when
2102 } 2100 }
2103 2101
2104 /* 2102 /*
2105 * keep the best match so far in next_match_* 2103 * keep the best match so far in next_match_*
2106 */ 2104 */
2107 /* Highlighting must start after startpos and end 2105 // Highlighting must start after startpos and end
2108 * before endpos. */ 2106 // before endpos.
2109 if (hl_startpos.lnum == current_lnum 2107 if (hl_startpos.lnum == current_lnum
2110 && (int)hl_startpos.col < startcol) 2108 && (int)hl_startpos.col < startcol)
2111 hl_startpos.col = startcol; 2109 hl_startpos.col = startcol;
2112 limit_pos_zero(&hl_endpos, &endpos); 2110 limit_pos_zero(&hl_endpos, &endpos);
2113 2111
2132 */ 2130 */
2133 if (next_match_idx >= 0 && next_match_col == (int)current_col) 2131 if (next_match_idx >= 0 && next_match_col == (int)current_col)
2134 { 2132 {
2135 synpat_T *lspp; 2133 synpat_T *lspp;
2136 2134
2137 /* When a zero-width item matched which has a nextgroup, 2135 // When a zero-width item matched which has a nextgroup,
2138 * don't push the item but set nextgroup. */ 2136 // don't push the item but set nextgroup.
2139 lspp = &(SYN_ITEMS(syn_block)[next_match_idx]); 2137 lspp = &(SYN_ITEMS(syn_block)[next_match_idx]);
2140 if (next_match_m_endpos.lnum == current_lnum 2138 if (next_match_m_endpos.lnum == current_lnum
2141 && next_match_m_endpos.col == current_col 2139 && next_match_m_endpos.col == current_col
2142 && lspp->sp_next_list != NULL) 2140 && lspp->sp_next_list != NULL)
2143 { 2141 {
2144 current_next_list = lspp->sp_next_list; 2142 current_next_list = lspp->sp_next_list;
2145 current_next_flags = lspp->sp_flags; 2143 current_next_flags = lspp->sp_flags;
2146 keep_next_list = TRUE; 2144 keep_next_list = TRUE;
2147 zero_width_next_list = TRUE; 2145 zero_width_next_list = TRUE;
2148 2146
2149 /* Add the index to a list, so that we can check 2147 // Add the index to a list, so that we can check
2150 * later that we don't match it again (and cause an 2148 // later that we don't match it again (and cause an
2151 * endless loop). */ 2149 // endless loop).
2152 if (ga_grow(&zero_width_next_ga, 1) == OK) 2150 if (ga_grow(&zero_width_next_ga, 1) == OK)
2153 { 2151 {
2154 ((int *)(zero_width_next_ga.ga_data)) 2152 ((int *)(zero_width_next_ga.ga_data))
2155 [zero_width_next_ga.ga_len++] = next_match_idx; 2153 [zero_width_next_ga.ga_len++] = next_match_idx;
2156 } 2154 }
2252 * set "can_spell" to TRUE if spell checking is supposed to be 2250 * set "can_spell" to TRUE if spell checking is supposed to be
2253 * done in the current item. 2251 * done in the current item.
2254 */ 2252 */
2255 if (syn_block->b_spell_cluster_id == 0) 2253 if (syn_block->b_spell_cluster_id == 0)
2256 { 2254 {
2257 /* There is no @Spell cluster: Do spelling for items without 2255 // There is no @Spell cluster: Do spelling for items without
2258 * @NoSpell cluster. */ 2256 // @NoSpell cluster.
2259 if (syn_block->b_nospell_cluster_id == 0 2257 if (syn_block->b_nospell_cluster_id == 0
2260 || current_trans_id == 0) 2258 || current_trans_id == 0)
2261 *can_spell = (syn_block->b_syn_spell != SYNSPL_NOTOP); 2259 *can_spell = (syn_block->b_syn_spell != SYNSPL_NOTOP);
2262 else 2260 else
2263 { 2261 {
2267 *can_spell = !in_id_list(sip, sip->si_cont_list, &sps, 0); 2265 *can_spell = !in_id_list(sip, sip->si_cont_list, &sps, 0);
2268 } 2266 }
2269 } 2267 }
2270 else 2268 else
2271 { 2269 {
2272 /* The @Spell cluster is defined: Do spelling in items with 2270 // The @Spell cluster is defined: Do spelling in items with
2273 * the @Spell cluster. But not when @NoSpell is also there. 2271 // the @Spell cluster. But not when @NoSpell is also there.
2274 * At the toplevel only spell check when ":syn spell toplevel" 2272 // At the toplevel only spell check when ":syn spell toplevel"
2275 * was used. */ 2273 // was used.
2276 if (current_trans_id == 0) 2274 if (current_trans_id == 0)
2277 *can_spell = (syn_block->b_syn_spell == SYNSPL_TOP); 2275 *can_spell = (syn_block->b_syn_spell == SYNSPL_TOP);
2278 else 2276 else
2279 { 2277 {
2280 sps.inc_tag = 0; 2278 sps.inc_tag = 0;
2312 --current_col; 2310 --current_col;
2313 } 2311 }
2314 } 2312 }
2315 } 2313 }
2316 else if (can_spell != NULL) 2314 else if (can_spell != NULL)
2317 /* Default: Only do spelling when there is no @Spell cluster or when 2315 // Default: Only do spelling when there is no @Spell cluster or when
2318 * ":syn spell toplevel" was used. */ 2316 // ":syn spell toplevel" was used.
2319 *can_spell = syn_block->b_syn_spell == SYNSPL_DEFAULT 2317 *can_spell = syn_block->b_syn_spell == SYNSPL_DEFAULT
2320 ? (syn_block->b_spell_cluster_id == 0) 2318 ? (syn_block->b_spell_cluster_id == 0)
2321 : (syn_block->b_syn_spell == SYNSPL_TOP); 2319 : (syn_block->b_syn_spell == SYNSPL_TOP);
2322 2320
2323 /* nextgroup ends at end of line, unless "skipnl" or "skipempty" present */ 2321 // nextgroup ends at end of line, unless "skipnl" or "skipempty" present
2324 if (current_next_list != NULL 2322 if (current_next_list != NULL
2325 && (line = syn_getcurline())[current_col] != NUL 2323 && (line = syn_getcurline())[current_col] != NUL
2326 && line[current_col + 1] == NUL 2324 && line[current_col + 1] == NUL
2327 && !(current_next_flags & (HL_SKIPNL | HL_SKIPEMPTY))) 2325 && !(current_next_flags & (HL_SKIPNL | HL_SKIPEMPTY)))
2328 current_next_list = NULL; 2326 current_next_list = NULL;
2329 2327
2330 if (zero_width_next_ga.ga_len > 0) 2328 if (zero_width_next_ga.ga_len > 0)
2331 ga_clear(&zero_width_next_ga); 2329 ga_clear(&zero_width_next_ga);
2332 2330
2333 /* No longer need external matches. But keep next_match_extmatch. */ 2331 // No longer need external matches. But keep next_match_extmatch.
2334 unref_extmatch(re_extmatch_out); 2332 unref_extmatch(re_extmatch_out);
2335 re_extmatch_out = NULL; 2333 re_extmatch_out = NULL;
2336 unref_extmatch(cur_extmatch); 2334 unref_extmatch(cur_extmatch);
2337 2335
2338 return current_attr; 2336 return current_attr;
2351 if (CUR_STATE(i).si_m_startcol == (int)current_col 2349 if (CUR_STATE(i).si_m_startcol == (int)current_col
2352 && CUR_STATE(i).si_m_lnum == (int)current_lnum 2350 && CUR_STATE(i).si_m_lnum == (int)current_lnum
2353 && CUR_STATE(i).si_idx == idx) 2351 && CUR_STATE(i).si_idx == idx)
2354 return TRUE; 2352 return TRUE;
2355 2353
2356 /* Zero-width matches with a nextgroup argument are not put on the syntax 2354 // Zero-width matches with a nextgroup argument are not put on the syntax
2357 * stack, and can only be matched once anyway. */ 2355 // stack, and can only be matched once anyway.
2358 for (i = gap->ga_len; --i >= 0; ) 2356 for (i = gap->ga_len; --i >= 0; )
2359 if (((int *)(gap->ga_data))[i] == idx) 2357 if (((int *)(gap->ga_data))[i] == idx)
2360 return TRUE; 2358 return TRUE;
2361 2359
2362 return FALSE; 2360 return FALSE;
2398 #endif 2396 #endif
2399 cur_si->si_next_list = spp->sp_next_list; 2397 cur_si->si_next_list = spp->sp_next_list;
2400 cur_si->si_extmatch = ref_extmatch(next_match_extmatch); 2398 cur_si->si_extmatch = ref_extmatch(next_match_extmatch);
2401 if (spp->sp_type == SPTYPE_START && !(spp->sp_flags & HL_ONELINE)) 2399 if (spp->sp_type == SPTYPE_START && !(spp->sp_flags & HL_ONELINE))
2402 { 2400 {
2403 /* Try to find the end pattern in the current line */ 2401 // Try to find the end pattern in the current line
2404 update_si_end(cur_si, (int)(next_match_m_endpos.col), TRUE); 2402 update_si_end(cur_si, (int)(next_match_m_endpos.col), TRUE);
2405 check_keepend(); 2403 check_keepend();
2406 } 2404 }
2407 else 2405 else
2408 { 2406 {
2448 check_keepend(); 2446 check_keepend();
2449 update_si_attr(current_state.ga_len - 1); 2447 update_si_attr(current_state.ga_len - 1);
2450 } 2448 }
2451 } 2449 }
2452 2450
2453 next_match_idx = -1; /* try other match next time */ 2451 next_match_idx = -1; // try other match next time
2454 2452
2455 return cur_si; 2453 return cur_si;
2456 } 2454 }
2457 2455
2458 /* 2456 /*
2493 if (cur_si->si_flags & HL_CONCEALENDS) 2491 if (cur_si->si_flags & HL_CONCEALENDS)
2494 cur_si->si_flags |= HL_CONCEAL; 2492 cur_si->si_flags |= HL_CONCEAL;
2495 #endif 2493 #endif
2496 update_si_attr(current_state.ga_len - 1); 2494 update_si_attr(current_state.ga_len - 1);
2497 2495
2498 /* nextgroup= should not match in the end pattern */ 2496 // nextgroup= should not match in the end pattern
2499 current_next_list = NULL; 2497 current_next_list = NULL;
2500 2498
2501 /* what matches next may be different now, clear it */ 2499 // what matches next may be different now, clear it
2502 next_match_idx = 0; 2500 next_match_idx = 0;
2503 next_match_col = MAXCOL; 2501 next_match_col = MAXCOL;
2504 break; 2502 break;
2505 } 2503 }
2506 else 2504 else
2507 { 2505 {
2508 /* handle next_list, unless at end of line and no "skipnl" or 2506 // handle next_list, unless at end of line and no "skipnl" or
2509 * "skipempty" */ 2507 // "skipempty"
2510 current_next_list = cur_si->si_next_list; 2508 current_next_list = cur_si->si_next_list;
2511 current_next_flags = cur_si->si_flags; 2509 current_next_flags = cur_si->si_flags;
2512 if (!(current_next_flags & (HL_SKIPNL | HL_SKIPEMPTY)) 2510 if (!(current_next_flags & (HL_SKIPNL | HL_SKIPEMPTY))
2513 && syn_getcurline()[current_col] == NUL) 2511 && syn_getcurline()[current_col] == NUL)
2514 current_next_list = NULL; 2512 current_next_list = NULL;
2515 2513
2516 /* When the ended item has "extend", another item with 2514 // When the ended item has "extend", another item with
2517 * "keepend" now needs to check for its end. */ 2515 // "keepend" now needs to check for its end.
2518 had_extend = (cur_si->si_flags & HL_EXTEND); 2516 had_extend = (cur_si->si_flags & HL_EXTEND);
2519 2517
2520 pop_current_state(); 2518 pop_current_state();
2521 2519
2522 if (current_state.ga_len == 0) 2520 if (current_state.ga_len == 0)
2567 update_si_attr(int idx) 2565 update_si_attr(int idx)
2568 { 2566 {
2569 stateitem_T *sip = &CUR_STATE(idx); 2567 stateitem_T *sip = &CUR_STATE(idx);
2570 synpat_T *spp; 2568 synpat_T *spp;
2571 2569
2572 /* This should not happen... */ 2570 // This should not happen...
2573 if (sip->si_idx < 0) 2571 if (sip->si_idx < 0)
2574 return; 2572 return;
2575 2573
2576 spp = &(SYN_ITEMS(syn_block)[sip->si_idx]); 2574 spp = &(SYN_ITEMS(syn_block)[sip->si_idx]);
2577 if (sip->si_flags & HL_MATCH) 2575 if (sip->si_flags & HL_MATCH)
2679 * Return the flags for the matched END. 2677 * Return the flags for the matched END.
2680 */ 2678 */
2681 static void 2679 static void
2682 update_si_end( 2680 update_si_end(
2683 stateitem_T *sip, 2681 stateitem_T *sip,
2684 int startcol, /* where to start searching for the end */ 2682 int startcol, // where to start searching for the end
2685 int force) /* when TRUE overrule a previous end */ 2683 int force) // when TRUE overrule a previous end
2686 { 2684 {
2687 lpos_T startpos; 2685 lpos_T startpos;
2688 lpos_T endpos; 2686 lpos_T endpos;
2689 lpos_T hl_endpos; 2687 lpos_T hl_endpos;
2690 lpos_T end_endpos; 2688 lpos_T end_endpos;
2691 int end_idx; 2689 int end_idx;
2692 2690
2693 /* return quickly for a keyword */ 2691 // return quickly for a keyword
2694 if (sip->si_idx < 0) 2692 if (sip->si_idx < 0)
2695 return; 2693 return;
2696 2694
2697 /* Don't update when it's already done. Can be a match of an end pattern 2695 // Don't update when it's already done. Can be a match of an end pattern
2698 * that started in a previous line. Watch out: can also be a "keepend" 2696 // that started in a previous line. Watch out: can also be a "keepend"
2699 * from a containing item. */ 2697 // from a containing item.
2700 if (!force && sip->si_m_endpos.lnum >= current_lnum) 2698 if (!force && sip->si_m_endpos.lnum >= current_lnum)
2701 return; 2699 return;
2702 2700
2703 /* 2701 /*
2704 * We need to find the end of the region. It may continue in the next 2702 * We need to find the end of the region. It may continue in the next
2710 find_endpos(sip->si_idx, &startpos, &endpos, &hl_endpos, 2708 find_endpos(sip->si_idx, &startpos, &endpos, &hl_endpos,
2711 &(sip->si_flags), &end_endpos, &end_idx, sip->si_extmatch); 2709 &(sip->si_flags), &end_endpos, &end_idx, sip->si_extmatch);
2712 2710
2713 if (endpos.lnum == 0) 2711 if (endpos.lnum == 0)
2714 { 2712 {
2715 /* No end pattern matched. */ 2713 // No end pattern matched.
2716 if (SYN_ITEMS(syn_block)[sip->si_idx].sp_flags & HL_ONELINE) 2714 if (SYN_ITEMS(syn_block)[sip->si_idx].sp_flags & HL_ONELINE)
2717 { 2715 {
2718 /* a "oneline" never continues in the next line */ 2716 // a "oneline" never continues in the next line
2719 sip->si_ends = TRUE; 2717 sip->si_ends = TRUE;
2720 sip->si_m_endpos.lnum = current_lnum; 2718 sip->si_m_endpos.lnum = current_lnum;
2721 sip->si_m_endpos.col = (colnr_T)STRLEN(syn_getcurline()); 2719 sip->si_m_endpos.col = (colnr_T)STRLEN(syn_getcurline());
2722 } 2720 }
2723 else 2721 else
2724 { 2722 {
2725 /* continues in the next line */ 2723 // continues in the next line
2726 sip->si_ends = FALSE; 2724 sip->si_ends = FALSE;
2727 sip->si_m_endpos.lnum = 0; 2725 sip->si_m_endpos.lnum = 0;
2728 } 2726 }
2729 sip->si_h_endpos = sip->si_m_endpos; 2727 sip->si_h_endpos = sip->si_m_endpos;
2730 } 2728 }
2731 else 2729 else
2732 { 2730 {
2733 /* match within this line */ 2731 // match within this line
2734 sip->si_m_endpos = endpos; 2732 sip->si_m_endpos = endpos;
2735 sip->si_h_endpos = hl_endpos; 2733 sip->si_h_endpos = hl_endpos;
2736 sip->si_eoe_pos = end_endpos; 2734 sip->si_eoe_pos = end_endpos;
2737 sip->si_ends = TRUE; 2735 sip->si_ends = TRUE;
2738 sip->si_end_idx = end_idx; 2736 sip->si_end_idx = end_idx;
2764 if (current_state.ga_len) 2762 if (current_state.ga_len)
2765 { 2763 {
2766 unref_extmatch(CUR_STATE(current_state.ga_len - 1).si_extmatch); 2764 unref_extmatch(CUR_STATE(current_state.ga_len - 1).si_extmatch);
2767 --current_state.ga_len; 2765 --current_state.ga_len;
2768 } 2766 }
2769 /* after the end of a pattern, try matching a keyword or pattern */ 2767 // after the end of a pattern, try matching a keyword or pattern
2770 next_match_idx = -1; 2768 next_match_idx = -1;
2771 2769
2772 /* if first state with "keepend" is popped, reset keepend_level */ 2770 // if first state with "keepend" is popped, reset keepend_level
2773 if (keepend_level >= current_state.ga_len) 2771 if (keepend_level >= current_state.ga_len)
2774 keepend_level = -1; 2772 keepend_level = -1;
2775 } 2773 }
2776 2774
2777 /* 2775 /*
2783 * If found, the end of the region and the end of the highlighting is 2781 * If found, the end of the region and the end of the highlighting is
2784 * computed. 2782 * computed.
2785 */ 2783 */
2786 static void 2784 static void
2787 find_endpos( 2785 find_endpos(
2788 int idx, /* index of the pattern */ 2786 int idx, // index of the pattern
2789 lpos_T *startpos, /* where to start looking for an END match */ 2787 lpos_T *startpos, // where to start looking for an END match
2790 lpos_T *m_endpos, /* return: end of match */ 2788 lpos_T *m_endpos, // return: end of match
2791 lpos_T *hl_endpos, /* return: end of highlighting */ 2789 lpos_T *hl_endpos, // return: end of highlighting
2792 long *flagsp, /* return: flags of matching END */ 2790 long *flagsp, // return: flags of matching END
2793 lpos_T *end_endpos, /* return: end of end pattern match */ 2791 lpos_T *end_endpos, // return: end of end pattern match
2794 int *end_idx, /* return: group ID for end pat. match, or 0 */ 2792 int *end_idx, // return: group ID for end pat. match, or 0
2795 reg_extmatch_T *start_ext) /* submatches from the start pattern */ 2793 reg_extmatch_T *start_ext) // submatches from the start pattern
2796 { 2794 {
2797 colnr_T matchcol; 2795 colnr_T matchcol;
2798 synpat_T *spp, *spp_skip; 2796 synpat_T *spp, *spp_skip;
2799 int start_idx; 2797 int start_idx;
2800 int best_idx; 2798 int best_idx;
2801 regmmatch_T regmatch; 2799 regmmatch_T regmatch;
2802 regmmatch_T best_regmatch; /* startpos/endpos of best match */ 2800 regmmatch_T best_regmatch; // startpos/endpos of best match
2803 lpos_T pos; 2801 lpos_T pos;
2804 char_u *line; 2802 char_u *line;
2805 int had_match = FALSE; 2803 int had_match = FALSE;
2806 char_u buf_chartab[32]; /* chartab array for syn option iskyeyword */ 2804 char_u buf_chartab[32]; // chartab array for syn option iskyeyword
2807 2805
2808 /* just in case we are invoked for a keyword */ 2806 // just in case we are invoked for a keyword
2809 if (idx < 0) 2807 if (idx < 0)
2810 return; 2808 return;
2811 2809
2812 /* 2810 /*
2813 * Check for being called with a START pattern. 2811 * Check for being called with a START pattern.
2841 ++idx; 2839 ++idx;
2842 } 2840 }
2843 else 2841 else
2844 spp_skip = NULL; 2842 spp_skip = NULL;
2845 2843
2846 /* Setup external matches for syn_regexec(). */ 2844 // Setup external matches for syn_regexec().
2847 unref_extmatch(re_extmatch_in); 2845 unref_extmatch(re_extmatch_in);
2848 re_extmatch_in = ref_extmatch(start_ext); 2846 re_extmatch_in = ref_extmatch(start_ext);
2849 2847
2850 matchcol = startpos->col; /* start looking for a match at sstart */ 2848 matchcol = startpos->col; // start looking for a match at sstart
2851 start_idx = idx; /* remember the first END pattern. */ 2849 start_idx = idx; // remember the first END pattern.
2852 best_regmatch.startpos[0].col = 0; /* avoid compiler warning */ 2850 best_regmatch.startpos[0].col = 0; // avoid compiler warning
2853 2851
2854 /* use syntax iskeyword option */ 2852 // use syntax iskeyword option
2855 save_chartab(buf_chartab); 2853 save_chartab(buf_chartab);
2856 2854
2857 for (;;) 2855 for (;;)
2858 { 2856 {
2859 /* 2857 /*
2864 { 2862 {
2865 int lc_col = matchcol; 2863 int lc_col = matchcol;
2866 int r; 2864 int r;
2867 2865
2868 spp = &(SYN_ITEMS(syn_block)[idx]); 2866 spp = &(SYN_ITEMS(syn_block)[idx]);
2869 if (spp->sp_type != SPTYPE_END) /* past last END pattern */ 2867 if (spp->sp_type != SPTYPE_END) // past last END pattern
2870 break; 2868 break;
2871 lc_col -= spp->sp_offsets[SPO_LC_OFF]; 2869 lc_col -= spp->sp_offsets[SPO_LC_OFF];
2872 if (lc_col < 0) 2870 if (lc_col < 0)
2873 lc_col = 0; 2871 lc_col = 0;
2874 2872
2915 if (r && regmatch.startpos[0].col 2913 if (r && regmatch.startpos[0].col
2916 <= best_regmatch.startpos[0].col) 2914 <= best_regmatch.startpos[0].col)
2917 { 2915 {
2918 int line_len; 2916 int line_len;
2919 2917
2920 /* Add offset to skip pattern match */ 2918 // Add offset to skip pattern match
2921 syn_add_end_off(&pos, &regmatch, spp_skip, SPO_ME_OFF, 1); 2919 syn_add_end_off(&pos, &regmatch, spp_skip, SPO_ME_OFF, 1);
2922 2920
2923 /* If the skip pattern goes on to the next line, there is no 2921 // If the skip pattern goes on to the next line, there is no
2924 * match with an end pattern in this line. */ 2922 // match with an end pattern in this line.
2925 if (pos.lnum > startpos->lnum) 2923 if (pos.lnum > startpos->lnum)
2926 break; 2924 break;
2927 2925
2928 line = ml_get_buf(syn_buf, startpos->lnum, FALSE); 2926 line = ml_get_buf(syn_buf, startpos->lnum, FALSE);
2929 line_len = (int)STRLEN(line); 2927 line_len = (int)STRLEN(line);
2930 2928
2931 /* take care of an empty match or negative offset */ 2929 // take care of an empty match or negative offset
2932 if (pos.col <= matchcol) 2930 if (pos.col <= matchcol)
2933 ++matchcol; 2931 ++matchcol;
2934 else if (pos.col <= regmatch.endpos[0].col) 2932 else if (pos.col <= regmatch.endpos[0].col)
2935 matchcol = pos.col; 2933 matchcol = pos.col;
2936 else 2934 else
2937 /* Be careful not to jump over the NUL at the end-of-line */ 2935 // Be careful not to jump over the NUL at the end-of-line
2938 for (matchcol = regmatch.endpos[0].col; 2936 for (matchcol = regmatch.endpos[0].col;
2939 matchcol < line_len && matchcol < pos.col; 2937 matchcol < line_len && matchcol < pos.col;
2940 ++matchcol) 2938 ++matchcol)
2941 ; 2939 ;
2942 2940
2943 /* if the skip pattern includes end-of-line, break here */ 2941 // if the skip pattern includes end-of-line, break here
2944 if (matchcol >= line_len) 2942 if (matchcol >= line_len)
2945 break; 2943 break;
2946 2944
2947 continue; /* start with first end pattern again */ 2945 continue; // start with first end pattern again
2948 } 2946 }
2949 } 2947 }
2950 2948
2951 /* 2949 /*
2952 * Match from start pattern to end pattern. 2950 * Match from start pattern to end pattern.
2953 * Correct for match and highlight offset of end pattern. 2951 * Correct for match and highlight offset of end pattern.
2954 */ 2952 */
2955 spp = &(SYN_ITEMS(syn_block)[best_idx]); 2953 spp = &(SYN_ITEMS(syn_block)[best_idx]);
2956 syn_add_end_off(m_endpos, &best_regmatch, spp, SPO_ME_OFF, 1); 2954 syn_add_end_off(m_endpos, &best_regmatch, spp, SPO_ME_OFF, 1);
2957 /* can't end before the start */ 2955 // can't end before the start
2958 if (m_endpos->lnum == startpos->lnum && m_endpos->col < startpos->col) 2956 if (m_endpos->lnum == startpos->lnum && m_endpos->col < startpos->col)
2959 m_endpos->col = startpos->col; 2957 m_endpos->col = startpos->col;
2960 2958
2961 syn_add_end_off(end_endpos, &best_regmatch, spp, SPO_HE_OFF, 1); 2959 syn_add_end_off(end_endpos, &best_regmatch, spp, SPO_HE_OFF, 1);
2962 /* can't end before the start */ 2960 // can't end before the start
2963 if (end_endpos->lnum == startpos->lnum 2961 if (end_endpos->lnum == startpos->lnum
2964 && end_endpos->col < startpos->col) 2962 && end_endpos->col < startpos->col)
2965 end_endpos->col = startpos->col; 2963 end_endpos->col = startpos->col;
2966 /* can't end after the match */ 2964 // can't end after the match
2967 limit_pos(end_endpos, m_endpos); 2965 limit_pos(end_endpos, m_endpos);
2968 2966
2969 /* 2967 /*
2970 * If the end group is highlighted differently, adjust the pointers. 2968 * If the end group is highlighted differently, adjust the pointers.
2971 */ 2969 */
2982 hl_endpos->lnum = best_regmatch.startpos[0].lnum; 2980 hl_endpos->lnum = best_regmatch.startpos[0].lnum;
2983 hl_endpos->col = best_regmatch.startpos[0].col; 2981 hl_endpos->col = best_regmatch.startpos[0].col;
2984 } 2982 }
2985 hl_endpos->col += spp->sp_offsets[SPO_RE_OFF]; 2983 hl_endpos->col += spp->sp_offsets[SPO_RE_OFF];
2986 2984
2987 /* can't end before the start */ 2985 // can't end before the start
2988 if (hl_endpos->lnum == startpos->lnum 2986 if (hl_endpos->lnum == startpos->lnum
2989 && hl_endpos->col < startpos->col) 2987 && hl_endpos->col < startpos->col)
2990 hl_endpos->col = startpos->col; 2988 hl_endpos->col = startpos->col;
2991 limit_pos(hl_endpos, m_endpos); 2989 limit_pos(hl_endpos, m_endpos);
2992 2990
2993 /* now the match ends where the highlighting ends, it is turned 2991 // now the match ends where the highlighting ends, it is turned
2994 * into the matchgroup for the end */ 2992 // into the matchgroup for the end
2995 *m_endpos = *hl_endpos; 2993 *m_endpos = *hl_endpos;
2996 } 2994 }
2997 else 2995 else
2998 { 2996 {
2999 *end_idx = 0; 2997 *end_idx = 0;
3004 3002
3005 had_match = TRUE; 3003 had_match = TRUE;
3006 break; 3004 break;
3007 } 3005 }
3008 3006
3009 /* no match for an END pattern in this line */ 3007 // no match for an END pattern in this line
3010 if (!had_match) 3008 if (!had_match)
3011 m_endpos->lnum = 0; 3009 m_endpos->lnum = 0;
3012 3010
3013 restore_chartab(buf_chartab); 3011 restore_chartab(buf_chartab);
3014 3012
3015 /* Remove external matches. */ 3013 // Remove external matches.
3016 unref_extmatch(re_extmatch_in); 3014 unref_extmatch(re_extmatch_in);
3017 re_extmatch_in = NULL; 3015 re_extmatch_in = NULL;
3018 } 3016 }
3019 3017
3020 /* 3018 /*
3046 /* 3044 /*
3047 * Add offset to matched text for end of match or highlight. 3045 * Add offset to matched text for end of match or highlight.
3048 */ 3046 */
3049 static void 3047 static void
3050 syn_add_end_off( 3048 syn_add_end_off(
3051 lpos_T *result, /* returned position */ 3049 lpos_T *result, // returned position
3052 regmmatch_T *regmatch, /* start/end of match */ 3050 regmmatch_T *regmatch, // start/end of match
3053 synpat_T *spp, /* matched pattern */ 3051 synpat_T *spp, // matched pattern
3054 int idx, /* index of offset */ 3052 int idx, // index of offset
3055 int extra) /* extra chars for offset to start */ 3053 int extra) // extra chars for offset to start
3056 { 3054 {
3057 int col; 3055 int col;
3058 int off; 3056 int off;
3059 char_u *base; 3057 char_u *base;
3060 char_u *p; 3058 char_u *p;
3069 { 3067 {
3070 result->lnum = regmatch->endpos[0].lnum; 3068 result->lnum = regmatch->endpos[0].lnum;
3071 col = regmatch->endpos[0].col; 3069 col = regmatch->endpos[0].col;
3072 off = spp->sp_offsets[idx]; 3070 off = spp->sp_offsets[idx];
3073 } 3071 }
3074 /* Don't go past the end of the line. Matters for "rs=e+2" when there 3072 // Don't go past the end of the line. Matters for "rs=e+2" when there
3075 * is a matchgroup. Watch out for match with last NL in the buffer. */ 3073 // is a matchgroup. Watch out for match with last NL in the buffer.
3076 if (result->lnum > syn_buf->b_ml.ml_line_count) 3074 if (result->lnum > syn_buf->b_ml.ml_line_count)
3077 col = 0; 3075 col = 0;
3078 else if (off != 0) 3076 else if (off != 0)
3079 { 3077 {
3080 base = ml_get_buf(syn_buf, result->lnum, FALSE); 3078 base = ml_get_buf(syn_buf, result->lnum, FALSE);
3098 * Add offset to matched text for start of match or highlight. 3096 * Add offset to matched text for start of match or highlight.
3099 * Avoid resulting column to become negative. 3097 * Avoid resulting column to become negative.
3100 */ 3098 */
3101 static void 3099 static void
3102 syn_add_start_off( 3100 syn_add_start_off(
3103 lpos_T *result, /* returned position */ 3101 lpos_T *result, // returned position
3104 regmmatch_T *regmatch, /* start/end of match */ 3102 regmmatch_T *regmatch, // start/end of match
3105 synpat_T *spp, 3103 synpat_T *spp,
3106 int idx, 3104 int idx,
3107 int extra) /* extra chars for offset to end */ 3105 int extra) // extra chars for offset to end
3108 { 3106 {
3109 int col; 3107 int col;
3110 int off; 3108 int off;
3111 char_u *base; 3109 char_u *base;
3112 char_u *p; 3110 char_u *p;
3123 col = regmatch->startpos[0].col; 3121 col = regmatch->startpos[0].col;
3124 off = spp->sp_offsets[idx]; 3122 off = spp->sp_offsets[idx];
3125 } 3123 }
3126 if (result->lnum > syn_buf->b_ml.ml_line_count) 3124 if (result->lnum > syn_buf->b_ml.ml_line_count)
3127 { 3125 {
3128 /* a "\n" at the end of the pattern may take us below the last line */ 3126 // a "\n" at the end of the pattern may take us below the last line
3129 result->lnum = syn_buf->b_ml.ml_line_count; 3127 result->lnum = syn_buf->b_ml.ml_line_count;
3130 col = (int)STRLEN(ml_get_buf(syn_buf, result->lnum, FALSE)); 3128 col = (int)STRLEN(ml_get_buf(syn_buf, result->lnum, FALSE));
3131 } 3129 }
3132 if (off != 0) 3130 if (off != 0)
3133 { 3131 {
3229 * Return its ID if found, 0 otherwise. 3227 * Return its ID if found, 0 otherwise.
3230 */ 3228 */
3231 static int 3229 static int
3232 check_keyword_id( 3230 check_keyword_id(
3233 char_u *line, 3231 char_u *line,
3234 int startcol, /* position in line to check for keyword */ 3232 int startcol, // position in line to check for keyword
3235 int *endcolp, /* return: character after found keyword */ 3233 int *endcolp, // return: character after found keyword
3236 long *flagsp, /* return: flags of matching keyword */ 3234 long *flagsp, // return: flags of matching keyword
3237 short **next_listp, /* return: next_list of matching keyword */ 3235 short **next_listp, // return: next_list of matching keyword
3238 stateitem_T *cur_si, /* item at the top of the stack */ 3236 stateitem_T *cur_si, // item at the top of the stack
3239 int *ccharp UNUSED) /* conceal substitution char */ 3237 int *ccharp UNUSED) // conceal substitution char
3240 { 3238 {
3241 keyentry_T *kp; 3239 keyentry_T *kp;
3242 char_u *kwp; 3240 char_u *kwp;
3243 int round; 3241 int round;
3244 int kwlen; 3242 int kwlen;
3245 char_u keyword[MAXKEYWLEN + 1]; /* assume max. keyword len is 80 */ 3243 char_u keyword[MAXKEYWLEN + 1]; // assume max. keyword len is 80
3246 hashtab_T *ht; 3244 hashtab_T *ht;
3247 hashitem_T *hi; 3245 hashitem_T *hi;
3248 3246
3249 /* Find first character after the keyword. First character was already 3247 // Find first character after the keyword. First character was already
3250 * checked. */ 3248 // checked.
3251 kwp = line + startcol; 3249 kwp = line + startcol;
3252 kwlen = 0; 3250 kwlen = 0;
3253 do 3251 do
3254 { 3252 {
3255 if (has_mbyte) 3253 if (has_mbyte)
3276 for (round = 1; round <= 2; ++round) 3274 for (round = 1; round <= 2; ++round)
3277 { 3275 {
3278 ht = round == 1 ? &syn_block->b_keywtab : &syn_block->b_keywtab_ic; 3276 ht = round == 1 ? &syn_block->b_keywtab : &syn_block->b_keywtab_ic;
3279 if (ht->ht_used == 0) 3277 if (ht->ht_used == 0)
3280 continue; 3278 continue;
3281 if (round == 2) /* ignore case */ 3279 if (round == 2) // ignore case
3282 (void)str_foldcase(kwp, kwlen, keyword, MAXKEYWLEN + 1); 3280 (void)str_foldcase(kwp, kwlen, keyword, MAXKEYWLEN + 1);
3283 3281
3284 /* 3282 /*
3285 * Find keywords that match. There can be several with different 3283 * Find keywords that match. There can be several with different
3286 * attributes. 3284 * attributes.
3405 { 3403 {
3406 semsg(_("E390: Illegal argument: %s"), arg); 3404 semsg(_("E390: Illegal argument: %s"), arg);
3407 return; 3405 return;
3408 } 3406 }
3409 3407
3410 /* assume spell checking changed, force a redraw */ 3408 // assume spell checking changed, force a redraw
3411 redraw_win_later(curwin, NOT_VALID); 3409 redraw_win_later(curwin, NOT_VALID);
3412 } 3410 }
3413 3411
3414 /* 3412 /*
3415 * Handle ":syntax iskeyword" command. 3413 * Handle ":syntax iskeyword" command.
3468 void 3466 void
3469 syntax_clear(synblock_T *block) 3467 syntax_clear(synblock_T *block)
3470 { 3468 {
3471 int i; 3469 int i;
3472 3470
3473 block->b_syn_error = FALSE; /* clear previous error */ 3471 block->b_syn_error = FALSE; // clear previous error
3474 #ifdef FEAT_RELTIME 3472 #ifdef FEAT_RELTIME
3475 block->b_syn_slow = FALSE; /* clear previous timeout */ 3473 block->b_syn_slow = FALSE; // clear previous timeout
3476 #endif 3474 #endif
3477 block->b_syn_ic = FALSE; /* Use case, by default */ 3475 block->b_syn_ic = FALSE; // Use case, by default
3478 block->b_syn_spell = SYNSPL_DEFAULT; /* default spell checking */ 3476 block->b_syn_spell = SYNSPL_DEFAULT; // default spell checking
3479 block->b_syn_containedin = FALSE; 3477 block->b_syn_containedin = FALSE;
3480 #ifdef FEAT_CONCEAL 3478 #ifdef FEAT_CONCEAL
3481 block->b_syn_conceal = FALSE; 3479 block->b_syn_conceal = FALSE;
3482 #endif 3480 #endif
3483 3481
3484 /* free the keywords */ 3482 // free the keywords
3485 clear_keywtab(&block->b_keywtab); 3483 clear_keywtab(&block->b_keywtab);
3486 clear_keywtab(&block->b_keywtab_ic); 3484 clear_keywtab(&block->b_keywtab_ic);
3487 3485
3488 /* free the syntax patterns */ 3486 // free the syntax patterns
3489 for (i = block->b_syn_patterns.ga_len; --i >= 0; ) 3487 for (i = block->b_syn_patterns.ga_len; --i >= 0; )
3490 syn_clear_pattern(block, i); 3488 syn_clear_pattern(block, i);
3491 ga_clear(&block->b_syn_patterns); 3489 ga_clear(&block->b_syn_patterns);
3492 3490
3493 /* free the syntax clusters */ 3491 // free the syntax clusters
3494 for (i = block->b_syn_clusters.ga_len; --i >= 0; ) 3492 for (i = block->b_syn_clusters.ga_len; --i >= 0; )
3495 syn_clear_cluster(block, i); 3493 syn_clear_cluster(block, i);
3496 ga_clear(&block->b_syn_clusters); 3494 ga_clear(&block->b_syn_clusters);
3497 block->b_spell_cluster_id = 0; 3495 block->b_spell_cluster_id = 0;
3498 block->b_nospell_cluster_id = 0; 3496 block->b_nospell_cluster_id = 0;
3508 #ifdef FEAT_FOLDING 3506 #ifdef FEAT_FOLDING
3509 block->b_syn_folditems = 0; 3507 block->b_syn_folditems = 0;
3510 #endif 3508 #endif
3511 clear_string_option(&block->b_syn_isk); 3509 clear_string_option(&block->b_syn_isk);
3512 3510
3513 /* free the stored states */ 3511 // free the stored states
3514 syn_stack_free_all(block); 3512 syn_stack_free_all(block);
3515 invalidate_current_state(); 3513 invalidate_current_state();
3516 3514
3517 /* Reset the counter for ":syn include" */ 3515 // Reset the counter for ":syn include"
3518 running_syn_inc_tag = 0; 3516 running_syn_inc_tag = 0;
3519 } 3517 }
3520 3518
3521 /* 3519 /*
3522 * Get rid of ownsyntax for window "wp". 3520 * Get rid of ownsyntax for window "wp".
3538 static void 3536 static void
3539 syntax_sync_clear(void) 3537 syntax_sync_clear(void)
3540 { 3538 {
3541 int i; 3539 int i;
3542 3540
3543 /* free the syntax patterns */ 3541 // free the syntax patterns
3544 for (i = curwin->w_s->b_syn_patterns.ga_len; --i >= 0; ) 3542 for (i = curwin->w_s->b_syn_patterns.ga_len; --i >= 0; )
3545 if (SYN_ITEMS(curwin->w_s)[i].sp_syncing) 3543 if (SYN_ITEMS(curwin->w_s)[i].sp_syncing)
3546 syn_remove_pattern(curwin->w_s, i); 3544 syn_remove_pattern(curwin->w_s, i);
3547 3545
3548 curwin->w_s->b_syn_sync_flags = 0; 3546 curwin->w_s->b_syn_sync_flags = 0;
3553 vim_regfree(curwin->w_s->b_syn_linecont_prog); 3551 vim_regfree(curwin->w_s->b_syn_linecont_prog);
3554 curwin->w_s->b_syn_linecont_prog = NULL; 3552 curwin->w_s->b_syn_linecont_prog = NULL;
3555 VIM_CLEAR(curwin->w_s->b_syn_linecont_pat); 3553 VIM_CLEAR(curwin->w_s->b_syn_linecont_pat);
3556 clear_string_option(&curwin->w_s->b_syn_isk); 3554 clear_string_option(&curwin->w_s->b_syn_isk);
3557 3555
3558 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ 3556 syn_stack_free_all(curwin->w_s); // Need to recompute all syntax.
3559 } 3557 }
3560 3558
3561 /* 3559 /*
3562 * Remove one pattern from the buffer's pattern list. 3560 * Remove one pattern from the buffer's pattern list.
3563 */ 3561 */
3586 static void 3584 static void
3587 syn_clear_pattern(synblock_T *block, int i) 3585 syn_clear_pattern(synblock_T *block, int i)
3588 { 3586 {
3589 vim_free(SYN_ITEMS(block)[i].sp_pattern); 3587 vim_free(SYN_ITEMS(block)[i].sp_pattern);
3590 vim_regfree(SYN_ITEMS(block)[i].sp_prog); 3588 vim_regfree(SYN_ITEMS(block)[i].sp_prog);
3591 /* Only free sp_cont_list and sp_next_list of first start pattern */ 3589 // Only free sp_cont_list and sp_next_list of first start pattern
3592 if (i == 0 || SYN_ITEMS(block)[i - 1].sp_type != SPTYPE_START) 3590 if (i == 0 || SYN_ITEMS(block)[i - 1].sp_type != SPTYPE_START)
3593 { 3591 {
3594 vim_free(SYN_ITEMS(block)[i].sp_cont_list); 3592 vim_free(SYN_ITEMS(block)[i].sp_cont_list);
3595 vim_free(SYN_ITEMS(block)[i].sp_next_list); 3593 vim_free(SYN_ITEMS(block)[i].sp_next_list);
3596 vim_free(SYN_ITEMS(block)[i].sp_syn.cont_in_list); 3594 vim_free(SYN_ITEMS(block)[i].sp_syn.cont_in_list);
3687 } 3685 }
3688 arg = skipwhite(arg_end); 3686 arg = skipwhite(arg_end);
3689 } 3687 }
3690 } 3688 }
3691 redraw_curbuf_later(SOME_VALID); 3689 redraw_curbuf_later(SOME_VALID);
3692 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ 3690 syn_stack_free_all(curwin->w_s); // Need to recompute all syntax.
3693 } 3691 }
3694 3692
3695 /* 3693 /*
3696 * Clear one syntax group for the current buffer. 3694 * Clear one syntax group for the current buffer.
3697 */ 3695 */
3699 syn_clear_one(int id, int syncing) 3697 syn_clear_one(int id, int syncing)
3700 { 3698 {
3701 synpat_T *spp; 3699 synpat_T *spp;
3702 int idx; 3700 int idx;
3703 3701
3704 /* Clear keywords only when not ":syn sync clear group-name" */ 3702 // Clear keywords only when not ":syn sync clear group-name"
3705 if (!syncing) 3703 if (!syncing)
3706 { 3704 {
3707 (void)syn_clear_keyword(id, &curwin->w_s->b_keywtab); 3705 (void)syn_clear_keyword(id, &curwin->w_s->b_keywtab);
3708 (void)syn_clear_keyword(id, &curwin->w_s->b_keywtab_ic); 3706 (void)syn_clear_keyword(id, &curwin->w_s->b_keywtab_ic);
3709 } 3707 }
3710 3708
3711 /* clear the patterns for "id" */ 3709 // clear the patterns for "id"
3712 for (idx = curwin->w_s->b_syn_patterns.ga_len; --idx >= 0; ) 3710 for (idx = curwin->w_s->b_syn_patterns.ga_len; --idx >= 0; )
3713 { 3711 {
3714 spp = &(SYN_ITEMS(curwin->w_s)[idx]); 3712 spp = &(SYN_ITEMS(curwin->w_s)[idx]);
3715 if (spp->sp_syn.id != id || spp->sp_syncing != syncing) 3713 if (spp->sp_syn.id != id || spp->sp_syncing != syncing)
3716 continue; 3714 continue;
3790 * Handle ":syntax [list]" command: list current syntax words. 3788 * Handle ":syntax [list]" command: list current syntax words.
3791 */ 3789 */
3792 static void 3790 static void
3793 syn_cmd_list( 3791 syn_cmd_list(
3794 exarg_T *eap, 3792 exarg_T *eap,
3795 int syncing) /* when TRUE: list syncing items */ 3793 int syncing) // when TRUE: list syncing items
3796 { 3794 {
3797 char_u *arg = eap->arg; 3795 char_u *arg = eap->arg;
3798 int id; 3796 int id;
3799 char_u *arg_end; 3797 char_u *arg_end;
3800 3798
3930 * List one syntax item, for ":syntax" or "syntax list syntax_name". 3928 * List one syntax item, for ":syntax" or "syntax list syntax_name".
3931 */ 3929 */
3932 static void 3930 static void
3933 syn_list_one( 3931 syn_list_one(
3934 int id, 3932 int id,
3935 int syncing, /* when TRUE: list syncing items */ 3933 int syncing, // when TRUE: list syncing items
3936 int link_only) /* when TRUE; list link-only too */ 3934 int link_only) // when TRUE; list link-only too
3937 { 3935 {
3938 int attr; 3936 int attr;
3939 int idx; 3937 int idx;
3940 int did_header = FALSE; 3938 int did_header = FALSE;
3941 synpat_T *spp; 3939 synpat_T *spp;
3961 {HL_SKIPNL, "skipnl"}, 3959 {HL_SKIPNL, "skipnl"},
3962 {HL_SKIPEMPTY, "skipempty"}, 3960 {HL_SKIPEMPTY, "skipempty"},
3963 {0, NULL} 3961 {0, NULL}
3964 }; 3962 };
3965 3963
3966 attr = HL_ATTR(HLF_D); /* highlight like directories */ 3964 attr = HL_ATTR(HLF_D); // highlight like directories
3967 3965
3968 /* list the keywords for "id" */ 3966 // list the keywords for "id"
3969 if (!syncing) 3967 if (!syncing)
3970 { 3968 {
3971 did_header = syn_list_keywords(id, &curwin->w_s->b_keywtab, FALSE, attr); 3969 did_header = syn_list_keywords(id, &curwin->w_s->b_keywtab, FALSE, attr);
3972 did_header = syn_list_keywords(id, &curwin->w_s->b_keywtab_ic, 3970 did_header = syn_list_keywords(id, &curwin->w_s->b_keywtab_ic,
3973 did_header, attr); 3971 did_header, attr);
3974 } 3972 }
3975 3973
3976 /* list the patterns for "id" */ 3974 // list the patterns for "id"
3977 for (idx = 0; idx < curwin->w_s->b_syn_patterns.ga_len && !got_int; ++idx) 3975 for (idx = 0; idx < curwin->w_s->b_syn_patterns.ga_len && !got_int; ++idx)
3978 { 3976 {
3979 spp = &(SYN_ITEMS(curwin->w_s)[idx]); 3977 spp = &(SYN_ITEMS(curwin->w_s)[idx]);
3980 if (spp->sp_syn.id != id || spp->sp_syncing != syncing) 3978 if (spp->sp_syn.id != id || spp->sp_syncing != syncing)
3981 continue; 3979 continue;
4028 msg_puts("NONE"); 4026 msg_puts("NONE");
4029 msg_putchar(' '); 4027 msg_putchar(' ');
4030 } 4028 }
4031 } 4029 }
4032 4030
4033 /* list the link, if there is one */ 4031 // list the link, if there is one
4034 if (highlight_link_id(id - 1) && (did_header || link_only) && !got_int) 4032 if (highlight_link_id(id - 1) && (did_header || link_only) && !got_int)
4035 { 4033 {
4036 (void)syn_list_header(did_header, 999, id); 4034 (void)syn_list_header(did_header, 999, id);
4037 msg_puts_attr("links to", attr); 4035 msg_puts_attr("links to", attr);
4038 msg_putchar(' '); 4036 msg_putchar(' ');
4059 static void 4057 static void
4060 syn_list_cluster(int id) 4058 syn_list_cluster(int id)
4061 { 4059 {
4062 int endcol = 15; 4060 int endcol = 15;
4063 4061
4064 /* slight hack: roughly duplicate the guts of syn_list_header() */ 4062 // slight hack: roughly duplicate the guts of syn_list_header()
4065 msg_putchar('\n'); 4063 msg_putchar('\n');
4066 msg_outtrans(SYN_CLSTR(curwin->w_s)[id].scl_name); 4064 msg_outtrans(SYN_CLSTR(curwin->w_s)[id].scl_name);
4067 4065
4068 if (msg_col >= endcol) /* output at least one space */ 4066 if (msg_col >= endcol) // output at least one space
4069 endcol = msg_col + 1; 4067 endcol = msg_col + 1;
4070 if (Columns <= endcol) /* avoid hang for tiny window */ 4068 if (Columns <= endcol) // avoid hang for tiny window
4071 endcol = Columns - 1; 4069 endcol = Columns - 1;
4072 4070
4073 msg_advance(endcol); 4071 msg_advance(endcol);
4074 if (SYN_CLSTR(curwin->w_s)[id].scl_list != NULL) 4072 if (SYN_CLSTR(curwin->w_s)[id].scl_list != NULL)
4075 { 4073 {
4133 int mask; 4131 int mask;
4134 int first; 4132 int first;
4135 static char *sepchars = "/+=-#@\"|'^&"; 4133 static char *sepchars = "/+=-#@\"|'^&";
4136 int i; 4134 int i;
4137 4135
4138 /* May have to write "matchgroup=group" */ 4136 // May have to write "matchgroup=group"
4139 if (last_matchgroup != spp->sp_syn_match_id) 4137 if (last_matchgroup != spp->sp_syn_match_id)
4140 { 4138 {
4141 last_matchgroup = spp->sp_syn_match_id; 4139 last_matchgroup = spp->sp_syn_match_id;
4142 msg_puts_attr("matchgroup", attr); 4140 msg_puts_attr("matchgroup", attr);
4143 msg_putchar('='); 4141 msg_putchar('=');
4146 else 4144 else
4147 msg_outtrans(highlight_group_name(last_matchgroup - 1)); 4145 msg_outtrans(highlight_group_name(last_matchgroup - 1));
4148 msg_putchar(' '); 4146 msg_putchar(' ');
4149 } 4147 }
4150 4148
4151 /* output the name of the pattern and an '=' or ' ' */ 4149 // output the name of the pattern and an '=' or ' '
4152 msg_puts_attr(s, attr); 4150 msg_puts_attr(s, attr);
4153 msg_putchar(c); 4151 msg_putchar(c);
4154 4152
4155 /* output the pattern, in between a char that is not in the pattern */ 4153 // output the pattern, in between a char that is not in the pattern
4156 for (i = 0; vim_strchr(spp->sp_pattern, sepchars[i]) != NULL; ) 4154 for (i = 0; vim_strchr(spp->sp_pattern, sepchars[i]) != NULL; )
4157 if (sepchars[++i] == NUL) 4155 if (sepchars[++i] == NUL)
4158 { 4156 {
4159 i = 0; /* no good char found, just use the first one */ 4157 i = 0; // no good char found, just use the first one
4160 break; 4158 break;
4161 } 4159 }
4162 msg_putchar(sepchars[i]); 4160 msg_putchar(sepchars[i]);
4163 msg_outtrans(spp->sp_pattern); 4161 msg_outtrans(spp->sp_pattern);
4164 msg_putchar(sepchars[i]); 4162 msg_putchar(sepchars[i]);
4165 4163
4166 /* output any pattern options */ 4164 // output any pattern options
4167 first = TRUE; 4165 first = TRUE;
4168 for (i = 0; i < SPO_COUNT; ++i) 4166 for (i = 0; i < SPO_COUNT; ++i)
4169 { 4167 {
4170 mask = (1 << i); 4168 mask = (1 << i);
4171 if (spp->sp_off_flags & (mask + (mask << SPO_COUNT))) 4169 if (spp->sp_off_flags & (mask + (mask << SPO_COUNT)))
4172 { 4170 {
4173 if (!first) 4171 if (!first)
4174 msg_putchar(','); /* separate with commas */ 4172 msg_putchar(','); // separate with commas
4175 msg_puts(spo_name_tab[i]); 4173 msg_puts(spo_name_tab[i]);
4176 n = spp->sp_offsets[i]; 4174 n = spp->sp_offsets[i];
4177 if (i != SPO_LC_OFF) 4175 if (i != SPO_LC_OFF)
4178 { 4176 {
4179 if (spp->sp_off_flags & mask) 4177 if (spp->sp_off_flags & mask)
4197 */ 4195 */
4198 static int 4196 static int
4199 syn_list_keywords( 4197 syn_list_keywords(
4200 int id, 4198 int id,
4201 hashtab_T *ht, 4199 hashtab_T *ht,
4202 int did_header, /* header has already been printed */ 4200 int did_header, // header has already been printed
4203 int attr) 4201 int attr)
4204 { 4202 {
4205 int outlen; 4203 int outlen;
4206 hashitem_T *hi; 4204 hashitem_T *hi;
4207 keyentry_T *kp; 4205 keyentry_T *kp;
4234 || prev_cont_in_list != kp->k_syn.cont_in_list 4232 || prev_cont_in_list != kp->k_syn.cont_in_list
4235 || prev_next_list != kp->next_list) 4233 || prev_next_list != kp->next_list)
4236 outlen = 9999; 4234 outlen = 9999;
4237 else 4235 else
4238 outlen = (int)STRLEN(kp->keyword); 4236 outlen = (int)STRLEN(kp->keyword);
4239 /* output "contained" and "nextgroup" on each line */ 4237 // output "contained" and "nextgroup" on each line
4240 if (syn_list_header(did_header, outlen, id)) 4238 if (syn_list_header(did_header, outlen, id))
4241 { 4239 {
4242 prev_contained = 0; 4240 prev_contained = 0;
4243 prev_next_list = NULL; 4241 prev_next_list = NULL;
4244 prev_cont_in_list = NULL; 4242 prev_cont_in_list = NULL;
4373 /* 4371 /*
4374 * Add a keyword to the list of keywords. 4372 * Add a keyword to the list of keywords.
4375 */ 4373 */
4376 static void 4374 static void
4377 add_keyword( 4375 add_keyword(
4378 char_u *name, /* name of keyword */ 4376 char_u *name, // name of keyword
4379 int id, /* group ID for this keyword */ 4377 int id, // group ID for this keyword
4380 int flags, /* flags for this keyword */ 4378 int flags, // flags for this keyword
4381 short *cont_in_list, /* containedin for this keyword */ 4379 short *cont_in_list, // containedin for this keyword
4382 short *next_list, /* nextgroup for this keyword */ 4380 short *next_list, // nextgroup for this keyword
4383 int conceal_char) 4381 int conceal_char)
4384 { 4382 {
4385 keyentry_T *kp; 4383 keyentry_T *kp;
4386 hashtab_T *ht; 4384 hashtab_T *ht;
4387 hashitem_T *hi; 4385 hashitem_T *hi;
4414 4412
4415 hash = hash_hash(kp->keyword); 4413 hash = hash_hash(kp->keyword);
4416 hi = hash_lookup(ht, kp->keyword, hash); 4414 hi = hash_lookup(ht, kp->keyword, hash);
4417 if (HASHITEM_EMPTY(hi)) 4415 if (HASHITEM_EMPTY(hi))
4418 { 4416 {
4419 /* new keyword, add to hashtable */ 4417 // new keyword, add to hashtable
4420 kp->ke_next = NULL; 4418 kp->ke_next = NULL;
4421 hash_add_item(ht, hi, kp->keyword, hash); 4419 hash_add_item(ht, hi, kp->keyword, hash);
4422 } 4420 }
4423 else 4421 else
4424 { 4422 {
4425 /* keyword already exists, prepend to list */ 4423 // keyword already exists, prepend to list
4426 kp->ke_next = HI2KE(hi); 4424 kp->ke_next = HI2KE(hi);
4427 hi->hi_key = KE2HIKEY(kp); 4425 hi->hi_key = KE2HIKEY(kp);
4428 } 4426 }
4429 } 4427 }
4430 4428
4433 * Return a pointer to the first argument. 4431 * Return a pointer to the first argument.
4434 * Return NULL if the end of the command was found instead of further args. 4432 * Return NULL if the end of the command was found instead of further args.
4435 */ 4433 */
4436 static char_u * 4434 static char_u *
4437 get_group_name( 4435 get_group_name(
4438 char_u *arg, /* start of the argument */ 4436 char_u *arg, // start of the argument
4439 char_u **name_end) /* pointer to end of the name */ 4437 char_u **name_end) // pointer to end of the name
4440 { 4438 {
4441 char_u *rest; 4439 char_u *rest;
4442 4440
4443 *name_end = skiptowhite(arg); 4441 *name_end = skiptowhite(arg);
4444 rest = skipwhite(*name_end); 4442 rest = skipwhite(*name_end);
4460 * Return a pointer to the next argument (which isn't an option). 4458 * Return a pointer to the next argument (which isn't an option).
4461 * Return NULL for any error; 4459 * Return NULL for any error;
4462 */ 4460 */
4463 static char_u * 4461 static char_u *
4464 get_syn_options( 4462 get_syn_options(
4465 char_u *arg, /* next argument to be checked */ 4463 char_u *arg, // next argument to be checked
4466 syn_opt_arg_T *opt, /* various things */ 4464 syn_opt_arg_T *opt, // various things
4467 int *conceal_char UNUSED, 4465 int *conceal_char UNUSED,
4468 int skip) /* TRUE if skipping over command */ 4466 int skip) // TRUE if skipping over command
4469 { 4467 {
4470 char_u *gname_start, *gname; 4468 char_u *gname_start, *gname;
4471 int syn_id; 4469 int syn_id;
4472 int len; 4470 int len;
4473 char *p; 4471 char *p;
4498 {"cCoOnNtTaAiInNeEdDiInN", 2, 0}, 4496 {"cCoOnNtTaAiInNeEdDiInN", 2, 0},
4499 {"nNeExXtTgGrRoOuUpP", 3, 0}, 4497 {"nNeExXtTgGrRoOuUpP", 3, 0},
4500 }; 4498 };
4501 static char *first_letters = "cCoOkKeEtTsSgGdDfFnN"; 4499 static char *first_letters = "cCoOkKeEtTsSgGdDfFnN";
4502 4500
4503 if (arg == NULL) /* already detected error */ 4501 if (arg == NULL) // already detected error
4504 return NULL; 4502 return NULL;
4505 4503
4506 #ifdef FEAT_CONCEAL 4504 #ifdef FEAT_CONCEAL
4507 if (curwin->w_s->b_syn_conceal) 4505 if (curwin->w_s->b_syn_conceal)
4508 opt->flags |= HL_CONCEAL; 4506 opt->flags |= HL_CONCEAL;
4531 { 4529 {
4532 if (opt->keyword 4530 if (opt->keyword
4533 && (flagtab[fidx].flags == HL_DISPLAY 4531 && (flagtab[fidx].flags == HL_DISPLAY
4534 || flagtab[fidx].flags == HL_FOLD 4532 || flagtab[fidx].flags == HL_FOLD
4535 || flagtab[fidx].flags == HL_EXTEND)) 4533 || flagtab[fidx].flags == HL_EXTEND))
4536 /* treat "display", "fold" and "extend" as a keyword */ 4534 // treat "display", "fold" and "extend" as a keyword
4537 fidx = -1; 4535 fidx = -1;
4538 break; 4536 break;
4539 } 4537 }
4540 } 4538 }
4541 if (fidx < 0) /* no match found */ 4539 if (fidx < 0) // no match found
4542 break; 4540 break;
4543 4541
4544 if (flagtab[fidx].argtype == 1) 4542 if (flagtab[fidx].argtype == 1)
4545 { 4543 {
4546 if (!opt->has_cont_list) 4544 if (!opt->has_cont_list)
4561 if (get_id_list(&arg, 9, &opt->next_list, skip) == FAIL) 4559 if (get_id_list(&arg, 9, &opt->next_list, skip) == FAIL)
4562 return NULL; 4560 return NULL;
4563 } 4561 }
4564 else if (flagtab[fidx].argtype == 11 && arg[5] == '=') 4562 else if (flagtab[fidx].argtype == 11 && arg[5] == '=')
4565 { 4563 {
4566 /* cchar=? */ 4564 // cchar=?
4567 if (has_mbyte) 4565 if (has_mbyte)
4568 { 4566 {
4569 #ifdef FEAT_CONCEAL 4567 #ifdef FEAT_CONCEAL
4570 *conceal_char = mb_ptr2char(arg + 6); 4568 *conceal_char = mb_ptr2char(arg + 6);
4571 #endif 4569 #endif
4632 arg = skipwhite(arg); 4630 arg = skipwhite(arg);
4633 } 4631 }
4634 #ifdef FEAT_FOLDING 4632 #ifdef FEAT_FOLDING
4635 else if (flagtab[fidx].flags == HL_FOLD 4633 else if (flagtab[fidx].flags == HL_FOLD
4636 && foldmethodIsSyntax(curwin)) 4634 && foldmethodIsSyntax(curwin))
4637 /* Need to update folds later. */ 4635 // Need to update folds later.
4638 foldUpdateAll(curwin); 4636 foldUpdateAll(curwin);
4639 #endif 4637 #endif
4640 } 4638 }
4641 } 4639 }
4642 4640
4654 if ((*flagsp & HL_CONTAINED) || curwin->w_s->b_syn_topgrp == 0) 4652 if ((*flagsp & HL_CONTAINED) || curwin->w_s->b_syn_topgrp == 0)
4655 return; 4653 return;
4656 *flagsp |= HL_CONTAINED; 4654 *flagsp |= HL_CONTAINED;
4657 if (curwin->w_s->b_syn_topgrp >= SYNID_CLUSTER) 4655 if (curwin->w_s->b_syn_topgrp >= SYNID_CLUSTER)
4658 { 4656 {
4659 /* We have to alloc this, because syn_combine_list() will free it. */ 4657 // We have to alloc this, because syn_combine_list() will free it.
4660 short *grp_list = ALLOC_MULT(short, 2); 4658 short *grp_list = ALLOC_MULT(short, 2);
4661 int tlg_id = curwin->w_s->b_syn_topgrp - SYNID_CLUSTER; 4659 int tlg_id = curwin->w_s->b_syn_topgrp - SYNID_CLUSTER;
4662 4660
4663 if (grp_list != NULL) 4661 if (grp_list != NULL)
4664 { 4662 {
4699 return; 4697 return;
4700 } 4698 }
4701 sgl_id = syn_check_cluster(arg, (int)(group_name_end - arg)); 4699 sgl_id = syn_check_cluster(arg, (int)(group_name_end - arg));
4702 if (sgl_id == 0) 4700 if (sgl_id == 0)
4703 return; 4701 return;
4704 /* separate_nextcmd() and expand_filename() depend on this */ 4702 // separate_nextcmd() and expand_filename() depend on this
4705 eap->arg = rest; 4703 eap->arg = rest;
4706 } 4704 }
4707 4705
4708 /* 4706 /*
4709 * Everything that's left, up to the next command, should be the 4707 * Everything that's left, up to the next command, should be the
4711 */ 4709 */
4712 eap->argt |= (EX_XFILE | EX_NOSPC); 4710 eap->argt |= (EX_XFILE | EX_NOSPC);
4713 separate_nextcmd(eap); 4711 separate_nextcmd(eap);
4714 if (*eap->arg == '<' || *eap->arg == '$' || mch_isFullName(eap->arg)) 4712 if (*eap->arg == '<' || *eap->arg == '$' || mch_isFullName(eap->arg))
4715 { 4713 {
4716 /* For an absolute path, "$VIM/..." or "<sfile>.." we ":source" the 4714 // For an absolute path, "$VIM/..." or "<sfile>.." we ":source" the
4717 * file. Need to expand the file name first. In other cases 4715 // file. Need to expand the file name first. In other cases
4718 * ":runtime!" is used. */ 4716 // ":runtime!" is used.
4719 source = TRUE; 4717 source = TRUE;
4720 if (expand_filename(eap, syn_cmdlinep, &errormsg) == FAIL) 4718 if (expand_filename(eap, syn_cmdlinep, &errormsg) == FAIL)
4721 { 4719 {
4722 if (errormsg != NULL) 4720 if (errormsg != NULL)
4723 emsg(errormsg); 4721 emsg(errormsg);
4769 if (eap->skip) 4767 if (eap->skip)
4770 syn_id = -1; 4768 syn_id = -1;
4771 else 4769 else
4772 syn_id = syn_check_group(arg, (int)(group_name_end - arg)); 4770 syn_id = syn_check_group(arg, (int)(group_name_end - arg));
4773 if (syn_id != 0) 4771 if (syn_id != 0)
4774 /* allocate a buffer, for removing backslashes in the keyword */ 4772 // allocate a buffer, for removing backslashes in the keyword
4775 keyword_copy = alloc(STRLEN(rest) + 1); 4773 keyword_copy = alloc(STRLEN(rest) + 1);
4776 if (keyword_copy != NULL) 4774 if (keyword_copy != NULL)
4777 { 4775 {
4778 syn_opt_arg.flags = 0; 4776 syn_opt_arg.flags = 0;
4779 syn_opt_arg.keyword = TRUE; 4777 syn_opt_arg.keyword = TRUE;
4793 { 4791 {
4794 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, 4792 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char,
4795 eap->skip); 4793 eap->skip);
4796 if (rest == NULL || ends_excmd(*rest)) 4794 if (rest == NULL || ends_excmd(*rest))
4797 break; 4795 break;
4798 /* Copy the keyword, removing backslashes, and add a NUL. */ 4796 // Copy the keyword, removing backslashes, and add a NUL.
4799 while (*rest != NUL && !VIM_ISWHITE(*rest)) 4797 while (*rest != NUL && !VIM_ISWHITE(*rest))
4800 { 4798 {
4801 if (*rest == '\\' && rest[1] != NUL) 4799 if (*rest == '\\' && rest[1] != NUL)
4802 ++rest; 4800 ++rest;
4803 *p++ = *rest++; 4801 *p++ = *rest++;
4806 ++cnt; 4804 ++cnt;
4807 } 4805 }
4808 4806
4809 if (!eap->skip) 4807 if (!eap->skip)
4810 { 4808 {
4811 /* Adjust flags for use of ":syn include". */ 4809 // Adjust flags for use of ":syn include".
4812 syn_incl_toplevel(syn_id, &syn_opt_arg.flags); 4810 syn_incl_toplevel(syn_id, &syn_opt_arg.flags);
4813 4811
4814 /* 4812 /*
4815 * 2: Add an entry for each keyword. 4813 * 2: Add an entry for each keyword.
4816 */ 4814 */
4836 { 4834 {
4837 semsg(_("E890: trailing char after ']': %s]%s"), 4835 semsg(_("E890: trailing char after ']': %s]%s"),
4838 kw, &p[2]); 4836 kw, &p[2]);
4839 goto error; 4837 goto error;
4840 } 4838 }
4841 kw = p + 1; /* skip over the "]" */ 4839 kw = p + 1; // skip over the "]"
4842 break; 4840 break;
4843 } 4841 }
4844 if (has_mbyte) 4842 if (has_mbyte)
4845 { 4843 {
4846 int l = (*mb_ptr2len)(p + 1); 4844 int l = (*mb_ptr2len)(p + 1);
4867 eap->nextcmd = check_nextcmd(rest); 4865 eap->nextcmd = check_nextcmd(rest);
4868 else 4866 else
4869 semsg(_(e_invarg2), arg); 4867 semsg(_(e_invarg2), arg);
4870 4868
4871 redraw_curbuf_later(SOME_VALID); 4869 redraw_curbuf_later(SOME_VALID);
4872 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ 4870 syn_stack_free_all(curwin->w_s); // Need to recompute all syntax.
4873 } 4871 }
4874 4872
4875 /* 4873 /*
4876 * Handle ":syntax match {name} [{options}] {pattern} [{options}]". 4874 * Handle ":syntax match {name} [{options}] {pattern} [{options}]".
4877 * 4875 *
4878 * Also ":syntax sync match {name} [[grouphere | groupthere] {group-name}] .." 4876 * Also ":syntax sync match {name} [[grouphere | groupthere] {group-name}] .."
4879 */ 4877 */
4880 static void 4878 static void
4881 syn_cmd_match( 4879 syn_cmd_match(
4882 exarg_T *eap, 4880 exarg_T *eap,
4883 int syncing) /* TRUE for ":syntax sync match .. " */ 4881 int syncing) // TRUE for ":syntax sync match .. "
4884 { 4882 {
4885 char_u *arg = eap->arg; 4883 char_u *arg = eap->arg;
4886 char_u *group_name_end; 4884 char_u *group_name_end;
4887 char_u *rest; 4885 char_u *rest;
4888 synpat_T item; /* the item found in the line */ 4886 synpat_T item; // the item found in the line
4889 int syn_id; 4887 int syn_id;
4890 int idx; 4888 int idx;
4891 syn_opt_arg_T syn_opt_arg; 4889 syn_opt_arg_T syn_opt_arg;
4892 int sync_idx = 0; 4890 int sync_idx = 0;
4893 int conceal_char = NUL; 4891 int conceal_char = NUL;
4894 4892
4895 /* Isolate the group name, check for validity */ 4893 // Isolate the group name, check for validity
4896 rest = get_group_name(arg, &group_name_end); 4894 rest = get_group_name(arg, &group_name_end);
4897 4895
4898 /* Get options before the pattern */ 4896 // Get options before the pattern
4899 syn_opt_arg.flags = 0; 4897 syn_opt_arg.flags = 0;
4900 syn_opt_arg.keyword = FALSE; 4898 syn_opt_arg.keyword = FALSE;
4901 syn_opt_arg.sync_idx = syncing ? &sync_idx : NULL; 4899 syn_opt_arg.sync_idx = syncing ? &sync_idx : NULL;
4902 syn_opt_arg.has_cont_list = TRUE; 4900 syn_opt_arg.has_cont_list = TRUE;
4903 syn_opt_arg.cont_list = NULL; 4901 syn_opt_arg.cont_list = NULL;
4904 syn_opt_arg.cont_in_list = NULL; 4902 syn_opt_arg.cont_in_list = NULL;
4905 syn_opt_arg.next_list = NULL; 4903 syn_opt_arg.next_list = NULL;
4906 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); 4904 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip);
4907 4905
4908 /* get the pattern. */ 4906 // get the pattern.
4909 init_syn_patterns(); 4907 init_syn_patterns();
4910 vim_memset(&item, 0, sizeof(item)); 4908 vim_memset(&item, 0, sizeof(item));
4911 rest = get_syn_pattern(rest, &item); 4909 rest = get_syn_pattern(rest, &item);
4912 if (vim_regcomp_had_eol() && !(syn_opt_arg.flags & HL_EXCLUDENL)) 4910 if (vim_regcomp_had_eol() && !(syn_opt_arg.flags & HL_EXCLUDENL))
4913 syn_opt_arg.flags |= HL_HAS_EOL; 4911 syn_opt_arg.flags |= HL_HAS_EOL;
4914 4912
4915 /* Get options after the pattern */ 4913 // Get options after the pattern
4916 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); 4914 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip);
4917 4915
4918 if (rest != NULL) /* all arguments are valid */ 4916 if (rest != NULL) // all arguments are valid
4919 { 4917 {
4920 /* 4918 /*
4921 * Check for trailing command and illegal trailing arguments. 4919 * Check for trailing command and illegal trailing arguments.
4922 */ 4920 */
4923 eap->nextcmd = check_nextcmd(rest); 4921 eap->nextcmd = check_nextcmd(rest);
4948 if (syn_opt_arg.cont_in_list != NULL) 4946 if (syn_opt_arg.cont_in_list != NULL)
4949 curwin->w_s->b_syn_containedin = TRUE; 4947 curwin->w_s->b_syn_containedin = TRUE;
4950 SYN_ITEMS(curwin->w_s)[idx].sp_next_list = syn_opt_arg.next_list; 4948 SYN_ITEMS(curwin->w_s)[idx].sp_next_list = syn_opt_arg.next_list;
4951 ++curwin->w_s->b_syn_patterns.ga_len; 4949 ++curwin->w_s->b_syn_patterns.ga_len;
4952 4950
4953 /* remember that we found a match for syncing on */ 4951 // remember that we found a match for syncing on
4954 if (syn_opt_arg.flags & (HL_SYNC_HERE|HL_SYNC_THERE)) 4952 if (syn_opt_arg.flags & (HL_SYNC_HERE|HL_SYNC_THERE))
4955 curwin->w_s->b_syn_sync_flags |= SF_MATCH; 4953 curwin->w_s->b_syn_sync_flags |= SF_MATCH;
4956 #ifdef FEAT_FOLDING 4954 #ifdef FEAT_FOLDING
4957 if (syn_opt_arg.flags & HL_FOLD) 4955 if (syn_opt_arg.flags & HL_FOLD)
4958 ++curwin->w_s->b_syn_folditems; 4956 ++curwin->w_s->b_syn_folditems;
4959 #endif 4957 #endif
4960 4958
4961 redraw_curbuf_later(SOME_VALID); 4959 redraw_curbuf_later(SOME_VALID);
4962 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ 4960 syn_stack_free_all(curwin->w_s); // Need to recompute all syntax.
4963 return; /* don't free the progs and patterns now */ 4961 return; // don't free the progs and patterns now
4964 } 4962 }
4965 } 4963 }
4966 4964
4967 /* 4965 /*
4968 * Something failed, free the allocated memory. 4966 * Something failed, free the allocated memory.
4982 * start {start} .. [skip {skip}] end {end} .. [{options}]". 4980 * start {start} .. [skip {skip}] end {end} .. [{options}]".
4983 */ 4981 */
4984 static void 4982 static void
4985 syn_cmd_region( 4983 syn_cmd_region(
4986 exarg_T *eap, 4984 exarg_T *eap,
4987 int syncing) /* TRUE for ":syntax sync region .." */ 4985 int syncing) // TRUE for ":syntax sync region .."
4988 { 4986 {
4989 char_u *arg = eap->arg; 4987 char_u *arg = eap->arg;
4990 char_u *group_name_end; 4988 char_u *group_name_end;
4991 char_u *rest; /* next arg, NULL on error */ 4989 char_u *rest; // next arg, NULL on error
4992 char_u *key_end; 4990 char_u *key_end;
4993 char_u *key = NULL; 4991 char_u *key = NULL;
4994 char_u *p; 4992 char_u *p;
4995 int item; 4993 int item;
4996 #define ITEM_START 0 4994 #define ITEM_START 0
4997 #define ITEM_SKIP 1 4995 #define ITEM_SKIP 1
4998 #define ITEM_END 2 4996 #define ITEM_END 2
4999 #define ITEM_MATCHGROUP 3 4997 #define ITEM_MATCHGROUP 3
5000 struct pat_ptr 4998 struct pat_ptr
5001 { 4999 {
5002 synpat_T *pp_synp; /* pointer to syn_pattern */ 5000 synpat_T *pp_synp; // pointer to syn_pattern
5003 int pp_matchgroup_id; /* matchgroup ID */ 5001 int pp_matchgroup_id; // matchgroup ID
5004 struct pat_ptr *pp_next; /* pointer to next pat_ptr */ 5002 struct pat_ptr *pp_next; // pointer to next pat_ptr
5005 } *(pat_ptrs[3]); 5003 } *(pat_ptrs[3]);
5006 /* patterns found in the line */ 5004 // patterns found in the line
5007 struct pat_ptr *ppp; 5005 struct pat_ptr *ppp;
5008 struct pat_ptr *ppp_next; 5006 struct pat_ptr *ppp_next;
5009 int pat_count = 0; /* nr of syn_patterns found */ 5007 int pat_count = 0; // nr of syn_patterns found
5010 int syn_id; 5008 int syn_id;
5011 int matchgroup_id = 0; 5009 int matchgroup_id = 0;
5012 int not_enough = FALSE; /* not enough arguments */ 5010 int not_enough = FALSE; // not enough arguments
5013 int illegal = FALSE; /* illegal arguments */ 5011 int illegal = FALSE; // illegal arguments
5014 int success = FALSE; 5012 int success = FALSE;
5015 int idx; 5013 int idx;
5016 syn_opt_arg_T syn_opt_arg; 5014 syn_opt_arg_T syn_opt_arg;
5017 int conceal_char = NUL; 5015 int conceal_char = NUL;
5018 5016
5019 /* Isolate the group name, check for validity */ 5017 // Isolate the group name, check for validity
5020 rest = get_group_name(arg, &group_name_end); 5018 rest = get_group_name(arg, &group_name_end);
5021 5019
5022 pat_ptrs[0] = NULL; 5020 pat_ptrs[0] = NULL;
5023 pat_ptrs[1] = NULL; 5021 pat_ptrs[1] = NULL;
5024 pat_ptrs[2] = NULL; 5022 pat_ptrs[2] = NULL;
5036 /* 5034 /*
5037 * get the options, patterns and matchgroup. 5035 * get the options, patterns and matchgroup.
5038 */ 5036 */
5039 while (rest != NULL && !ends_excmd(*rest)) 5037 while (rest != NULL && !ends_excmd(*rest))
5040 { 5038 {
5041 /* Check for option arguments */ 5039 // Check for option arguments
5042 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); 5040 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip);
5043 if (rest == NULL || ends_excmd(*rest)) 5041 if (rest == NULL || ends_excmd(*rest))
5044 break; 5042 break;
5045 5043
5046 /* must be a pattern or matchgroup then */ 5044 // must be a pattern or matchgroup then
5047 key_end = rest; 5045 key_end = rest;
5048 while (*key_end && !VIM_ISWHITE(*key_end) && *key_end != '=') 5046 while (*key_end && !VIM_ISWHITE(*key_end) && *key_end != '=')
5049 ++key_end; 5047 ++key_end;
5050 vim_free(key); 5048 vim_free(key);
5051 key = vim_strnsave_up(rest, (int)(key_end - rest)); 5049 key = vim_strnsave_up(rest, (int)(key_end - rest));
5052 if (key == NULL) /* out of memory */ 5050 if (key == NULL) // out of memory
5053 { 5051 {
5054 rest = NULL; 5052 rest = NULL;
5055 break; 5053 break;
5056 } 5054 }
5057 if (STRCMP(key, "MATCHGROUP") == 0) 5055 if (STRCMP(key, "MATCHGROUP") == 0)
5060 item = ITEM_START; 5058 item = ITEM_START;
5061 else if (STRCMP(key, "END") == 0) 5059 else if (STRCMP(key, "END") == 0)
5062 item = ITEM_END; 5060 item = ITEM_END;
5063 else if (STRCMP(key, "SKIP") == 0) 5061 else if (STRCMP(key, "SKIP") == 0)
5064 { 5062 {
5065 if (pat_ptrs[ITEM_SKIP] != NULL) /* one skip pattern allowed */ 5063 if (pat_ptrs[ITEM_SKIP] != NULL) // one skip pattern allowed
5066 { 5064 {
5067 illegal = TRUE; 5065 illegal = TRUE;
5068 break; 5066 break;
5069 } 5067 }
5070 item = ITEM_SKIP; 5068 item = ITEM_SKIP;
5124 } 5122 }
5125 5123
5126 /* 5124 /*
5127 * Get the syntax pattern and the following offset(s). 5125 * Get the syntax pattern and the following offset(s).
5128 */ 5126 */
5129 /* Enable the appropriate \z specials. */ 5127 // Enable the appropriate \z specials.
5130 if (item == ITEM_START) 5128 if (item == ITEM_START)
5131 reg_do_extmatch = REX_SET; 5129 reg_do_extmatch = REX_SET;
5132 else if (item == ITEM_SKIP || item == ITEM_END) 5130 else if (item == ITEM_SKIP || item == ITEM_END)
5133 reg_do_extmatch = REX_USE; 5131 reg_do_extmatch = REX_USE;
5134 rest = get_syn_pattern(rest, ppp->pp_synp); 5132 rest = get_syn_pattern(rest, ppp->pp_synp);
5209 #endif 5207 #endif
5210 } 5208 }
5211 } 5209 }
5212 5210
5213 redraw_curbuf_later(SOME_VALID); 5211 redraw_curbuf_later(SOME_VALID);
5214 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ 5212 syn_stack_free_all(curwin->w_s); // Need to recompute all syntax.
5215 success = TRUE; /* don't free the progs and patterns now */ 5213 success = TRUE; // don't free the progs and patterns now
5216 } 5214 }
5217 } 5215 }
5218 5216
5219 /* 5217 /*
5220 * Free the allocated memory. 5218 * Free the allocated memory.
5388 syn_scl_name2id(char_u *name) 5386 syn_scl_name2id(char_u *name)
5389 { 5387 {
5390 int i; 5388 int i;
5391 char_u *name_u; 5389 char_u *name_u;
5392 5390
5393 /* Avoid using stricmp() too much, it's slow on some systems */ 5391 // Avoid using stricmp() too much, it's slow on some systems
5394 name_u = vim_strsave_up(name); 5392 name_u = vim_strsave_up(name);
5395 if (name_u == NULL) 5393 if (name_u == NULL)
5396 return 0; 5394 return 0;
5397 for (i = curwin->w_s->b_syn_clusters.ga_len; --i >= 0; ) 5395 for (i = curwin->w_s->b_syn_clusters.ga_len; --i >= 0; )
5398 if (SYN_CLSTR(curwin->w_s)[i].scl_name_u != NULL 5396 if (SYN_CLSTR(curwin->w_s)[i].scl_name_u != NULL
5435 name = vim_strnsave(pp, len); 5433 name = vim_strnsave(pp, len);
5436 if (name == NULL) 5434 if (name == NULL)
5437 return 0; 5435 return 0;
5438 5436
5439 id = syn_scl_name2id(name); 5437 id = syn_scl_name2id(name);
5440 if (id == 0) /* doesn't exist yet */ 5438 if (id == 0) // doesn't exist yet
5441 id = syn_add_cluster(name); 5439 id = syn_add_cluster(name);
5442 else 5440 else
5443 vim_free(name); 5441 vim_free(name);
5444 return id; 5442 return id;
5445 } 5443 }
5561 } 5559 }
5562 5560
5563 if (got_clstr) 5561 if (got_clstr)
5564 { 5562 {
5565 redraw_curbuf_later(SOME_VALID); 5563 redraw_curbuf_later(SOME_VALID);
5566 syn_stack_free_all(curwin->w_s); /* Need to recompute all. */ 5564 syn_stack_free_all(curwin->w_s); // Need to recompute all.
5567 } 5565 }
5568 } 5566 }
5569 5567
5570 if (!got_clstr) 5568 if (!got_clstr)
5571 emsg(_("E400: No cluster specified")); 5569 emsg(_("E400: No cluster specified"));
5594 char_u *end; 5592 char_u *end;
5595 int *p; 5593 int *p;
5596 int idx; 5594 int idx;
5597 char_u *cpo_save; 5595 char_u *cpo_save;
5598 5596
5599 /* need at least three chars */ 5597 // need at least three chars
5600 if (arg == NULL || arg[0] == NUL || arg[1] == NUL || arg[2] == NUL) 5598 if (arg == NULL || arg[0] == NUL || arg[1] == NUL || arg[2] == NUL)
5601 return NULL; 5599 return NULL;
5602 5600
5603 end = skip_regexp(arg + 1, *arg, TRUE, NULL); 5601 end = skip_regexp(arg + 1, *arg, TRUE, NULL);
5604 if (*end != *arg) /* end delimiter not found */ 5602 if (*end != *arg) // end delimiter not found
5605 { 5603 {
5606 semsg(_("E401: Pattern delimiter not found: %s"), arg); 5604 semsg(_("E401: Pattern delimiter not found: %s"), arg);
5607 return NULL; 5605 return NULL;
5608 } 5606 }
5609 /* store the pattern and compiled regexp program */ 5607 // store the pattern and compiled regexp program
5610 if ((ci->sp_pattern = vim_strnsave(arg + 1, (int)(end - arg - 1))) == NULL) 5608 if ((ci->sp_pattern = vim_strnsave(arg + 1, (int)(end - arg - 1))) == NULL)
5611 return NULL; 5609 return NULL;
5612 5610
5613 /* Make 'cpoptions' empty, to avoid the 'l' flag */ 5611 // Make 'cpoptions' empty, to avoid the 'l' flag
5614 cpo_save = p_cpo; 5612 cpo_save = p_cpo;
5615 p_cpo = (char_u *)""; 5613 p_cpo = (char_u *)"";
5616 ci->sp_prog = vim_regcomp(ci->sp_pattern, RE_MAGIC); 5614 ci->sp_prog = vim_regcomp(ci->sp_pattern, RE_MAGIC);
5617 p_cpo = cpo_save; 5615 p_cpo = cpo_save;
5618 5616
5644 default: idx = -1; break; 5642 default: idx = -1; break;
5645 } 5643 }
5646 if (idx >= 0) 5644 if (idx >= 0)
5647 { 5645 {
5648 ci->sp_off_flags |= (1 << idx); 5646 ci->sp_off_flags |= (1 << idx);
5649 if (idx == SPO_LC_OFF) /* lc=99 */ 5647 if (idx == SPO_LC_OFF) // lc=99
5650 { 5648 {
5651 end += 3; 5649 end += 3;
5652 *p = getdigits(&end); 5650 *p = getdigits(&end);
5653 5651
5654 /* "lc=" offset automatically sets "ms=" offset */ 5652 // "lc=" offset automatically sets "ms=" offset
5655 if (!(ci->sp_off_flags & (1 << SPO_MS_OFF))) 5653 if (!(ci->sp_off_flags & (1 << SPO_MS_OFF)))
5656 { 5654 {
5657 ci->sp_off_flags |= (1 << SPO_MS_OFF); 5655 ci->sp_off_flags |= (1 << SPO_MS_OFF);
5658 ci->sp_offsets[SPO_MS_OFF] = *p; 5656 ci->sp_offsets[SPO_MS_OFF] = *p;
5659 } 5657 }
5660 } 5658 }
5661 else /* yy=x+99 */ 5659 else // yy=x+99
5662 { 5660 {
5663 end += 4; 5661 end += 4;
5664 if (*end == '+') 5662 if (*end == '+')
5665 { 5663 {
5666 ++end; 5664 ++end;
5667 *p = getdigits(&end); /* positive offset */ 5665 *p = getdigits(&end); // positive offset
5668 } 5666 }
5669 else if (*end == '-') 5667 else if (*end == '-')
5670 { 5668 {
5671 ++end; 5669 ++end;
5672 *p = -getdigits(&end); /* negative offset */ 5670 *p = -getdigits(&end); // negative offset
5673 } 5671 }
5674 } 5672 }
5675 if (*end != ',') 5673 if (*end != ',')
5676 break; 5674 break;
5677 ++end; 5675 ++end;
5764 curwin->w_s->b_syn_sync_maxlines = 0; 5762 curwin->w_s->b_syn_sync_maxlines = 0;
5765 } 5763 }
5766 } 5764 }
5767 else if (STRCMP(key, "LINECONT") == 0) 5765 else if (STRCMP(key, "LINECONT") == 0)
5768 { 5766 {
5769 if (*next_arg == NUL) /* missing pattern */ 5767 if (*next_arg == NUL) // missing pattern
5770 { 5768 {
5771 illegal = TRUE; 5769 illegal = TRUE;
5772 break; 5770 break;
5773 } 5771 }
5774 if (curwin->w_s->b_syn_linecont_pat != NULL) 5772 if (curwin->w_s->b_syn_linecont_pat != NULL)
5776 emsg(_("E403: syntax sync: line continuations pattern specified twice")); 5774 emsg(_("E403: syntax sync: line continuations pattern specified twice"));
5777 finished = TRUE; 5775 finished = TRUE;
5778 break; 5776 break;
5779 } 5777 }
5780 arg_end = skip_regexp(next_arg + 1, *next_arg, TRUE, NULL); 5778 arg_end = skip_regexp(next_arg + 1, *next_arg, TRUE, NULL);
5781 if (*arg_end != *next_arg) /* end delimiter not found */ 5779 if (*arg_end != *next_arg) // end delimiter not found
5782 { 5780 {
5783 illegal = TRUE; 5781 illegal = TRUE;
5784 break; 5782 break;
5785 } 5783 }
5786 5784
5787 if (!eap->skip) 5785 if (!eap->skip)
5788 { 5786 {
5789 /* store the pattern and compiled regexp program */ 5787 // store the pattern and compiled regexp program
5790 if ((curwin->w_s->b_syn_linecont_pat = vim_strnsave(next_arg + 1, 5788 if ((curwin->w_s->b_syn_linecont_pat = vim_strnsave(next_arg + 1,
5791 (int)(arg_end - next_arg - 1))) == NULL) 5789 (int)(arg_end - next_arg - 1))) == NULL)
5792 { 5790 {
5793 finished = TRUE; 5791 finished = TRUE;
5794 break; 5792 break;
5795 } 5793 }
5796 curwin->w_s->b_syn_linecont_ic = curwin->w_s->b_syn_ic; 5794 curwin->w_s->b_syn_linecont_ic = curwin->w_s->b_syn_ic;
5797 5795
5798 /* Make 'cpoptions' empty, to avoid the 'l' flag */ 5796 // Make 'cpoptions' empty, to avoid the 'l' flag
5799 cpo_save = p_cpo; 5797 cpo_save = p_cpo;
5800 p_cpo = (char_u *)""; 5798 p_cpo = (char_u *)"";
5801 curwin->w_s->b_syn_linecont_prog = 5799 curwin->w_s->b_syn_linecont_prog =
5802 vim_regcomp(curwin->w_s->b_syn_linecont_pat, RE_MAGIC); 5800 vim_regcomp(curwin->w_s->b_syn_linecont_pat, RE_MAGIC);
5803 p_cpo = cpo_save; 5801 p_cpo = cpo_save;
5835 semsg(_("E404: Illegal arguments: %s"), arg_start); 5833 semsg(_("E404: Illegal arguments: %s"), arg_start);
5836 else if (!finished) 5834 else if (!finished)
5837 { 5835 {
5838 eap->nextcmd = check_nextcmd(arg_start); 5836 eap->nextcmd = check_nextcmd(arg_start);
5839 redraw_curbuf_later(SOME_VALID); 5837 redraw_curbuf_later(SOME_VALID);
5840 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ 5838 syn_stack_free_all(curwin->w_s); // Need to recompute all syntax.
5841 } 5839 }
5842 } 5840 }
5843 5841
5844 /* 5842 /*
5845 * Convert a line of highlight group names into a list of group ID numbers. 5843 * Convert a line of highlight group names into a list of group ID numbers.
5849 * returns FAIL for some error, OK for success. 5847 * returns FAIL for some error, OK for success.
5850 */ 5848 */
5851 static int 5849 static int
5852 get_id_list( 5850 get_id_list(
5853 char_u **arg, 5851 char_u **arg,
5854 int keylen, /* length of keyword */ 5852 int keylen, // length of keyword
5855 short **list, /* where to store the resulting list, if not 5853 short **list, // where to store the resulting list, if not
5856 NULL, the list is silently skipped! */ 5854 // NULL, the list is silently skipped!
5857 int skip) 5855 int skip)
5858 { 5856 {
5859 char_u *p = NULL; 5857 char_u *p = NULL;
5860 char_u *end; 5858 char_u *end;
5861 int round; 5859 int round;
5899 count = 0; 5897 count = 0;
5900 while (!ends_excmd(*p)) 5898 while (!ends_excmd(*p))
5901 { 5899 {
5902 for (end = p; *end && !VIM_ISWHITE(*end) && *end != ','; ++end) 5900 for (end = p; *end && !VIM_ISWHITE(*end) && *end != ','; ++end)
5903 ; 5901 ;
5904 name = alloc(end - p + 3); /* leave room for "^$" */ 5902 name = alloc(end - p + 3); // leave room for "^$"
5905 if (name == NULL) 5903 if (name == NULL)
5906 { 5904 {
5907 failed = TRUE; 5905 failed = TRUE;
5908 break; 5906 break;
5909 } 5907 }
5972 if (vim_regexec(&regmatch, highlight_group_name(i), 5970 if (vim_regexec(&regmatch, highlight_group_name(i),
5973 (colnr_T)0)) 5971 (colnr_T)0))
5974 { 5972 {
5975 if (round == 2) 5973 if (round == 2)
5976 { 5974 {
5977 /* Got more items than expected; can happen 5975 // Got more items than expected; can happen
5978 * when adding items that match: 5976 // when adding items that match:
5979 * "contains=a.*b,axb". 5977 // "contains=a.*b,axb".
5980 * Go back to first round */ 5978 // Go back to first round
5981 if (count >= total_count) 5979 if (count >= total_count)
5982 { 5980 {
5983 vim_free(retval); 5981 vim_free(retval);
5984 round = 1; 5982 round = 1;
5985 } 5983 }
5986 else 5984 else
5987 retval[count] = i + 1; 5985 retval[count] = i + 1;
5988 } 5986 }
5989 ++count; 5987 ++count;
5990 id = -1; /* remember that we found one */ 5988 id = -1; // remember that we found one
5991 } 5989 }
5992 } 5990 }
5993 vim_regfree(regmatch.regprog); 5991 vim_regfree(regmatch.regprog);
5994 } 5992 }
5995 } 5993 }
6002 } 6000 }
6003 if (id > 0) 6001 if (id > 0)
6004 { 6002 {
6005 if (round == 2) 6003 if (round == 2)
6006 { 6004 {
6007 /* Got more items than expected, go back to first round */ 6005 // Got more items than expected, go back to first round
6008 if (count >= total_count) 6006 if (count >= total_count)
6009 { 6007 {
6010 vim_free(retval); 6008 vim_free(retval);
6011 round = 1; 6009 round = 1;
6012 } 6010 }
6016 ++count; 6014 ++count;
6017 } 6015 }
6018 p = skipwhite(end); 6016 p = skipwhite(end);
6019 if (*p != ',') 6017 if (*p != ',')
6020 break; 6018 break;
6021 p = skipwhite(p + 1); /* skip comma in between arguments */ 6019 p = skipwhite(p + 1); // skip comma in between arguments
6022 } 6020 }
6023 if (failed) 6021 if (failed)
6024 break; 6022 break;
6025 if (round == 1) 6023 if (round == 1)
6026 { 6024 {
6027 retval = ALLOC_MULT(short, count + 1); 6025 retval = ALLOC_MULT(short, count + 1);
6028 if (retval == NULL) 6026 if (retval == NULL)
6029 break; 6027 break;
6030 retval[count] = 0; /* zero means end of the list */ 6028 retval[count] = 0; // zero means end of the list
6031 total_count = count; 6029 total_count = count;
6032 } 6030 }
6033 } 6031 }
6034 6032
6035 *arg = p; 6033 *arg = p;
6040 } 6038 }
6041 6039
6042 if (*list == NULL) 6040 if (*list == NULL)
6043 *list = retval; 6041 *list = retval;
6044 else 6042 else
6045 vim_free(retval); /* list already found, don't overwrite it */ 6043 vim_free(retval); // list already found, don't overwrite it
6046 6044
6047 return OK; 6045 return OK;
6048 } 6046 }
6049 6047
6050 /* 6048 /*
6077 * the current item. 6075 * the current item.
6078 * This function is called very often, keep it fast!! 6076 * This function is called very often, keep it fast!!
6079 */ 6077 */
6080 static int 6078 static int
6081 in_id_list( 6079 in_id_list(
6082 stateitem_T *cur_si, /* current item or NULL */ 6080 stateitem_T *cur_si, // current item or NULL
6083 short *list, /* id list */ 6081 short *list, // id list
6084 struct sp_syn *ssp, /* group id and ":syn include" tag of group */ 6082 struct sp_syn *ssp, // group id and ":syn include" tag of group
6085 int contained) /* group id is contained */ 6083 int contained) // group id is contained
6086 { 6084 {
6087 int retval; 6085 int retval;
6088 short *scl_list; 6086 short *scl_list;
6089 short item; 6087 short item;
6090 short id = ssp->id; 6088 short id = ssp->id;
6091 static int depth = 0; 6089 static int depth = 0;
6092 int r; 6090 int r;
6093 6091
6094 /* If ssp has a "containedin" list and "cur_si" is in it, return TRUE. */ 6092 // If ssp has a "containedin" list and "cur_si" is in it, return TRUE.
6095 if (cur_si != NULL && ssp->cont_in_list != NULL 6093 if (cur_si != NULL && ssp->cont_in_list != NULL
6096 && !(cur_si->si_flags & HL_MATCH)) 6094 && !(cur_si->si_flags & HL_MATCH))
6097 { 6095 {
6098 /* Ignore transparent items without a contains argument. Double check 6096 // Ignore transparent items without a contains argument. Double check
6099 * that we don't go back past the first one. */ 6097 // that we don't go back past the first one.
6100 while ((cur_si->si_flags & HL_TRANS_CONT) 6098 while ((cur_si->si_flags & HL_TRANS_CONT)
6101 && cur_si > (stateitem_T *)(current_state.ga_data)) 6099 && cur_si > (stateitem_T *)(current_state.ga_data))
6102 --cur_si; 6100 --cur_si;
6103 /* cur_si->si_idx is -1 for keywords, these never contain anything. */ 6101 // cur_si->si_idx is -1 for keywords, these never contain anything.
6104 if (cur_si->si_idx >= 0 && in_id_list(NULL, ssp->cont_in_list, 6102 if (cur_si->si_idx >= 0 && in_id_list(NULL, ssp->cont_in_list,
6105 &(SYN_ITEMS(syn_block)[cur_si->si_idx].sp_syn), 6103 &(SYN_ITEMS(syn_block)[cur_si->si_idx].sp_syn),
6106 SYN_ITEMS(syn_block)[cur_si->si_idx].sp_flags & HL_CONTAINED)) 6104 SYN_ITEMS(syn_block)[cur_si->si_idx].sp_flags & HL_CONTAINED))
6107 return TRUE; 6105 return TRUE;
6108 } 6106 }
6125 item = *list; 6123 item = *list;
6126 if (item >= SYNID_ALLBUT && item < SYNID_CLUSTER) 6124 if (item >= SYNID_ALLBUT && item < SYNID_CLUSTER)
6127 { 6125 {
6128 if (item < SYNID_TOP) 6126 if (item < SYNID_TOP)
6129 { 6127 {
6130 /* ALL or ALLBUT: accept all groups in the same file */ 6128 // ALL or ALLBUT: accept all groups in the same file
6131 if (item - SYNID_ALLBUT != ssp->inc_tag) 6129 if (item - SYNID_ALLBUT != ssp->inc_tag)
6132 return FALSE; 6130 return FALSE;
6133 } 6131 }
6134 else if (item < SYNID_CONTAINED) 6132 else if (item < SYNID_CONTAINED)
6135 { 6133 {
6136 /* TOP: accept all not-contained groups in the same file */ 6134 // TOP: accept all not-contained groups in the same file
6137 if (item - SYNID_TOP != ssp->inc_tag || contained) 6135 if (item - SYNID_TOP != ssp->inc_tag || contained)
6138 return FALSE; 6136 return FALSE;
6139 } 6137 }
6140 else 6138 else
6141 { 6139 {
6142 /* CONTAINED: accept all contained groups in the same file */ 6140 // CONTAINED: accept all contained groups in the same file
6143 if (item - SYNID_CONTAINED != ssp->inc_tag || !contained) 6141 if (item - SYNID_CONTAINED != ssp->inc_tag || !contained)
6144 return FALSE; 6142 return FALSE;
6145 } 6143 }
6146 item = *++list; 6144 item = *++list;
6147 retval = FALSE; 6145 retval = FALSE;
6157 if (item == id) 6155 if (item == id)
6158 return retval; 6156 return retval;
6159 if (item >= SYNID_CLUSTER) 6157 if (item >= SYNID_CLUSTER)
6160 { 6158 {
6161 scl_list = SYN_CLSTR(syn_block)[item - SYNID_CLUSTER].scl_list; 6159 scl_list = SYN_CLSTR(syn_block)[item - SYNID_CLUSTER].scl_list;
6162 /* restrict recursiveness to 30 to avoid an endless loop for a 6160 // restrict recursiveness to 30 to avoid an endless loop for a
6163 * cluster that includes itself (indirectly) */ 6161 // cluster that includes itself (indirectly)
6164 if (scl_list != NULL && depth < 30) 6162 if (scl_list != NULL && depth < 30)
6165 { 6163 {
6166 ++depth; 6164 ++depth;
6167 r = in_id_list(NULL, scl_list, ssp, contained); 6165 r = in_id_list(NULL, scl_list, ssp, contained);
6168 --depth; 6166 --depth;
6175 return !retval; 6173 return !retval;
6176 } 6174 }
6177 6175
6178 struct subcommand 6176 struct subcommand
6179 { 6177 {
6180 char *name; /* subcommand name */ 6178 char *name; // subcommand name
6181 void (*func)(exarg_T *, int); /* function to call */ 6179 void (*func)(exarg_T *, int); // function to call
6182 }; 6180 };
6183 6181
6184 static struct subcommand subcommands[] = 6182 static struct subcommand subcommands[] =
6185 { 6183 {
6186 {"case", syn_cmd_case}, 6184 {"case", syn_cmd_case},
6217 char_u *subcmd_name; 6215 char_u *subcmd_name;
6218 int i; 6216 int i;
6219 6217
6220 syn_cmdlinep = eap->cmdlinep; 6218 syn_cmdlinep = eap->cmdlinep;
6221 6219
6222 /* isolate subcommand name */ 6220 // isolate subcommand name
6223 for (subcmd_end = arg; ASCII_ISALPHA(*subcmd_end); ++subcmd_end) 6221 for (subcmd_end = arg; ASCII_ISALPHA(*subcmd_end); ++subcmd_end)
6224 ; 6222 ;
6225 subcmd_name = vim_strnsave(arg, (int)(subcmd_end - arg)); 6223 subcmd_name = vim_strnsave(arg, (int)(subcmd_end - arg));
6226 if (subcmd_name != NULL) 6224 if (subcmd_name != NULL)
6227 { 6225 {
6228 if (eap->skip) /* skip error messages for all subcommands */ 6226 if (eap->skip) // skip error messages for all subcommands
6229 ++emsg_skip; 6227 ++emsg_skip;
6230 for (i = 0; ; ++i) 6228 for (i = 0; ; ++i)
6231 { 6229 {
6232 if (subcommands[i].name == NULL) 6230 if (subcommands[i].name == NULL)
6233 { 6231 {
6258 curwin->w_s = ALLOC_ONE(synblock_T); 6256 curwin->w_s = ALLOC_ONE(synblock_T);
6259 memset(curwin->w_s, 0, sizeof(synblock_T)); 6257 memset(curwin->w_s, 0, sizeof(synblock_T));
6260 hash_init(&curwin->w_s->b_keywtab); 6258 hash_init(&curwin->w_s->b_keywtab);
6261 hash_init(&curwin->w_s->b_keywtab_ic); 6259 hash_init(&curwin->w_s->b_keywtab_ic);
6262 #ifdef FEAT_SPELL 6260 #ifdef FEAT_SPELL
6263 /* TODO: keep the spell checking as it was. */ 6261 // TODO: keep the spell checking as it was.
6264 curwin->w_p_spell = FALSE; /* No spell checking */ 6262 curwin->w_p_spell = FALSE; // No spell checking
6265 clear_string_option(&curwin->w_s->b_p_spc); 6263 clear_string_option(&curwin->w_s->b_p_spc);
6266 clear_string_option(&curwin->w_s->b_p_spf); 6264 clear_string_option(&curwin->w_s->b_p_spf);
6267 clear_string_option(&curwin->w_s->b_p_spl); 6265 clear_string_option(&curwin->w_s->b_p_spl);
6268 #endif 6266 #endif
6269 clear_string_option(&curwin->w_s->b_syn_isk); 6267 clear_string_option(&curwin->w_s->b_syn_isk);
6270 } 6268 }
6271 6269
6272 /* save value of b:current_syntax */ 6270 // save value of b:current_syntax
6273 old_value = get_var_value((char_u *)"b:current_syntax"); 6271 old_value = get_var_value((char_u *)"b:current_syntax");
6274 if (old_value != NULL) 6272 if (old_value != NULL)
6275 old_value = vim_strsave(old_value); 6273 old_value = vim_strsave(old_value);
6276 6274
6277 /* Apply the "syntax" autocommand event, this finds and loads the syntax 6275 // Apply the "syntax" autocommand event, this finds and loads the syntax
6278 * file. */ 6276 // file.
6279 apply_autocmds(EVENT_SYNTAX, eap->arg, curbuf->b_fname, TRUE, curbuf); 6277 apply_autocmds(EVENT_SYNTAX, eap->arg, curbuf->b_fname, TRUE, curbuf);
6280 6278
6281 /* move value of b:current_syntax to w:current_syntax */ 6279 // move value of b:current_syntax to w:current_syntax
6282 new_value = get_var_value((char_u *)"b:current_syntax"); 6280 new_value = get_var_value((char_u *)"b:current_syntax");
6283 if (new_value != NULL) 6281 if (new_value != NULL)
6284 set_internal_string_var((char_u *)"w:current_syntax", new_value); 6282 set_internal_string_var((char_u *)"w:current_syntax", new_value);
6285 6283
6286 /* restore value of b:current_syntax */ 6284 // restore value of b:current_syntax
6287 if (old_value == NULL) 6285 if (old_value == NULL)
6288 do_unlet((char_u *)"b:current_syntax", TRUE); 6286 do_unlet((char_u *)"b:current_syntax", TRUE);
6289 else 6287 else
6290 { 6288 {
6291 set_internal_string_var((char_u *)"b:current_syntax", old_value); 6289 set_internal_string_var((char_u *)"b:current_syntax", old_value);
6303 } 6301 }
6304 6302
6305 6303
6306 static enum 6304 static enum
6307 { 6305 {
6308 EXP_SUBCMD, /* expand ":syn" sub-commands */ 6306 EXP_SUBCMD, // expand ":syn" sub-commands
6309 EXP_CASE, /* expand ":syn case" arguments */ 6307 EXP_CASE, // expand ":syn case" arguments
6310 EXP_SPELL, /* expand ":syn spell" arguments */ 6308 EXP_SPELL, // expand ":syn spell" arguments
6311 EXP_SYNC /* expand ":syn sync" arguments */ 6309 EXP_SYNC // expand ":syn sync" arguments
6312 } expand_what; 6310 } expand_what;
6313 6311
6314 /* 6312 /*
6315 * Reset include_link, include_default, include_none to 0. 6313 * Reset include_link, include_default, include_none to 0.
6316 * Called when we are done expanding. 6314 * Called when we are done expanding.
6339 void 6337 void
6340 set_context_in_syntax_cmd(expand_T *xp, char_u *arg) 6338 set_context_in_syntax_cmd(expand_T *xp, char_u *arg)
6341 { 6339 {
6342 char_u *p; 6340 char_u *p;
6343 6341
6344 /* Default: expand subcommands */ 6342 // Default: expand subcommands
6345 xp->xp_context = EXPAND_SYNTAX; 6343 xp->xp_context = EXPAND_SYNTAX;
6346 expand_what = EXP_SUBCMD; 6344 expand_what = EXP_SUBCMD;
6347 xp->xp_pattern = arg; 6345 xp->xp_pattern = arg;
6348 include_link = 0; 6346 include_link = 0;
6349 include_default = 0; 6347 include_default = 0;
6350 6348
6351 /* (part of) subcommand already typed */ 6349 // (part of) subcommand already typed
6352 if (*arg != NUL) 6350 if (*arg != NUL)
6353 { 6351 {
6354 p = skiptowhite(arg); 6352 p = skiptowhite(arg);
6355 if (*p != NUL) /* past first word */ 6353 if (*p != NUL) // past first word
6356 { 6354 {
6357 xp->xp_pattern = skipwhite(p); 6355 xp->xp_pattern = skipwhite(p);
6358 if (*skiptowhite(xp->xp_pattern) != NUL) 6356 if (*skiptowhite(xp->xp_pattern) != NUL)
6359 xp->xp_context = EXPAND_NOTHING; 6357 xp->xp_context = EXPAND_NOTHING;
6360 else if (STRNICMP(arg, "case", p - arg) == 0) 6358 else if (STRNICMP(arg, "case", p - arg) == 0)
6415 int 6413 int
6416 syn_get_id( 6414 syn_get_id(
6417 win_T *wp, 6415 win_T *wp,
6418 long lnum, 6416 long lnum,
6419 colnr_T col, 6417 colnr_T col,
6420 int trans, /* remove transparency */ 6418 int trans, // remove transparency
6421 int *spellp, /* return: can do spell checking */ 6419 int *spellp, // return: can do spell checking
6422 int keep_state) /* keep state of char at "col" */ 6420 int keep_state) // keep state of char at "col"
6423 { 6421 {
6424 /* When the position is not after the current position and in the same 6422 // When the position is not after the current position and in the same
6425 * line of the same buffer, need to restart parsing. */ 6423 // line of the same buffer, need to restart parsing.
6426 if (wp->w_buffer != syn_buf 6424 if (wp->w_buffer != syn_buf
6427 || lnum != current_lnum 6425 || lnum != current_lnum
6428 || col < current_col) 6426 || col < current_col)
6429 syntax_start(wp, lnum); 6427 syntax_start(wp, lnum);
6430 else if (wp->w_buffer == syn_buf 6428 else if (wp->w_buffer == syn_buf
6431 && lnum == current_lnum 6429 && lnum == current_lnum
6432 && col > current_col) 6430 && col > current_col)
6433 /* next_match may not be correct when moving around, e.g. with the 6431 // next_match may not be correct when moving around, e.g. with the
6434 * "skip" expression in searchpair() */ 6432 // "skip" expression in searchpair()
6435 next_match_idx = -1; 6433 next_match_idx = -1;
6436 6434
6437 (void)get_syntax_attr(col, spellp, keep_state); 6435 (void)get_syntax_attr(col, spellp, keep_state);
6438 6436
6439 return (trans ? current_trans_id : current_id); 6437 return (trans ? current_trans_id : current_id);
6472 int 6470 int
6473 syn_get_stack_item(int i) 6471 syn_get_stack_item(int i)
6474 { 6472 {
6475 if (i >= current_state.ga_len) 6473 if (i >= current_state.ga_len)
6476 { 6474 {
6477 /* Need to invalidate the state, because we didn't properly finish it 6475 // Need to invalidate the state, because we didn't properly finish it
6478 * for the last character, "keep_state" was TRUE. */ 6476 // for the last character, "keep_state" was TRUE.
6479 invalidate_current_state(); 6477 invalidate_current_state();
6480 current_col = MAXCOL; 6478 current_col = MAXCOL;
6481 return -1; 6479 return -1;
6482 } 6480 }
6483 return CUR_STATE(i).si_id; 6481 return CUR_STATE(i).si_id;
6492 syn_get_foldlevel(win_T *wp, long lnum) 6490 syn_get_foldlevel(win_T *wp, long lnum)
6493 { 6491 {
6494 int level = 0; 6492 int level = 0;
6495 int i; 6493 int i;
6496 6494
6497 /* Return quickly when there are no fold items at all. */ 6495 // Return quickly when there are no fold items at all.
6498 if (wp->w_s->b_syn_folditems != 0 6496 if (wp->w_s->b_syn_folditems != 0
6499 && !wp->w_s->b_syn_error 6497 && !wp->w_s->b_syn_error
6500 # ifdef SYN_TIME_LIMIT 6498 # ifdef SYN_TIME_LIMIT
6501 && !wp->w_s->b_syn_slow 6499 && !wp->w_s->b_syn_slow
6502 # endif 6500 # endif
6650 p->pattern = spp->sp_pattern; 6648 p->pattern = spp->sp_pattern;
6651 ++ga.ga_len; 6649 ++ga.ga_len;
6652 } 6650 }
6653 } 6651 }
6654 6652
6655 /* Sort on total time. Skip if there are no items to avoid passing NULL 6653 // Sort on total time. Skip if there are no items to avoid passing NULL
6656 * pointer to qsort(). */ 6654 // pointer to qsort().
6657 if (ga.ga_len > 1) 6655 if (ga.ga_len > 1)
6658 qsort(ga.ga_data, (size_t)ga.ga_len, sizeof(time_entry_T), 6656 qsort(ga.ga_data, (size_t)ga.ga_len, sizeof(time_entry_T),
6659 syn_compare_syntime); 6657 syn_compare_syntime);
6660 6658
6661 msg_puts_title(_(" TOTAL COUNT MATCH SLOWEST AVERAGE NAME PATTERN")); 6659 msg_puts_title(_(" TOTAL COUNT MATCH SLOWEST AVERAGE NAME PATTERN"));
6663 for (idx = 0; idx < ga.ga_len && !got_int; ++idx) 6661 for (idx = 0; idx < ga.ga_len && !got_int; ++idx)
6664 { 6662 {
6665 p = ((time_entry_T *)ga.ga_data) + idx; 6663 p = ((time_entry_T *)ga.ga_data) + idx;
6666 6664
6667 msg_puts(profile_msg(&p->total)); 6665 msg_puts(profile_msg(&p->total));
6668 msg_puts(" "); /* make sure there is always a separating space */ 6666 msg_puts(" "); // make sure there is always a separating space
6669 msg_advance(13); 6667 msg_advance(13);
6670 msg_outnum(p->count); 6668 msg_outnum(p->count);
6671 msg_puts(" "); 6669 msg_puts(" ");
6672 msg_advance(20); 6670 msg_advance(20);
6673 msg_outnum(p->match); 6671 msg_outnum(p->match);
6684 msg_outtrans(highlight_group_name(p->id - 1)); 6682 msg_outtrans(highlight_group_name(p->id - 1));
6685 msg_puts(" "); 6683 msg_puts(" ");
6686 6684
6687 msg_advance(69); 6685 msg_advance(69);
6688 if (Columns < 80) 6686 if (Columns < 80)
6689 len = 20; /* will wrap anyway */ 6687 len = 20; // will wrap anyway
6690 else 6688 else
6691 len = Columns - 70; 6689 len = Columns - 70;
6692 if (len > (int)STRLEN(p->pattern)) 6690 if (len > (int)STRLEN(p->pattern))
6693 len = (int)STRLEN(p->pattern); 6691 len = (int)STRLEN(p->pattern);
6694 msg_outtrans_len(p->pattern, len); 6692 msg_outtrans_len(p->pattern, len);
6704 msg_puts("\n"); 6702 msg_puts("\n");
6705 } 6703 }
6706 } 6704 }
6707 #endif 6705 #endif
6708 6706
6709 #endif /* FEAT_SYN_HL */ 6707 #endif // FEAT_SYN_HL