comparison src/eval.c @ 533:c8b6b7e1005d v7.0150

updated for version 7.0150
author vimboss
date Sun, 25 Sep 2005 22:20:24 +0000
parents da9142bd190a
children c6296b0ad9ea
comparison
equal deleted inserted replaced
532:7052f11a3dc9 533:c8b6b7e1005d
407 static int tv_equal __ARGS((typval_T *tv1, typval_T *tv2, int ic)); 407 static int tv_equal __ARGS((typval_T *tv1, typval_T *tv2, int ic));
408 static listitem_T *list_find __ARGS((list_T *l, long n)); 408 static listitem_T *list_find __ARGS((list_T *l, long n));
409 static long list_idx_of_item __ARGS((list_T *l, listitem_T *item)); 409 static long list_idx_of_item __ARGS((list_T *l, listitem_T *item));
410 static void list_append __ARGS((list_T *l, listitem_T *item)); 410 static void list_append __ARGS((list_T *l, listitem_T *item));
411 static int list_append_tv __ARGS((list_T *l, typval_T *tv)); 411 static int list_append_tv __ARGS((list_T *l, typval_T *tv));
412 static int list_append_string __ARGS((list_T *l, char_u *str)); 412 static int list_append_string __ARGS((list_T *l, char_u *str, int len));
413 static int list_append_number __ARGS((list_T *l, varnumber_T n));
413 static int list_insert_tv __ARGS((list_T *l, typval_T *tv, listitem_T *item)); 414 static int list_insert_tv __ARGS((list_T *l, typval_T *tv, listitem_T *item));
414 static int list_extend __ARGS((list_T *l1, list_T *l2, listitem_T *bef)); 415 static int list_extend __ARGS((list_T *l1, list_T *l2, listitem_T *bef));
415 static int list_concat __ARGS((list_T *l1, list_T *l2, typval_T *tv)); 416 static int list_concat __ARGS((list_T *l1, list_T *l2, typval_T *tv));
416 static list_T *list_copy __ARGS((list_T *orig, int deep, int copyID)); 417 static list_T *list_copy __ARGS((list_T *orig, int deep, int copyID));
417 static void list_remove __ARGS((list_T *l, listitem_T *item, listitem_T *item2)); 418 static void list_remove __ARGS((list_T *l, listitem_T *item, listitem_T *item2));
2549 typval_T *rettv; 2550 typval_T *rettv;
2550 int copy; 2551 int copy;
2551 char_u *op; 2552 char_u *op;
2552 { 2553 {
2553 int cc; 2554 int cc;
2554 listitem_T *ni;
2555 listitem_T *ri; 2555 listitem_T *ri;
2556 dictitem_T *di; 2556 dictitem_T *di;
2557 2557
2558 if (lp->ll_tv == NULL) 2558 if (lp->ll_tv == NULL)
2559 { 2559 {
2601 if (ri == NULL || (!lp->ll_empty2 && lp->ll_n2 == lp->ll_n1)) 2601 if (ri == NULL || (!lp->ll_empty2 && lp->ll_n2 == lp->ll_n1))
2602 break; 2602 break;
2603 if (lp->ll_li->li_next == NULL) 2603 if (lp->ll_li->li_next == NULL)
2604 { 2604 {
2605 /* Need to add an empty item. */ 2605 /* Need to add an empty item. */
2606 ni = listitem_alloc(); 2606 if (list_append_number(lp->ll_list, 0) == FAIL)
2607 if (ni == NULL)
2608 { 2607 {
2609 ri = NULL; 2608 ri = NULL;
2610 break; 2609 break;
2611 } 2610 }
2612 ni->li_tv.v_type = VAR_NUMBER;
2613 ni->li_tv.v_lock = 0;
2614 ni->li_tv.vval.v_number = 0;
2615 list_append(lp->ll_list, ni);
2616 } 2611 }
2617 lp->ll_li = lp->ll_li->li_next; 2612 lp->ll_li = lp->ll_li->li_next;
2618 ++lp->ll_n1; 2613 ++lp->ll_n1;
2619 } 2614 }
2620 if (ri != NULL) 2615 if (ri != NULL)
3596 3591
3597 /* 3592 /*
3598 * Handle zero level expression. 3593 * Handle zero level expression.
3599 * This calls eval1() and handles error message and nextcmd. 3594 * This calls eval1() and handles error message and nextcmd.
3600 * Put the result in "rettv" when returning OK and "evaluate" is TRUE. 3595 * Put the result in "rettv" when returning OK and "evaluate" is TRUE.
3596 * Note: "rettv.v_lock" is not set.
3601 * Return OK or FAIL. 3597 * Return OK or FAIL.
3602 */ 3598 */
3603 static int 3599 static int
3604 eval0(arg, rettv, nextcmd, evaluate) 3600 eval0(arg, rettv, nextcmd, evaluate)
3605 char_u *arg; 3601 char_u *arg;
3635 * Handle top level expression: 3631 * Handle top level expression:
3636 * expr1 ? expr0 : expr0 3632 * expr1 ? expr0 : expr0
3637 * 3633 *
3638 * "arg" must point to the first non-white of the expression. 3634 * "arg" must point to the first non-white of the expression.
3639 * "arg" is advanced to the next non-white after the recognized expression. 3635 * "arg" is advanced to the next non-white after the recognized expression.
3636 *
3637 * Note: "rettv.v_lock" is not set.
3640 * 3638 *
3641 * Return OK or FAIL. 3639 * Return OK or FAIL.
3642 */ 3640 */
3643 static int 3641 static int
3644 eval1(arg, rettv, evaluate) 3642 eval1(arg, rettv, evaluate)
5555 return OK; 5553 return OK;
5556 } 5554 }
5557 5555
5558 /* 5556 /*
5559 * Make a copy of "str" and append it as an item to list "l". 5557 * Make a copy of "str" and append it as an item to list "l".
5558 * When "len" >= 0 use "str[len]".
5560 * Returns FAIL when out of memory. 5559 * Returns FAIL when out of memory.
5561 */ 5560 */
5562 static int 5561 static int
5563 list_append_string(l, str) 5562 list_append_string(l, str, len)
5564 list_T *l; 5563 list_T *l;
5565 char_u *str; 5564 char_u *str;
5565 int len;
5566 { 5566 {
5567 listitem_T *li = listitem_alloc(); 5567 listitem_T *li = listitem_alloc();
5568 5568
5569 if (li == NULL) 5569 if (li == NULL)
5570 return FAIL; 5570 return FAIL;
5571 list_append(l, li); 5571 list_append(l, li);
5572 li->li_tv.v_type = VAR_STRING; 5572 li->li_tv.v_type = VAR_STRING;
5573 li->li_tv.v_lock = 0; 5573 li->li_tv.v_lock = 0;
5574 if ((li->li_tv.vval.v_string = vim_strsave(str)) == NULL) 5574 if ((li->li_tv.vval.v_string = len >= 0 ? vim_strnsave(str, len)
5575 : vim_strsave(str)) == NULL)
5575 return FAIL; 5576 return FAIL;
5577 return OK;
5578 }
5579
5580 /*
5581 * Append "n" to list "l".
5582 * Returns FAIL when out of memory.
5583 */
5584 static int
5585 list_append_number(l, n)
5586 list_T *l;
5587 varnumber_T n;
5588 {
5589 listitem_T *li;
5590
5591 li = listitem_alloc();
5592 if (li == NULL)
5593 return FAIL;
5594 li->li_tv.v_type = VAR_NUMBER;
5595 li->li_tv.v_lock = 0;
5596 li->li_tv.vval.v_number = n;
5597 list_append(l, li);
5576 return OK; 5598 return OK;
5577 } 5599 }
5578 5600
5579 /* 5601 /*
5580 * Insert typval_T "tv" in list "l" before "item". 5602 * Insert typval_T "tv" in list "l" before "item".
6862 {"setreg", 2, 3, f_setreg}, 6884 {"setreg", 2, 3, f_setreg},
6863 {"setwinvar", 3, 3, f_setwinvar}, 6885 {"setwinvar", 3, 3, f_setwinvar},
6864 {"simplify", 1, 1, f_simplify}, 6886 {"simplify", 1, 1, f_simplify},
6865 {"sort", 1, 2, f_sort}, 6887 {"sort", 1, 2, f_sort},
6866 {"soundfold", 1, 1, f_soundfold}, 6888 {"soundfold", 1, 1, f_soundfold},
6867 {"spellbadword", 0, 0, f_spellbadword}, 6889 {"spellbadword", 0, 1, f_spellbadword},
6868 {"spellsuggest", 1, 2, f_spellsuggest}, 6890 {"spellsuggest", 1, 2, f_spellsuggest},
6869 {"split", 1, 3, f_split}, 6891 {"split", 1, 3, f_split},
6870 #ifdef HAVE_STRFTIME 6892 #ifdef HAVE_STRFTIME
6871 {"strftime", 1, 2, f_strftime}, 6893 {"strftime", 1, 2, f_strftime},
6872 #endif 6894 #endif
8840 } 8862 }
8841 if (map) 8863 if (map)
8842 { 8864 {
8843 /* map(): replace the list item value */ 8865 /* map(): replace the list item value */
8844 clear_tv(tv); 8866 clear_tv(tv);
8867 rettv.v_lock = 0;
8845 *tv = rettv; 8868 *tv = rettv;
8846 } 8869 }
8847 else 8870 else
8848 { 8871 {
8849 int error = FALSE; 8872 int error = FALSE;
9259 if (start < 1) 9282 if (start < 1)
9260 start = 1; 9283 start = 1;
9261 if (end > buf->b_ml.ml_line_count) 9284 if (end > buf->b_ml.ml_line_count)
9262 end = buf->b_ml.ml_line_count; 9285 end = buf->b_ml.ml_line_count;
9263 while (start <= end) 9286 while (start <= end)
9264 if (list_append_string(l, ml_get_buf(buf, start++, FALSE)) == FAIL) 9287 if (list_append_string(l, ml_get_buf(buf, start++, FALSE), -1)
9288 == FAIL)
9265 break; 9289 break;
9266 } 9290 }
9267 } 9291 }
9268 9292
9269 /* 9293 /*
10853 if (argvars[1].v_type != VAR_UNKNOWN) 10877 if (argvars[1].v_type != VAR_UNKNOWN)
10854 { 10878 {
10855 defstr = get_tv_string_buf_chk(&argvars[1], buf); 10879 defstr = get_tv_string_buf_chk(&argvars[1], buf);
10856 if (defstr != NULL) 10880 if (defstr != NULL)
10857 stuffReadbuffSpec(defstr); 10881 stuffReadbuffSpec(defstr);
10858 } 10882
10859 10883 if (argvars[2].v_type != VAR_UNKNOWN)
10860 if (argvars[2].v_type != VAR_UNKNOWN) 10884 {
10861 { 10885 char_u *xp_name;
10862 char_u *xp_name; 10886 int xp_namelen;
10863 int xp_namelen; 10887 long argt;
10864 long argt; 10888
10865 10889 rettv->vval.v_string = NULL;
10866 rettv->vval.v_string = NULL; 10890
10867 10891 xp_name = get_tv_string_buf_chk(&argvars[2], buf);
10868 xp_name = get_tv_string_buf_chk(&argvars[2], buf); 10892 if (xp_name == NULL)
10869 if (xp_name == NULL) 10893 return;
10870 return; 10894
10871 10895 xp_namelen = STRLEN(xp_name);
10872 xp_namelen = STRLEN(xp_name); 10896
10873 10897 if (parse_compl_arg(xp_name, xp_namelen, &xp_type, &argt,
10874 if (parse_compl_arg(xp_name, xp_namelen, &xp_type, &argt, &xp_arg) 10898 &xp_arg) == FAIL)
10875 == FAIL) 10899 return;
10876 return; 10900 }
10877 } 10901 }
10878 10902
10879 if (defstr != NULL) 10903 if (defstr != NULL)
10880 rettv->vval.v_string = 10904 rettv->vval.v_string =
10881 getcmdline_prompt(inputsecret_flag ? NUL : '@', p, echo_attr, 10905 getcmdline_prompt(inputsecret_flag ? NUL : '@', p, echo_attr,
11711 /* return list with matched string and submatches */ 11735 /* return list with matched string and submatches */
11712 for (i = 0; i < NSUBEXP; ++i) 11736 for (i = 0; i < NSUBEXP; ++i)
11713 { 11737 {
11714 if (regmatch.endp[i] == NULL) 11738 if (regmatch.endp[i] == NULL)
11715 break; 11739 break;
11716 li = listitem_alloc(); 11740 if (list_append_string(rettv->vval.v_list,
11717 if (li == NULL) 11741 regmatch.startp[i],
11742 (int)(regmatch.endp[i] - regmatch.startp[i]))
11743 == FAIL)
11718 break; 11744 break;
11719 li->li_tv.v_type = VAR_STRING;
11720 li->li_tv.v_lock = 0;
11721 li->li_tv.vval.v_string = vim_strnsave(regmatch.startp[i],
11722 (int)(regmatch.endp[i] - regmatch.startp[i]));
11723 list_append(rettv->vval.v_list, li);
11724 } 11745 }
11725 } 11746 }
11726 else if (type == 2) 11747 else if (type == 2)
11727 { 11748 {
11728 /* return matched string */ 11749 /* return matched string */
12110 long start; 12131 long start;
12111 long end; 12132 long end;
12112 long stride = 1; 12133 long stride = 1;
12113 long i; 12134 long i;
12114 list_T *l; 12135 list_T *l;
12115 listitem_T *li;
12116 int error = FALSE; 12136 int error = FALSE;
12117 12137
12118 start = get_tv_number_chk(&argvars[0], &error); 12138 start = get_tv_number_chk(&argvars[0], &error);
12119 if (argvars[1].v_type == VAR_UNKNOWN) 12139 if (argvars[1].v_type == VAR_UNKNOWN)
12120 { 12140 {
12143 rettv->v_type = VAR_LIST; 12163 rettv->v_type = VAR_LIST;
12144 rettv->vval.v_list = l; 12164 rettv->vval.v_list = l;
12145 ++l->lv_refcount; 12165 ++l->lv_refcount;
12146 12166
12147 for (i = start; stride > 0 ? i <= end : i >= end; i += stride) 12167 for (i = start; stride > 0 ? i <= end : i >= end; i += stride)
12148 { 12168 if (list_append_number(l, (varnumber_T)i) == FAIL)
12149 li = listitem_alloc();
12150 if (li == NULL)
12151 break; 12169 break;
12152 li->li_tv.v_type = VAR_NUMBER;
12153 li->li_tv.v_lock = 0;
12154 li->li_tv.vval.v_number = i;
12155 list_append(l, li);
12156 }
12157 } 12170 }
12158 } 12171 }
12159 } 12172 }
12160 12173
12161 /* 12174 /*
13885 static void 13898 static void
13886 f_spellbadword(argvars, rettv) 13899 f_spellbadword(argvars, rettv)
13887 typval_T *argvars; 13900 typval_T *argvars;
13888 typval_T *rettv; 13901 typval_T *rettv;
13889 { 13902 {
13903 char_u *word = (char_u *)"";
13904 #ifdef FEAT_SYN_HL
13890 int len; 13905 int len;
13891 13906 int attr = 0;
13892 rettv->vval.v_string = NULL; 13907 list_T *l;
13893 rettv->v_type = VAR_STRING; 13908 #endif
13909
13910 l = list_alloc();
13911 if (l == NULL)
13912 return;
13913 rettv->v_type = VAR_LIST;
13914 rettv->vval.v_list = l;
13915 ++l->lv_refcount;
13894 13916
13895 #ifdef FEAT_SYN_HL 13917 #ifdef FEAT_SYN_HL
13896 /* Find the start and length of the badly spelled word. */ 13918 if (argvars[0].v_type == VAR_UNKNOWN)
13897 len = spell_move_to(curwin, FORWARD, TRUE, TRUE, NULL); 13919 {
13898 if (len != 0) 13920 /* Find the start and length of the badly spelled word. */
13899 rettv->vval.v_string = vim_strnsave(ml_get_cursor(), len); 13921 len = spell_move_to(curwin, FORWARD, TRUE, TRUE, &attr);
13900 #endif 13922 if (len != 0)
13923 word = ml_get_cursor();
13924 }
13925 else if (curwin->w_p_spell && *curbuf->b_p_spl != NUL)
13926 {
13927 char_u *str = get_tv_string_chk(&argvars[0]);
13928 int capcol = -1;
13929
13930 if (str != NULL)
13931 {
13932 /* Check the argument for spelling. */
13933 while (*str != NUL)
13934 {
13935 len = spell_check(curwin, str, &attr, &capcol);
13936 if (attr != 0)
13937 {
13938 word = str;
13939 break;
13940 }
13941 str += len;
13942 }
13943 }
13944 }
13945 #endif
13946
13947 list_append_string(l, word, len);
13948 list_append_string(l, (char_u *)(
13949 attr == highlight_attr[HLF_SPB] ? "bad" :
13950 attr == highlight_attr[HLF_SPR] ? "rare" :
13951 attr == highlight_attr[HLF_SPL] ? "local" :
13952 attr == highlight_attr[HLF_SPC] ? "caps" :
13953 ""), -1);
13901 } 13954 }
13902 13955
13903 /* 13956 /*
13904 * "spellsuggest()" function 13957 * "spellsuggest()" function
13905 */ 13958 */
13967 char_u *pat = NULL; 14020 char_u *pat = NULL;
13968 regmatch_T regmatch; 14021 regmatch_T regmatch;
13969 char_u patbuf[NUMBUFLEN]; 14022 char_u patbuf[NUMBUFLEN];
13970 char_u *save_cpo; 14023 char_u *save_cpo;
13971 int match; 14024 int match;
13972 listitem_T *ni;
13973 list_T *l; 14025 list_T *l;
13974 colnr_T col = 0; 14026 colnr_T col = 0;
13975 int keepempty = FALSE; 14027 int keepempty = FALSE;
13976 int typeerr = FALSE; 14028 int typeerr = FALSE;
13977 14029
14015 else 14067 else
14016 end = str + STRLEN(str); 14068 end = str + STRLEN(str);
14017 if (keepempty || end > str || (l->lv_len > 0 && *str != NUL 14069 if (keepempty || end > str || (l->lv_len > 0 && *str != NUL
14018 && match && end < regmatch.endp[0])) 14070 && match && end < regmatch.endp[0]))
14019 { 14071 {
14020 ni = listitem_alloc(); 14072 if (list_append_string(l, str, (int)(end - str)) == FAIL)
14021 if (ni == NULL)
14022 break; 14073 break;
14023 ni->li_tv.v_type = VAR_STRING;
14024 ni->li_tv.v_lock = 0;
14025 ni->li_tv.vval.v_string = vim_strnsave(str, end - str);
14026 list_append(l, ni);
14027 } 14074 }
14028 if (!match) 14075 if (!match)
14029 break; 14076 break;
14030 /* Advance to just after the match. */ 14077 /* Advance to just after the match. */
14031 if (regmatch.endp[0] > str) 14078 if (regmatch.endp[0] > str)
14581 ++l->lv_refcount; 14628 ++l->lv_refcount;
14582 14629
14583 get_tagfname(TRUE, NULL); 14630 get_tagfname(TRUE, NULL);
14584 for (;;) 14631 for (;;)
14585 if (get_tagfname(FALSE, fname) == FAIL 14632 if (get_tagfname(FALSE, fname) == FAIL
14586 || list_append_string(l, fname) == FAIL) 14633 || list_append_string(l, fname, -1) == FAIL)
14587 break; 14634 break;
14588 } 14635 }
14589 14636
14590 /* 14637 /*
14591 * "taglist()" function 14638 * "taglist()" function