comparison src/eval.c @ 338:bfd8935d6200 v7.0087

updated for version 7.0087
author vimboss
date Fri, 17 Jun 2005 22:03:40 +0000
parents 03b3684919e3
children 7033303ea0c0
comparison
equal deleted inserted replaced
337:75786cfb4e86 338:bfd8935d6200
105 static char *e_funcdict = N_("E717: Dictionary entry already exists"); 105 static char *e_funcdict = N_("E717: Dictionary entry already exists");
106 static char *e_funcref = N_("E718: Funcref required"); 106 static char *e_funcref = N_("E718: Funcref required");
107 static char *e_dictrange = N_("E719: Cannot use [:] with a Dictionary"); 107 static char *e_dictrange = N_("E719: Cannot use [:] with a Dictionary");
108 static char *e_letwrong = N_("E734: Wrong variable type for %s="); 108 static char *e_letwrong = N_("E734: Wrong variable type for %s=");
109 static char *e_nofunc = N_("E130: Unknown function: %s"); 109 static char *e_nofunc = N_("E130: Unknown function: %s");
110 110 static char *e_illvar = N_("E461: Illegal variable name: %s");
111 /* 111 /*
112 * All user-defined global variables are stored in dictionary "globvardict". 112 * All user-defined global variables are stored in dictionary "globvardict".
113 * "globvars_var" is the variable that is used for "g:". 113 * "globvars_var" is the variable that is used for "g:".
114 */ 114 */
115 static dict_T globvardict; 115 static dict_T globvardict;
1551 else 1551 else
1552 return skip_var_one(arg); 1552 return skip_var_one(arg);
1553 } 1553 }
1554 1554
1555 /* 1555 /*
1556 * Skip one (assignable) variable name, includig $VAR, d.key, l[idx]. 1556 * Skip one (assignable) variable name, includig @r, $VAR, &option, d.key,
1557 * l[idx].
1557 */ 1558 */
1558 static char_u * 1559 static char_u *
1559 skip_var_one(arg) 1560 skip_var_one(arg)
1560 char_u *arg; 1561 char_u *arg;
1561 { 1562 {
1562 if (vim_strchr((char_u *)"$@&", *arg) != NULL) 1563 if (*arg == '@' && arg[1] != NUL)
1563 ++arg; 1564 return arg + 2;
1564 return find_name_end(arg, NULL, NULL, FNE_INCL_BR | FNE_CHECK_START); 1565 return find_name_end(*arg == '$' || *arg == '&' ? arg + 1 : arg,
1566 NULL, NULL, FNE_INCL_BR | FNE_CHECK_START);
1565 } 1567 }
1566 1568
1567 /* 1569 /*
1568 * List variables for hashtab "ht" with prefix "prefix". 1570 * List variables for hashtab "ht" with prefix "prefix".
1569 * If "empty" is TRUE also list NULL strings as empty strings. 1571 * If "empty" is TRUE also list NULL strings as empty strings.
1884 char_u *s; 1886 char_u *s;
1885 1887
1886 p = get_tv_string_chk(tv); 1888 p = get_tv_string_chk(tv);
1887 if (p != NULL && op != NULL && *op == '.') 1889 if (p != NULL && op != NULL && *op == '.')
1888 { 1890 {
1889 s = get_reg_contents(*arg == '@' ? '"' : *arg, FALSE, FALSE); 1891 s = get_reg_contents(*arg == '@' ? '"' : *arg, TRUE, TRUE);
1890 if (s != NULL) 1892 if (s != NULL)
1891 { 1893 {
1892 p = tofree = concat_str(s, p); 1894 p = tofree = concat_str(s, p);
1893 vim_free(s); 1895 vim_free(s);
1894 } 1896 }
4171 */ 4173 */
4172 case '@': ++*arg; 4174 case '@': ++*arg;
4173 if (evaluate) 4175 if (evaluate)
4174 { 4176 {
4175 rettv->v_type = VAR_STRING; 4177 rettv->v_type = VAR_STRING;
4176 rettv->vval.v_string = get_reg_contents(**arg, 4178 rettv->vval.v_string = get_reg_contents(**arg, TRUE, TRUE);
4177 FALSE, FALSE);
4178 } 4179 }
4179 if (**arg != NUL) 4180 if (**arg != NUL)
4180 ++*arg; 4181 ++*arg;
4181 break; 4182 break;
4182 4183
11413 rettv->vval.v_number = 0; 11414 rettv->vval.v_number = 0;
11414 if (error) 11415 if (error)
11415 return; /* type error; errmsg already given */ 11416 return; /* type error; errmsg already given */
11416 if (stride == 0) 11417 if (stride == 0)
11417 EMSG(_("E726: Stride is zero")); 11418 EMSG(_("E726: Stride is zero"));
11418 else if (stride > 0 ? end < start : end > start) 11419 else if (stride > 0 ? end + 1 < start : end - 1 > start)
11419 EMSG(_("E727: Start past end")); 11420 EMSG(_("E727: Start past end"));
11420 else 11421 else
11421 { 11422 {
11422 l = list_alloc(); 11423 l = list_alloc();
11423 if (l != NULL) 11424 if (l != NULL)
12583 12584
12584 if (check_restricted() || check_secure()) 12585 if (check_restricted() || check_secure())
12585 return; 12586 return;
12586 (void)get_tv_number(&argvars[0]); /* issue errmsg if type error */ 12587 (void)get_tv_number(&argvars[0]); /* issue errmsg if type error */
12587 varname = get_tv_string_chk(&argvars[1]); 12588 varname = get_tv_string_chk(&argvars[1]);
12588 ++emsg_off;
12589 buf = get_buf_tv(&argvars[0]); 12589 buf = get_buf_tv(&argvars[0]);
12590 varp = &argvars[2]; 12590 varp = &argvars[2];
12591 12591
12592 if (buf != NULL && varname != NULL && varp != NULL) 12592 if (buf != NULL && varname != NULL && varp != NULL)
12593 { 12593 {
12604 long numval; 12604 long numval;
12605 char_u *strval; 12605 char_u *strval;
12606 int error = FALSE; 12606 int error = FALSE;
12607 12607
12608 ++varname; 12608 ++varname;
12609 --emsg_off;
12610 numval = get_tv_number_chk(varp, &error); 12609 numval = get_tv_number_chk(varp, &error);
12611 strval = get_tv_string_buf_chk(varp, nbuf); 12610 strval = get_tv_string_buf_chk(varp, nbuf);
12612 ++emsg_off;
12613 if (!error && strval != NULL) 12611 if (!error && strval != NULL)
12614 set_option_value(varname, numval, strval, OPT_LOCAL); 12612 set_option_value(varname, numval, strval, OPT_LOCAL);
12615 } 12613 }
12616 else 12614 else
12617 { 12615 {
12630 aucmd_restbuf(&aco); 12628 aucmd_restbuf(&aco);
12631 #else 12629 #else
12632 curbuf = save_curbuf; 12630 curbuf = save_curbuf;
12633 #endif 12631 #endif
12634 } 12632 }
12635 --emsg_off;
12636 } 12633 }
12637 12634
12638 /* 12635 /*
12639 * "setcmdpos()" function 12636 * "setcmdpos()" function
12640 */ 12637 */
12842 12839
12843 if (check_restricted() || check_secure()) 12840 if (check_restricted() || check_secure())
12844 return; 12841 return;
12845 win = find_win_by_nr(&argvars[0]); 12842 win = find_win_by_nr(&argvars[0]);
12846 varname = get_tv_string_chk(&argvars[1]); 12843 varname = get_tv_string_chk(&argvars[1]);
12847 ++emsg_off;
12848 varp = &argvars[2]; 12844 varp = &argvars[2];
12849 12845
12850 if (win != NULL && varname != NULL && varp != NULL) 12846 if (win != NULL && varname != NULL && varp != NULL)
12851 { 12847 {
12852 #ifdef FEAT_WINDOWS 12848 #ifdef FEAT_WINDOWS
12861 long numval; 12857 long numval;
12862 char_u *strval; 12858 char_u *strval;
12863 int error = FALSE; 12859 int error = FALSE;
12864 12860
12865 ++varname; 12861 ++varname;
12866 --emsg_off;
12867 numval = get_tv_number_chk(varp, &error); 12862 numval = get_tv_number_chk(varp, &error);
12868 strval = get_tv_string_buf_chk(varp, nbuf); 12863 strval = get_tv_string_buf_chk(varp, nbuf);
12869 ++emsg_off;
12870 if (!error && strval != NULL) 12864 if (!error && strval != NULL)
12871 set_option_value(varname, numval, strval, OPT_LOCAL); 12865 set_option_value(varname, numval, strval, OPT_LOCAL);
12872 } 12866 }
12873 else 12867 else
12874 { 12868 {
12890 curwin = save_curwin; 12884 curwin = save_curwin;
12891 curbuf = curwin->w_buffer; 12885 curbuf = curwin->w_buffer;
12892 } 12886 }
12893 #endif 12887 #endif
12894 } 12888 }
12895 --emsg_off;
12896 } 12889 }
12897 12890
12898 /* 12891 /*
12899 * "simplify()" function 12892 * "simplify()" function
12900 */ 12893 */
13457 int id = 0; 13450 int id = 0;
13458 #ifdef FEAT_SYN_HL 13451 #ifdef FEAT_SYN_HL
13459 long lnum; 13452 long lnum;
13460 long col; 13453 long col;
13461 int trans; 13454 int trans;
13462 int transerr; 13455 int transerr = FALSE;
13463 13456
13464 lnum = get_tv_lnum(argvars); /* -1 on type error */ 13457 lnum = get_tv_lnum(argvars); /* -1 on type error */
13465 col = get_tv_number(&argvars[1]) - 1; /* -1 on type error */ 13458 col = get_tv_number(&argvars[1]) - 1; /* -1 on type error */
13466 trans = get_tv_number_chk(&argvars[2], &transerr); 13459 trans = get_tv_number_chk(&argvars[2], &transerr);
13467 13460
15441 int copy; /* make copy of value in "tv" */ 15434 int copy; /* make copy of value in "tv" */
15442 { 15435 {
15443 dictitem_T *v; 15436 dictitem_T *v;
15444 char_u *varname; 15437 char_u *varname;
15445 hashtab_T *ht; 15438 hashtab_T *ht;
15439 char_u *p;
15446 15440
15447 if (tv->v_type == VAR_FUNC) 15441 if (tv->v_type == VAR_FUNC)
15448 { 15442 {
15449 if (!(vim_strchr((char_u *)"wbs", name[0]) != NULL && name[1] == ':') 15443 if (!(vim_strchr((char_u *)"wbs", name[0]) != NULL && name[1] == ':')
15450 && !ASCII_ISUPPER((name[0] != NUL && name[1] == ':') 15444 && !ASCII_ISUPPER((name[0] != NUL && name[1] == ':')
15462 } 15456 }
15463 15457
15464 ht = find_var_ht(name, &varname); 15458 ht = find_var_ht(name, &varname);
15465 if (ht == NULL || *varname == NUL) 15459 if (ht == NULL || *varname == NUL)
15466 { 15460 {
15467 EMSG2(_("E461: Illegal variable name: %s"), name); 15461 EMSG2(_(e_illvar), name);
15468 return; 15462 return;
15469 } 15463 }
15470 15464
15471 v = find_var_in_ht(ht, varname, TRUE); 15465 v = find_var_in_ht(ht, varname, TRUE);
15472 if (v != NULL) 15466 if (v != NULL)
15512 15506
15513 clear_tv(&v->di_tv); 15507 clear_tv(&v->di_tv);
15514 } 15508 }
15515 else /* add a new variable */ 15509 else /* add a new variable */
15516 { 15510 {
15511 /* Make sure the variable name is valid. */
15512 for (p = varname; *p != NUL; ++p)
15513 if (!eval_isnamec1(*p) && (p == varname || !VIM_ISDIGIT(*p)))
15514 {
15515 EMSG2(_(e_illvar), varname);
15516 return;
15517 }
15518
15517 v = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T) 15519 v = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T)
15518 + STRLEN(varname))); 15520 + STRLEN(varname)));
15519 if (v == NULL) 15521 if (v == NULL)
15520 return; 15522 return;
15521 STRCPY(v->di_key, varname); 15523 STRCPY(v->di_key, varname);