option.c
资源名称:vim53src.zip [点击查看]
上传用户:gddssl
上传日期:2007-01-06
资源大小:1003k
文件大小:133k
源码类别:
编辑器/阅读器
开发平台:
DOS
- /* 'term' */
- if (varp == &T_NAME)
- {
- if (T_NAME[0] == NUL)
- errmsg = (char_u *)"Cannot set 'term' to empty string";
- #ifdef USE_GUI
- if (gui.in_use)
- errmsg = (char_u *)"Cannot change term in GUI";
- else if (term_is_gui(T_NAME))
- errmsg = (char_u *)"Use ":gui" to start the GUI";
- #endif
- else if (set_termname(T_NAME) == FAIL)
- errmsg = (char_u *)"Not found in termcap";
- else
- {
- /* Screen colors may have changed. */
- out_str(T_ME);
- update_screen(CLEAR);
- }
- }
- /* 'backupext' and 'patchmode' */
- else if ((varp == &p_bex || varp == &p_pm))
- {
- if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
- *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
- errmsg = (char_u *)"'backupext' and 'patchmode' are equal";
- }
- /*
- * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
- * If the new option is invalid, use old value. 'lisp' option: refill
- * chartab[] for '-' char
- */
- else if ( varp == &p_isi
- || varp == &(curbuf->b_p_isk)
- || varp == &p_isp
- || varp == &p_isf)
- {
- if (init_chartab() == FAIL)
- {
- did_chartab = TRUE; /* need to restore it below */
- errmsg = e_invarg; /* error in value */
- }
- }
- /* 'highlight' */
- else if (varp == &p_hl)
- {
- if (highlight_changed() == FAIL)
- errmsg = e_invarg; /* invalid flags */
- }
- /* 'nrformats' */
- else if (varp == &(curbuf->b_p_nf))
- {
- if (check_opt_strings(curbuf->b_p_nf, p_nf_values, TRUE) != OK)
- errmsg = e_invarg;
- }
- /* 'sessionoptions' */
- else if (varp == &(p_sessopt))
- {
- if (check_opt_strings(p_sessopt, p_sessopt_values, TRUE) != OK)
- errmsg = e_invarg;
- }
- /* 'background' */
- else if (varp == &p_bg)
- {
- if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
- {
- if (full_screen)
- init_highlight(FALSE);
- }
- else
- errmsg = e_invarg;
- }
- /* 'wildmode' */
- else if (varp == &p_wim)
- {
- if (check_opt_wim() == FAIL)
- errmsg = e_invarg;
- }
- #if defined(USE_GUI_WIN32) || defined(USE_GUI_MOTIF)
- /* 'winaltkeys' */
- else if (varp == &p_wak)
- {
- if (check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
- errmsg = e_invarg;
- # ifdef USE_GUI_MOTIF
- else if (gui.in_use)
- gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
- # endif
- }
- #endif
- #ifdef AUTOCMD
- /* 'eventignore' */
- else if (varp == &p_ei)
- {
- if (check_ei() == FAIL)
- errmsg = e_invarg;
- }
- #endif
- #ifdef MULTI_BYTE
- /* 'fileencoding' */
- else if (varp == &(curbuf->b_p_fe))
- {
- if (check_opt_strings(curbuf->b_p_fe, p_fe_values, FALSE) != OK)
- errmsg = e_invarg;
- else
- {
- int is_dbcs_new;
- /* set flags for various items */
- is_dbcs_new = 0;
- is_unicode = 0;
- if (STRCMP(curbuf->b_p_fe, FE_DBJPN) == 0)
- is_dbcs_new = DBCS_JPN;
- else if (STRCMP(curbuf->b_p_fe, FE_DBKOR) == 0)
- is_dbcs_new = DBCS_KOR;
- else if (STRCMP(curbuf->b_p_fe, FE_DBCHT) == 0)
- is_dbcs_new = DBCS_CHT;
- else if (STRCMP(curbuf->b_p_fe, FE_DBCHS) == 0)
- is_dbcs_new = DBCS_CHS;
- else if (STRCMP(curbuf->b_p_fe, FE_UNICODE) == 0)
- {
- is_unicode = 1;
- }
- /* if a DBCS locale, make sure it is valid */
- # ifdef USE_GUI_WIN32
- if (is_dbcs_new)
- {
- if (!IsValidCodePage(is_dbcs_new))
- {
- errmsg = (char_u *)"Not a valid codepage";
- }
- else
- {
- /* ok code page, so let's set is_dbcs and set pgm
- * language
- * */
- is_dbcs = is_dbcs_new;
- }
- }
- else
- # endif
- is_dbcs = is_dbcs_new;
- # ifdef USE_GUI_WIN32
- is_funky_dbcs = is_dbcs && ((int)GetACP() != is_dbcs);
- # endif
- # ifdef AUTOCMD
- /* fire off an autocommand to let people do custom font setup,
- * whatever */
- if (errmsg == NULL)
- apply_autocmds(EVENT_FILEENCODING, NULL, (char_u *)"",
- FALSE, curbuf);
- # endif
- }
- }
- #endif /* MULTI_BYTE */
- /* 'fileformat' */
- else if (varp == &(curbuf->b_p_ff))
- {
- if (check_opt_strings(curbuf->b_p_ff, p_ff_values, FALSE) != OK)
- errmsg = e_invarg;
- else
- {
- /* also change 'textmode' */
- if (get_fileformat(curbuf) == EOL_DOS)
- curbuf->b_p_tx = TRUE;
- else
- curbuf->b_p_tx = FALSE;
- }
- }
- /* 'fileformats' */
- else if (varp == &p_ffs)
- {
- if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
- errmsg = e_invarg;
- else
- {
- /* also change 'textauto' */
- if (*p_ffs == NUL)
- p_ta = FALSE;
- else
- p_ta = TRUE;
- }
- }
- /* 'matchpairs' */
- else if (varp == &(curbuf->b_p_mps))
- {
- /* Check for "x:y,x:y" */
- for (p = curbuf->b_p_mps; *p; p += 4)
- {
- if (!p[0] || p[1] != ':' || !p[2] || (p[3] && p[3] != ','))
- {
- errmsg = e_invarg;
- break;
- }
- if (!p[3])
- break;
- }
- }
- /* 'comments' */
- else if (varp == &(curbuf->b_p_com))
- {
- for (s = curbuf->b_p_com; *s; )
- {
- while (*s && *s != ':')
- {
- if (vim_strchr((char_u *)COM_ALL, *s) == NULL)
- {
- errmsg = (char_u *)"Illegal flag";
- break;
- }
- ++s;
- }
- if (*s++ == NUL)
- errmsg = (char_u *)"Missing colon";
- else if (*s == ',' || *s == NUL)
- errmsg = (char_u *)"Zero length string";
- if (errmsg != NULL)
- break;
- while (*s && *s != ',')
- {
- if (*s == '\' && s[1] != NUL)
- ++s;
- ++s;
- }
- s = skip_to_option_part(s);
- }
- }
- /* 'listtabstring' */
- else if (varp == &p_lcs)
- {
- int round, i, len;
- /* first round: check for valid value, second round: assign values */
- for (round = 0; round <= 1 && errmsg == NULL; ++round)
- {
- static struct lcstab
- {
- int *lcsp;
- char *name;
- } lcstab[] =
- {
- {&lcs_eol, "eol"},
- {&lcs_ext, "extends"},
- {&lcs_tab2, "tab"},
- {&lcs_trail, "trail"},
- };
- if (round)
- {
- for (i = 0; i < sizeof(lcstab) / sizeof(struct lcstab); ++i)
- *(lcstab[i].lcsp) = NUL;
- lcs_tab1 = NUL;
- }
- p = p_lcs;
- while (*p)
- {
- for (i = 0; i < sizeof(lcstab) / sizeof(struct lcstab); ++i)
- {
- len = STRLEN(lcstab[i].name);
- if (STRNCMP(p, lcstab[i].name, len) == 0
- && p[len] == ':'
- && p[len + 1] != NUL)
- {
- if (lcstab[i].lcsp == &lcs_tab2)
- ++len;
- if (p[len + 1] != NUL
- && (p[len + 2] == ',' || p[len + 2] == NUL))
- {
- if (round)
- {
- *(lcstab[i].lcsp) = p[len + 1];
- if (lcstab[i].lcsp == &lcs_tab2)
- lcs_tab1 = p[len];
- }
- p += len + 2;
- break;
- }
- }
- }
- if (i == sizeof(lcstab) / sizeof(struct lcstab))
- {
- errmsg = e_invarg;
- break;
- }
- if (*p == ',')
- ++p;
- }
- }
- }
- #ifdef VIMINFO
- /* 'viminfo' */
- else if (varp == &(p_viminfo))
- {
- for (s = p_viminfo; *s;)
- {
- /* Check it's a valid character */
- if (vim_strchr((char_u *)""'%frn:/", *s) == NULL)
- {
- if (errbuf != NULL)
- {
- illegal_char(errbuf, *s);
- errmsg = errbuf;
- }
- else
- errmsg = (char_u *)"";
- break;
- }
- if (*s == 'n') /* name is always last one */
- {
- break;
- }
- else if (*s == 'r') /* skip until next ',' */
- {
- while (*++s && *s != ',')
- ;
- }
- else if (*s == '%') /* no extra chars */
- ++s;
- else /* must have a number */
- {
- while (isdigit(*++s))
- ;
- if (!isdigit(*(s - 1)))
- {
- if (errbuf != NULL)
- {
- sprintf((char *)errbuf, "Missing number after <%s>",
- transchar(*(s - 1)));
- errmsg = errbuf;
- }
- else
- errmsg = (char_u *)"";
- break;
- }
- }
- s = skip_to_option_part(s);
- }
- if (*p_viminfo && errmsg == NULL && get_viminfo_parameter(''') < 0)
- errmsg = (char_u *)"Must specify a ' value";
- }
- #endif /* VIMINFO */
- /* terminal options */
- else if (istermoption(&options[opt_idx]) && full_screen)
- {
- /* ":set t_Co=0" does ":set t_Co=" */
- if (varp == &T_CCO && atoi((char *)T_CCO) == 0)
- {
- if (new_value_alloced)
- vim_free(T_CCO);
- T_CCO = empty_option;
- }
- ttest(FALSE);
- if (varp == &T_ME)
- {
- out_str(T_ME);
- update_screen(CLEAR);
- }
- }
- /* 'showbreak' */
- else if (varp == &p_sbr)
- {
- for (s = p_sbr; *s; ++s)
- if (charsize(*s) != 1)
- errmsg = (char_u *)"contains unprintable character";
- }
- #ifdef USE_GUI
- /* 'guifont' */
- else if (varp == &p_guifont)
- {
- if (gui.in_use && gui_init_font(p_guifont) != OK)
- errmsg = (char_u *)"Cannot set font(s)";
- }
- #endif
- #ifdef CURSOR_SHAPE
- /* 'guicursor' */
- else if (varp == &p_guicursor)
- errmsg = parse_guicursor();
- #endif
- #ifdef HAVE_LANGMAP
- /* 'langmap' */
- else if (varp == &p_langmap)
- langmap_set();
- #endif
- /* 'breakat' */
- else if (varp == &p_breakat)
- fill_breakat_flags();
- /* 'titlestring' and 'iconstring' */
- else if (varp == &p_titlestring)
- did_set_title(FALSE);
- else if (varp == &p_iconstring)
- did_set_title(TRUE);
- #ifdef USE_GUI
- /* 'guioptions' */
- else if (varp == &p_guioptions)
- gui_init_which_components(oldval);
- #endif
- #if defined(USE_MOUSE) && defined(UNIX)
- /* 'ttymouse' */
- else if (varp == &p_ttym)
- {
- # ifdef XTERM_MOUSE
- if (use_xterm_mouse())
- set_mouse_termcode(KS_MOUSE, (char_u *)"