Mercurial > vim
comparison src/optionstr.c @ 18100:df5778d73320 v8.1.2045
patch 8.1.2045: the option.c file is too big
Commit: https://github.com/vim/vim/commit/dac1347b4d9c1a1aef6aa73fdea08a9d1077d6ea
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Sep 16 21:06:21 2019 +0200
patch 8.1.2045: the option.c file is too big
Problem: The option.c file is too big.
Solution: Split off the code dealing with strings. (Yegappan Lakshmanan,
closes #4937)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 16 Sep 2019 21:15:05 +0200 |
parents | |
children | e0ec4cd7a865 |
comparison
equal
deleted
inserted
replaced
18099:349ea1199661 | 18100:df5778d73320 |
---|---|
1 /* vi:set ts=8 sts=4 sw=4 noet: | |
2 * | |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * optionstr.c: Functions related to string options | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 | |
16 static char *(p_ambw_values[]) = {"single", "double", NULL}; | |
17 static char *(p_bg_values[]) = {"light", "dark", NULL}; | |
18 static char *(p_bkc_values[]) = {"yes", "auto", "no", "breaksymlink", "breakhardlink", NULL}; | |
19 static char *(p_bo_values[]) = {"all", "backspace", "cursor", "complete", | |
20 "copy", "ctrlg", "error", "esc", "ex", | |
21 "hangul", "insertmode", "lang", "mess", | |
22 "showmatch", "operator", "register", "shell", | |
23 "spell", "wildmode", NULL}; | |
24 static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL}; | |
25 static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL}; | |
26 #ifdef FEAT_CRYPT | |
27 static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL}; | |
28 #endif | |
29 static char *(p_cmp_values[]) = {"internal", "keepascii", NULL}; | |
30 static char *(p_dy_values[]) = {"lastline", "truncate", "uhex", NULL}; | |
31 #ifdef FEAT_FOLDING | |
32 static char *(p_fdo_values[]) = {"all", "block", "hor", "mark", "percent", | |
33 "quickfix", "search", "tag", "insert", | |
34 "undo", "jump", NULL}; | |
35 #endif | |
36 #ifdef FEAT_SESSION | |
37 // Also used for 'viewoptions'! | |
38 static char *(p_ssop_values[]) = {"buffers", "winpos", "resize", "winsize", | |
39 "localoptions", "options", "help", "blank", "globals", "slash", "unix", | |
40 "sesdir", "curdir", "folds", "cursor", "tabpages", "terminal", NULL}; | |
41 #endif | |
42 static char *(p_swb_values[]) = {"useopen", "usetab", "split", "newtab", "vsplit", NULL}; | |
43 static char *(p_tc_values[]) = {"followic", "ignore", "match", "followscs", "smart", NULL}; | |
44 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN) | |
45 static char *(p_toolbar_values[]) = {"text", "icons", "tooltips", "horiz", NULL}; | |
46 #endif | |
47 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) | |
48 static char *(p_tbis_values[]) = {"tiny", "small", "medium", "large", "huge", "giant", NULL}; | |
49 #endif | |
50 #if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS)) | |
51 static char *(p_ttym_values[]) = {"xterm", "xterm2", "dec", "netterm", "jsbterm", "pterm", "urxvt", "sgr", NULL}; | |
52 #endif | |
53 static char *(p_ve_values[]) = {"block", "insert", "all", "onemore", NULL}; | |
54 static char *(p_wop_values[]) = {"tagfile", NULL}; | |
55 #ifdef FEAT_WAK | |
56 static char *(p_wak_values[]) = {"yes", "menu", "no", NULL}; | |
57 #endif | |
58 static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL}; | |
59 static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL}; | |
60 static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL}; | |
61 static char *(p_km_values[]) = {"startsel", "stopsel", NULL}; | |
62 #ifdef FEAT_BROWSE | |
63 static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL}; | |
64 #endif | |
65 static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL}; | |
66 static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL}; | |
67 static char *(p_ead_values[]) = {"both", "ver", "hor", NULL}; | |
68 static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", "popup", NULL}; | |
69 static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL}; | |
70 static char *(p_bs_values[]) = {"indent", "eol", "start", NULL}; | |
71 #ifdef FEAT_FOLDING | |
72 static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax", | |
73 # ifdef FEAT_DIFF | |
74 "diff", | |
75 # endif | |
76 NULL}; | |
77 static char *(p_fcl_values[]) = {"all", NULL}; | |
78 #endif | |
79 static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "popup", "noinsert", "noselect", NULL}; | |
80 #ifdef BACKSLASH_IN_FILENAME | |
81 static char *(p_csl_values[]) = {"slash", "backslash", NULL}; | |
82 #endif | |
83 #ifdef FEAT_SIGNS | |
84 static char *(p_scl_values[]) = {"yes", "no", "auto", "number", NULL}; | |
85 #endif | |
86 #if defined(MSWIN) && defined(FEAT_TERMINAL) | |
87 static char *(p_twt_values[]) = {"winpty", "conpty", "", NULL}; | |
88 #endif | |
89 | |
90 static int check_opt_strings(char_u *val, char **values, int list); | |
91 static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list); | |
92 | |
93 /* | |
94 * After setting various option values: recompute variables that depend on | |
95 * option values. | |
96 */ | |
97 void | |
98 didset_string_options(void) | |
99 { | |
100 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE); | |
101 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE); | |
102 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE); | |
103 #ifdef FEAT_SESSION | |
104 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE); | |
105 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE); | |
106 #endif | |
107 #ifdef FEAT_FOLDING | |
108 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE); | |
109 #endif | |
110 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE); | |
111 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE); | |
112 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE); | |
113 #if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS)) | |
114 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE); | |
115 #endif | |
116 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN) | |
117 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE); | |
118 #endif | |
119 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) | |
120 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE); | |
121 #endif | |
122 } | |
123 | |
124 #if defined(FEAT_EVAL) | |
125 /* | |
126 * Trigger the OptionSet autocommand. | |
127 * "opt_idx" is the index of the option being set. | |
128 * "opt_flags" can be OPT_LOCAL etc. | |
129 * "oldval" the old value | |
130 * "oldval_l" the old local value (only non-NULL if global and local value | |
131 * are set) | |
132 * "oldval_g" the old global value (only non-NULL if global and local value | |
133 * are set) | |
134 * "newval" the new value | |
135 */ | |
136 void | |
137 trigger_optionsset_string( | |
138 int opt_idx, | |
139 int opt_flags, | |
140 char_u *oldval, | |
141 char_u *oldval_l, | |
142 char_u *oldval_g, | |
143 char_u *newval) | |
144 { | |
145 // Don't do this recursively. | |
146 if (oldval != NULL && newval != NULL | |
147 && *get_vim_var_str(VV_OPTION_TYPE) == NUL) | |
148 { | |
149 char_u buf_type[7]; | |
150 | |
151 sprintf((char *)buf_type, "%s", | |
152 (opt_flags & OPT_LOCAL) ? "local" : "global"); | |
153 set_vim_var_string(VV_OPTION_OLD, oldval, -1); | |
154 set_vim_var_string(VV_OPTION_NEW, newval, -1); | |
155 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1); | |
156 if (opt_flags & OPT_LOCAL) | |
157 { | |
158 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1); | |
159 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1); | |
160 } | |
161 if (opt_flags & OPT_GLOBAL) | |
162 { | |
163 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1); | |
164 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval, -1); | |
165 } | |
166 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) | |
167 { | |
168 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1); | |
169 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval_l, -1); | |
170 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval_g, -1); | |
171 } | |
172 if (opt_flags & OPT_MODELINE) | |
173 { | |
174 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1); | |
175 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1); | |
176 } | |
177 apply_autocmds(EVENT_OPTIONSET, | |
178 (char_u *)get_option_fullname(opt_idx), NULL, FALSE, | |
179 NULL); | |
180 reset_v_option_vars(); | |
181 } | |
182 } | |
183 #endif | |
184 | |
185 static char * | |
186 illegal_char(char *errbuf, int c) | |
187 { | |
188 if (errbuf == NULL) | |
189 return ""; | |
190 sprintf((char *)errbuf, _("E539: Illegal character <%s>"), | |
191 (char *)transchar(c)); | |
192 return errbuf; | |
193 } | |
194 | |
195 /* | |
196 * Check string options in a buffer for NULL value. | |
197 */ | |
198 void | |
199 check_buf_options(buf_T *buf) | |
200 { | |
201 check_string_option(&buf->b_p_bh); | |
202 check_string_option(&buf->b_p_bt); | |
203 check_string_option(&buf->b_p_fenc); | |
204 check_string_option(&buf->b_p_ff); | |
205 #ifdef FEAT_FIND_ID | |
206 check_string_option(&buf->b_p_def); | |
207 check_string_option(&buf->b_p_inc); | |
208 # ifdef FEAT_EVAL | |
209 check_string_option(&buf->b_p_inex); | |
210 # endif | |
211 #endif | |
212 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL) | |
213 check_string_option(&buf->b_p_inde); | |
214 check_string_option(&buf->b_p_indk); | |
215 #endif | |
216 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL) | |
217 check_string_option(&buf->b_p_bexpr); | |
218 #endif | |
219 #if defined(FEAT_CRYPT) | |
220 check_string_option(&buf->b_p_cm); | |
221 #endif | |
222 check_string_option(&buf->b_p_fp); | |
223 #if defined(FEAT_EVAL) | |
224 check_string_option(&buf->b_p_fex); | |
225 #endif | |
226 #ifdef FEAT_CRYPT | |
227 check_string_option(&buf->b_p_key); | |
228 #endif | |
229 check_string_option(&buf->b_p_kp); | |
230 check_string_option(&buf->b_p_mps); | |
231 check_string_option(&buf->b_p_fo); | |
232 check_string_option(&buf->b_p_flp); | |
233 check_string_option(&buf->b_p_isk); | |
234 #ifdef FEAT_COMMENTS | |
235 check_string_option(&buf->b_p_com); | |
236 #endif | |
237 #ifdef FEAT_FOLDING | |
238 check_string_option(&buf->b_p_cms); | |
239 #endif | |
240 check_string_option(&buf->b_p_nf); | |
241 #ifdef FEAT_TEXTOBJ | |
242 check_string_option(&buf->b_p_qe); | |
243 #endif | |
244 #ifdef FEAT_SYN_HL | |
245 check_string_option(&buf->b_p_syn); | |
246 check_string_option(&buf->b_s.b_syn_isk); | |
247 #endif | |
248 #ifdef FEAT_SPELL | |
249 check_string_option(&buf->b_s.b_p_spc); | |
250 check_string_option(&buf->b_s.b_p_spf); | |
251 check_string_option(&buf->b_s.b_p_spl); | |
252 #endif | |
253 #ifdef FEAT_SEARCHPATH | |
254 check_string_option(&buf->b_p_sua); | |
255 #endif | |
256 #ifdef FEAT_CINDENT | |
257 check_string_option(&buf->b_p_cink); | |
258 check_string_option(&buf->b_p_cino); | |
259 parse_cino(buf); | |
260 #endif | |
261 check_string_option(&buf->b_p_ft); | |
262 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) | |
263 check_string_option(&buf->b_p_cinw); | |
264 #endif | |
265 check_string_option(&buf->b_p_cpt); | |
266 #ifdef FEAT_COMPL_FUNC | |
267 check_string_option(&buf->b_p_cfu); | |
268 check_string_option(&buf->b_p_ofu); | |
269 #endif | |
270 #ifdef FEAT_EVAL | |
271 check_string_option(&buf->b_p_tfu); | |
272 #endif | |
273 #ifdef FEAT_KEYMAP | |
274 check_string_option(&buf->b_p_keymap); | |
275 #endif | |
276 #ifdef FEAT_QUICKFIX | |
277 check_string_option(&buf->b_p_gp); | |
278 check_string_option(&buf->b_p_mp); | |
279 check_string_option(&buf->b_p_efm); | |
280 #endif | |
281 check_string_option(&buf->b_p_ep); | |
282 check_string_option(&buf->b_p_path); | |
283 check_string_option(&buf->b_p_tags); | |
284 check_string_option(&buf->b_p_tc); | |
285 check_string_option(&buf->b_p_dict); | |
286 check_string_option(&buf->b_p_tsr); | |
287 #ifdef FEAT_LISP | |
288 check_string_option(&buf->b_p_lw); | |
289 #endif | |
290 check_string_option(&buf->b_p_bkc); | |
291 check_string_option(&buf->b_p_menc); | |
292 #ifdef FEAT_VARTABS | |
293 check_string_option(&buf->b_p_vsts); | |
294 check_string_option(&buf->b_p_vts); | |
295 #endif | |
296 } | |
297 | |
298 /* | |
299 * Free the string allocated for an option. | |
300 * Checks for the string being empty_option. This may happen if we're out of | |
301 * memory, vim_strsave() returned NULL, which was replaced by empty_option by | |
302 * check_options(). | |
303 * Does NOT check for P_ALLOCED flag! | |
304 */ | |
305 void | |
306 free_string_option(char_u *p) | |
307 { | |
308 if (p != empty_option) | |
309 vim_free(p); | |
310 } | |
311 | |
312 void | |
313 clear_string_option(char_u **pp) | |
314 { | |
315 if (*pp != empty_option) | |
316 vim_free(*pp); | |
317 *pp = empty_option; | |
318 } | |
319 | |
320 void | |
321 check_string_option(char_u **pp) | |
322 { | |
323 if (*pp == NULL) | |
324 *pp = empty_option; | |
325 } | |
326 | |
327 /* | |
328 * Set global value for string option when it's a local option. | |
329 */ | |
330 static void | |
331 set_string_option_global( | |
332 int opt_idx, // option index | |
333 char_u **varp) // pointer to option variable | |
334 { | |
335 char_u **p, *s; | |
336 | |
337 // the global value is always allocated | |
338 if (is_window_local_option(opt_idx)) | |
339 p = (char_u **)GLOBAL_WO(varp); | |
340 else | |
341 p = (char_u **)get_option_var(opt_idx); | |
342 if (!is_global_option(opt_idx) | |
343 && p != varp | |
344 && (s = vim_strsave(*varp)) != NULL) | |
345 { | |
346 free_string_option(*p); | |
347 *p = s; | |
348 } | |
349 } | |
350 | |
351 /* | |
352 * Set a string option to a new value (without checking the effect). | |
353 * The string is copied into allocated memory. | |
354 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used. | |
355 * When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When | |
356 * "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to | |
357 * "set_sid". | |
358 */ | |
359 void | |
360 set_string_option_direct( | |
361 char_u *name, | |
362 int opt_idx, | |
363 char_u *val, | |
364 int opt_flags, // OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL | |
365 int set_sid UNUSED) | |
366 { | |
367 char_u *s; | |
368 char_u **varp; | |
369 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; | |
370 int idx = opt_idx; | |
371 | |
372 if (idx == -1) // use name | |
373 { | |
374 idx = findoption(name); | |
375 if (idx < 0) // not found (should not happen) | |
376 { | |
377 semsg(_(e_intern2), "set_string_option_direct()"); | |
378 siemsg(_("For option %s"), name); | |
379 return; | |
380 } | |
381 } | |
382 | |
383 if (is_hidden_option(idx)) // can't set hidden option | |
384 return; | |
385 | |
386 s = vim_strsave(val); | |
387 if (s != NULL) | |
388 { | |
389 varp = (char_u **)get_option_varp_scope(idx, | |
390 both ? OPT_LOCAL : opt_flags); | |
391 if ((opt_flags & OPT_FREE) && (get_option_flags(idx) & P_ALLOCED)) | |
392 free_string_option(*varp); | |
393 *varp = s; | |
394 | |
395 // For buffer/window local option may also set the global value. | |
396 if (both) | |
397 set_string_option_global(idx, varp); | |
398 | |
399 set_option_flag(idx, P_ALLOCED); | |
400 | |
401 // When setting both values of a global option with a local value, | |
402 // make the local value empty, so that the global value is used. | |
403 if (is_global_local_option(idx) && both) | |
404 { | |
405 free_string_option(*varp); | |
406 *varp = empty_option; | |
407 } | |
408 # ifdef FEAT_EVAL | |
409 if (set_sid != SID_NONE) | |
410 { | |
411 sctx_T script_ctx; | |
412 | |
413 if (set_sid == 0) | |
414 script_ctx = current_sctx; | |
415 else | |
416 { | |
417 script_ctx.sc_sid = set_sid; | |
418 script_ctx.sc_seq = 0; | |
419 script_ctx.sc_lnum = 0; | |
420 script_ctx.sc_version = 1; | |
421 } | |
422 set_option_sctx_idx(idx, opt_flags, script_ctx); | |
423 } | |
424 # endif | |
425 } | |
426 } | |
427 | |
428 /* | |
429 * Like set_string_option_direct(), but for a window-local option in "wp". | |
430 * Blocks autocommands to avoid the old curwin becoming invalid. | |
431 */ | |
432 void | |
433 set_string_option_direct_in_win( | |
434 win_T *wp, | |
435 char_u *name, | |
436 int opt_idx, | |
437 char_u *val, | |
438 int opt_flags, | |
439 int set_sid) | |
440 { | |
441 win_T *save_curwin = curwin; | |
442 | |
443 block_autocmds(); | |
444 curwin = wp; | |
445 curbuf = curwin->w_buffer; | |
446 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid); | |
447 curwin = save_curwin; | |
448 curbuf = curwin->w_buffer; | |
449 unblock_autocmds(); | |
450 } | |
451 | |
452 /* | |
453 * Like set_string_option_direct(), but for a buffer-local option in "buf". | |
454 * Blocks autocommands to avoid the old curbuf becoming invalid. | |
455 */ | |
456 void | |
457 set_string_option_direct_in_buf( | |
458 buf_T *buf, | |
459 char_u *name, | |
460 int opt_idx, | |
461 char_u *val, | |
462 int opt_flags, | |
463 int set_sid) | |
464 { | |
465 buf_T *save_curbuf = curbuf; | |
466 | |
467 block_autocmds(); | |
468 curbuf = buf; | |
469 curwin->w_buffer = curbuf; | |
470 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid); | |
471 curbuf = save_curbuf; | |
472 curwin->w_buffer = curbuf; | |
473 unblock_autocmds(); | |
474 } | |
475 | |
476 /* | |
477 * Set a string option to a new value, and handle the effects. | |
478 * | |
479 * Returns NULL on success or error message on error. | |
480 */ | |
481 char * | |
482 set_string_option( | |
483 int opt_idx, | |
484 char_u *value, | |
485 int opt_flags) // OPT_LOCAL and/or OPT_GLOBAL | |
486 { | |
487 char_u *s; | |
488 char_u **varp; | |
489 char_u *oldval; | |
490 #if defined(FEAT_EVAL) | |
491 char_u *oldval_l = NULL; | |
492 char_u *oldval_g = NULL; | |
493 char_u *saved_oldval = NULL; | |
494 char_u *saved_oldval_l = NULL; | |
495 char_u *saved_oldval_g = NULL; | |
496 char_u *saved_newval = NULL; | |
497 #endif | |
498 char *r = NULL; | |
499 int value_checked = FALSE; | |
500 | |
501 if (is_hidden_option(opt_idx)) // don't set hidden option | |
502 return NULL; | |
503 | |
504 s = vim_strsave(value); | |
505 if (s != NULL) | |
506 { | |
507 varp = (char_u **)get_option_varp_scope(opt_idx, | |
508 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0 | |
509 ? (is_global_local_option(opt_idx) | |
510 ? OPT_GLOBAL : OPT_LOCAL) | |
511 : opt_flags); | |
512 oldval = *varp; | |
513 #if defined(FEAT_EVAL) | |
514 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) | |
515 { | |
516 oldval_l = *(char_u **)get_option_varp_scope(opt_idx, OPT_LOCAL); | |
517 oldval_g = *(char_u **)get_option_varp_scope(opt_idx, OPT_GLOBAL); | |
518 } | |
519 #endif | |
520 *varp = s; | |
521 | |
522 #if defined(FEAT_EVAL) | |
523 if (!starting | |
524 # ifdef FEAT_CRYPT | |
525 && !is_crypt_key_option(opt_idx) | |
526 # endif | |
527 ) | |
528 { | |
529 if (oldval_l != NULL) | |
530 saved_oldval_l = vim_strsave(oldval_l); | |
531 if (oldval_g != NULL) | |
532 saved_oldval_g = vim_strsave(oldval_g); | |
533 saved_oldval = vim_strsave(oldval); | |
534 saved_newval = vim_strsave(s); | |
535 } | |
536 #endif | |
537 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL, | |
538 opt_flags, &value_checked)) == NULL) | |
539 did_set_option(opt_idx, opt_flags, TRUE, value_checked); | |
540 | |
541 #if defined(FEAT_EVAL) | |
542 // call autocommand after handling side effects | |
543 if (r == NULL) | |
544 trigger_optionsset_string(opt_idx, opt_flags, | |
545 saved_oldval, saved_oldval_l, | |
546 saved_oldval_g, saved_newval); | |
547 vim_free(saved_oldval); | |
548 vim_free(saved_oldval_l); | |
549 vim_free(saved_oldval_g); | |
550 vim_free(saved_newval); | |
551 #endif | |
552 } | |
553 return r; | |
554 } | |
555 | |
556 /* | |
557 * Return TRUE if "val" is a valid 'filetype' name. | |
558 * Also used for 'syntax' and 'keymap'. | |
559 */ | |
560 static int | |
561 valid_filetype(char_u *val) | |
562 { | |
563 return valid_name(val, ".-_"); | |
564 } | |
565 | |
566 #ifdef FEAT_STL_OPT | |
567 /* | |
568 * Check validity of options with the 'statusline' format. | |
569 * Return error message or NULL. | |
570 */ | |
571 static char * | |
572 check_stl_option(char_u *s) | |
573 { | |
574 int itemcnt = 0; | |
575 int groupdepth = 0; | |
576 static char errbuf[80]; | |
577 | |
578 while (*s && itemcnt < STL_MAX_ITEM) | |
579 { | |
580 // Check for valid keys after % sequences | |
581 while (*s && *s != '%') | |
582 s++; | |
583 if (!*s) | |
584 break; | |
585 s++; | |
586 if (*s != '%' && *s != ')') | |
587 ++itemcnt; | |
588 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK) | |
589 { | |
590 s++; | |
591 continue; | |
592 } | |
593 if (*s == ')') | |
594 { | |
595 s++; | |
596 if (--groupdepth < 0) | |
597 break; | |
598 continue; | |
599 } | |
600 if (*s == '-') | |
601 s++; | |
602 while (VIM_ISDIGIT(*s)) | |
603 s++; | |
604 if (*s == STL_USER_HL) | |
605 continue; | |
606 if (*s == '.') | |
607 { | |
608 s++; | |
609 while (*s && VIM_ISDIGIT(*s)) | |
610 s++; | |
611 } | |
612 if (*s == '(') | |
613 { | |
614 groupdepth++; | |
615 continue; | |
616 } | |
617 if (vim_strchr(STL_ALL, *s) == NULL) | |
618 { | |
619 return illegal_char(errbuf, *s); | |
620 } | |
621 if (*s == '{') | |
622 { | |
623 s++; | |
624 while (*s != '}' && *s) | |
625 s++; | |
626 if (*s != '}') | |
627 return N_("E540: Unclosed expression sequence"); | |
628 } | |
629 } | |
630 if (itemcnt >= STL_MAX_ITEM) | |
631 return N_("E541: too many items"); | |
632 if (groupdepth != 0) | |
633 return N_("E542: unbalanced groups"); | |
634 return NULL; | |
635 } | |
636 #endif | |
637 | |
638 /* | |
639 * Handle string options that need some action to perform when changed. | |
640 * Returns NULL for success, or an error message for an error. | |
641 */ | |
642 char * | |
643 did_set_string_option( | |
644 int opt_idx, // index in options[] table | |
645 char_u **varp, // pointer to the option variable | |
646 int new_value_alloced, // new value was allocated | |
647 char_u *oldval, // previous value of the option | |
648 char *errbuf, // buffer for errors, or NULL | |
649 int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL | |
650 int *value_checked) // value was checked to be save, no | |
651 // need to set P_INSECURE | |
652 { | |
653 char *errmsg = NULL; | |
654 char_u *s, *p; | |
655 int did_chartab = FALSE; | |
656 char_u **gvarp; | |
657 long_u free_oldval = (get_option_flags(opt_idx) & P_ALLOCED); | |
658 #ifdef FEAT_GUI | |
659 // set when changing an option that only requires a redraw in the GUI | |
660 int redraw_gui_only = FALSE; | |
661 #endif | |
662 int value_changed = FALSE; | |
663 #if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS) | |
664 int did_swaptcap = FALSE; | |
665 #endif | |
666 | |
667 // Get the global option to compare with, otherwise we would have to check | |
668 // two values for all local options. | |
669 gvarp = (char_u **)get_option_varp_scope(opt_idx, OPT_GLOBAL); | |
670 | |
671 // Disallow changing some options from secure mode | |
672 if ((secure | |
673 #ifdef HAVE_SANDBOX | |
674 || sandbox != 0 | |
675 #endif | |
676 ) && (get_option_flags(opt_idx) & P_SECURE)) | |
677 errmsg = e_secure; | |
678 | |
679 // Check for a "normal" directory or file name in some options. Disallow a | |
680 // path separator (slash and/or backslash), wildcards and characters that | |
681 // are often illegal in a file name. Be more permissive if "secure" is off. | |
682 else if (((get_option_flags(opt_idx) & P_NFNAME) | |
683 && vim_strpbrk(*varp, (char_u *)(secure | |
684 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL) | |
685 || ((get_option_flags(opt_idx) & P_NDNAME) | |
686 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL)) | |
687 errmsg = e_invarg; | |
688 | |
689 // 'term' | |
690 else if (varp == &T_NAME) | |
691 { | |
692 if (T_NAME[0] == NUL) | |
693 errmsg = N_("E529: Cannot set 'term' to empty string"); | |
694 #ifdef FEAT_GUI | |
695 if (gui.in_use) | |
696 errmsg = N_("E530: Cannot change term in GUI"); | |
697 else if (term_is_gui(T_NAME)) | |
698 errmsg = N_("E531: Use \":gui\" to start the GUI"); | |
699 #endif | |
700 else if (set_termname(T_NAME) == FAIL) | |
701 errmsg = N_("E522: Not found in termcap"); | |
702 else | |
703 { | |
704 // Screen colors may have changed. | |
705 redraw_later_clear(); | |
706 | |
707 // Both 'term' and 'ttytype' point to T_NAME, only set the | |
708 // P_ALLOCED flag on 'term'. | |
709 opt_idx = findoption((char_u *)"term"); | |
710 free_oldval = (get_option_flags(opt_idx) & P_ALLOCED); | |
711 } | |
712 } | |
713 | |
714 // 'backupcopy' | |
715 else if (gvarp == &p_bkc) | |
716 { | |
717 char_u *bkc = p_bkc; | |
718 unsigned int *flags = &bkc_flags; | |
719 | |
720 if (opt_flags & OPT_LOCAL) | |
721 { | |
722 bkc = curbuf->b_p_bkc; | |
723 flags = &curbuf->b_bkc_flags; | |
724 } | |
725 | |
726 if ((opt_flags & OPT_LOCAL) && *bkc == NUL) | |
727 // make the local value empty: use the global value | |
728 *flags = 0; | |
729 else | |
730 { | |
731 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK) | |
732 errmsg = e_invarg; | |
733 if ((((int)*flags & BKC_AUTO) != 0) | |
734 + (((int)*flags & BKC_YES) != 0) | |
735 + (((int)*flags & BKC_NO) != 0) != 1) | |
736 { | |
737 // Must have exactly one of "auto", "yes" and "no". | |
738 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE); | |
739 errmsg = e_invarg; | |
740 } | |
741 } | |
742 } | |
743 | |
744 // 'backupext' and 'patchmode' | |
745 else if (varp == &p_bex || varp == &p_pm) | |
746 { | |
747 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex, | |
748 *p_pm == '.' ? p_pm + 1 : p_pm) == 0) | |
749 errmsg = N_("E589: 'backupext' and 'patchmode' are equal"); | |
750 } | |
751 #ifdef FEAT_LINEBREAK | |
752 // 'breakindentopt' | |
753 else if (varp == &curwin->w_p_briopt) | |
754 { | |
755 if (briopt_check(curwin) == FAIL) | |
756 errmsg = e_invarg; | |
757 } | |
758 #endif | |
759 | |
760 // 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[] | |
761 // If the new option is invalid, use old value. 'lisp' option: refill | |
762 // g_chartab[] for '-' char | |
763 else if ( varp == &p_isi | |
764 || varp == &(curbuf->b_p_isk) | |
765 || varp == &p_isp | |
766 || varp == &p_isf) | |
767 { | |
768 if (init_chartab() == FAIL) | |
769 { | |
770 did_chartab = TRUE; // need to restore it below | |
771 errmsg = e_invarg; // error in value | |
772 } | |
773 } | |
774 | |
775 // 'helpfile' | |
776 else if (varp == &p_hf) | |
777 { | |
778 // May compute new values for $VIM and $VIMRUNTIME | |
779 if (didset_vim) | |
780 { | |
781 vim_setenv((char_u *)"VIM", (char_u *)""); | |
782 didset_vim = FALSE; | |
783 } | |
784 if (didset_vimruntime) | |
785 { | |
786 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)""); | |
787 didset_vimruntime = FALSE; | |
788 } | |
789 } | |
790 | |
791 #ifdef FEAT_SYN_HL | |
792 // 'cursorlineopt' | |
793 else if (varp == &curwin->w_p_culopt | |
794 || gvarp == &curwin->w_allbuf_opt.wo_culopt) | |
795 { | |
796 if (**varp == NUL || fill_culopt_flags(*varp, curwin) != OK) | |
797 errmsg = e_invarg; | |
798 } | |
799 | |
800 // 'colorcolumn' | |
801 else if (varp == &curwin->w_p_cc) | |
802 errmsg = check_colorcolumn(curwin); | |
803 #endif | |
804 | |
805 #ifdef FEAT_MULTI_LANG | |
806 // 'helplang' | |
807 else if (varp == &p_hlg) | |
808 { | |
809 // Check for "", "ab", "ab,cd", etc. | |
810 for (s = p_hlg; *s != NUL; s += 3) | |
811 { | |
812 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL)) | |
813 { | |
814 errmsg = e_invarg; | |
815 break; | |
816 } | |
817 if (s[2] == NUL) | |
818 break; | |
819 } | |
820 } | |
821 #endif | |
822 | |
823 // 'highlight' | |
824 else if (varp == &p_hl) | |
825 { | |
826 if (highlight_changed() == FAIL) | |
827 errmsg = e_invarg; // invalid flags | |
828 } | |
829 | |
830 // 'nrformats' | |
831 else if (gvarp == &p_nf) | |
832 { | |
833 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK) | |
834 errmsg = e_invarg; | |
835 } | |
836 | |
837 #ifdef FEAT_SESSION | |
838 // 'sessionoptions' | |
839 else if (varp == &p_ssop) | |
840 { | |
841 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK) | |
842 errmsg = e_invarg; | |
843 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR)) | |
844 { | |
845 // Don't allow both "sesdir" and "curdir". | |
846 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE); | |
847 errmsg = e_invarg; | |
848 } | |
849 } | |
850 // 'viewoptions' | |
851 else if (varp == &p_vop) | |
852 { | |
853 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK) | |
854 errmsg = e_invarg; | |
855 } | |
856 #endif | |
857 | |
858 // 'scrollopt' | |
859 else if (varp == &p_sbo) | |
860 { | |
861 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK) | |
862 errmsg = e_invarg; | |
863 } | |
864 | |
865 // 'ambiwidth' | |
866 else if (varp == &p_ambw || varp == &p_emoji) | |
867 { | |
868 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK) | |
869 errmsg = e_invarg; | |
870 else if (set_chars_option(&p_lcs) != NULL) | |
871 errmsg = _("E834: Conflicts with value of 'listchars'"); | |
872 else if (set_chars_option(&p_fcs) != NULL) | |
873 errmsg = _("E835: Conflicts with value of 'fillchars'"); | |
874 } | |
875 | |
876 // 'background' | |
877 else if (varp == &p_bg) | |
878 { | |
879 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK) | |
880 { | |
881 #ifdef FEAT_EVAL | |
882 int dark = (*p_bg == 'd'); | |
883 #endif | |
884 | |
885 init_highlight(FALSE, FALSE); | |
886 | |
887 #ifdef FEAT_EVAL | |
888 if (dark != (*p_bg == 'd') | |
889 && get_var_value((char_u *)"g:colors_name") != NULL) | |
890 { | |
891 // The color scheme must have set 'background' back to another | |
892 // value, that's not what we want here. Disable the color | |
893 // scheme and set the colors again. | |
894 do_unlet((char_u *)"g:colors_name", TRUE); | |
895 free_string_option(p_bg); | |
896 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light")); | |
897 check_string_option(&p_bg); | |
898 init_highlight(FALSE, FALSE); | |
899 } | |
900 #endif | |
901 } | |
902 else | |
903 errmsg = e_invarg; | |
904 } | |
905 | |
906 // 'wildmode' | |
907 else if (varp == &p_wim) | |
908 { | |
909 if (check_opt_wim() == FAIL) | |
910 errmsg = e_invarg; | |
911 } | |
912 | |
913 // 'wildoptions' | |
914 else if (varp == &p_wop) | |
915 { | |
916 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK) | |
917 errmsg = e_invarg; | |
918 } | |
919 | |
920 #ifdef FEAT_WAK | |
921 // 'winaltkeys' | |
922 else if (varp == &p_wak) | |
923 { | |
924 if (*p_wak == NUL | |
925 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK) | |
926 errmsg = e_invarg; | |
927 # ifdef FEAT_MENU | |
928 # ifdef FEAT_GUI_MOTIF | |
929 else if (gui.in_use) | |
930 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm'); | |
931 # else | |
932 # ifdef FEAT_GUI_GTK | |
933 else if (gui.in_use) | |
934 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm'); | |
935 # endif | |
936 # endif | |
937 # endif | |
938 } | |
939 #endif | |
940 | |
941 // 'eventignore' | |
942 else if (varp == &p_ei) | |
943 { | |
944 if (check_ei() == FAIL) | |
945 errmsg = e_invarg; | |
946 } | |
947 | |
948 // 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' | |
949 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc | |
950 || gvarp == &p_menc) | |
951 { | |
952 if (gvarp == &p_fenc) | |
953 { | |
954 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL) | |
955 errmsg = e_modifiable; | |
956 else if (vim_strchr(*varp, ',') != NULL) | |
957 // No comma allowed in 'fileencoding'; catches confusing it | |
958 // with 'fileencodings'. | |
959 errmsg = e_invarg; | |
960 else | |
961 { | |
962 #ifdef FEAT_TITLE | |
963 // May show a "+" in the title now. | |
964 redraw_titles(); | |
965 #endif | |
966 // Add 'fileencoding' to the swap file. | |
967 ml_setflags(curbuf); | |
968 } | |
969 } | |
970 if (errmsg == NULL) | |
971 { | |
972 // canonize the value, so that STRCMP() can be used on it | |
973 p = enc_canonize(*varp); | |
974 if (p != NULL) | |
975 { | |
976 vim_free(*varp); | |
977 *varp = p; | |
978 } | |
979 if (varp == &p_enc) | |
980 { | |
981 errmsg = mb_init(); | |
982 #ifdef FEAT_TITLE | |
983 redraw_titles(); | |
984 #endif | |
985 } | |
986 } | |
987 | |
988 #if defined(FEAT_GUI_GTK) | |
989 if (errmsg == NULL && varp == &p_tenc && gui.in_use) | |
990 { | |
991 // GTK+ 2 uses only a single encoding, and that is UTF-8. | |
992 if (STRCMP(p_tenc, "utf-8") != 0) | |
993 errmsg = N_("E617: Cannot be changed in the GTK+ 2 GUI"); | |
994 } | |
995 #endif | |
996 | |
997 if (errmsg == NULL) | |
998 { | |
999 #ifdef FEAT_KEYMAP | |
1000 // When 'keymap' is used and 'encoding' changes, reload the keymap | |
1001 // (with another encoding). | |
1002 if (varp == &p_enc && *curbuf->b_p_keymap != NUL) | |
1003 (void)keymap_init(); | |
1004 #endif | |
1005 | |
1006 // When 'termencoding' is not empty and 'encoding' changes or when | |
1007 // 'termencoding' changes, need to setup for keyboard input and | |
1008 // display output conversion. | |
1009 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc)) | |
1010 { | |
1011 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL | |
1012 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL) | |
1013 { | |
1014 semsg(_("E950: Cannot convert between %s and %s"), | |
1015 p_tenc, p_enc); | |
1016 errmsg = e_invarg; | |
1017 } | |
1018 } | |
1019 | |
1020 #if defined(MSWIN) | |
1021 // $HOME may have characters in active code page. | |
1022 if (varp == &p_enc) | |
1023 init_homedir(); | |
1024 #endif | |
1025 } | |
1026 } | |
1027 | |
1028 #if defined(FEAT_POSTSCRIPT) | |
1029 else if (varp == &p_penc) | |
1030 { | |
1031 // Canonize printencoding if VIM standard one | |
1032 p = enc_canonize(p_penc); | |
1033 if (p != NULL) | |
1034 { | |
1035 vim_free(p_penc); | |
1036 p_penc = p; | |
1037 } | |
1038 else | |
1039 { | |
1040 // Ensure lower case and '-' for '_' | |
1041 for (s = p_penc; *s != NUL; s++) | |
1042 { | |
1043 if (*s == '_') | |
1044 *s = '-'; | |
1045 else | |
1046 *s = TOLOWER_ASC(*s); | |
1047 } | |
1048 } | |
1049 } | |
1050 #endif | |
1051 | |
1052 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) | |
1053 else if (varp == &p_imak) | |
1054 { | |
1055 if (!im_xim_isvalid_imactivate()) | |
1056 errmsg = e_invarg; | |
1057 } | |
1058 #endif | |
1059 | |
1060 #ifdef FEAT_KEYMAP | |
1061 else if (varp == &curbuf->b_p_keymap) | |
1062 { | |
1063 if (!valid_filetype(*varp)) | |
1064 errmsg = e_invarg; | |
1065 else | |
1066 { | |
1067 int secure_save = secure; | |
1068 | |
1069 // Reset the secure flag, since the value of 'keymap' has | |
1070 // been checked to be safe. | |
1071 secure = 0; | |
1072 | |
1073 // load or unload key mapping tables | |
1074 errmsg = keymap_init(); | |
1075 | |
1076 secure = secure_save; | |
1077 | |
1078 // Since we check the value, there is no need to set P_INSECURE, | |
1079 // even when the value comes from a modeline. | |
1080 *value_checked = TRUE; | |
1081 } | |
1082 | |
1083 if (errmsg == NULL) | |
1084 { | |
1085 if (*curbuf->b_p_keymap != NUL) | |
1086 { | |
1087 // Installed a new keymap, switch on using it. | |
1088 curbuf->b_p_iminsert = B_IMODE_LMAP; | |
1089 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT) | |
1090 curbuf->b_p_imsearch = B_IMODE_LMAP; | |
1091 } | |
1092 else | |
1093 { | |
1094 // Cleared the keymap, may reset 'iminsert' and 'imsearch'. | |
1095 if (curbuf->b_p_iminsert == B_IMODE_LMAP) | |
1096 curbuf->b_p_iminsert = B_IMODE_NONE; | |
1097 if (curbuf->b_p_imsearch == B_IMODE_LMAP) | |
1098 curbuf->b_p_imsearch = B_IMODE_USE_INSERT; | |
1099 } | |
1100 if ((opt_flags & OPT_LOCAL) == 0) | |
1101 { | |
1102 set_iminsert_global(); | |
1103 set_imsearch_global(); | |
1104 } | |
1105 status_redraw_curbuf(); | |
1106 } | |
1107 } | |
1108 #endif | |
1109 | |
1110 // 'fileformat' | |
1111 else if (gvarp == &p_ff) | |
1112 { | |
1113 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL)) | |
1114 errmsg = e_modifiable; | |
1115 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK) | |
1116 errmsg = e_invarg; | |
1117 else | |
1118 { | |
1119 // may also change 'textmode' | |
1120 if (get_fileformat(curbuf) == EOL_DOS) | |
1121 curbuf->b_p_tx = TRUE; | |
1122 else | |
1123 curbuf->b_p_tx = FALSE; | |
1124 #ifdef FEAT_TITLE | |
1125 redraw_titles(); | |
1126 #endif | |
1127 // update flag in swap file | |
1128 ml_setflags(curbuf); | |
1129 // Redraw needed when switching to/from "mac": a CR in the text | |
1130 // will be displayed differently. | |
1131 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm') | |
1132 redraw_curbuf_later(NOT_VALID); | |
1133 } | |
1134 } | |
1135 | |
1136 // 'fileformats' | |
1137 else if (varp == &p_ffs) | |
1138 { | |
1139 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK) | |
1140 errmsg = e_invarg; | |
1141 else | |
1142 { | |
1143 // also change 'textauto' | |
1144 if (*p_ffs == NUL) | |
1145 p_ta = FALSE; | |
1146 else | |
1147 p_ta = TRUE; | |
1148 } | |
1149 } | |
1150 | |
1151 #if defined(FEAT_CRYPT) | |
1152 // 'cryptkey' | |
1153 else if (gvarp == &p_key) | |
1154 { | |
1155 // Make sure the ":set" command doesn't show the new value in the | |
1156 // history. | |
1157 remove_key_from_history(); | |
1158 | |
1159 if (STRCMP(curbuf->b_p_key, oldval) != 0) | |
1160 // Need to update the swapfile. | |
1161 ml_set_crypt_key(curbuf, oldval, | |
1162 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm); | |
1163 } | |
1164 | |
1165 else if (gvarp == &p_cm) | |
1166 { | |
1167 if (opt_flags & OPT_LOCAL) | |
1168 p = curbuf->b_p_cm; | |
1169 else | |
1170 p = p_cm; | |
1171 if (check_opt_strings(p, p_cm_values, TRUE) != OK) | |
1172 errmsg = e_invarg; | |
1173 else if (crypt_self_test() == FAIL) | |
1174 errmsg = e_invarg; | |
1175 else | |
1176 { | |
1177 // When setting the global value to empty, make it "zip". | |
1178 if (*p_cm == NUL) | |
1179 { | |
1180 if (new_value_alloced) | |
1181 free_string_option(p_cm); | |
1182 p_cm = vim_strsave((char_u *)"zip"); | |
1183 new_value_alloced = TRUE; | |
1184 } | |
1185 // When using ":set cm=name" the local value is going to be empty. | |
1186 // Do that here, otherwise the crypt functions will still use the | |
1187 // local value. | |
1188 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) | |
1189 { | |
1190 free_string_option(curbuf->b_p_cm); | |
1191 curbuf->b_p_cm = empty_option; | |
1192 } | |
1193 | |
1194 // Need to update the swapfile when the effective method changed. | |
1195 // Set "s" to the effective old value, "p" to the effective new | |
1196 // method and compare. | |
1197 if ((opt_flags & OPT_LOCAL) && *oldval == NUL) | |
1198 s = p_cm; // was previously using the global value | |
1199 else | |
1200 s = oldval; | |
1201 if (*curbuf->b_p_cm == NUL) | |
1202 p = p_cm; // is now using the global value | |
1203 else | |
1204 p = curbuf->b_p_cm; | |
1205 if (STRCMP(s, p) != 0) | |
1206 ml_set_crypt_key(curbuf, curbuf->b_p_key, s); | |
1207 | |
1208 // If the global value changes need to update the swapfile for all | |
1209 // buffers using that value. | |
1210 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0) | |
1211 { | |
1212 buf_T *buf; | |
1213 | |
1214 FOR_ALL_BUFFERS(buf) | |
1215 if (buf != curbuf && *buf->b_p_cm == NUL) | |
1216 ml_set_crypt_key(buf, buf->b_p_key, oldval); | |
1217 } | |
1218 } | |
1219 } | |
1220 #endif | |
1221 | |
1222 // 'matchpairs' | |
1223 else if (gvarp == &p_mps) | |
1224 { | |
1225 if (has_mbyte) | |
1226 { | |
1227 for (p = *varp; *p != NUL; ++p) | |
1228 { | |
1229 int x2 = -1; | |
1230 int x3 = -1; | |
1231 | |
1232 if (*p != NUL) | |
1233 p += mb_ptr2len(p); | |
1234 if (*p != NUL) | |
1235 x2 = *p++; | |
1236 if (*p != NUL) | |
1237 { | |
1238 x3 = mb_ptr2char(p); | |
1239 p += mb_ptr2len(p); | |
1240 } | |
1241 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ',')) | |
1242 { | |
1243 errmsg = e_invarg; | |
1244 break; | |
1245 } | |
1246 if (*p == NUL) | |
1247 break; | |
1248 } | |
1249 } | |
1250 else | |
1251 { | |
1252 // Check for "x:y,x:y" | |
1253 for (p = *varp; *p != NUL; p += 4) | |
1254 { | |
1255 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ',')) | |
1256 { | |
1257 errmsg = e_invarg; | |
1258 break; | |
1259 } | |
1260 if (p[3] == NUL) | |
1261 break; | |
1262 } | |
1263 } | |
1264 } | |
1265 | |
1266 #ifdef FEAT_COMMENTS | |
1267 // 'comments' | |
1268 else if (gvarp == &p_com) | |
1269 { | |
1270 for (s = *varp; *s; ) | |
1271 { | |
1272 while (*s && *s != ':') | |
1273 { | |
1274 if (vim_strchr((char_u *)COM_ALL, *s) == NULL | |
1275 && !VIM_ISDIGIT(*s) && *s != '-') | |
1276 { | |
1277 errmsg = illegal_char(errbuf, *s); | |
1278 break; | |
1279 } | |
1280 ++s; | |
1281 } | |
1282 if (*s++ == NUL) | |
1283 errmsg = N_("E524: Missing colon"); | |
1284 else if (*s == ',' || *s == NUL) | |
1285 errmsg = N_("E525: Zero length string"); | |
1286 if (errmsg != NULL) | |
1287 break; | |
1288 while (*s && *s != ',') | |
1289 { | |
1290 if (*s == '\\' && s[1] != NUL) | |
1291 ++s; | |
1292 ++s; | |
1293 } | |
1294 s = skip_to_option_part(s); | |
1295 } | |
1296 } | |
1297 #endif | |
1298 | |
1299 // 'listchars' | |
1300 else if (varp == &p_lcs) | |
1301 { | |
1302 errmsg = set_chars_option(varp); | |
1303 } | |
1304 | |
1305 // 'fillchars' | |
1306 else if (varp == &p_fcs) | |
1307 { | |
1308 errmsg = set_chars_option(varp); | |
1309 } | |
1310 | |
1311 #ifdef FEAT_CMDWIN | |
1312 // 'cedit' | |
1313 else if (varp == &p_cedit) | |
1314 { | |
1315 errmsg = check_cedit(); | |
1316 } | |
1317 #endif | |
1318 | |
1319 // 'verbosefile' | |
1320 else if (varp == &p_vfile) | |
1321 { | |
1322 verbose_stop(); | |
1323 if (*p_vfile != NUL && verbose_open() == FAIL) | |
1324 errmsg = e_invarg; | |
1325 } | |
1326 | |
1327 #ifdef FEAT_VIMINFO | |
1328 // 'viminfo' | |
1329 else if (varp == &p_viminfo) | |
1330 { | |
1331 for (s = p_viminfo; *s;) | |
1332 { | |
1333 // Check it's a valid character | |
1334 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL) | |
1335 { | |
1336 errmsg = illegal_char(errbuf, *s); | |
1337 break; | |
1338 } | |
1339 if (*s == 'n') // name is always last one | |
1340 break; | |
1341 else if (*s == 'r') // skip until next ',' | |
1342 { | |
1343 while (*++s && *s != ',') | |
1344 ; | |
1345 } | |
1346 else if (*s == '%') | |
1347 { | |
1348 // optional number | |
1349 while (vim_isdigit(*++s)) | |
1350 ; | |
1351 } | |
1352 else if (*s == '!' || *s == 'h' || *s == 'c') | |
1353 ++s; // no extra chars | |
1354 else // must have a number | |
1355 { | |
1356 while (vim_isdigit(*++s)) | |
1357 ; | |
1358 | |
1359 if (!VIM_ISDIGIT(*(s - 1))) | |
1360 { | |
1361 if (errbuf != NULL) | |
1362 { | |
1363 sprintf(errbuf, _("E526: Missing number after <%s>"), | |
1364 transchar_byte(*(s - 1))); | |
1365 errmsg = errbuf; | |
1366 } | |
1367 else | |
1368 errmsg = ""; | |
1369 break; | |
1370 } | |
1371 } | |
1372 if (*s == ',') | |
1373 ++s; | |
1374 else if (*s) | |
1375 { | |
1376 if (errbuf != NULL) | |
1377 errmsg = N_("E527: Missing comma"); | |
1378 else | |
1379 errmsg = ""; | |
1380 break; | |
1381 } | |
1382 } | |
1383 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0) | |
1384 errmsg = N_("E528: Must specify a ' value"); | |
1385 } | |
1386 #endif // FEAT_VIMINFO | |
1387 | |
1388 // terminal options | |
1389 else if (istermoption_idx(opt_idx) && full_screen) | |
1390 { | |
1391 // ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" | |
1392 if (varp == &T_CCO) | |
1393 { | |
1394 int colors = atoi((char *)T_CCO); | |
1395 | |
1396 // Only reinitialize colors if t_Co value has really changed to | |
1397 // avoid expensive reload of colorscheme if t_Co is set to the | |
1398 // same value multiple times. | |
1399 if (colors != t_colors) | |
1400 { | |
1401 t_colors = colors; | |
1402 if (t_colors <= 1) | |
1403 { | |
1404 if (new_value_alloced) | |
1405 vim_free(T_CCO); | |
1406 T_CCO = empty_option; | |
1407 } | |
1408 #if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS) | |
1409 if (is_term_win32()) | |
1410 { | |
1411 swap_tcap(); | |
1412 did_swaptcap = TRUE; | |
1413 } | |
1414 #endif | |
1415 // We now have a different color setup, initialize it again. | |
1416 init_highlight(TRUE, FALSE); | |
1417 } | |
1418 } | |
1419 ttest(FALSE); | |
1420 if (varp == &T_ME) | |
1421 { | |
1422 out_str(T_ME); | |
1423 redraw_later(CLEAR); | |
1424 #if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL)) | |
1425 // Since t_me has been set, this probably means that the user | |
1426 // wants to use this as default colors. Need to reset default | |
1427 // background/foreground colors. | |
1428 # ifdef VIMDLL | |
1429 if (!gui.in_use && !gui.starting) | |
1430 # endif | |
1431 mch_set_normal_colors(); | |
1432 #endif | |
1433 } | |
1434 if (varp == &T_BE && termcap_active) | |
1435 { | |
1436 if (*T_BE == NUL) | |
1437 // When clearing t_BE we assume the user no longer wants | |
1438 // bracketed paste, thus disable it by writing t_BD. | |
1439 out_str(T_BD); | |
1440 else | |
1441 out_str(T_BE); | |
1442 } | |
1443 } | |
1444 | |
1445 #ifdef FEAT_LINEBREAK | |
1446 // 'showbreak' | |
1447 else if (varp == &p_sbr) | |
1448 { | |
1449 for (s = p_sbr; *s; ) | |
1450 { | |
1451 if (ptr2cells(s) != 1) | |
1452 errmsg = N_("E595: contains unprintable or wide character"); | |
1453 MB_PTR_ADV(s); | |
1454 } | |
1455 } | |
1456 #endif | |
1457 | |
1458 #ifdef FEAT_GUI | |
1459 // 'guifont' | |
1460 else if (varp == &p_guifont) | |
1461 { | |
1462 if (gui.in_use) | |
1463 { | |
1464 p = p_guifont; | |
1465 # if defined(FEAT_GUI_GTK) | |
1466 // Put up a font dialog and let the user select a new value. | |
1467 // If this is cancelled go back to the old value but don't | |
1468 // give an error message. | |
1469 if (STRCMP(p, "*") == 0) | |
1470 { | |
1471 p = gui_mch_font_dialog(oldval); | |
1472 | |
1473 if (new_value_alloced) | |
1474 free_string_option(p_guifont); | |
1475 | |
1476 p_guifont = (p != NULL) ? p : vim_strsave(oldval); | |
1477 new_value_alloced = TRUE; | |
1478 } | |
1479 # endif | |
1480 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK) | |
1481 { | |
1482 # if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON) | |
1483 if (STRCMP(p_guifont, "*") == 0) | |
1484 { | |
1485 // Dialog was cancelled: Keep the old value without giving | |
1486 // an error message. | |
1487 if (new_value_alloced) | |
1488 free_string_option(p_guifont); | |
1489 p_guifont = vim_strsave(oldval); | |
1490 new_value_alloced = TRUE; | |
1491 } | |
1492 else | |
1493 # endif | |
1494 errmsg = N_("E596: Invalid font(s)"); | |
1495 } | |
1496 } | |
1497 redraw_gui_only = TRUE; | |
1498 } | |
1499 # ifdef FEAT_XFONTSET | |
1500 else if (varp == &p_guifontset) | |
1501 { | |
1502 if (STRCMP(p_guifontset, "*") == 0) | |
1503 errmsg = N_("E597: can't select fontset"); | |
1504 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK) | |
1505 errmsg = N_("E598: Invalid fontset"); | |
1506 redraw_gui_only = TRUE; | |
1507 } | |
1508 # endif | |
1509 else if (varp == &p_guifontwide) | |
1510 { | |
1511 if (STRCMP(p_guifontwide, "*") == 0) | |
1512 errmsg = N_("E533: can't select wide font"); | |
1513 else if (gui_get_wide_font() == FAIL) | |
1514 errmsg = N_("E534: Invalid wide font"); | |
1515 redraw_gui_only = TRUE; | |
1516 } | |
1517 #endif | |
1518 | |
1519 #ifdef CURSOR_SHAPE | |
1520 // 'guicursor' | |
1521 else if (varp == &p_guicursor) | |
1522 errmsg = parse_shape_opt(SHAPE_CURSOR); | |
1523 #endif | |
1524 | |
1525 #ifdef FEAT_MOUSESHAPE | |
1526 // 'mouseshape' | |
1527 else if (varp == &p_mouseshape) | |
1528 { | |
1529 errmsg = parse_shape_opt(SHAPE_MOUSE); | |
1530 update_mouseshape(-1); | |
1531 } | |
1532 #endif | |
1533 | |
1534 #ifdef FEAT_PRINTER | |
1535 else if (varp == &p_popt) | |
1536 errmsg = parse_printoptions(); | |
1537 # if defined(FEAT_POSTSCRIPT) | |
1538 else if (varp == &p_pmfn) | |
1539 errmsg = parse_printmbfont(); | |
1540 # endif | |
1541 #endif | |
1542 | |
1543 #ifdef FEAT_LANGMAP | |
1544 // 'langmap' | |
1545 else if (varp == &p_langmap) | |
1546 langmap_set(); | |
1547 #endif | |
1548 | |
1549 #ifdef FEAT_LINEBREAK | |
1550 // 'breakat' | |
1551 else if (varp == &p_breakat) | |
1552 fill_breakat_flags(); | |
1553 #endif | |
1554 | |
1555 #ifdef FEAT_TITLE | |
1556 // 'titlestring' and 'iconstring' | |
1557 else if (varp == &p_titlestring || varp == &p_iconstring) | |
1558 { | |
1559 # ifdef FEAT_STL_OPT | |
1560 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON; | |
1561 | |
1562 // NULL => statusline syntax | |
1563 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL) | |
1564 stl_syntax |= flagval; | |
1565 else | |
1566 stl_syntax &= ~flagval; | |
1567 # endif | |
1568 did_set_title(); | |
1569 } | |
1570 #endif | |
1571 | |
1572 #ifdef FEAT_GUI | |
1573 // 'guioptions' | |
1574 else if (varp == &p_go) | |
1575 { | |
1576 gui_init_which_components(oldval); | |
1577 redraw_gui_only = TRUE; | |
1578 } | |
1579 #endif | |
1580 | |
1581 #if defined(FEAT_GUI_TABLINE) | |
1582 // 'guitablabel' | |
1583 else if (varp == &p_gtl) | |
1584 { | |
1585 redraw_tabline = TRUE; | |
1586 redraw_gui_only = TRUE; | |
1587 } | |
1588 // 'guitabtooltip' | |
1589 else if (varp == &p_gtt) | |
1590 { | |
1591 redraw_gui_only = TRUE; | |
1592 } | |
1593 #endif | |
1594 | |
1595 #if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS)) | |
1596 // 'ttymouse' | |
1597 else if (varp == &p_ttym) | |
1598 { | |
1599 // Switch the mouse off before changing the escape sequences used for | |
1600 // that. | |
1601 mch_setmouse(FALSE); | |
1602 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK) | |
1603 errmsg = e_invarg; | |
1604 else | |
1605 check_mouse_termcode(); | |
1606 if (termcap_active) | |
1607 setmouse(); // may switch it on again | |
1608 } | |
1609 #endif | |
1610 | |
1611 // 'selection' | |
1612 else if (varp == &p_sel) | |
1613 { | |
1614 if (*p_sel == NUL | |
1615 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK) | |
1616 errmsg = e_invarg; | |
1617 } | |
1618 | |
1619 // 'selectmode' | |
1620 else if (varp == &p_slm) | |
1621 { | |
1622 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK) | |
1623 errmsg = e_invarg; | |
1624 } | |
1625 | |
1626 #ifdef FEAT_BROWSE | |
1627 // 'browsedir' | |
1628 else if (varp == &p_bsdir) | |
1629 { | |
1630 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK | |
1631 && !mch_isdir(p_bsdir)) | |
1632 errmsg = e_invarg; | |
1633 } | |
1634 #endif | |
1635 | |
1636 // 'keymodel' | |
1637 else if (varp == &p_km) | |
1638 { | |
1639 if (check_opt_strings(p_km, p_km_values, TRUE) != OK) | |
1640 errmsg = e_invarg; | |
1641 else | |
1642 { | |
1643 km_stopsel = (vim_strchr(p_km, 'o') != NULL); | |
1644 km_startsel = (vim_strchr(p_km, 'a') != NULL); | |
1645 } | |
1646 } | |
1647 | |
1648 // 'mousemodel' | |
1649 else if (varp == &p_mousem) | |
1650 { | |
1651 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK) | |
1652 errmsg = e_invarg; | |
1653 #if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002) | |
1654 else if (*p_mousem != *oldval) | |
1655 // Changed from "extend" to "popup" or "popup_setpos" or vv: need | |
1656 // to create or delete the popup menus. | |
1657 gui_motif_update_mousemodel(root_menu); | |
1658 #endif | |
1659 } | |
1660 | |
1661 // 'switchbuf' | |
1662 else if (varp == &p_swb) | |
1663 { | |
1664 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK) | |
1665 errmsg = e_invarg; | |
1666 } | |
1667 | |
1668 // 'debug' | |
1669 else if (varp == &p_debug) | |
1670 { | |
1671 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK) | |
1672 errmsg = e_invarg; | |
1673 } | |
1674 | |
1675 // 'display' | |
1676 else if (varp == &p_dy) | |
1677 { | |
1678 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK) | |
1679 errmsg = e_invarg; | |
1680 else | |
1681 (void)init_chartab(); | |
1682 | |
1683 } | |
1684 | |
1685 // 'eadirection' | |
1686 else if (varp == &p_ead) | |
1687 { | |
1688 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK) | |
1689 errmsg = e_invarg; | |
1690 } | |
1691 | |
1692 #ifdef FEAT_CLIPBOARD | |
1693 // 'clipboard' | |
1694 else if (varp == &p_cb) | |
1695 errmsg = check_clipboard_option(); | |
1696 #endif | |
1697 | |
1698 #ifdef FEAT_SPELL | |
1699 // When 'spelllang' or 'spellfile' is set and there is a window for this | |
1700 // buffer in which 'spell' is set load the wordlists. | |
1701 else if (varp == &(curwin->w_s->b_p_spl) | |
1702 || varp == &(curwin->w_s->b_p_spf)) | |
1703 { | |
1704 int is_spellfile = varp == &(curwin->w_s->b_p_spf); | |
1705 | |
1706 if ((is_spellfile && !valid_spellfile(*varp)) | |
1707 || (!is_spellfile && !valid_spellang(*varp))) | |
1708 errmsg = e_invarg; | |
1709 else | |
1710 errmsg = did_set_spell_option(is_spellfile); | |
1711 } | |
1712 // When 'spellcapcheck' is set compile the regexp program. | |
1713 else if (varp == &(curwin->w_s->b_p_spc)) | |
1714 { | |
1715 errmsg = compile_cap_prog(curwin->w_s); | |
1716 } | |
1717 // 'spellsuggest' | |
1718 else if (varp == &p_sps) | |
1719 { | |
1720 if (spell_check_sps() != OK) | |
1721 errmsg = e_invarg; | |
1722 } | |
1723 // 'mkspellmem' | |
1724 else if (varp == &p_msm) | |
1725 { | |
1726 if (spell_check_msm() != OK) | |
1727 errmsg = e_invarg; | |
1728 } | |
1729 #endif | |
1730 | |
1731 // When 'bufhidden' is set, check for valid value. | |
1732 else if (gvarp == &p_bh) | |
1733 { | |
1734 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK) | |
1735 errmsg = e_invarg; | |
1736 } | |
1737 | |
1738 // When 'buftype' is set, check for valid value. | |
1739 else if (gvarp == &p_bt) | |
1740 { | |
1741 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK) | |
1742 errmsg = e_invarg; | |
1743 else | |
1744 { | |
1745 if (curwin->w_status_height) | |
1746 { | |
1747 curwin->w_redr_status = TRUE; | |
1748 redraw_later(VALID); | |
1749 } | |
1750 curbuf->b_help = (curbuf->b_p_bt[0] == 'h'); | |
1751 #ifdef FEAT_TITLE | |
1752 redraw_titles(); | |
1753 #endif | |
1754 } | |
1755 } | |
1756 | |
1757 #ifdef FEAT_STL_OPT | |
1758 // 'statusline' or 'rulerformat' | |
1759 else if (gvarp == &p_stl || varp == &p_ruf) | |
1760 { | |
1761 int wid; | |
1762 | |
1763 if (varp == &p_ruf) // reset ru_wid first | |
1764 ru_wid = 0; | |
1765 s = *varp; | |
1766 if (varp == &p_ruf && *s == '%') | |
1767 { | |
1768 // set ru_wid if 'ruf' starts with "%99(" | |
1769 if (*++s == '-') // ignore a '-' | |
1770 s++; | |
1771 wid = getdigits(&s); | |
1772 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL) | |
1773 ru_wid = wid; | |
1774 else | |
1775 errmsg = check_stl_option(p_ruf); | |
1776 } | |
1777 // check 'statusline' only if it doesn't start with "%!" | |
1778 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!') | |
1779 errmsg = check_stl_option(s); | |
1780 if (varp == &p_ruf && errmsg == NULL) | |
1781 comp_col(); | |
1782 } | |
1783 #endif | |
1784 | |
1785 // check if it is a valid value for 'complete' -- Acevedo | |
1786 else if (gvarp == &p_cpt) | |
1787 { | |
1788 for (s = *varp; *s;) | |
1789 { | |
1790 while (*s == ',' || *s == ' ') | |
1791 s++; | |
1792 if (!*s) | |
1793 break; | |
1794 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL) | |
1795 { | |
1796 errmsg = illegal_char(errbuf, *s); | |
1797 break; | |
1798 } | |
1799 if (*++s != NUL && *s != ',' && *s != ' ') | |
1800 { | |
1801 if (s[-1] == 'k' || s[-1] == 's') | |
1802 { | |
1803 // skip optional filename after 'k' and 's' | |
1804 while (*s && *s != ',' && *s != ' ') | |
1805 { | |
1806 if (*s == '\\' && s[1] != NUL) | |
1807 ++s; | |
1808 ++s; | |
1809 } | |
1810 } | |
1811 else | |
1812 { | |
1813 if (errbuf != NULL) | |
1814 { | |
1815 sprintf((char *)errbuf, | |
1816 _("E535: Illegal character after <%c>"), | |
1817 *--s); | |
1818 errmsg = errbuf; | |
1819 } | |
1820 else | |
1821 errmsg = ""; | |
1822 break; | |
1823 } | |
1824 } | |
1825 } | |
1826 } | |
1827 | |
1828 // 'completeopt' | |
1829 else if (varp == &p_cot) | |
1830 { | |
1831 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK) | |
1832 errmsg = e_invarg; | |
1833 else | |
1834 completeopt_was_set(); | |
1835 } | |
1836 | |
1837 #ifdef BACKSLASH_IN_FILENAME | |
1838 // 'completeslash' | |
1839 else if (gvarp == &p_csl) | |
1840 { | |
1841 if (check_opt_strings(p_csl, p_csl_values, FALSE) != OK | |
1842 || check_opt_strings(curbuf->b_p_csl, p_csl_values, FALSE) != OK) | |
1843 errmsg = e_invarg; | |
1844 } | |
1845 #endif | |
1846 | |
1847 #ifdef FEAT_SIGNS | |
1848 // 'signcolumn' | |
1849 else if (varp == &curwin->w_p_scl) | |
1850 { | |
1851 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK) | |
1852 errmsg = e_invarg; | |
1853 // When changing the 'signcolumn' to or from 'number', recompute the | |
1854 // width of the number column if 'number' or 'relativenumber' is set. | |
1855 if (((*oldval == 'n' && *(oldval + 1) == 'u') | |
1856 || (*curwin->w_p_scl == 'n' && *(curwin->w_p_scl + 1) =='u')) | |
1857 && (curwin->w_p_nu || curwin->w_p_rnu)) | |
1858 curwin->w_nrwidth_line_count = 0; | |
1859 } | |
1860 #endif | |
1861 | |
1862 | |
1863 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN) | |
1864 // 'toolbar' | |
1865 else if (varp == &p_toolbar) | |
1866 { | |
1867 if (opt_strings_flags(p_toolbar, p_toolbar_values, | |
1868 &toolbar_flags, TRUE) != OK) | |
1869 errmsg = e_invarg; | |
1870 else | |
1871 { | |
1872 out_flush(); | |
1873 gui_mch_show_toolbar((toolbar_flags & | |
1874 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0); | |
1875 } | |
1876 } | |
1877 #endif | |
1878 | |
1879 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) | |
1880 // 'toolbariconsize': GTK+ 2 only | |
1881 else if (varp == &p_tbis) | |
1882 { | |
1883 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK) | |
1884 errmsg = e_invarg; | |
1885 else | |
1886 { | |
1887 out_flush(); | |
1888 gui_mch_show_toolbar((toolbar_flags & | |
1889 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0); | |
1890 } | |
1891 } | |
1892 #endif | |
1893 | |
1894 // 'pastetoggle': translate key codes like in a mapping | |
1895 else if (varp == &p_pt) | |
1896 { | |
1897 if (*p_pt) | |
1898 { | |
1899 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE); | |
1900 if (p != NULL) | |
1901 { | |
1902 if (new_value_alloced) | |
1903 free_string_option(p_pt); | |
1904 p_pt = p; | |
1905 new_value_alloced = TRUE; | |
1906 } | |
1907 } | |
1908 } | |
1909 | |
1910 // 'backspace' | |
1911 else if (varp == &p_bs) | |
1912 { | |
1913 if (VIM_ISDIGIT(*p_bs)) | |
1914 { | |
1915 if (*p_bs > '2' || p_bs[1] != NUL) | |
1916 errmsg = e_invarg; | |
1917 } | |
1918 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK) | |
1919 errmsg = e_invarg; | |
1920 } | |
1921 else if (varp == &p_bo) | |
1922 { | |
1923 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK) | |
1924 errmsg = e_invarg; | |
1925 } | |
1926 | |
1927 // 'tagcase' | |
1928 else if (gvarp == &p_tc) | |
1929 { | |
1930 unsigned int *flags; | |
1931 | |
1932 if (opt_flags & OPT_LOCAL) | |
1933 { | |
1934 p = curbuf->b_p_tc; | |
1935 flags = &curbuf->b_tc_flags; | |
1936 } | |
1937 else | |
1938 { | |
1939 p = p_tc; | |
1940 flags = &tc_flags; | |
1941 } | |
1942 | |
1943 if ((opt_flags & OPT_LOCAL) && *p == NUL) | |
1944 // make the local value empty: use the global value | |
1945 *flags = 0; | |
1946 else if (*p == NUL | |
1947 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK) | |
1948 errmsg = e_invarg; | |
1949 } | |
1950 | |
1951 // 'casemap' | |
1952 else if (varp == &p_cmp) | |
1953 { | |
1954 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK) | |
1955 errmsg = e_invarg; | |
1956 } | |
1957 | |
1958 #ifdef FEAT_DIFF | |
1959 // 'diffopt' | |
1960 else if (varp == &p_dip) | |
1961 { | |
1962 if (diffopt_changed() == FAIL) | |
1963 errmsg = e_invarg; | |
1964 } | |
1965 #endif | |
1966 | |
1967 #ifdef FEAT_FOLDING | |
1968 // 'foldmethod' | |
1969 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm) | |
1970 { | |
1971 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK | |
1972 || *curwin->w_p_fdm == NUL) | |
1973 errmsg = e_invarg; | |
1974 else | |
1975 { | |
1976 foldUpdateAll(curwin); | |
1977 if (foldmethodIsDiff(curwin)) | |
1978 newFoldLevel(); | |
1979 } | |
1980 } | |
1981 # ifdef FEAT_EVAL | |
1982 // 'foldexpr' | |
1983 else if (varp == &curwin->w_p_fde) | |
1984 { | |
1985 if (foldmethodIsExpr(curwin)) | |
1986 foldUpdateAll(curwin); | |
1987 } | |
1988 # endif | |
1989 // 'foldmarker' | |
1990 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr) | |
1991 { | |
1992 p = vim_strchr(*varp, ','); | |
1993 if (p == NULL) | |
1994 errmsg = N_("E536: comma required"); | |
1995 else if (p == *varp || p[1] == NUL) | |
1996 errmsg = e_invarg; | |
1997 else if (foldmethodIsMarker(curwin)) | |
1998 foldUpdateAll(curwin); | |
1999 } | |
2000 // 'commentstring' | |
2001 else if (gvarp == &p_cms) | |
2002 { | |
2003 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL) | |
2004 errmsg = N_("E537: 'commentstring' must be empty or contain %s"); | |
2005 } | |
2006 // 'foldopen' | |
2007 else if (varp == &p_fdo) | |
2008 { | |
2009 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK) | |
2010 errmsg = e_invarg; | |
2011 } | |
2012 // 'foldclose' | |
2013 else if (varp == &p_fcl) | |
2014 { | |
2015 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK) | |
2016 errmsg = e_invarg; | |
2017 } | |
2018 // 'foldignore' | |
2019 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi) | |
2020 { | |
2021 if (foldmethodIsIndent(curwin)) | |
2022 foldUpdateAll(curwin); | |
2023 } | |
2024 #endif | |
2025 | |
2026 // 'virtualedit' | |
2027 else if (varp == &p_ve) | |
2028 { | |
2029 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK) | |
2030 errmsg = e_invarg; | |
2031 else if (STRCMP(p_ve, oldval) != 0) | |
2032 { | |
2033 // Recompute cursor position in case the new 've' setting | |
2034 // changes something. | |
2035 validate_virtcol(); | |
2036 coladvance(curwin->w_virtcol); | |
2037 } | |
2038 } | |
2039 | |
2040 #if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX) | |
2041 else if (varp == &p_csqf) | |
2042 { | |
2043 if (p_csqf != NULL) | |
2044 { | |
2045 p = p_csqf; | |
2046 while (*p != NUL) | |
2047 { | |
2048 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL | |
2049 || p[1] == NUL | |
2050 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL | |
2051 || (p[2] != NUL && p[2] != ',')) | |
2052 { | |
2053 errmsg = e_invarg; | |
2054 break; | |
2055 } | |
2056 else if (p[2] == NUL) | |
2057 break; | |
2058 else | |
2059 p += 3; | |
2060 } | |
2061 } | |
2062 } | |
2063 #endif | |
2064 | |
2065 #ifdef FEAT_CINDENT | |
2066 // 'cinoptions' | |
2067 else if (gvarp == &p_cino) | |
2068 { | |
2069 // TODO: recognize errors | |
2070 parse_cino(curbuf); | |
2071 } | |
2072 #endif | |
2073 | |
2074 #if defined(FEAT_RENDER_OPTIONS) | |
2075 // 'renderoptions' | |
2076 else if (varp == &p_rop) | |
2077 { | |
2078 if (!gui_mch_set_rendering_options(p_rop)) | |
2079 errmsg = e_invarg; | |
2080 } | |
2081 #endif | |
2082 | |
2083 else if (gvarp == &p_ft) | |
2084 { | |
2085 if (!valid_filetype(*varp)) | |
2086 errmsg = e_invarg; | |
2087 else | |
2088 { | |
2089 value_changed = STRCMP(oldval, *varp) != 0; | |
2090 | |
2091 // Since we check the value, there is no need to set P_INSECURE, | |
2092 // even when the value comes from a modeline. | |
2093 *value_checked = TRUE; | |
2094 } | |
2095 } | |
2096 | |
2097 #ifdef FEAT_SYN_HL | |
2098 else if (gvarp == &p_syn) | |
2099 { | |
2100 if (!valid_filetype(*varp)) | |
2101 errmsg = e_invarg; | |
2102 else | |
2103 { | |
2104 value_changed = STRCMP(oldval, *varp) != 0; | |
2105 | |
2106 // Since we check the value, there is no need to set P_INSECURE, | |
2107 // even when the value comes from a modeline. | |
2108 *value_checked = TRUE; | |
2109 } | |
2110 } | |
2111 #endif | |
2112 | |
2113 #ifdef FEAT_TERMINAL | |
2114 // 'termwinkey' | |
2115 else if (varp == &curwin->w_p_twk) | |
2116 { | |
2117 if (*curwin->w_p_twk != NUL | |
2118 && string_to_key(curwin->w_p_twk, TRUE) == 0) | |
2119 errmsg = e_invarg; | |
2120 } | |
2121 // 'termwinsize' | |
2122 else if (varp == &curwin->w_p_tws) | |
2123 { | |
2124 if (*curwin->w_p_tws != NUL) | |
2125 { | |
2126 p = skipdigits(curwin->w_p_tws); | |
2127 if (p == curwin->w_p_tws | |
2128 || (*p != 'x' && *p != '*') | |
2129 || *skipdigits(p + 1) != NUL) | |
2130 errmsg = e_invarg; | |
2131 } | |
2132 } | |
2133 # if defined(MSWIN) | |
2134 // 'termwintype' | |
2135 else if (varp == &p_twt) | |
2136 { | |
2137 if (check_opt_strings(*varp, p_twt_values, FALSE) != OK) | |
2138 errmsg = e_invarg; | |
2139 } | |
2140 # endif | |
2141 #endif | |
2142 | |
2143 #ifdef FEAT_VARTABS | |
2144 // 'varsofttabstop' | |
2145 else if (varp == &(curbuf->b_p_vsts)) | |
2146 { | |
2147 char_u *cp; | |
2148 | |
2149 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1])) | |
2150 { | |
2151 if (curbuf->b_p_vsts_array) | |
2152 { | |
2153 vim_free(curbuf->b_p_vsts_array); | |
2154 curbuf->b_p_vsts_array = 0; | |
2155 } | |
2156 } | |
2157 else | |
2158 { | |
2159 for (cp = *varp; *cp; ++cp) | |
2160 { | |
2161 if (vim_isdigit(*cp)) | |
2162 continue; | |
2163 if (*cp == ',' && cp > *varp && *(cp-1) != ',') | |
2164 continue; | |
2165 errmsg = e_invarg; | |
2166 break; | |
2167 } | |
2168 if (errmsg == NULL) | |
2169 { | |
2170 int *oldarray = curbuf->b_p_vsts_array; | |
2171 if (tabstop_set(*varp, &(curbuf->b_p_vsts_array))) | |
2172 { | |
2173 if (oldarray) | |
2174 vim_free(oldarray); | |
2175 } | |
2176 else | |
2177 errmsg = e_invarg; | |
2178 } | |
2179 } | |
2180 } | |
2181 | |
2182 // 'vartabstop' | |
2183 else if (varp == &(curbuf->b_p_vts)) | |
2184 { | |
2185 char_u *cp; | |
2186 | |
2187 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1])) | |
2188 { | |
2189 if (curbuf->b_p_vts_array) | |
2190 { | |
2191 vim_free(curbuf->b_p_vts_array); | |
2192 curbuf->b_p_vts_array = NULL; | |
2193 } | |
2194 } | |
2195 else | |
2196 { | |
2197 for (cp = *varp; *cp; ++cp) | |
2198 { | |
2199 if (vim_isdigit(*cp)) | |
2200 continue; | |
2201 if (*cp == ',' && cp > *varp && *(cp-1) != ',') | |
2202 continue; | |
2203 errmsg = e_invarg; | |
2204 break; | |
2205 } | |
2206 if (errmsg == NULL) | |
2207 { | |
2208 int *oldarray = curbuf->b_p_vts_array; | |
2209 | |
2210 if (tabstop_set(*varp, &(curbuf->b_p_vts_array))) | |
2211 { | |
2212 vim_free(oldarray); | |
2213 #ifdef FEAT_FOLDING | |
2214 if (foldmethodIsIndent(curwin)) | |
2215 foldUpdateAll(curwin); | |
2216 #endif | |
2217 } | |
2218 else | |
2219 errmsg = e_invarg; | |
2220 } | |
2221 } | |
2222 } | |
2223 #endif | |
2224 | |
2225 #ifdef FEAT_TEXT_PROP | |
2226 // 'previewpopup' | |
2227 else if (varp == &p_pvp) | |
2228 { | |
2229 if (parse_previewpopup(NULL) == FAIL) | |
2230 errmsg = e_invarg; | |
2231 } | |
2232 # ifdef FEAT_QUICKFIX | |
2233 // 'completepopup' | |
2234 else if (varp == &p_cpp) | |
2235 { | |
2236 if (parse_completepopup(NULL) == FAIL) | |
2237 errmsg = e_invarg; | |
2238 } | |
2239 # endif | |
2240 #endif | |
2241 | |
2242 // Options that are a list of flags. | |
2243 else | |
2244 { | |
2245 p = NULL; | |
2246 if (varp == &p_ww) // 'whichwrap' | |
2247 p = (char_u *)WW_ALL; | |
2248 if (varp == &p_shm) // 'shortmess' | |
2249 p = (char_u *)SHM_ALL; | |
2250 else if (varp == &(p_cpo)) // 'cpoptions' | |
2251 p = (char_u *)CPO_ALL; | |
2252 else if (varp == &(curbuf->b_p_fo)) // 'formatoptions' | |
2253 p = (char_u *)FO_ALL; | |
2254 #ifdef FEAT_CONCEAL | |
2255 else if (varp == &curwin->w_p_cocu) // 'concealcursor' | |
2256 p = (char_u *)COCU_ALL; | |
2257 #endif | |
2258 else if (varp == &p_mouse) // 'mouse' | |
2259 { | |
2260 #ifdef FEAT_MOUSE | |
2261 p = (char_u *)MOUSE_ALL; | |
2262 #else | |
2263 if (*p_mouse != NUL) | |
2264 errmsg = N_("E538: No mouse support"); | |
2265 #endif | |
2266 } | |
2267 #if defined(FEAT_GUI) | |
2268 else if (varp == &p_go) // 'guioptions' | |
2269 p = (char_u *)GO_ALL; | |
2270 #endif | |
2271 if (p != NULL) | |
2272 { | |
2273 for (s = *varp; *s; ++s) | |
2274 if (vim_strchr(p, *s) == NULL) | |
2275 { | |
2276 errmsg = illegal_char(errbuf, *s); | |
2277 break; | |
2278 } | |
2279 } | |
2280 } | |
2281 | |
2282 // If error detected, restore the previous value. | |
2283 if (errmsg != NULL) | |
2284 { | |
2285 if (new_value_alloced) | |
2286 free_string_option(*varp); | |
2287 *varp = oldval; | |
2288 // When resetting some values, need to act on it. | |
2289 if (did_chartab) | |
2290 (void)init_chartab(); | |
2291 if (varp == &p_hl) | |
2292 (void)highlight_changed(); | |
2293 } | |
2294 else | |
2295 { | |
2296 #ifdef FEAT_EVAL | |
2297 // Remember where the option was set. | |
2298 set_option_sctx_idx(opt_idx, opt_flags, current_sctx); | |
2299 #endif | |
2300 // Free string options that are in allocated memory. | |
2301 // Use "free_oldval", because recursiveness may change the flags under | |
2302 // our fingers (esp. init_highlight()). | |
2303 if (free_oldval) | |
2304 free_string_option(oldval); | |
2305 if (new_value_alloced) | |
2306 set_option_flag(opt_idx, P_ALLOCED); | |
2307 else | |
2308 clear_option_flag(opt_idx, P_ALLOCED); | |
2309 | |
2310 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0 | |
2311 && is_global_local_option(opt_idx)) | |
2312 { | |
2313 // global option with local value set to use global value; free | |
2314 // the local value and make it empty | |
2315 p = get_option_varp_scope(opt_idx, OPT_LOCAL); | |
2316 free_string_option(*(char_u **)p); | |
2317 *(char_u **)p = empty_option; | |
2318 } | |
2319 | |
2320 // May set global value for local option. | |
2321 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL) | |
2322 set_string_option_global(opt_idx, varp); | |
2323 | |
2324 // Trigger the autocommand only after setting the flags. | |
2325 #ifdef FEAT_SYN_HL | |
2326 // When 'syntax' is set, load the syntax of that name | |
2327 if (varp == &(curbuf->b_p_syn)) | |
2328 { | |
2329 static int syn_recursive = 0; | |
2330 | |
2331 ++syn_recursive; | |
2332 // Only pass TRUE for "force" when the value changed or not used | |
2333 // recursively, to avoid endless recurrence. | |
2334 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname, | |
2335 value_changed || syn_recursive == 1, curbuf); | |
2336 curbuf->b_flags |= BF_SYN_SET; | |
2337 --syn_recursive; | |
2338 } | |
2339 #endif | |
2340 else if (varp == &(curbuf->b_p_ft)) | |
2341 { | |
2342 // 'filetype' is set, trigger the FileType autocommand. | |
2343 // Skip this when called from a modeline and the filetype was | |
2344 // already set to this value. | |
2345 if (!(opt_flags & OPT_MODELINE) || value_changed) | |
2346 { | |
2347 static int ft_recursive = 0; | |
2348 int secure_save = secure; | |
2349 | |
2350 // Reset the secure flag, since the value of 'filetype' has | |
2351 // been checked to be safe. | |
2352 secure = 0; | |
2353 | |
2354 ++ft_recursive; | |
2355 did_filetype = TRUE; | |
2356 // Only pass TRUE for "force" when the value changed or not | |
2357 // used recursively, to avoid endless recurrence. | |
2358 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname, | |
2359 value_changed || ft_recursive == 1, curbuf); | |
2360 --ft_recursive; | |
2361 // Just in case the old "curbuf" is now invalid. | |
2362 if (varp != &(curbuf->b_p_ft)) | |
2363 varp = NULL; | |
2364 | |
2365 secure = secure_save; | |
2366 } | |
2367 } | |
2368 #ifdef FEAT_SPELL | |
2369 if (varp == &(curwin->w_s->b_p_spl)) | |
2370 { | |
2371 char_u fname[200]; | |
2372 char_u *q = curwin->w_s->b_p_spl; | |
2373 | |
2374 // Skip the first name if it is "cjk". | |
2375 if (STRNCMP(q, "cjk,", 4) == 0) | |
2376 q += 4; | |
2377 | |
2378 // Source the spell/LANG.vim in 'runtimepath'. | |
2379 // They could set 'spellcapcheck' depending on the language. | |
2380 // Use the first name in 'spelllang' up to '_region' or | |
2381 // '.encoding'. | |
2382 for (p = q; *p != NUL; ++p) | |
2383 if (!ASCII_ISALNUM(*p) && *p != '-') | |
2384 break; | |
2385 if (p > q) | |
2386 { | |
2387 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", | |
2388 (int)(p - q), q); | |
2389 source_runtime(fname, DIP_ALL); | |
2390 } | |
2391 } | |
2392 #endif | |
2393 } | |
2394 | |
2395 #ifdef FEAT_MOUSE | |
2396 if (varp == &p_mouse) | |
2397 { | |
2398 # ifdef FEAT_MOUSE_TTY | |
2399 if (*p_mouse == NUL) | |
2400 mch_setmouse(FALSE); // switch mouse off | |
2401 else | |
2402 # endif | |
2403 setmouse(); // in case 'mouse' changed | |
2404 } | |
2405 #endif | |
2406 | |
2407 if (curwin->w_curswant != MAXCOL | |
2408 && (get_option_flags(opt_idx) & (P_CURSWANT | P_RALL)) != 0) | |
2409 curwin->w_set_curswant = TRUE; | |
2410 | |
2411 #ifdef FEAT_GUI | |
2412 // check redraw when it's not a GUI option or the GUI is active. | |
2413 if (!redraw_gui_only || gui.in_use) | |
2414 #endif | |
2415 check_redraw(get_option_flags(opt_idx)); | |
2416 | |
2417 #if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS) | |
2418 if (did_swaptcap) | |
2419 { | |
2420 set_termname((char_u *)"win32"); | |
2421 init_highlight(TRUE, FALSE); | |
2422 } | |
2423 #endif | |
2424 | |
2425 return errmsg; | |
2426 } | |
2427 | |
2428 /* | |
2429 * Check an option that can be a range of string values. | |
2430 * | |
2431 * Return OK for correct value, FAIL otherwise. | |
2432 * Empty is always OK. | |
2433 */ | |
2434 static int | |
2435 check_opt_strings( | |
2436 char_u *val, | |
2437 char **values, | |
2438 int list) // when TRUE: accept a list of values | |
2439 { | |
2440 return opt_strings_flags(val, values, NULL, list); | |
2441 } | |
2442 | |
2443 /* | |
2444 * Handle an option that can be a range of string values. | |
2445 * Set a flag in "*flagp" for each string present. | |
2446 * | |
2447 * Return OK for correct value, FAIL otherwise. | |
2448 * Empty is always OK. | |
2449 */ | |
2450 static int | |
2451 opt_strings_flags( | |
2452 char_u *val, // new value | |
2453 char **values, // array of valid string values | |
2454 unsigned *flagp, | |
2455 int list) // when TRUE: accept a list of values | |
2456 { | |
2457 int i; | |
2458 int len; | |
2459 unsigned new_flags = 0; | |
2460 | |
2461 while (*val) | |
2462 { | |
2463 for (i = 0; ; ++i) | |
2464 { | |
2465 if (values[i] == NULL) // val not found in values[] | |
2466 return FAIL; | |
2467 | |
2468 len = (int)STRLEN(values[i]); | |
2469 if (STRNCMP(values[i], val, len) == 0 | |
2470 && ((list && val[len] == ',') || val[len] == NUL)) | |
2471 { | |
2472 val += len + (val[len] == ','); | |
2473 new_flags |= (1 << i); | |
2474 break; // check next item in val list | |
2475 } | |
2476 } | |
2477 } | |
2478 if (flagp != NULL) | |
2479 *flagp = new_flags; | |
2480 | |
2481 return OK; | |
2482 } | |
2483 | |
2484 /* | |
2485 * return OK if "p" is a valid fileformat name, FAIL otherwise. | |
2486 */ | |
2487 int | |
2488 check_ff_value(char_u *p) | |
2489 { | |
2490 return check_opt_strings(p, p_ff_values, FALSE); | |
2491 } |