comparison src/option.c @ 838:8e5830943bff v7.0e04

updated for version 7.0e04
author vimboss
date Thu, 20 Apr 2006 22:17:20 +0000
parents 5a7843c57316
children 1f3b1021f002
comparison
equal deleted inserted replaced
837:6bb1fa855dc9 838:8e5830943bff
2994 2994
2995 /* 2995 /*
2996 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory 2996 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
2997 */ 2997 */
2998 opt_idx = findoption((char_u *)"maxmemtot"); 2998 opt_idx = findoption((char_u *)"maxmemtot");
2999 if (opt_idx >= 0)
3000 {
2999 #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM) 3001 #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3000 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L) 3002 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3001 #endif 3003 #endif
3002 { 3004 {
3003 #ifdef HAVE_AVAIL_MEM 3005 #ifdef HAVE_AVAIL_MEM
3004 /* Use amount of memory available at this moment. */ 3006 /* Use amount of memory available at this moment. */
3005 n = (mch_avail_mem(FALSE) >> 11); 3007 n = (mch_avail_mem(FALSE) >> 11);
3006 #else 3008 #else
3007 # ifdef HAVE_TOTAL_MEM 3009 # ifdef HAVE_TOTAL_MEM
3008 /* Use amount of memory available to Vim. */ 3010 /* Use amount of memory available to Vim. */
3009 n = (mch_total_mem(FALSE) >> 11); 3011 n = (mch_total_mem(FALSE) >> 11);
3010 # else 3012 # else
3011 n = (0x7fffffff >> 11); 3013 n = (0x7fffffff >> 11);
3012 # endif 3014 # endif
3013 #endif 3015 #endif
3014 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n; 3016 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3015 opt_idx = findoption((char_u *)"maxmem"); 3017 opt_idx = findoption((char_u *)"maxmem");
3018 if (opt_idx >= 0)
3019 {
3016 #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM) 3020 #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3017 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n 3021 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
3018 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L) 3022 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3019 #endif 3023 #endif
3020 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n; 3024 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3025 }
3026 }
3021 } 3027 }
3022 3028
3023 #ifdef FEAT_GUI_W32 3029 #ifdef FEAT_GUI_W32
3024 /* force 'shortname' for Win32s */ 3030 /* force 'shortname' for Win32s */
3025 if (gui_is_win32s()) 3031 if (gui_is_win32s())
3026 options[findoption((char_u *)"shortname")].def_val[VI_DEFAULT] = 3032 {
3027 (char_u *)TRUE; 3033 opt_idx = findoption((char_u *)"shortname");
3034 if (opt_idx >= 0)
3035 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3036 }
3028 #endif 3037 #endif
3029 3038
3030 #ifdef FEAT_SEARCHPATH 3039 #ifdef FEAT_SEARCHPATH
3031 { 3040 {
3032 char_u *cdpath; 3041 char_u *cdpath;
3055 buf[j++] = cdpath[i]; 3064 buf[j++] = cdpath[i];
3056 } 3065 }
3057 } 3066 }
3058 buf[j] = NUL; 3067 buf[j] = NUL;
3059 opt_idx = findoption((char_u *)"cdpath"); 3068 opt_idx = findoption((char_u *)"cdpath");
3060 options[opt_idx].def_val[VI_DEFAULT] = buf; 3069 if (opt_idx >= 0)
3061 options[opt_idx].flags |= P_DEF_ALLOCED; 3070 {
3071 options[opt_idx].def_val[VI_DEFAULT] = buf;
3072 options[opt_idx].flags |= P_DEF_ALLOCED;
3073 }
3062 } 3074 }
3063 if (mustfree) 3075 if (mustfree)
3064 vim_free(cdpath); 3076 vim_free(cdpath);
3065 } 3077 }
3066 } 3078 }
3257 save_enc = p_enc; 3269 save_enc = p_enc;
3258 p_enc = p; 3270 p_enc = p;
3259 if (mb_init() == NULL) 3271 if (mb_init() == NULL)
3260 { 3272 {
3261 opt_idx = findoption((char_u *)"encoding"); 3273 opt_idx = findoption((char_u *)"encoding");
3262 options[opt_idx].def_val[VI_DEFAULT] = p_enc; 3274 if (opt_idx >= 0)
3263 options[opt_idx].flags |= P_DEF_ALLOCED; 3275 {
3276 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3277 options[opt_idx].flags |= P_DEF_ALLOCED;
3278 }
3264 3279
3265 #if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \ 3280 #if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3266 || defined(VMS) 3281 || defined(VMS)
3267 if (STRCMP(p_enc, "latin1") == 0 3282 if (STRCMP(p_enc, "latin1") == 0
3268 # ifdef FEAT_MBYTE 3283 # ifdef FEAT_MBYTE
3276 set_string_option_direct((char_u *)"isp", -1, 3291 set_string_option_direct((char_u *)"isp", -1,
3277 ISP_LATIN1, OPT_FREE, SID_NONE); 3292 ISP_LATIN1, OPT_FREE, SID_NONE);
3278 set_string_option_direct((char_u *)"isk", -1, 3293 set_string_option_direct((char_u *)"isk", -1,
3279 ISK_LATIN1, OPT_FREE, SID_NONE); 3294 ISK_LATIN1, OPT_FREE, SID_NONE);
3280 opt_idx = findoption((char_u *)"isp"); 3295 opt_idx = findoption((char_u *)"isp");
3281 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1; 3296 if (opt_idx >= 0)
3297 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
3282 opt_idx = findoption((char_u *)"isk"); 3298 opt_idx = findoption((char_u *)"isk");
3283 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1; 3299 if (opt_idx >= 0)
3300 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
3284 (void)init_chartab(); 3301 (void)init_chartab();
3285 } 3302 }
3286 #endif 3303 #endif
3287 3304
3288 # if defined(WIN3264) && !defined(FEAT_GUI) 3305 # if defined(WIN3264) && !defined(FEAT_GUI)
3295 sprintf(buf, "cp%ld", (long)GetConsoleCP()); 3312 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3296 p_tenc = vim_strsave((char_u *)buf); 3313 p_tenc = vim_strsave((char_u *)buf);
3297 if (p_tenc != NULL) 3314 if (p_tenc != NULL)
3298 { 3315 {
3299 opt_idx = findoption((char_u *)"termencoding"); 3316 opt_idx = findoption((char_u *)"termencoding");
3300 options[opt_idx].def_val[VI_DEFAULT] = p_tenc; 3317 if (opt_idx >= 0)
3301 options[opt_idx].flags |= P_DEF_ALLOCED; 3318 {
3319 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3320 options[opt_idx].flags |= P_DEF_ALLOCED;
3321 }
3302 convert_setup(&input_conv, p_tenc, p_enc); 3322 convert_setup(&input_conv, p_tenc, p_enc);
3303 convert_setup(&output_conv, p_enc, p_tenc); 3323 convert_setup(&output_conv, p_enc, p_tenc);
3304 } 3324 }
3305 else 3325 else
3306 p_tenc = empty_option; 3326 p_tenc = empty_option;
3434 3454
3435 p = vim_strsave(val); 3455 p = vim_strsave(val);
3436 if (p != NULL) /* we don't want a NULL */ 3456 if (p != NULL) /* we don't want a NULL */
3437 { 3457 {
3438 opt_idx = findoption((char_u *)name); 3458 opt_idx = findoption((char_u *)name);
3439 if (options[opt_idx].flags & P_DEF_ALLOCED) 3459 if (opt_idx >= 0)
3440 vim_free(options[opt_idx].def_val[VI_DEFAULT]); 3460 {
3441 options[opt_idx].def_val[VI_DEFAULT] = p; 3461 if (options[opt_idx].flags & P_DEF_ALLOCED)
3442 options[opt_idx].flags |= P_DEF_ALLOCED; 3462 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3463 options[opt_idx].def_val[VI_DEFAULT] = p;
3464 options[opt_idx].flags |= P_DEF_ALLOCED;
3465 }
3443 } 3466 }
3444 } 3467 }
3445 3468
3446 /* 3469 /*
3447 * Set the Vi-default value of a number option. 3470 * Set the Vi-default value of a number option.
3450 void 3473 void
3451 set_number_default(name, val) 3474 set_number_default(name, val)
3452 char *name; 3475 char *name;
3453 long val; 3476 long val;
3454 { 3477 {
3455 options[findoption((char_u *)name)].def_val[VI_DEFAULT] = (char_u *)val; 3478 int opt_idx;
3479
3480 opt_idx = findoption((char_u *)name);
3481 if (opt_idx >= 0)
3482 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)val;
3456 } 3483 }
3457 3484
3458 #if defined(EXITFREE) || defined(PROTO) 3485 #if defined(EXITFREE) || defined(PROTO)
3459 /* 3486 /*
3460 * Free all options. 3487 * Free all options.
3496 * 'scroll' defaults to half the window height. Note that this default is 3523 * 'scroll' defaults to half the window height. Note that this default is
3497 * wrong when the window height changes. 3524 * wrong when the window height changes.
3498 */ 3525 */
3499 set_number_default("scroll", (long)((long_u)Rows >> 1)); 3526 set_number_default("scroll", (long)((long_u)Rows >> 1));
3500 idx = findoption((char_u *)"scroll"); 3527 idx = findoption((char_u *)"scroll");
3501 if (!(options[idx].flags & P_WAS_SET)) 3528 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
3502 set_option_default(idx, OPT_LOCAL, p_cp); 3529 set_option_default(idx, OPT_LOCAL, p_cp);
3503 comp_col(); 3530 comp_col();
3504 3531
3505 /* 3532 /*
3506 * 'window' is only for backwards compatibility with Vi. 3533 * 'window' is only for backwards compatibility with Vi.
3507 * Default is Rows - 1. 3534 * Default is Rows - 1.
3508 */ 3535 */
3509 idx = findoption((char_u *)"wi"); 3536 idx = findoption((char_u *)"wi");
3510 if (!(options[idx].flags & P_WAS_SET)) 3537 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
3511 p_window = Rows - 1; 3538 p_window = Rows - 1;
3512 set_number_default("window", Rows - 1); 3539 set_number_default("window", Rows - 1);
3513 3540
3514 /* For DOS console the default is always black. */ 3541 /* For DOS console the default is always black. */
3515 #if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)) 3542 #if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
3517 * If 'background' wasn't set by the user, try guessing the value, 3544 * If 'background' wasn't set by the user, try guessing the value,
3518 * depending on the terminal name. Only need to check for terminals 3545 * depending on the terminal name. Only need to check for terminals
3519 * with a dark background, that can handle color. 3546 * with a dark background, that can handle color.
3520 */ 3547 */
3521 idx = findoption((char_u *)"bg"); 3548 idx = findoption((char_u *)"bg");
3522 if (!(options[idx].flags & P_WAS_SET) && *term_bg_default() == 'd') 3549 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3550 && *term_bg_default() == 'd')
3523 { 3551 {
3524 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0); 3552 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
3525 /* don't mark it as set, when starting the GUI it may be 3553 /* don't mark it as set, when starting the GUI it may be
3526 * changed again */ 3554 * changed again */
3527 options[idx].flags &= ~P_WAS_SET; 3555 options[idx].flags &= ~P_WAS_SET;
3592 int idx_sp; 3620 int idx_sp;
3593 int do_sp; 3621 int do_sp;
3594 #endif 3622 #endif
3595 3623
3596 idx_srr = findoption((char_u *)"srr"); 3624 idx_srr = findoption((char_u *)"srr");
3597 do_srr = !(options[idx_srr].flags & P_WAS_SET); 3625 if (idx_srr < 0)
3626 do_srr = FALSE;
3627 else
3628 do_srr = !(options[idx_srr].flags & P_WAS_SET);
3598 #ifdef FEAT_QUICKFIX 3629 #ifdef FEAT_QUICKFIX
3599 idx_sp = findoption((char_u *)"sp"); 3630 idx_sp = findoption((char_u *)"sp");
3600 do_sp = !(options[idx_sp].flags & P_WAS_SET); 3631 if (idx_sp < 0)
3632 do_sp = FALSE;
3633 else
3634 do_sp = !(options[idx_sp].flags & P_WAS_SET);
3601 #endif 3635 #endif
3602 3636
3603 /* 3637 /*
3604 * Isolate the name of the shell: 3638 * Isolate the name of the shell:
3605 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f". 3639 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3690 if (strstr((char *)gettail(p_sh), "sh") != NULL) 3724 if (strstr((char *)gettail(p_sh), "sh") != NULL)
3691 { 3725 {
3692 int idx3; 3726 int idx3;
3693 3727
3694 idx3 = findoption((char_u *)"shcf"); 3728 idx3 = findoption((char_u *)"shcf");
3695 if (!(options[idx3].flags & P_WAS_SET)) 3729 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3696 { 3730 {
3697 p_shcf = (char_u *)"-c"; 3731 p_shcf = (char_u *)"-c";
3698 options[idx3].def_val[VI_DEFAULT] = p_shcf; 3732 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3699 } 3733 }
3700 3734
3701 # ifndef DJGPP 3735 # ifndef DJGPP
3702 # ifdef WIN3264 3736 # ifdef WIN3264
3703 /* Somehow Win32 requires the quotes around the redirection too */ 3737 /* Somehow Win32 requires the quotes around the redirection too */
3704 idx3 = findoption((char_u *)"sxq"); 3738 idx3 = findoption((char_u *)"sxq");
3705 if (!(options[idx3].flags & P_WAS_SET)) 3739 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3706 { 3740 {
3707 p_sxq = (char_u *)"\""; 3741 p_sxq = (char_u *)"\"";
3708 options[idx3].def_val[VI_DEFAULT] = p_sxq; 3742 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3709 } 3743 }
3710 # else 3744 # else
3711 idx3 = findoption((char_u *)"shq"); 3745 idx3 = findoption((char_u *)"shq");
3712 if (!(options[idx3].flags & P_WAS_SET)) 3746 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3713 { 3747 {
3714 p_shq = (char_u *)"\""; 3748 p_shq = (char_u *)"\"";
3715 options[idx3].def_val[VI_DEFAULT] = p_shq; 3749 options[idx3].def_val[VI_DEFAULT] = p_shq;
3716 } 3750 }
3717 # endif 3751 # endif
3736 int idx; 3770 int idx;
3737 3771
3738 if (lang == NULL || STRLEN(lang) < 2) /* safety check */ 3772 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3739 return; 3773 return;
3740 idx = findoption((char_u *)"hlg"); 3774 idx = findoption((char_u *)"hlg");
3741 if (!(options[idx].flags & P_WAS_SET)) 3775 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
3742 { 3776 {
3743 if (options[idx].flags & P_ALLOCED) 3777 if (options[idx].flags & P_ALLOCED)
3744 free_string_option(p_hlg); 3778 free_string_option(p_hlg);
3745 p_hlg = vim_strsave(lang); 3779 p_hlg = vim_strsave(lang);
3746 if (p_hlg == NULL) 3780 if (p_hlg == NULL)
3805 * If GUI is (going to be) used, we can always set the window title and 3839 * If GUI is (going to be) used, we can always set the window title and
3806 * icon name. Saves a bit of time, because the X11 display server does 3840 * icon name. Saves a bit of time, because the X11 display server does
3807 * not need to be contacted. 3841 * not need to be contacted.
3808 */ 3842 */
3809 idx1 = findoption((char_u *)"title"); 3843 idx1 = findoption((char_u *)"title");
3810 if (!(options[idx1].flags & P_WAS_SET)) 3844 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
3811 { 3845 {
3812 #ifdef FEAT_GUI 3846 #ifdef FEAT_GUI
3813 if (gui.starting || gui.in_use) 3847 if (gui.starting || gui.in_use)
3814 val = TRUE; 3848 val = TRUE;
3815 else 3849 else
3817 val = mch_can_restore_title(); 3851 val = mch_can_restore_title();
3818 options[idx1].def_val[VI_DEFAULT] = (char_u *)val; 3852 options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
3819 p_title = val; 3853 p_title = val;
3820 } 3854 }
3821 idx1 = findoption((char_u *)"icon"); 3855 idx1 = findoption((char_u *)"icon");
3822 if (!(options[idx1].flags & P_WAS_SET)) 3856 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
3823 { 3857 {
3824 #ifdef FEAT_GUI 3858 #ifdef FEAT_GUI
3825 if (gui.starting || gui.in_use) 3859 if (gui.starting || gui.in_use)
3826 val = TRUE; 3860 val = TRUE;
3827 else 3861 else
5222 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; 5256 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
5223 5257
5224 if (opt_idx == -1) /* use name */ 5258 if (opt_idx == -1) /* use name */
5225 { 5259 {
5226 opt_idx = findoption(name); 5260 opt_idx = findoption(name);
5227 if (opt_idx == -1) /* not found (should not happen) */ 5261 if (opt_idx < 0) /* not found (should not happen) */
5228 { 5262 {
5229 EMSG2(_(e_intern2), "set_string_option_direct()"); 5263 EMSG2(_(e_intern2), "set_string_option_direct()");
5230 return; 5264 return;
5231 } 5265 }
5232 } 5266 }
8125 int opt_idx; 8159 int opt_idx;
8126 char_u *varp; 8160 char_u *varp;
8127 long_u flags; 8161 long_u flags;
8128 8162
8129 opt_idx = findoption(name); 8163 opt_idx = findoption(name);
8130 if (opt_idx == -1) 8164 if (opt_idx < 0)
8131 EMSG2(_("E355: Unknown option: %s"), name); 8165 EMSG2(_("E355: Unknown option: %s"), name);
8132 else 8166 else
8133 { 8167 {
8134 flags = options[opt_idx].flags; 8168 flags = options[opt_idx].flags;
8135 #ifdef HAVE_SANDBOX 8169 #ifdef HAVE_SANDBOX
9462 int opt_idx; 9496 int opt_idx;
9463 9497
9464 curbuf->b_p_ma = FALSE; 9498 curbuf->b_p_ma = FALSE;
9465 p_ma = FALSE; 9499 p_ma = FALSE;
9466 opt_idx = findoption((char_u *)"ma"); 9500 opt_idx = findoption((char_u *)"ma");
9467 options[opt_idx].def_val[VI_DEFAULT] = FALSE; 9501 if (opt_idx >= 0)
9502 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
9468 } 9503 }
9469 9504
9470 /* 9505 /*
9471 * Set the global value for 'iminsert' to the local value. 9506 * Set the global value for 'iminsert' to the local value.
9472 */ 9507 */
10295 */ 10330 */
10296 void 10331 void
10297 change_compatible(on) 10332 change_compatible(on)
10298 int on; 10333 int on;
10299 { 10334 {
10335 int opt_idx;
10336
10300 if (p_cp != on) 10337 if (p_cp != on)
10301 { 10338 {
10302 p_cp = on; 10339 p_cp = on;
10303 compatible_set(); 10340 compatible_set();
10304 } 10341 }
10305 options[findoption((char_u *)"cp")].flags |= P_WAS_SET; 10342 opt_idx = findoption((char_u *)"cp");
10343 if (opt_idx >= 0)
10344 options[opt_idx].flags |= P_WAS_SET;
10306 } 10345 }
10307 10346
10308 /* 10347 /*
10309 * Return TRUE when option "name" has been set. 10348 * Return TRUE when option "name" has been set.
10310 */ 10349 */