comparison src/eval.c @ 1733:5a7384b9ca66 v7.2.031

updated for version 7.2-031
author vimboss
date Sun, 09 Nov 2008 12:46:09 +0000
parents e9624acb93a7
children 619b90abfdc9
comparison
equal deleted inserted replaced
1732:f84061aa57e4 1733:5a7384b9ca66
346 {VV_NAME("mouse_win", VAR_NUMBER), 0}, 346 {VV_NAME("mouse_win", VAR_NUMBER), 0},
347 {VV_NAME("mouse_lnum", VAR_NUMBER), 0}, 347 {VV_NAME("mouse_lnum", VAR_NUMBER), 0},
348 {VV_NAME("mouse_col", VAR_NUMBER), 0}, 348 {VV_NAME("mouse_col", VAR_NUMBER), 0},
349 {VV_NAME("operator", VAR_STRING), VV_RO}, 349 {VV_NAME("operator", VAR_STRING), VV_RO},
350 {VV_NAME("searchforward", VAR_NUMBER), 0}, 350 {VV_NAME("searchforward", VAR_NUMBER), 0},
351 {VV_NAME("oldfiles", VAR_LIST), 0},
351 }; 352 };
352 353
353 /* shorthand */ 354 /* shorthand */
354 #define vv_type vv_di.di_tv.v_type 355 #define vv_type vv_di.di_tv.v_type
355 #define vv_nr vv_di.di_tv.vval.v_number 356 #define vv_nr vv_di.di_tv.vval.v_number
356 #define vv_float vv_di.di_tv.vval.v_float 357 #define vv_float vv_di.di_tv.vval.v_float
357 #define vv_str vv_di.di_tv.vval.v_string 358 #define vv_str vv_di.di_tv.vval.v_string
359 #define vv_list vv_di.di_tv.vval.v_list
358 #define vv_tv vv_di.di_tv 360 #define vv_tv vv_di.di_tv
359 361
360 /* 362 /*
361 * The v: variables are stored in dictionary "vimvardict". 363 * The v: variables are stored in dictionary "vimvardict".
362 * "vimvars_var" is the variable that is used for the "l:" scope. 364 * "vimvars_var" is the variable that is used for the "l:" scope.
424 static listitem_T *list_find __ARGS((list_T *l, long n)); 426 static listitem_T *list_find __ARGS((list_T *l, long n));
425 static long list_find_nr __ARGS((list_T *l, long idx, int *errorp)); 427 static long list_find_nr __ARGS((list_T *l, long idx, int *errorp));
426 static long list_idx_of_item __ARGS((list_T *l, listitem_T *item)); 428 static long list_idx_of_item __ARGS((list_T *l, listitem_T *item));
427 static void list_append __ARGS((list_T *l, listitem_T *item)); 429 static void list_append __ARGS((list_T *l, listitem_T *item));
428 static int list_append_tv __ARGS((list_T *l, typval_T *tv)); 430 static int list_append_tv __ARGS((list_T *l, typval_T *tv));
429 static int list_append_string __ARGS((list_T *l, char_u *str, int len));
430 static int list_append_number __ARGS((list_T *l, varnumber_T n)); 431 static int list_append_number __ARGS((list_T *l, varnumber_T n));
431 static int list_insert_tv __ARGS((list_T *l, typval_T *tv, listitem_T *item)); 432 static int list_insert_tv __ARGS((list_T *l, typval_T *tv, listitem_T *item));
432 static int list_extend __ARGS((list_T *l1, list_T *l2, listitem_T *bef)); 433 static int list_extend __ARGS((list_T *l1, list_T *l2, listitem_T *bef));
433 static int list_concat __ARGS((list_T *l1, list_T *l2, typval_T *tv)); 434 static int list_concat __ARGS((list_T *l1, list_T *l2, typval_T *tv));
434 static list_T *list_copy __ARGS((list_T *orig, int deep, int copyID)); 435 static list_T *list_copy __ARGS((list_T *orig, int deep, int copyID));
843 for (i = 0; i < VV_LEN; ++i) 844 for (i = 0; i < VV_LEN; ++i)
844 { 845 {
845 p = &vimvars[i]; 846 p = &vimvars[i];
846 if (p->vv_di.di_tv.v_type == VAR_STRING) 847 if (p->vv_di.di_tv.v_type == VAR_STRING)
847 { 848 {
848 vim_free(p->vv_di.di_tv.vval.v_string); 849 vim_free(p->vv_string);
849 p->vv_di.di_tv.vval.v_string = NULL; 850 p->vv_string = NULL;
851 }
852 else if (p->vv_di.di_tv.v_type == VAR_LIST)
853 {
854 list_unref(p->vv_list);
855 p->vv_list = NULL;
850 } 856 }
851 } 857 }
852 hash_clear(&vimvarht); 858 hash_clear(&vimvarht);
853 hash_clear(&compat_hashtab); 859 hash_clear(&compat_hashtab);
854 860
6055 } 6061 }
6056 return get_tv_number_chk(&li->li_tv, errorp); 6062 return get_tv_number_chk(&li->li_tv, errorp);
6057 } 6063 }
6058 6064
6059 /* 6065 /*
6066 * Get list item "l[idx - 1]" as a string. Returns NULL for failure.
6067 */
6068 char_u *
6069 list_find_str(l, idx)
6070 list_T *l;
6071 long idx;
6072 {
6073 listitem_T *li;
6074
6075 li = list_find(l, idx - 1);
6076 if (li == NULL)
6077 {
6078 EMSGN(_(e_listidx), idx);
6079 return NULL;
6080 }
6081 return get_tv_string(&li->li_tv);
6082 }
6083
6084 /*
6060 * Locate "item" list "l" and return its index. 6085 * Locate "item" list "l" and return its index.
6061 * Returns -1 when "item" is not in the list. 6086 * Returns -1 when "item" is not in the list.
6062 */ 6087 */
6063 static long 6088 static long
6064 list_idx_of_item(l, item) 6089 list_idx_of_item(l, item)
6145 /* 6170 /*
6146 * Make a copy of "str" and append it as an item to list "l". 6171 * Make a copy of "str" and append it as an item to list "l".
6147 * When "len" >= 0 use "str[len]". 6172 * When "len" >= 0 use "str[len]".
6148 * Returns FAIL when out of memory. 6173 * Returns FAIL when out of memory.
6149 */ 6174 */
6150 static int 6175 int
6151 list_append_string(l, str, len) 6176 list_append_string(l, str, len)
6152 list_T *l; 6177 list_T *l;
6153 char_u *str; 6178 char_u *str;
6154 int len; 6179 int len;
6155 { 6180 {
6505 { 6530 {
6506 set_ref_in_ht(&fc->l_vars.dv_hashtab, copyID); 6531 set_ref_in_ht(&fc->l_vars.dv_hashtab, copyID);
6507 set_ref_in_ht(&fc->l_avars.dv_hashtab, copyID); 6532 set_ref_in_ht(&fc->l_avars.dv_hashtab, copyID);
6508 } 6533 }
6509 6534
6535 /* v: vars */
6536 set_ref_in_ht(&vimvarht, copyID);
6537
6510 /* 6538 /*
6511 * 2. Go through the list of dicts and free items without the copyID. 6539 * 2. Go through the list of dicts and free items without the copyID.
6512 */ 6540 */
6513 for (dd = first_dict; dd != NULL; ) 6541 for (dd = first_dict; dd != NULL; )
6514 if (dd->dv_copyID != copyID) 6542 if (dd->dv_copyID != copyID)
6595 6623
6596 switch (tv->v_type) 6624 switch (tv->v_type)
6597 { 6625 {
6598 case VAR_DICT: 6626 case VAR_DICT:
6599 dd = tv->vval.v_dict; 6627 dd = tv->vval.v_dict;
6600 if (dd->dv_copyID != copyID) 6628 if (dd != NULL && dd->dv_copyID != copyID)
6601 { 6629 {
6602 /* Didn't see this dict yet. */ 6630 /* Didn't see this dict yet. */
6603 dd->dv_copyID = copyID; 6631 dd->dv_copyID = copyID;
6604 set_ref_in_ht(&dd->dv_hashtab, copyID); 6632 set_ref_in_ht(&dd->dv_hashtab, copyID);
6605 } 6633 }
6606 break; 6634 break;
6607 6635
6608 case VAR_LIST: 6636 case VAR_LIST:
6609 ll = tv->vval.v_list; 6637 ll = tv->vval.v_list;
6610 if (ll->lv_copyID != copyID) 6638 if (ll != NULL && ll->lv_copyID != copyID)
6611 { 6639 {
6612 /* Didn't see this list yet. */ 6640 /* Didn't see this list yet. */
6613 ll->lv_copyID = copyID; 6641 ll->lv_copyID = copyID;
6614 set_ref_in_list(ll, copyID); 6642 set_ref_in_list(ll, copyID);
6615 } 6643 }
18104 { 18132 {
18105 return get_tv_string(&vimvars[idx].vv_tv); 18133 return get_tv_string(&vimvars[idx].vv_tv);
18106 } 18134 }
18107 18135
18108 /* 18136 /*
18137 * Get List v: variable value. Caller must take care of reference count when
18138 * needed.
18139 */
18140 list_T *
18141 get_vim_var_list(idx)
18142 int idx;
18143 {
18144 return vimvars[idx].vv_list;
18145 }
18146
18147 /*
18109 * Set v:count, v:count1 and v:prevcount. 18148 * Set v:count, v:count1 and v:prevcount.
18110 */ 18149 */
18111 void 18150 void
18112 set_vcount(count, count1) 18151 set_vcount(count, count1)
18113 long count; 18152 long count;
18136 vimvars[idx].vv_str = NULL; 18175 vimvars[idx].vv_str = NULL;
18137 else if (len == -1) 18176 else if (len == -1)
18138 vimvars[idx].vv_str = vim_strsave(val); 18177 vimvars[idx].vv_str = vim_strsave(val);
18139 else 18178 else
18140 vimvars[idx].vv_str = vim_strnsave(val, len); 18179 vimvars[idx].vv_str = vim_strnsave(val, len);
18180 }
18181
18182 /*
18183 * Set List v: variable to "val".
18184 */
18185 void
18186 set_vim_var_list(idx, val)
18187 int idx;
18188 list_T *val;
18189 {
18190 list_unref(vimvars[idx].vv_list);
18191 vimvars[idx].vv_list = val;
18192 if (val != NULL)
18193 ++val->lv_refcount;
18141 } 18194 }
18142 18195
18143 /* 18196 /*
18144 * Set v:register if needed. 18197 * Set v:register if needed.
18145 */ 18198 */
21898 verbose_leave(); 21951 verbose_leave();
21899 } 21952 }
21900 } 21953 }
21901 } 21954 }
21902 21955
21956 /*
21957 * List v:oldfiles in a nice way.
21958 */
21959 /*ARGSUSED*/
21960 void
21961 ex_oldfiles(eap)
21962 exarg_T *eap;
21963 {
21964 list_T *l = vimvars[VV_OLDFILES].vv_list;
21965 listitem_T *li;
21966 int nr = 0;
21967
21968 if (l == NULL)
21969 msg((char_u *)_("No old files"));
21970 else
21971 {
21972 msg_start();
21973 msg_scroll = TRUE;
21974 for (li = l->lv_first; li != NULL && !got_int; li = li->li_next)
21975 {
21976 msg_outnum((long)++nr);
21977 MSG_PUTS(": ");
21978 msg_outtrans(get_tv_string(&li->li_tv));
21979 msg_putchar('\n');
21980 out_flush(); /* output one line at a time */
21981 ui_breakcheck();
21982 }
21983 /* Assume "got_int" was set to truncate the listing. */
21984 got_int = FALSE;
21985
21986 #ifdef FEAT_BROWSE_CMD
21987 if (cmdmod.browse)
21988 {
21989 quit_more = FALSE;
21990 nr = prompt_for_number(FALSE);
21991 msg_starthere();
21992 if (nr > 0)
21993 {
21994 char_u *p = list_find_str(get_vim_var_list(VV_OLDFILES),
21995 (long)nr);
21996
21997 if (p != NULL)
21998 {
21999 p = expand_env_save(p);
22000 eap->arg = p;
22001 eap->cmdidx = CMD_edit;
22002 cmdmod.browse = FALSE;
22003 do_exedit(eap, NULL);
22004 vim_free(p);
22005 }
22006 }
22007 }
22008 #endif
22009 }
22010 }
22011
21903 #endif /* FEAT_EVAL */ 22012 #endif /* FEAT_EVAL */
21904 22013
21905 22014
21906 #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) || defined(PROTO) 22015 #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) || defined(PROTO)
21907 22016