comparison src/eval.c @ 411:5f33b64a6694 v7.0107

updated for version 7.0107
author vimboss
date Mon, 11 Jul 2005 22:42:07 +0000
parents 06234af3a8b7
children f713fc55bf7b
comparison
equal deleted inserted replaced
410:c60ba877860b 411:5f33b64a6694
351 */ 351 */
352 static dict_T vimvardict; 352 static dict_T vimvardict;
353 static dictitem_T vimvars_var; 353 static dictitem_T vimvars_var;
354 #define vimvarht vimvardict.dv_hashtab 354 #define vimvarht vimvardict.dv_hashtab
355 355
356 static void prepare_vimvar __ARGS((int idx, typval_T *save_tv));
357 static void restore_vimvar __ARGS((int idx, typval_T *save_tv));
358 #if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL)
359 static int call_vim_function __ARGS((char_u *func, int argc, char_u **argv, int safe, typval_T *rettv));
360 #endif
361 static int ex_let_vars __ARGS((char_u *arg, typval_T *tv, int copy, int semicolon, int var_count, char_u *nextchars));
362 static char_u *skip_var_list __ARGS((char_u *arg, int *var_count, int *semicolon));
363 static char_u *skip_var_one __ARGS((char_u *arg));
364 static void list_hashtable_vars __ARGS((hashtab_T *ht, char_u *prefix, int empty));
365 static void list_glob_vars __ARGS((void));
366 static void list_buf_vars __ARGS((void));
367 static void list_win_vars __ARGS((void));
368 static void list_vim_vars __ARGS((void));
369 static char_u *list_arg_vars __ARGS((exarg_T *eap, char_u *arg));
370 static char_u *ex_let_one __ARGS((char_u *arg, typval_T *tv, int copy, char_u *endchars, char_u *op));
371 static int check_changedtick __ARGS((char_u *arg));
372 static char_u *get_lval __ARGS((char_u *name, typval_T *rettv, lval_T *lp, int unlet, int skip, int quiet, int fne_flags));
373 static void clear_lval __ARGS((lval_T *lp));
374 static void set_var_lval __ARGS((lval_T *lp, char_u *endp, typval_T *rettv, int copy, char_u *op));
375 static int tv_op __ARGS((typval_T *tv1, typval_T *tv2, char_u *op));
376 static void list_add_watch __ARGS((list_T *l, listwatch_T *lw));
377 static void list_rem_watch __ARGS((list_T *l, listwatch_T *lwrem));
378 static void list_fix_watch __ARGS((list_T *l, listitem_T *item));
379 static void ex_unletlock __ARGS((exarg_T *eap, char_u *argstart, int deep));
380 static int do_unlet_var __ARGS((lval_T *lp, char_u *name_end, int forceit));
381 static int do_lock_var __ARGS((lval_T *lp, char_u *name_end, int deep, int lock));
382 static void item_lock __ARGS((typval_T *tv, int deep, int lock));
383 static int tv_islocked __ARGS((typval_T *tv));
384
356 static int eval0 __ARGS((char_u *arg, typval_T *rettv, char_u **nextcmd, int evaluate)); 385 static int eval0 __ARGS((char_u *arg, typval_T *rettv, char_u **nextcmd, int evaluate));
357 static int eval1 __ARGS((char_u **arg, typval_T *rettv, int evaluate)); 386 static int eval1 __ARGS((char_u **arg, typval_T *rettv, int evaluate));
358 static int eval2 __ARGS((char_u **arg, typval_T *rettv, int evaluate)); 387 static int eval2 __ARGS((char_u **arg, typval_T *rettv, int evaluate));
359 static int eval3 __ARGS((char_u **arg, typval_T *rettv, int evaluate)); 388 static int eval3 __ARGS((char_u **arg, typval_T *rettv, int evaluate));
360 static int eval4 __ARGS((char_u **arg, typval_T *rettv, int evaluate)); 389 static int eval4 __ARGS((char_u **arg, typval_T *rettv, int evaluate));
361 static int eval5 __ARGS((char_u **arg, typval_T *rettv, int evaluate)); 390 static int eval5 __ARGS((char_u **arg, typval_T *rettv, int evaluate));
362 static int eval6 __ARGS((char_u **arg, typval_T *rettv, int evaluate)); 391 static int eval6 __ARGS((char_u **arg, typval_T *rettv, int evaluate));
363 static int eval7 __ARGS((char_u **arg, typval_T *rettv, int evaluate)); 392 static int eval7 __ARGS((char_u **arg, typval_T *rettv, int evaluate));
393
364 static int eval_index __ARGS((char_u **arg, typval_T *rettv, int evaluate, int verbose)); 394 static int eval_index __ARGS((char_u **arg, typval_T *rettv, int evaluate, int verbose));
365 static int get_option_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate)); 395 static int get_option_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate));
366 static int get_string_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate)); 396 static int get_string_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate));
367 static int get_lit_string_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate)); 397 static int get_lit_string_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate));
368 static int get_list_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate)); 398 static int get_list_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate));
384 static int list_concat __ARGS((list_T *l1, list_T *l2, typval_T *tv)); 414 static int list_concat __ARGS((list_T *l1, list_T *l2, typval_T *tv));
385 static list_T *list_copy __ARGS((list_T *orig, int deep, int copyID)); 415 static list_T *list_copy __ARGS((list_T *orig, int deep, int copyID));
386 static void list_remove __ARGS((list_T *l, listitem_T *item, listitem_T *item2)); 416 static void list_remove __ARGS((list_T *l, listitem_T *item, listitem_T *item2));
387 static char_u *list2string __ARGS((typval_T *tv)); 417 static char_u *list2string __ARGS((typval_T *tv));
388 static int list_join __ARGS((garray_T *gap, list_T *l, char_u *sep, int echo)); 418 static int list_join __ARGS((garray_T *gap, list_T *l, char_u *sep, int echo));
389
390 static void set_ref_in_ht __ARGS((hashtab_T *ht, int copyID)); 419 static void set_ref_in_ht __ARGS((hashtab_T *ht, int copyID));
391 static void set_ref_in_list __ARGS((list_T *l, int copyID)); 420 static void set_ref_in_list __ARGS((list_T *l, int copyID));
392 static void set_ref_in_item __ARGS((typval_T *tv, int copyID)); 421 static void set_ref_in_item __ARGS((typval_T *tv, int copyID));
393
394 static void dict_unref __ARGS((dict_T *d)); 422 static void dict_unref __ARGS((dict_T *d));
395 static void dict_free __ARGS((dict_T *d)); 423 static void dict_free __ARGS((dict_T *d));
396 static dictitem_T *dictitem_alloc __ARGS((char_u *key)); 424 static dictitem_T *dictitem_alloc __ARGS((char_u *key));
397 static dictitem_T *dictitem_copy __ARGS((dictitem_T *org)); 425 static dictitem_T *dictitem_copy __ARGS((dictitem_T *org));
398 static void dictitem_remove __ARGS((dict_T *dict, dictitem_T *item)); 426 static void dictitem_remove __ARGS((dict_T *dict, dictitem_T *item));
401 static int dict_add __ARGS((dict_T *d, dictitem_T *item)); 429 static int dict_add __ARGS((dict_T *d, dictitem_T *item));
402 static long dict_len __ARGS((dict_T *d)); 430 static long dict_len __ARGS((dict_T *d));
403 static dictitem_T *dict_find __ARGS((dict_T *d, char_u *key, int len)); 431 static dictitem_T *dict_find __ARGS((dict_T *d, char_u *key, int len));
404 static char_u *dict2string __ARGS((typval_T *tv)); 432 static char_u *dict2string __ARGS((typval_T *tv));
405 static int get_dict_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate)); 433 static int get_dict_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate));
406
407 static char_u *echo_string __ARGS((typval_T *tv, char_u **tofree, char_u *numbuf)); 434 static char_u *echo_string __ARGS((typval_T *tv, char_u **tofree, char_u *numbuf));
408 static char_u *tv2string __ARGS((typval_T *tv, char_u **tofree, char_u *numbuf)); 435 static char_u *tv2string __ARGS((typval_T *tv, char_u **tofree, char_u *numbuf));
409 static char_u *string_quote __ARGS((char_u *str, int function)); 436 static char_u *string_quote __ARGS((char_u *str, int function));
410 static int get_env_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate)); 437 static int get_env_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate));
411 static int find_internal_func __ARGS((char_u *name)); 438 static int find_internal_func __ARGS((char_u *name));
593 static void f_winnr __ARGS((typval_T *argvars, typval_T *rettv)); 620 static void f_winnr __ARGS((typval_T *argvars, typval_T *rettv));
594 static void f_winrestcmd __ARGS((typval_T *argvars, typval_T *rettv)); 621 static void f_winrestcmd __ARGS((typval_T *argvars, typval_T *rettv));
595 static void f_winwidth __ARGS((typval_T *argvars, typval_T *rettv)); 622 static void f_winwidth __ARGS((typval_T *argvars, typval_T *rettv));
596 static void f_writefile __ARGS((typval_T *argvars, typval_T *rettv)); 623 static void f_writefile __ARGS((typval_T *argvars, typval_T *rettv));
597 624
598 static void prepare_vimvar __ARGS((int idx, typval_T *save_tv));
599 static void restore_vimvar __ARGS((int idx, typval_T *save_tv));
600 static win_T *find_win_by_nr __ARGS((typval_T *vp));
601 static pos_T *var2fpos __ARGS((typval_T *varp, int lnum)); 625 static pos_T *var2fpos __ARGS((typval_T *varp, int lnum));
602 static int get_env_len __ARGS((char_u **arg)); 626 static int get_env_len __ARGS((char_u **arg));
603 static int get_id_len __ARGS((char_u **arg)); 627 static int get_id_len __ARGS((char_u **arg));
604 static int get_name_len __ARGS((char_u **arg, char_u **alias, int evaluate, int verbose)); 628 static int get_name_len __ARGS((char_u **arg, char_u **alias, int evaluate, int verbose));
605 static char_u *find_name_end __ARGS((char_u *arg, char_u **expr_start, char_u **expr_end, int flags)); 629 static char_u *find_name_end __ARGS((char_u *arg, char_u **expr_start, char_u **expr_end, int flags));
606 #define FNE_INCL_BR 1 /* find_name_end(): include [] in name */ 630 #define FNE_INCL_BR 1 /* find_name_end(): include [] in name */
607 #define FNE_CHECK_START 2 /* find_name_end(): check name starts with 631 #define FNE_CHECK_START 2 /* find_name_end(): check name starts with
608 valid character */ 632 valid character */
633 static char_u * make_expanded_name __ARGS((char_u *in_start, char_u *expr_start, char_u *expr_end, char_u *in_end));
609 static int eval_isnamec __ARGS((int c)); 634 static int eval_isnamec __ARGS((int c));
610 static int eval_isnamec1 __ARGS((int c)); 635 static int eval_isnamec1 __ARGS((int c));
611 static int get_var_tv __ARGS((char_u *name, int len, typval_T *rettv, int verbose)); 636 static int get_var_tv __ARGS((char_u *name, int len, typval_T *rettv, int verbose));
612 static int handle_subscript __ARGS((char_u **arg, typval_T *rettv, int evaluate, int verbose)); 637 static int handle_subscript __ARGS((char_u **arg, typval_T *rettv, int evaluate, int verbose));
613 static typval_T *alloc_tv __ARGS((void)); 638 static typval_T *alloc_tv __ARGS((void));
617 static void init_tv __ARGS((typval_T *varp)); 642 static void init_tv __ARGS((typval_T *varp));
618 static long get_tv_number __ARGS((typval_T *varp)); 643 static long get_tv_number __ARGS((typval_T *varp));
619 static long get_tv_number_chk __ARGS((typval_T *varp, int *denote)); 644 static long get_tv_number_chk __ARGS((typval_T *varp, int *denote));
620 static linenr_T get_tv_lnum __ARGS((typval_T *argvars)); 645 static linenr_T get_tv_lnum __ARGS((typval_T *argvars));
621 static char_u *get_tv_string __ARGS((typval_T *varp)); 646 static char_u *get_tv_string __ARGS((typval_T *varp));
647 static char_u *get_tv_string_buf __ARGS((typval_T *varp, char_u *buf));
622 static char_u *get_tv_string_chk __ARGS((typval_T *varp)); 648 static char_u *get_tv_string_chk __ARGS((typval_T *varp));
623 static char_u *get_tv_string_buf __ARGS((typval_T *varp, char_u *buf));
624 static char_u *get_tv_string_buf_chk __ARGS((typval_T *varp, char_u *buf)); 649 static char_u *get_tv_string_buf_chk __ARGS((typval_T *varp, char_u *buf));
625 static dictitem_T *find_var __ARGS((char_u *name, hashtab_T **htp)); 650 static dictitem_T *find_var __ARGS((char_u *name, hashtab_T **htp));
626 static dictitem_T *find_var_in_ht __ARGS((hashtab_T *ht, char_u *varname, int writing)); 651 static dictitem_T *find_var_in_ht __ARGS((hashtab_T *ht, char_u *varname, int writing));
627 static hashtab_T *find_var_ht __ARGS((char_u *name, char_u **varname)); 652 static hashtab_T *find_var_ht __ARGS((char_u *name, char_u **varname));
628 static void vars_clear_ext __ARGS((hashtab_T *ht, int free_val)); 653 static void vars_clear_ext __ARGS((hashtab_T *ht, int free_val));
637 static char_u *find_option_end __ARGS((char_u **arg, int *opt_flags)); 662 static char_u *find_option_end __ARGS((char_u **arg, int *opt_flags));
638 static char_u *trans_function_name __ARGS((char_u **pp, int skip, int flags, funcdict_T *fd)); 663 static char_u *trans_function_name __ARGS((char_u **pp, int skip, int flags, funcdict_T *fd));
639 static int eval_fname_script __ARGS((char_u *p)); 664 static int eval_fname_script __ARGS((char_u *p));
640 static int eval_fname_sid __ARGS((char_u *p)); 665 static int eval_fname_sid __ARGS((char_u *p));
641 static void list_func_head __ARGS((ufunc_T *fp, int indent)); 666 static void list_func_head __ARGS((ufunc_T *fp, int indent));
642 static void cat_func_name __ARGS((char_u *buf, ufunc_T *fp));
643 static ufunc_T *find_func __ARGS((char_u *name)); 667 static ufunc_T *find_func __ARGS((char_u *name));
644 static int function_exists __ARGS((char_u *name)); 668 static int function_exists __ARGS((char_u *name));
645 static int builtin_function __ARGS((char_u *name)); 669 static int builtin_function __ARGS((char_u *name));
646 #ifdef FEAT_PROFILE 670 #ifdef FEAT_PROFILE
647 static void func_do_profile __ARGS((ufunc_T *fp)); 671 static void func_do_profile __ARGS((ufunc_T *fp));
658 # endif 682 # endif
659 prof_self_cmp __ARGS((const void *s1, const void *s2)); 683 prof_self_cmp __ARGS((const void *s1, const void *s2));
660 #endif 684 #endif
661 static int script_autoload __ARGS((char_u *name)); 685 static int script_autoload __ARGS((char_u *name));
662 static char_u *autoload_name __ARGS((char_u *name)); 686 static char_u *autoload_name __ARGS((char_u *name));
687 static void cat_func_name __ARGS((char_u *buf, ufunc_T *fp));
663 static void func_free __ARGS((ufunc_T *fp)); 688 static void func_free __ARGS((ufunc_T *fp));
664 static void func_unref __ARGS((char_u *name)); 689 static void func_unref __ARGS((char_u *name));
665 static void func_ref __ARGS((char_u *name)); 690 static void func_ref __ARGS((char_u *name));
666 static void call_user_func __ARGS((ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rettv, linenr_T firstline, linenr_T lastline, dict_T *selfdict)); 691 static void call_user_func __ARGS((ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rettv, linenr_T firstline, linenr_T lastline, dict_T *selfdict));
667 static void add_nr_var __ARGS((dict_T *dp, dictitem_T *v, char *name, varnumber_T nr)); 692 static void add_nr_var __ARGS((dict_T *dp, dictitem_T *v, char *name, varnumber_T nr));
668
669 static char_u * make_expanded_name __ARGS((char_u *in_start, char_u *expr_start, char_u *expr_end, char_u *in_end));
670
671 static int ex_let_vars __ARGS((char_u *arg, typval_T *tv, int copy, int semicolon, int var_count, char_u *nextchars));
672 static char_u *skip_var_list __ARGS((char_u *arg, int *var_count, int *semicolon));
673 static char_u *skip_var_one __ARGS((char_u *arg));
674 static void list_hashtable_vars __ARGS((hashtab_T *ht, char_u *prefix, int empty));
675 static void list_glob_vars __ARGS((void));
676 static void list_buf_vars __ARGS((void));
677 static void list_win_vars __ARGS((void));
678 static void list_vim_vars __ARGS((void));
679 static char_u *list_arg_vars __ARGS((exarg_T *eap, char_u *arg));
680 static char_u *ex_let_one __ARGS((char_u *arg, typval_T *tv, int copy, char_u *endchars, char_u *op));
681 static int check_changedtick __ARGS((char_u *arg));
682 static char_u *get_lval __ARGS((char_u *name, typval_T *rettv, lval_T *lp, int unlet, int skip, int quiet, int fne_flags));
683 static void clear_lval __ARGS((lval_T *lp));
684 static void set_var_lval __ARGS((lval_T *lp, char_u *endp, typval_T *rettv, int copy, char_u *op));
685 static int tv_op __ARGS((typval_T *tv1, typval_T *tv2, char_u *op));
686 static void list_add_watch __ARGS((list_T *l, listwatch_T *lw));
687 static void list_rem_watch __ARGS((list_T *l, listwatch_T *lwrem));
688 static void list_fix_watch __ARGS((list_T *l, listitem_T *item));
689 static void ex_unletlock __ARGS((exarg_T *eap, char_u *argstart, int deep));
690 static int do_unlet_var __ARGS((lval_T *lp, char_u *name_end, int forceit));
691 static int do_lock_var __ARGS((lval_T *lp, char_u *name_end, int deep, int lock));
692 static void item_lock __ARGS((typval_T *tv, int deep, int lock));
693 static int tv_islocked __ARGS((typval_T *tv));
694 693
695 /* Character used as separated in autoload function/variable names. */ 694 /* Character used as separated in autoload function/variable names. */
696 #define AUTOLOAD_CHAR '#' 695 #define AUTOLOAD_CHAR '#'
697 696
698 /* 697 /*
1203 clear_tv(&rettv); 1202 clear_tv(&rettv);
1204 } 1203 }
1205 --emsg_off; 1204 --emsg_off;
1206 1205
1207 return retval; 1206 return retval;
1207 }
1208
1209 /*
1210 * Prepare v: variable "idx" to be used.
1211 * Save the current typeval in "save_tv".
1212 * When not used yet add the variable to the v: hashtable.
1213 */
1214 static void
1215 prepare_vimvar(idx, save_tv)
1216 int idx;
1217 typval_T *save_tv;
1218 {
1219 *save_tv = vimvars[idx].vv_tv;
1220 if (vimvars[idx].vv_type == VAR_UNKNOWN)
1221 hash_add(&vimvarht, vimvars[idx].vv_di.di_key);
1222 }
1223
1224 /*
1225 * Restore v: variable "idx" to typeval "save_tv".
1226 * When no longer defined, remove the variable from the v: hashtable.
1227 */
1228 static void
1229 restore_vimvar(idx, save_tv)
1230 int idx;
1231 typval_T *save_tv;
1232 {
1233 hashitem_T *hi;
1234
1235 clear_tv(&vimvars[idx].vv_tv);
1236 vimvars[idx].vv_tv = *save_tv;
1237 if (vimvars[idx].vv_type == VAR_UNKNOWN)
1238 {
1239 hi = hash_find(&vimvarht, vimvars[idx].vv_di.di_key);
1240 if (HASHITEM_EMPTY(hi))
1241 EMSG2(_(e_intern2), "restore_vimvar()");
1242 else
1243 hash_remove(&vimvarht, hi);
1244 }
1208 } 1245 }
1209 1246
1210 #if defined(FEAT_SYN_HL) || defined(PROTO) 1247 #if defined(FEAT_SYN_HL) || defined(PROTO)
1211 /* 1248 /*
1212 * Evaluate an expression to a list with suggestions. 1249 * Evaluate an expression to a list with suggestions.
3310 } 3347 }
3311 } 3348 }
3312 } 3349 }
3313 } 3350 }
3314 --recurse; 3351 --recurse;
3352 }
3353
3354 /*
3355 * Return TRUE if typeval "tv" is locked: Either tha value is locked itself or
3356 * it refers to a List or Dictionary that is locked.
3357 */
3358 static int
3359 tv_islocked(tv)
3360 typval_T *tv;
3361 {
3362 return (tv->v_lock & VAR_LOCKED)
3363 || (tv->v_type == VAR_LIST
3364 && tv->vval.v_list != NULL
3365 && (tv->vval.v_list->lv_lock & VAR_LOCKED))
3366 || (tv->v_type == VAR_DICT
3367 && tv->vval.v_dict != NULL
3368 && (tv->vval.v_dict->dv_lock & VAR_LOCKED));
3315 } 3369 }
3316 3370
3317 #if (defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)) || defined(PROTO) 3371 #if (defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)) || defined(PROTO)
3318 /* 3372 /*
3319 * Delete all "menutrans_" variables. 3373 * Delete all "menutrans_" variables.
8535 8589
8536 static void filter_map __ARGS((typval_T *argvars, typval_T *rettv, int map)); 8590 static void filter_map __ARGS((typval_T *argvars, typval_T *rettv, int map));
8537 static int filter_map_one __ARGS((typval_T *tv, char_u *expr, int map, int *remp)); 8591 static int filter_map_one __ARGS((typval_T *tv, char_u *expr, int map, int *remp));
8538 8592
8539 /* 8593 /*
8540 * Prepare v: variable "idx" to be used.
8541 * Save the current typeval in "save_tv".
8542 * When not used yet add the variable to the v: hashtable.
8543 */
8544 static void
8545 prepare_vimvar(idx, save_tv)
8546 int idx;
8547 typval_T *save_tv;
8548 {
8549 *save_tv = vimvars[idx].vv_tv;
8550 if (vimvars[idx].vv_type == VAR_UNKNOWN)
8551 hash_add(&vimvarht, vimvars[idx].vv_di.di_key);
8552 }
8553
8554 /*
8555 * Restore v: variable "idx" to typeval "save_tv".
8556 * When no longer defined, remove the variable from the v: hashtable.
8557 */
8558 static void
8559 restore_vimvar(idx, save_tv)
8560 int idx;
8561 typval_T *save_tv;
8562 {
8563 hashitem_T *hi;
8564
8565 clear_tv(&vimvars[idx].vv_tv);
8566 vimvars[idx].vv_tv = *save_tv;
8567 if (vimvars[idx].vv_type == VAR_UNKNOWN)
8568 {
8569 hi = hash_find(&vimvarht, vimvars[idx].vv_di.di_key);
8570 if (HASHITEM_EMPTY(hi))
8571 EMSG2(_(e_intern2), "restore_vimvar()");
8572 else
8573 hash_remove(&vimvarht, hi);
8574 }
8575 }
8576
8577 /*
8578 * Implementation of map() and filter(). 8594 * Implementation of map() and filter().
8579 */ 8595 */
8580 static void 8596 static void
8581 filter_map(argvars, rettv, map) 8597 filter_map(argvars, rettv, map)
8582 typval_T *argvars; 8598 typval_T *argvars;
9640 rettv->vval.v_number = y; 9656 rettv->vval.v_number = y;
9641 } 9657 }
9642 #endif 9658 #endif
9643 } 9659 }
9644 9660
9661 static win_T *find_win_by_nr __ARGS((typval_T *vp));
9662
9663 static win_T *
9664 find_win_by_nr(vp)
9665 typval_T *vp;
9666 {
9667 #ifdef FEAT_WINDOWS
9668 win_T *wp;
9669 #endif
9670 int nr;
9671
9672 nr = get_tv_number_chk(vp, NULL);
9673
9674 #ifdef FEAT_WINDOWS
9675 if (nr < 0)
9676 return NULL;
9677 if (nr == 0)
9678 return curwin;
9679
9680 for (wp = firstwin; wp != NULL; wp = wp->w_next)
9681 if (--nr <= 0)
9682 break;
9683 return wp;
9684 #else
9685 if (nr == 0 || nr == 1)
9686 return curwin;
9687 return NULL;
9688 #endif
9689 }
9690
9645 /* 9691 /*
9646 * "getwinvar()" function 9692 * "getwinvar()" function
9647 */ 9693 */
9648 static void 9694 static void
9649 f_getwinvar(argvars, rettv) 9695 f_getwinvar(argvars, rettv)
10773 f_isdirectory(argvars, rettv) 10819 f_isdirectory(argvars, rettv)
10774 typval_T *argvars; 10820 typval_T *argvars;
10775 typval_T *rettv; 10821 typval_T *rettv;
10776 { 10822 {
10777 rettv->vval.v_number = mch_isdir(get_tv_string(&argvars[0])); 10823 rettv->vval.v_number = mch_isdir(get_tv_string(&argvars[0]));
10778 }
10779
10780 /*
10781 * Return TRUE if typeval "tv" is locked: Either tha value is locked itself or
10782 * it refers to a List or Dictionary that is locked.
10783 */
10784 static int
10785 tv_islocked(tv)
10786 typval_T *tv;
10787 {
10788 return (tv->v_lock & VAR_LOCKED)
10789 || (tv->v_type == VAR_LIST
10790 && tv->vval.v_list != NULL
10791 && (tv->vval.v_list->lv_lock & VAR_LOCKED))
10792 || (tv->v_type == VAR_DICT
10793 && tv->vval.v_dict != NULL
10794 && (tv->vval.v_dict->dv_lock & VAR_LOCKED));
10795 } 10824 }
10796 10825
10797 /* 10826 /*
10798 * "islocked()" function 10827 * "islocked()" function
10799 */ 10828 */
14627 else 14656 else
14628 #ifdef FEAT_VERTSPLIT 14657 #ifdef FEAT_VERTSPLIT
14629 rettv->vval.v_number = wp->w_width; 14658 rettv->vval.v_number = wp->w_width;
14630 #else 14659 #else
14631 rettv->vval.v_number = Columns; 14660 rettv->vval.v_number = Columns;
14632 #endif
14633 }
14634
14635 static win_T *
14636 find_win_by_nr(vp)
14637 typval_T *vp;
14638 {
14639 #ifdef FEAT_WINDOWS
14640 win_T *wp;
14641 #endif
14642 int nr;
14643
14644 nr = get_tv_number_chk(vp, NULL);
14645
14646 #ifdef FEAT_WINDOWS
14647 if (nr < 0)
14648 return NULL;
14649 if (nr == 0)
14650 return curwin;
14651
14652 for (wp = firstwin; wp != NULL; wp = wp->w_next)
14653 if (--nr <= 0)
14654 break;
14655 return wp;
14656 #else
14657 if (nr == 0 || nr == 1)
14658 return curwin;
14659 return NULL;
14660 #endif 14661 #endif
14661 } 14662 }
14662 14663
14663 /* 14664 /*
14664 * "writefile()" function 14665 * "writefile()" function