comparison src/eval.c @ 713:0c381fb7846c v7.0214

updated for version 7.0214
author vimboss
date Sat, 04 Mar 2006 21:58:33 +0000
parents ecee28dd16d2
children 0f9f4761ad9c
comparison
equal deleted inserted replaced
712:2e887dfa8917 713:0c381fb7846c
643 static void f_wincol __ARGS((typval_T *argvars, typval_T *rettv)); 643 static void f_wincol __ARGS((typval_T *argvars, typval_T *rettv));
644 static void f_winheight __ARGS((typval_T *argvars, typval_T *rettv)); 644 static void f_winheight __ARGS((typval_T *argvars, typval_T *rettv));
645 static void f_winline __ARGS((typval_T *argvars, typval_T *rettv)); 645 static void f_winline __ARGS((typval_T *argvars, typval_T *rettv));
646 static void f_winnr __ARGS((typval_T *argvars, typval_T *rettv)); 646 static void f_winnr __ARGS((typval_T *argvars, typval_T *rettv));
647 static void f_winrestcmd __ARGS((typval_T *argvars, typval_T *rettv)); 647 static void f_winrestcmd __ARGS((typval_T *argvars, typval_T *rettv));
648 static void f_winrestview __ARGS((typval_T *argvars, typval_T *rettv));
649 static void f_winsaveview __ARGS((typval_T *argvars, typval_T *rettv));
648 static void f_winwidth __ARGS((typval_T *argvars, typval_T *rettv)); 650 static void f_winwidth __ARGS((typval_T *argvars, typval_T *rettv));
649 static void f_writefile __ARGS((typval_T *argvars, typval_T *rettv)); 651 static void f_writefile __ARGS((typval_T *argvars, typval_T *rettv));
650 652
651 static int list2fpos __ARGS((typval_T *arg, pos_T *posp, int *fnump)); 653 static int list2fpos __ARGS((typval_T *arg, pos_T *posp, int *fnump));
652 static pos_T *var2fpos __ARGS((typval_T *varp, int lnum, int *fnum)); 654 static pos_T *var2fpos __ARGS((typval_T *varp, int lnum, int *fnum));
7052 {"wincol", 0, 0, f_wincol}, 7054 {"wincol", 0, 0, f_wincol},
7053 {"winheight", 1, 1, f_winheight}, 7055 {"winheight", 1, 1, f_winheight},
7054 {"winline", 0, 0, f_winline}, 7056 {"winline", 0, 0, f_winline},
7055 {"winnr", 0, 1, f_winnr}, 7057 {"winnr", 0, 1, f_winnr},
7056 {"winrestcmd", 0, 0, f_winrestcmd}, 7058 {"winrestcmd", 0, 0, f_winrestcmd},
7059 {"winrestview", 1, 1, f_winrestview},
7060 {"winsaveview", 0, 0, f_winsaveview},
7057 {"winwidth", 1, 1, f_winwidth}, 7061 {"winwidth", 1, 1, f_winwidth},
7058 {"writefile", 2, 3, f_writefile}, 7062 {"writefile", 2, 3, f_writefile},
7059 }; 7063 };
7060 7064
7061 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) 7065 #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
13198 rettv->v_type = VAR_LIST; 13202 rettv->v_type = VAR_LIST;
13199 ++l->lv_refcount; 13203 ++l->lv_refcount;
13200 } 13204 }
13201 } 13205 }
13202 13206
13203 #define SP_NOMOVE 1 /* don't move cursor */ 13207 #define SP_NOMOVE 0x01 /* don't move cursor */
13204 #define SP_REPEAT 2 /* repeat to find outer pair */ 13208 #define SP_REPEAT 0x02 /* repeat to find outer pair */
13205 #define SP_RETCOUNT 4 /* return matchcount */ 13209 #define SP_RETCOUNT 0x04 /* return matchcount */
13206 #define SP_SETPCMARK 8 /* set previous context mark */ 13210 #define SP_SETPCMARK 0x08 /* set previous context mark */
13207 #define SP_START 16 /* accept match at start position */ 13211 #define SP_START 0x10 /* accept match at start position */
13212 #define SP_SUBPAT 0x20 /* return nr of matching sub-pattern */
13213 #define SP_END 0x40 /* leave cursor at end of match */
13208 13214
13209 static int get_search_arg __ARGS((typval_T *varp, int *flagsp)); 13215 static int get_search_arg __ARGS((typval_T *varp, int *flagsp));
13210 13216
13211 /* 13217 /*
13212 * Get flags for a search function. 13218 * Get flags for a search function.
13237 case 'W': p_ws = FALSE; break; 13243 case 'W': p_ws = FALSE; break;
13238 default: mask = 0; 13244 default: mask = 0;
13239 if (flagsp != NULL) 13245 if (flagsp != NULL)
13240 switch (*flags) 13246 switch (*flags)
13241 { 13247 {
13248 case 'c': mask = SP_START; break;
13249 case 'e': mask = SP_END; break;
13250 case 'm': mask = SP_RETCOUNT; break;
13242 case 'n': mask = SP_NOMOVE; break; 13251 case 'n': mask = SP_NOMOVE; break;
13252 case 'p': mask = SP_SUBPAT; break;
13243 case 'r': mask = SP_REPEAT; break; 13253 case 'r': mask = SP_REPEAT; break;
13244 case 'm': mask = SP_RETCOUNT; break;
13245 case 's': mask = SP_SETPCMARK; break; 13254 case 's': mask = SP_SETPCMARK; break;
13246 case 'c': mask = SP_START; break;
13247 } 13255 }
13248 if (mask == 0) 13256 if (mask == 0)
13249 { 13257 {
13250 EMSG2(_(e_invarg2), flags); 13258 EMSG2(_(e_invarg2), flags);
13251 dir = 0; 13259 dir = 0;
13276 int dir; 13284 int dir;
13277 int flags = 0; 13285 int flags = 0;
13278 int retval = 0; /* default: FAIL */ 13286 int retval = 0; /* default: FAIL */
13279 long lnum_stop = 0; 13287 long lnum_stop = 0;
13280 int options = SEARCH_KEEP; 13288 int options = SEARCH_KEEP;
13289 int subpatnum;
13281 13290
13282 pat = get_tv_string(&argvars[0]); 13291 pat = get_tv_string(&argvars[0]);
13283 dir = get_search_arg(&argvars[1], &flags); /* may set p_ws */ 13292 dir = get_search_arg(&argvars[1], &flags); /* may set p_ws */
13284 if (dir == 0) 13293 if (dir == 0)
13285 goto theend; 13294 goto theend;
13286 if (flags & SP_START) 13295 if (flags & SP_START)
13287 options |= SEARCH_START; 13296 options |= SEARCH_START;
13297 if (flags & SP_END)
13298 options |= SEARCH_END;
13288 13299
13289 /* Optional extra argument: line number to stop searching. */ 13300 /* Optional extra argument: line number to stop searching. */
13290 if (argvars[1].v_type != VAR_UNKNOWN 13301 if (argvars[1].v_type != VAR_UNKNOWN
13291 && argvars[2].v_type != VAR_UNKNOWN) 13302 && argvars[2].v_type != VAR_UNKNOWN)
13292 { 13303 {
13294 if (lnum_stop < 0) 13305 if (lnum_stop < 0)
13295 goto theend; 13306 goto theend;
13296 } 13307 }
13297 13308
13298 /* 13309 /*
13299 * This function accepts only SP_NOMOVE, SP_START and SP_SETPCMARK flags. 13310 * This function does not accept SP_REPEAT and SP_RETCOUNT flags.
13300 * Check to make sure only those flags are set. 13311 * Check to make sure only those flags are set.
13301 * Also, Only the SP_NOMOVE or the SP_SETPCMARK flag can be set. Both 13312 * Also, Only the SP_NOMOVE or the SP_SETPCMARK flag can be set. Both
13302 * flags cannot be set. Check for that condition also. 13313 * flags cannot be set. Check for that condition also.
13303 */ 13314 */
13304 if (((flags & ~(SP_NOMOVE | SP_SETPCMARK | SP_START)) != 0) 13315 if (((flags & (SP_REPEAT | SP_RETCOUNT)) != 0)
13305 || ((flags & SP_NOMOVE) && (flags & SP_SETPCMARK))) 13316 || ((flags & SP_NOMOVE) && (flags & SP_SETPCMARK)))
13306 { 13317 {
13307 EMSG2(_(e_invarg2), get_tv_string(&argvars[1])); 13318 EMSG2(_(e_invarg2), get_tv_string(&argvars[1]));
13308 goto theend; 13319 goto theend;
13309 } 13320 }
13310 13321
13311 pos = save_cursor = curwin->w_cursor; 13322 pos = save_cursor = curwin->w_cursor;
13312 if (searchit(curwin, curbuf, &pos, dir, pat, 1L, 13323 subpatnum = searchit(curwin, curbuf, &pos, dir, pat, 1L,
13313 options, RE_SEARCH, (linenr_T)lnum_stop) != FAIL) 13324 options, RE_SEARCH, (linenr_T)lnum_stop);
13314 { 13325 if (subpatnum != FAIL)
13315 retval = pos.lnum; 13326 {
13327 if (flags & SP_SUBPAT)
13328 retval = subpatnum;
13329 else
13330 retval = pos.lnum;
13316 if (flags & SP_SETPCMARK) 13331 if (flags & SP_SETPCMARK)
13317 setpcmark(); 13332 setpcmark();
13318 curwin->w_cursor = pos; 13333 curwin->w_cursor = pos;
13319 if (match_pos != NULL) 13334 if (match_pos != NULL)
13320 { 13335 {
13402 13417
13403 /* Handle the optional fourth argument: flags */ 13418 /* Handle the optional fourth argument: flags */
13404 dir = get_search_arg(&argvars[3], &flags); /* may set p_ws */ 13419 dir = get_search_arg(&argvars[3], &flags); /* may set p_ws */
13405 if (dir == 0) 13420 if (dir == 0)
13406 goto theend; 13421 goto theend;
13407 /* 13422
13423 /* Don't accept SP_END or SP_SUBPAT.
13408 * Only one of the SP_NOMOVE or SP_SETPCMARK flags can be set. 13424 * Only one of the SP_NOMOVE or SP_SETPCMARK flags can be set.
13409 */ 13425 */
13410 if ((flags & SP_NOMOVE) && (flags & SP_SETPCMARK)) 13426 if ((flags & (SP_END | SP_SUBPAT)) != 0
13411 { 13427 || ((flags & SP_NOMOVE) && (flags & SP_SETPCMARK)))
13412 EMSG2(_(e_invarg2), get_tv_string(&argvars[1])); 13428 {
13429 EMSG2(_(e_invarg2), get_tv_string(&argvars[3]));
13413 goto theend; 13430 goto theend;
13414 } 13431 }
13415 13432
13416 /* Optional fifth argument: skip expression */ 13433 /* Optional fifth argument: skip expression */
13417 if (argvars[3].v_type == VAR_UNKNOWN 13434 if (argvars[3].v_type == VAR_UNKNOWN
13487 char_u *spat; /* start pattern */ 13504 char_u *spat; /* start pattern */
13488 char_u *mpat; /* middle pattern */ 13505 char_u *mpat; /* middle pattern */
13489 char_u *epat; /* end pattern */ 13506 char_u *epat; /* end pattern */
13490 int dir; /* BACKWARD or FORWARD */ 13507 int dir; /* BACKWARD or FORWARD */
13491 char_u *skip; /* skip expression */ 13508 char_u *skip; /* skip expression */
13492 int flags; /* SP_RETCOUNT, SP_REPEAT, SP_NOMOVE, SP_START */ 13509 int flags; /* SP_SETPCMARK and other SP_ values */
13493 pos_T *match_pos; 13510 pos_T *match_pos;
13494 linenr_T lnum_stop; /* stop at this line if not zero */ 13511 linenr_T lnum_stop; /* stop at this line if not zero */
13495 { 13512 {
13496 char_u *save_cpo; 13513 char_u *save_cpo;
13497 char_u *pat, *pat2 = NULL, *pat3 = NULL; 13514 char_u *pat, *pat2 = NULL, *pat3 = NULL;
15632 rettv->vval.v_string = ga.ga_data; 15649 rettv->vval.v_string = ga.ga_data;
15633 #else 15650 #else
15634 rettv->vval.v_string = NULL; 15651 rettv->vval.v_string = NULL;
15635 #endif 15652 #endif
15636 rettv->v_type = VAR_STRING; 15653 rettv->v_type = VAR_STRING;
15654 }
15655
15656 /*
15657 * "winrestview()" function
15658 */
15659 /* ARGSUSED */
15660 static void
15661 f_winrestview(argvars, rettv)
15662 typval_T *argvars;
15663 typval_T *rettv;
15664 {
15665 dict_T *dict;
15666
15667 if (argvars[0].v_type != VAR_DICT
15668 || (dict = argvars[0].vval.v_dict) == NULL)
15669 EMSG(_(e_invarg));
15670 else
15671 {
15672 curwin->w_cursor.lnum = get_dict_number(dict, (char_u *)"lnum");
15673 curwin->w_cursor.col = get_dict_number(dict, (char_u *)"col");
15674 #ifdef FEAT_VIRTUALEDIT
15675 curwin->w_cursor.coladd = get_dict_number(dict, (char_u *)"coladd");
15676 #endif
15677 curwin->w_curswant = get_dict_number(dict, (char_u *)"curswant");
15678
15679 curwin->w_topline = get_dict_number(dict, (char_u *)"topline");
15680 #ifdef FEAT_DIFF
15681 curwin->w_topfill = get_dict_number(dict, (char_u *)"topfill");
15682 #endif
15683 curwin->w_leftcol = get_dict_number(dict, (char_u *)"leftcol");
15684 curwin->w_skipcol = get_dict_number(dict, (char_u *)"skipcol");
15685
15686 check_cursor();
15687 changed_cline_bef_curs();
15688 invalidate_botline();
15689 redraw_later(VALID);
15690
15691 if (curwin->w_topline == 0)
15692 curwin->w_topline = 1;
15693 if (curwin->w_topline > curbuf->b_ml.ml_line_count)
15694 curwin->w_topline = curbuf->b_ml.ml_line_count;
15695 #ifdef FEAT_DIFF
15696 check_topfill(curwin, TRUE);
15697 #endif
15698 }
15699 }
15700
15701 /*
15702 * "winsaveview()" function
15703 */
15704 /* ARGSUSED */
15705 static void
15706 f_winsaveview(argvars, rettv)
15707 typval_T *argvars;
15708 typval_T *rettv;
15709 {
15710 dict_T *dict;
15711
15712 dict = dict_alloc();
15713 if (dict == NULL)
15714 return;
15715 rettv->v_type = VAR_DICT;
15716 rettv->vval.v_dict = dict;
15717 ++dict->dv_refcount;
15718
15719 dict_add_nr_str(dict, "lnum", (long)curwin->w_cursor.lnum, NULL);
15720 dict_add_nr_str(dict, "col", (long)curwin->w_cursor.col, NULL);
15721 #ifdef FEAT_VIRTUALEDIT
15722 dict_add_nr_str(dict, "coladd", (long)curwin->w_cursor.coladd, NULL);
15723 #endif
15724 dict_add_nr_str(dict, "curswant", (long)curwin->w_curswant, NULL);
15725
15726 dict_add_nr_str(dict, "topline", (long)curwin->w_topline, NULL);
15727 #ifdef FEAT_DIFF
15728 dict_add_nr_str(dict, "topfill", (long)curwin->w_topfill, NULL);
15729 #endif
15730 dict_add_nr_str(dict, "leftcol", (long)curwin->w_leftcol, NULL);
15731 dict_add_nr_str(dict, "skipcol", (long)curwin->w_skipcol, NULL);
15637 } 15732 }
15638 15733
15639 /* 15734 /*
15640 * "winwidth(nr)" function 15735 * "winwidth(nr)" function
15641 */ 15736 */