Mercurial > vim
comparison src/eval.c @ 86:8173ec1e9f1f v7.0034
updated for version 7.0034
author | vimboss |
---|---|
date | Sat, 08 Jan 2005 16:11:57 +0000 |
parents | d9030055c432 |
children | 2b4debdc8d2c |
comparison
equal
deleted
inserted
replaced
85:fc244e0a6e7e | 86:8173ec1e9f1f |
---|---|
103 | 103 |
104 typedef struct listvar_S listvar; | 104 typedef struct listvar_S listvar; |
105 | 105 |
106 #define VAR_LIST_MAXNEST 100 /* maximum nesting of lists */ | 106 #define VAR_LIST_MAXNEST 100 /* maximum nesting of lists */ |
107 static char *e_letunexp = N_("E18: Unexpected characters in :let"); | 107 static char *e_letunexp = N_("E18: Unexpected characters in :let"); |
108 static char *e_listidx = N_("E999: list index out of range: %ld"); | 108 static char *e_listidx = N_("E684: list index out of range: %ld"); |
109 static char *e_undefvar = N_("E121: Undefined variable: %s"); | 109 static char *e_undefvar = N_("E121: Undefined variable: %s"); |
110 static char *e_missbrac = N_("E111: Missing ']'"); | 110 static char *e_missbrac = N_("E111: Missing ']'"); |
111 static char *e_intern2 = N_("E999: Internal error: %s"); | 111 static char *e_intern2 = N_("E685: Internal error: %s"); |
112 static char *e_listarg = N_("E999: Argument of %s must be a list"); | 112 static char *e_listarg = N_("E686: Argument of %s must be a list"); |
113 | 113 |
114 /* | 114 /* |
115 * All user-defined global variables are stored in "variables". | 115 * All user-defined global variables are stored in "variables". |
116 */ | 116 */ |
117 garray_T variables = {0, 0, sizeof(var), 4, NULL}; | 117 garray_T variables = {0, 0, sizeof(var), 4, NULL}; |
367 static void f_deepcopy __ARGS((typeval *argvars, typeval *rettv)); | 367 static void f_deepcopy __ARGS((typeval *argvars, typeval *rettv)); |
368 static void f_delete __ARGS((typeval *argvars, typeval *rettv)); | 368 static void f_delete __ARGS((typeval *argvars, typeval *rettv)); |
369 static void f_did_filetype __ARGS((typeval *argvars, typeval *rettv)); | 369 static void f_did_filetype __ARGS((typeval *argvars, typeval *rettv)); |
370 static void f_diff_filler __ARGS((typeval *argvars, typeval *rettv)); | 370 static void f_diff_filler __ARGS((typeval *argvars, typeval *rettv)); |
371 static void f_diff_hlID __ARGS((typeval *argvars, typeval *rettv)); | 371 static void f_diff_hlID __ARGS((typeval *argvars, typeval *rettv)); |
372 static void f_empty __ARGS((typeval *argvars, typeval *rettv)); | |
372 static void f_escape __ARGS((typeval *argvars, typeval *rettv)); | 373 static void f_escape __ARGS((typeval *argvars, typeval *rettv)); |
373 static void f_eventhandler __ARGS((typeval *argvars, typeval *rettv)); | 374 static void f_eventhandler __ARGS((typeval *argvars, typeval *rettv)); |
374 static void f_executable __ARGS((typeval *argvars, typeval *rettv)); | 375 static void f_executable __ARGS((typeval *argvars, typeval *rettv)); |
375 static void f_exists __ARGS((typeval *argvars, typeval *rettv)); | 376 static void f_exists __ARGS((typeval *argvars, typeval *rettv)); |
376 static void f_expand __ARGS((typeval *argvars, typeval *rettv)); | 377 static void f_expand __ARGS((typeval *argvars, typeval *rettv)); |
1139 } | 1140 } |
1140 | 1141 |
1141 i = list_len(l); | 1142 i = list_len(l); |
1142 if (semicolon == 0 && var_count < i) | 1143 if (semicolon == 0 && var_count < i) |
1143 { | 1144 { |
1144 EMSG(_("E999: Less targets than List items")); | 1145 EMSG(_("E687: Less targets than List items")); |
1145 return FAIL; | 1146 return FAIL; |
1146 } | 1147 } |
1147 if (var_count - semicolon > i) | 1148 if (var_count - semicolon > i) |
1148 { | 1149 { |
1149 EMSG(_("E999: More targets than List items")); | 1150 EMSG(_("E688: More targets than List items")); |
1150 return FAIL; | 1151 return FAIL; |
1151 } | 1152 } |
1152 | 1153 |
1153 item = l->lv_first; | 1154 item = l->lv_first; |
1154 while (*arg != ']') | 1155 while (*arg != ']') |
1572 tv = &v->tv; | 1573 tv = &v->tv; |
1573 for (p = ip; *p == '['; p = skipwhite(p + 1)) | 1574 for (p = ip; *p == '['; p = skipwhite(p + 1)) |
1574 { | 1575 { |
1575 if (tv->v_type != VAR_LIST || tv->vval.v_list == NULL) | 1576 if (tv->v_type != VAR_LIST || tv->vval.v_list == NULL) |
1576 { | 1577 { |
1577 EMSG(_("E999: Can only index a List")); | 1578 EMSG(_("E689: Can only index a List")); |
1578 p = NULL; | 1579 p = NULL; |
1579 break; | 1580 break; |
1580 } | 1581 } |
1581 p = skipwhite(p + 1); | 1582 p = skipwhite(p + 1); |
1582 if (eval1(&p, &var1, TRUE) == FAIL) /* recursive! */ | 1583 if (eval1(&p, &var1, TRUE) == FAIL) /* recursive! */ |
1705 return fi; | 1706 return fi; |
1706 | 1707 |
1707 expr = skipwhite(expr); | 1708 expr = skipwhite(expr); |
1708 if (expr[0] != 'i' || expr[1] != 'n' || !vim_iswhite(expr[2])) | 1709 if (expr[0] != 'i' || expr[1] != 'n' || !vim_iswhite(expr[2])) |
1709 { | 1710 { |
1710 EMSG(_("E999: Missing \"in\" after :for")); | 1711 EMSG(_("E690: Missing \"in\" after :for")); |
1711 return fi; | 1712 return fi; |
1712 } | 1713 } |
1713 | 1714 |
1714 if (skip) | 1715 if (skip) |
1715 ++emsg_skip; | 1716 ++emsg_skip; |
2585 } | 2586 } |
2586 else if (rettv->v_type != var2.v_type | 2587 else if (rettv->v_type != var2.v_type |
2587 || (type != TYPE_EQUAL && type != TYPE_NEQUAL)) | 2588 || (type != TYPE_EQUAL && type != TYPE_NEQUAL)) |
2588 { | 2589 { |
2589 if (rettv->v_type != var2.v_type) | 2590 if (rettv->v_type != var2.v_type) |
2590 EMSG(_("E999: Can only compare List with List")); | 2591 EMSG(_("E691: Can only compare List with List")); |
2591 else | 2592 else |
2592 EMSG(_("E999: Invalid operation for Lists")); | 2593 EMSG(_("E692: Invalid operation for Lists")); |
2593 clear_tv(rettv); | 2594 clear_tv(rettv); |
2594 clear_tv(&var2); | 2595 clear_tv(&var2); |
2595 return FAIL; | 2596 return FAIL; |
2596 } | 2597 } |
2597 else | 2598 else |
2607 { | 2608 { |
2608 if (rettv->v_type != var2.v_type | 2609 if (rettv->v_type != var2.v_type |
2609 || (type != TYPE_EQUAL && type != TYPE_NEQUAL)) | 2610 || (type != TYPE_EQUAL && type != TYPE_NEQUAL)) |
2610 { | 2611 { |
2611 if (rettv->v_type != var2.v_type) | 2612 if (rettv->v_type != var2.v_type) |
2612 EMSG(_("E999: Can only compare Funcref with Funcref")); | 2613 EMSG(_("E693: Can only compare Funcref with Funcref")); |
2613 else | 2614 else |
2614 EMSG(_("E999: Invalid operation for Funcrefs")); | 2615 EMSG(_("E694: Invalid operation for Funcrefs")); |
2615 clear_tv(rettv); | 2616 clear_tv(rettv); |
2616 clear_tv(&var2); | 2617 clear_tv(&var2); |
2617 return FAIL; | 2618 return FAIL; |
2618 } | 2619 } |
2619 else | 2620 else |
3113 int range; | 3114 int range; |
3114 char_u *s; | 3115 char_u *s; |
3115 | 3116 |
3116 if (rettv->v_type == VAR_FUNC) | 3117 if (rettv->v_type == VAR_FUNC) |
3117 { | 3118 { |
3118 EMSG(_("E999: Cannot index a Funcref")); | 3119 EMSG(_("E695: Cannot index a Funcref")); |
3119 return FAIL; | 3120 return FAIL; |
3120 } | 3121 } |
3121 | 3122 |
3122 /* | 3123 /* |
3123 * Get the (first) variable from inside the []. | 3124 * Get the (first) variable from inside the []. |
3586 | 3587 |
3587 if (**arg == ']') | 3588 if (**arg == ']') |
3588 break; | 3589 break; |
3589 if (**arg != ',') | 3590 if (**arg != ',') |
3590 { | 3591 { |
3591 EMSG2(_("E999: Missing comma in list: %s"), *arg); | 3592 EMSG2(_("E696: Missing comma in list: %s"), *arg); |
3592 goto failret; | 3593 goto failret; |
3593 } | 3594 } |
3594 *arg = skipwhite(*arg + 1); | 3595 *arg = skipwhite(*arg + 1); |
3595 } | 3596 } |
3596 | 3597 |
3597 if (**arg != ']') | 3598 if (**arg != ']') |
3598 { | 3599 { |
3599 EMSG2(_("E999: Missing end of list ']': %s"), *arg); | 3600 EMSG2(_("E697: Missing end of list ']': %s"), *arg); |
3600 failret: | 3601 failret: |
3601 if (evaluate) | 3602 if (evaluate) |
3602 list_free(l); | 3603 list_free(l); |
3603 return FAIL; | 3604 return FAIL; |
3604 } | 3605 } |
3950 | 3951 |
3951 if (orig == NULL) | 3952 if (orig == NULL) |
3952 return NULL; | 3953 return NULL; |
3953 if (recurse >= VAR_LIST_MAXNEST) | 3954 if (recurse >= VAR_LIST_MAXNEST) |
3954 { | 3955 { |
3955 EMSG(_("E999: List nested too deep for making a copy")); | 3956 EMSG(_("E698: List nested too deep for making a copy")); |
3956 return NULL; | 3957 return NULL; |
3957 } | 3958 } |
3958 ++recurse; | 3959 ++recurse; |
3959 | 3960 |
3960 copy = list_alloc(); | 3961 copy = list_alloc(); |
4176 {"deepcopy", 1, 1, f_deepcopy}, | 4177 {"deepcopy", 1, 1, f_deepcopy}, |
4177 {"delete", 1, 1, f_delete}, | 4178 {"delete", 1, 1, f_delete}, |
4178 {"did_filetype", 0, 0, f_did_filetype}, | 4179 {"did_filetype", 0, 0, f_did_filetype}, |
4179 {"diff_filler", 1, 1, f_diff_filler}, | 4180 {"diff_filler", 1, 1, f_diff_filler}, |
4180 {"diff_hlID", 2, 2, f_diff_hlID}, | 4181 {"diff_hlID", 2, 2, f_diff_hlID}, |
4182 {"empty", 1, 1, f_empty}, | |
4181 {"escape", 2, 2, f_escape}, | 4183 {"escape", 2, 2, f_escape}, |
4182 {"eventhandler", 0, 0, f_eventhandler}, | 4184 {"eventhandler", 0, 0, f_eventhandler}, |
4183 {"executable", 1, 1, f_executable}, | 4185 {"executable", 1, 1, f_executable}, |
4184 {"exists", 1, 1, f_exists}, | 4186 {"exists", 1, 1, f_exists}, |
4185 {"expand", 1, 2, f_expand}, | 4187 {"expand", 1, 2, f_expand}, |
5116 for (item = argvars[1].vval.v_list->lv_first; item != NULL; | 5118 for (item = argvars[1].vval.v_list->lv_first; item != NULL; |
5117 item = item->li_next) | 5119 item = item->li_next) |
5118 { | 5120 { |
5119 if (argc == MAX_FUNC_ARGS) | 5121 if (argc == MAX_FUNC_ARGS) |
5120 { | 5122 { |
5121 EMSG(_("E999: Too many arguments")); | 5123 EMSG(_("E699: Too many arguments")); |
5122 break; | 5124 break; |
5123 } | 5125 } |
5124 /* Make a copy of each argument (is this really needed?) */ | 5126 /* Make a copy of each argument (is this really needed?) */ |
5125 copy_tv(&item->li_tv, &argv[argc++]); | 5127 copy_tv(&item->li_tv, &argv[argc++]); |
5126 } | 5128 } |
5508 rettv->vval.v_number = hlID == (enum hlf_value)0 ? 0 : (int)hlID; | 5510 rettv->vval.v_number = hlID == (enum hlf_value)0 ? 0 : (int)hlID; |
5509 #endif | 5511 #endif |
5510 } | 5512 } |
5511 | 5513 |
5512 /* | 5514 /* |
5515 * "empty({expr})" function | |
5516 */ | |
5517 static void | |
5518 f_empty(argvars, rettv) | |
5519 typeval *argvars; | |
5520 typeval *rettv; | |
5521 { | |
5522 int n; | |
5523 | |
5524 switch (argvars[0].v_type) | |
5525 { | |
5526 case VAR_STRING: | |
5527 case VAR_FUNC: | |
5528 n = argvars[0].vval.v_string == NULL | |
5529 || *argvars[0].vval.v_string == NUL; | |
5530 break; | |
5531 case VAR_NUMBER: | |
5532 n = argvars[0].vval.v_number == 0; | |
5533 break; | |
5534 case VAR_LIST: | |
5535 n = argvars[0].vval.v_list == NULL | |
5536 || argvars[0].vval.v_list->lv_first == NULL; | |
5537 break; | |
5538 default: | |
5539 EMSG2(_(e_intern2), "f_empty()"); | |
5540 n = 0; | |
5541 } | |
5542 | |
5543 rettv->vval.v_number = n; | |
5544 } | |
5545 | |
5546 /* | |
5513 * "escape({string}, {chars})" function | 5547 * "escape({string}, {chars})" function |
5514 */ | 5548 */ |
5515 static void | 5549 static void |
5516 f_escape(argvars, rettv) | 5550 f_escape(argvars, rettv) |
5517 typeval *argvars; | 5551 typeval *argvars; |
6068 | 6102 |
6069 s = get_tv_string(&argvars[0]); | 6103 s = get_tv_string(&argvars[0]); |
6070 if (s == NULL || *s == NUL || isdigit(*s)) | 6104 if (s == NULL || *s == NUL || isdigit(*s)) |
6071 EMSG2(_(e_invarg2), s); | 6105 EMSG2(_(e_invarg2), s); |
6072 else if (!function_exists(s)) | 6106 else if (!function_exists(s)) |
6073 EMSG2(_("E999: Unknown function: %s"), s); | 6107 EMSG2(_("E700: Unknown function: %s"), s); |
6074 else | 6108 else |
6075 { | 6109 { |
6076 rettv->vval.v_string = vim_strsave(s); | 6110 rettv->vval.v_string = vim_strsave(s); |
6077 rettv->v_type = VAR_FUNC; | 6111 rettv->v_type = VAR_FUNC; |
6078 } | 6112 } |
7708 break; | 7742 break; |
7709 case VAR_LIST: | 7743 case VAR_LIST: |
7710 rettv->vval.v_number = list_len(argvars[0].vval.v_list); | 7744 rettv->vval.v_number = list_len(argvars[0].vval.v_list); |
7711 break; | 7745 break; |
7712 default: | 7746 default: |
7713 EMSG(_("E999: Invalid type for len()")); | 7747 EMSG(_("E701: Invalid type for len()")); |
7714 break; | 7748 break; |
7715 } | 7749 } |
7716 } | 7750 } |
7717 | 7751 |
7718 static void libcall_common __ARGS((typeval *argvars, typeval *rettv, int type)); | 7752 static void libcall_common __ARGS((typeval *argvars, typeval *rettv, int type)); |
9411 | 9445 |
9412 /* test the compare function */ | 9446 /* test the compare function */ |
9413 if (item_compare_func != NULL | 9447 if (item_compare_func != NULL |
9414 && item_compare2((void *)&ptrs[0], (void *)&ptrs[1]) | 9448 && item_compare2((void *)&ptrs[0], (void *)&ptrs[1]) |
9415 == ITEM_COMPARE_FAIL) | 9449 == ITEM_COMPARE_FAIL) |
9416 EMSG(_("E999: Sort compare function failed")); | 9450 EMSG(_("E702: Sort compare function failed")); |
9417 else | 9451 else |
9418 { | 9452 { |
9419 /* Sort the array with item pointers. */ | 9453 /* Sort the array with item pointers. */ |
9420 qsort((void *)ptrs, (size_t)len, sizeof(listitem *), | 9454 qsort((void *)ptrs, (size_t)len, sizeof(listitem *), |
9421 item_compare_func == NULL ? item_compare : item_compare2); | 9455 item_compare_func == NULL ? item_compare : item_compare2); |
11046 { | 11080 { |
11047 case VAR_NUMBER: | 11081 case VAR_NUMBER: |
11048 n = (long)(varp->vval.v_number); | 11082 n = (long)(varp->vval.v_number); |
11049 break; | 11083 break; |
11050 case VAR_FUNC: | 11084 case VAR_FUNC: |
11051 EMSG(_("E999: Using function reference as a number")); | 11085 EMSG(_("E703: Using function reference as a number")); |
11052 break; | 11086 break; |
11053 case VAR_STRING: | 11087 case VAR_STRING: |
11054 if (varp->vval.v_string != NULL) | 11088 if (varp->vval.v_string != NULL) |
11055 vim_str2nr(varp->vval.v_string, NULL, NULL, | 11089 vim_str2nr(varp->vval.v_string, NULL, NULL, |
11056 TRUE, TRUE, &n, NULL); | 11090 TRUE, TRUE, &n, NULL); |
11418 { | 11452 { |
11419 if (!(vim_strchr((char_u *)"wbs", name[0]) != NULL && name[1] == ':') | 11453 if (!(vim_strchr((char_u *)"wbs", name[0]) != NULL && name[1] == ':') |
11420 && !ASCII_ISUPPER((name[0] != NUL && name[1] == ':') | 11454 && !ASCII_ISUPPER((name[0] != NUL && name[1] == ':') |
11421 ? name[2] : name[0])) | 11455 ? name[2] : name[0])) |
11422 { | 11456 { |
11423 EMSG2(_("E999: Funcref variable name must start with a capital: %s"), name); | 11457 EMSG2(_("E704: Funcref variable name must start with a capital: %s"), name); |
11424 return; | 11458 return; |
11425 } | 11459 } |
11426 if (function_exists(name)) | 11460 if (function_exists(name)) |
11427 { | 11461 { |
11428 EMSG2(_("E999: Variable name conflicts with existing function: %s"), name); | 11462 EMSG2(_("705: Variable name conflicts with existing function: %s"), name); |
11429 return; | 11463 return; |
11430 } | 11464 } |
11431 } | 11465 } |
11432 | 11466 |
11433 v = find_var(name, TRUE); | 11467 v = find_var(name, TRUE); |
11437 && !((v->tv.v_type == VAR_STRING | 11471 && !((v->tv.v_type == VAR_STRING |
11438 || v->tv.v_type == VAR_NUMBER) | 11472 || v->tv.v_type == VAR_NUMBER) |
11439 && (tv->v_type == VAR_STRING | 11473 && (tv->v_type == VAR_STRING |
11440 || tv->v_type == VAR_NUMBER))) | 11474 || tv->v_type == VAR_NUMBER))) |
11441 { | 11475 { |
11442 EMSG2(_("E999: Variable type mismatch for: %s"), name); | 11476 EMSG2(_("E706: Variable type mismatch for: %s"), name); |
11443 return; | 11477 return; |
11444 } | 11478 } |
11445 clear_tv(&v->tv); | 11479 clear_tv(&v->tv); |
11446 } | 11480 } |
11447 else /* add a new variable */ | 11481 else /* add a new variable */ |
12063 * If there are no errors, add the function | 12097 * If there are no errors, add the function |
12064 */ | 12098 */ |
12065 v = find_var(name, FALSE); | 12099 v = find_var(name, FALSE); |
12066 if (v != NULL && v->tv.v_type == VAR_FUNC) | 12100 if (v != NULL && v->tv.v_type == VAR_FUNC) |
12067 { | 12101 { |
12068 EMSG2(_("E999: Function name conflicts with variable: %s"), name); | 12102 EMSG2(_("E707: Function name conflicts with variable: %s"), name); |
12069 goto erret; | 12103 goto erret; |
12070 } | 12104 } |
12071 | 12105 |
12072 fp = find_func(name); | 12106 fp = find_func(name); |
12073 if (fp != NULL) | 12107 if (fp != NULL) |