Mercurial > vim
annotate src/eval.c @ 18920:a76fdc6560c3 v8.2.0021
patch 8.2.0021: timer test fails too often on Travis with MacOS
Commit: https://github.com/vim/vim/commit/bc28e9f15bed94a7680a6bb84690965049da12d8
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Dec 18 20:10:23 2019 +0100
patch 8.2.0021: timer test fails too often on Travis with MacOS
Problem: Timer test fails too often on Travis with MacOS.
Solution: Be less strict with the time.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 18 Dec 2019 20:15:03 +0100 |
parents | 3cf9529b3a4a |
children | 25ebc35e104f |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
10000
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * eval.c: Expression evaluation. | |
12 */ | |
8295
18fd94bd4eb8
commit https://github.com/vim/vim/commit/fefecb0fbe14c44d46f91036d76bbb6c28162da8
Christian Brabandt <cb@256bit.org>
parents:
8291
diff
changeset
|
13 #define USING_FLOAT_STUFF |
7 | 14 |
15 #include "vim.h" | |
16 | |
1624 | 17 #if defined(FEAT_EVAL) || defined(PROTO) |
18 | |
2529
2aaa88366cbb
Fix for float values on VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2513
diff
changeset
|
19 #ifdef VMS |
2aaa88366cbb
Fix for float values on VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2513
diff
changeset
|
20 # include <float.h> |
2aaa88366cbb
Fix for float values on VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2513
diff
changeset
|
21 #endif |
2aaa88366cbb
Fix for float values on VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2513
diff
changeset
|
22 |
71 | 23 static char *e_missbrac = N_("E111: Missing ']'"); |
117 | 24 static char *e_dictrange = N_("E719: Cannot use [:] with a Dictionary"); |
4936
ae05437a744a
updated for version 7.3.1213
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
25 #ifdef FEAT_FLOAT |
4870
b7bb20390111
updated for version 7.3.1181
Bram Moolenaar <bram@vim.org>
parents:
4859
diff
changeset
|
26 static char *e_float_as_string = N_("E806: using Float as a String"); |
4936
ae05437a744a
updated for version 7.3.1213
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
27 #endif |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
28 static char *e_nowhitespace = N_("E274: No white space allowed before parenthesis"); |
1624 | 29 |
7611
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
30 #define NAMESPACE_CHAR (char_u *)"abglstvw" |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
31 |
142 | 32 /* |
364 | 33 * When recursively copying lists and dicts we need to remember which ones we |
34 * have done to avoid endless recursiveness. This unique ID is used for that. | |
1891 | 35 * The last bit is used for previous_funccal, ignored when comparing. |
364 | 36 */ |
37 static int current_copyID = 0; | |
5973 | 38 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
39 static int echo_attr = 0; // attributes used for ":echo" |
7 | 40 |
41 /* | |
76 | 42 * Info used by a ":for" loop. |
43 */ | |
137 | 44 typedef struct |
76 | 45 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
46 int fi_semicolon; // TRUE if ending in '; var]' |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
47 int fi_varcount; // nr of variables in the list |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
48 listwatch_T fi_lw; // keep an eye on the item used. |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
49 list_T *fi_list; // list being used |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
50 int fi_bi; // index of blob |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
51 blob_T *fi_blob; // blob being used |
137 | 52 } forinfo_T; |
76 | 53 |
7720
7c52f11e6df3
commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents:
7718
diff
changeset
|
54 static int tv_op(typval_T *tv1, typval_T *tv2, char_u *op); |
7c52f11e6df3
commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents:
7718
diff
changeset
|
55 static int eval2(char_u **arg, typval_T *rettv, int evaluate); |
7c52f11e6df3
commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents:
7718
diff
changeset
|
56 static int eval3(char_u **arg, typval_T *rettv, int evaluate); |
7c52f11e6df3
commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents:
7718
diff
changeset
|
57 static int eval4(char_u **arg, typval_T *rettv, int evaluate); |
7c52f11e6df3
commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents:
7718
diff
changeset
|
58 static int eval5(char_u **arg, typval_T *rettv, int evaluate); |
7c52f11e6df3
commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents:
7718
diff
changeset
|
59 static int eval6(char_u **arg, typval_T *rettv, int evaluate, int want_string); |
7c52f11e6df3
commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents:
7718
diff
changeset
|
60 static int eval7(char_u **arg, typval_T *rettv, int evaluate, int want_string); |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
61 static int eval7_leader(typval_T *rettv, char_u *start_leader, char_u **end_leaderp); |
7720
7c52f11e6df3
commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents:
7718
diff
changeset
|
62 |
7c52f11e6df3
commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents:
7718
diff
changeset
|
63 static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate); |
7c52f11e6df3
commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents:
7718
diff
changeset
|
64 static int get_lit_string_tv(char_u **arg, typval_T *rettv, int evaluate); |
7c52f11e6df3
commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents:
7718
diff
changeset
|
65 static int free_unref_items(int copyID); |
7c52f11e6df3
commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents:
7718
diff
changeset
|
66 static int get_env_tv(char_u **arg, typval_T *rettv, int evaluate); |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
67 static char_u *make_expanded_name(char_u *in_start, char_u *expr_start, char_u *expr_end, char_u *in_end); |
15780
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
68 static int tv_check_lock(typval_T *tv, char_u *name, int use_gettext); |
2247
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
69 |
15969
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
70 /* |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
71 * Return "n1" divided by "n2", taking care of dividing by zero. |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
72 */ |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17833
diff
changeset
|
73 varnumber_T |
15969
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
74 num_divide(varnumber_T n1, varnumber_T n2) |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
75 { |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
76 varnumber_T result; |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
77 |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
78 if (n2 == 0) // give an error message? |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
79 { |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
80 if (n1 == 0) |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
81 result = VARNUM_MIN; // similar to NaN |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
82 else if (n1 < 0) |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
83 result = -VARNUM_MAX; |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
84 else |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
85 result = VARNUM_MAX; |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
86 } |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
87 else |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
88 result = n1 / n2; |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
89 |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
90 return result; |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
91 } |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
92 |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
93 /* |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
94 * Return "n1" modulus "n2", taking care of dividing by zero. |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
95 */ |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17833
diff
changeset
|
96 varnumber_T |
15969
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
97 num_modulus(varnumber_T n1, varnumber_T n2) |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
98 { |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
99 // Give an error when n2 is 0? |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
100 return (n2 == 0) ? 0 : (n1 % n2); |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
101 } |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
102 |
10567
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
103 #if defined(EBCDIC) || defined(PROTO) |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
104 /* |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
105 * Compare struct fst by function name. |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
106 */ |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
107 static int |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
108 compare_func_name(const void *s1, const void *s2) |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
109 { |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
110 struct fst *p1 = (struct fst *)s1; |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
111 struct fst *p2 = (struct fst *)s2; |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
112 |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
113 return STRCMP(p1->f_name, p2->f_name); |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
114 } |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
115 |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
116 /* |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
117 * Sort the function table by function name. |
15490
98c35d312987
patch 8.1.0753: printf format not checked for semsg()
Bram Moolenaar <Bram@vim.org>
parents:
15482
diff
changeset
|
118 * The sorting of the table above is ASCII dependent. |
10567
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
119 * On machines using EBCDIC we have to sort it. |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
120 */ |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
121 static void |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
122 sortFunctions(void) |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
123 { |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
124 int funcCnt = (int)(sizeof(functions) / sizeof(struct fst)) - 1; |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
125 |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
126 qsort(functions, (size_t)funcCnt, sizeof(struct fst), compare_func_name); |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
127 } |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
128 #endif |
82c2c450dad0
patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents:
10540
diff
changeset
|
129 |
137 | 130 /* |
131 * Initialize the global and v: variables. | |
132 */ | |
133 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
134 eval_init(void) |
137 | 135 { |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
136 evalvars_init(); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
137 func_init(); |
137 | 138 |
2247
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
139 #ifdef EBCDIC |
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
140 /* |
3178 | 141 * Sort the function table, to enable binary search. |
2247
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
142 */ |
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
143 sortFunctions(); |
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
144 #endif |
137 | 145 } |
146 | |
357 | 147 #if defined(EXITFREE) || defined(PROTO) |
148 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
149 eval_clear(void) |
357 | 150 { |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
151 evalvars_clear(); |
357 | 152 |
364 | 153 free_scriptnames(); |
2849 | 154 free_locales(); |
357 | 155 |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
156 // autoloaded script names |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
157 free_autoload_scriptnames(); |
855 | 158 |
16967
586d625e21b4
patch 8.1.1484: some tests are slow
Bram Moolenaar <Bram@vim.org>
parents:
16872
diff
changeset
|
159 // unreferenced lists and dicts |
8881
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
160 (void)garbage_collect(FALSE); |
16969
8c794a694d66
patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents:
16967
diff
changeset
|
161 |
8c794a694d66
patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents:
16967
diff
changeset
|
162 // functions not garbage collected |
8c794a694d66
patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents:
16967
diff
changeset
|
163 free_all_functions(); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
164 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
165 #endif |
137 | 166 |
7 | 167 /* |
168 * Top level evaluation function, returning a boolean. | |
169 * Sets "error" to TRUE if there was an error. | |
170 * Return TRUE or FALSE. | |
171 */ | |
172 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
173 eval_to_bool( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
174 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
175 int *error, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
176 char_u **nextcmd, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
177 int skip) // only parse, don't execute |
7 | 178 { |
137 | 179 typval_T tv; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
180 varnumber_T retval = FALSE; |
7 | 181 |
182 if (skip) | |
183 ++emsg_skip; | |
71 | 184 if (eval0(arg, &tv, nextcmd, !skip) == FAIL) |
7 | 185 *error = TRUE; |
186 else | |
187 { | |
188 *error = FALSE; | |
189 if (!skip) | |
190 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
191 retval = (tv_get_number_chk(&tv, error) != 0); |
71 | 192 clear_tv(&tv); |
7 | 193 } |
194 } | |
195 if (skip) | |
196 --emsg_skip; | |
197 | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
198 return (int)retval; |
7 | 199 } |
200 | |
15478
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
201 /* |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
202 * Call eval1() and give an error message if not done at a lower level. |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
203 */ |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
204 static int |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
205 eval1_emsg(char_u **arg, typval_T *rettv, int evaluate) |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
206 { |
15482
18dd04f7c4a1
patch 8.1.0749: error message contains garbage
Bram Moolenaar <Bram@vim.org>
parents:
15478
diff
changeset
|
207 char_u *start = *arg; |
15478
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
208 int ret; |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
209 int did_emsg_before = did_emsg; |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
210 int called_emsg_before = called_emsg; |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
211 |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
212 ret = eval1(arg, rettv, evaluate); |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
213 if (ret == FAIL) |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
214 { |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
215 // Report the invalid expression unless the expression evaluation has |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
216 // been cancelled due to an aborting error, an interrupt, or an |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
217 // exception, or we already gave a more specific error. |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
218 // Also check called_emsg for when using assert_fails(). |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
219 if (!aborting() && did_emsg == did_emsg_before |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
220 && called_emsg == called_emsg_before) |
15482
18dd04f7c4a1
patch 8.1.0749: error message contains garbage
Bram Moolenaar <Bram@vim.org>
parents:
15478
diff
changeset
|
221 semsg(_(e_invexpr2), start); |
15478
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
222 } |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
223 return ret; |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
224 } |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
225 |
16231
0761a4c111a7
patch 8.1.1120: cannot easily get directory entry matches
Bram Moolenaar <Bram@vim.org>
parents:
16223
diff
changeset
|
226 int |
12722
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
227 eval_expr_typval(typval_T *expr, typval_T *argv, int argc, typval_T *rettv) |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
228 { |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
229 char_u *s; |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
230 char_u buf[NUMBUFLEN]; |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
231 funcexe_T funcexe; |
12722
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
232 |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
233 if (expr->v_type == VAR_FUNC) |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
234 { |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
235 s = expr->vval.v_string; |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
236 if (s == NULL || *s == NUL) |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
237 return FAIL; |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
238 vim_memset(&funcexe, 0, sizeof(funcexe)); |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
239 funcexe.evaluate = TRUE; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
240 if (call_func(s, -1, rettv, argc, argv, &funcexe) == FAIL) |
12722
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
241 return FAIL; |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
242 } |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
243 else if (expr->v_type == VAR_PARTIAL) |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
244 { |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
245 partial_T *partial = expr->vval.v_partial; |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
246 |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
247 s = partial_name(partial); |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
248 if (s == NULL || *s == NUL) |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
249 return FAIL; |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
250 vim_memset(&funcexe, 0, sizeof(funcexe)); |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
251 funcexe.evaluate = TRUE; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
252 funcexe.partial = partial; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
253 if (call_func(s, -1, rettv, argc, argv, &funcexe) == FAIL) |
12722
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
254 return FAIL; |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
255 } |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
256 else |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
257 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
258 s = tv_get_string_buf_chk(expr, buf); |
12722
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
259 if (s == NULL) |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
260 return FAIL; |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
261 s = skipwhite(s); |
15478
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
262 if (eval1_emsg(&s, rettv, TRUE) == FAIL) |
12722
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
263 return FAIL; |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
264 if (*s != NUL) // check for trailing chars after expr |
12722
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
265 { |
14331
f8280e1bfc84
patch 8.1.0181: memory leak with trailing characters in skip expression
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
266 clear_tv(rettv); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
267 semsg(_(e_invexpr2), s); |
12722
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
268 return FAIL; |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
269 } |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
270 } |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
271 return OK; |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
272 } |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
273 |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
274 /* |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
275 * Like eval_to_bool() but using a typval_T instead of a string. |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
276 * Works for string, funcref and partial. |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
277 */ |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
278 int |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
279 eval_expr_to_bool(typval_T *expr, int *error) |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
280 { |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
281 typval_T rettv; |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
282 int res; |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
283 |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
284 if (eval_expr_typval(expr, NULL, 0, &rettv) == FAIL) |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
285 { |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
286 *error = TRUE; |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
287 return FALSE; |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
288 } |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
289 res = (tv_get_number_chk(&rettv, error) != 0); |
12722
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
290 clear_tv(&rettv); |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
291 return res; |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
292 } |
7749260f261c
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
293 |
7 | 294 /* |
295 * Top level evaluation function, returning a string. If "skip" is TRUE, | |
296 * only parsing to "nextcmd" is done, without reporting errors. Return | |
297 * pointer to allocated memory, or NULL for failure or when "skip" is TRUE. | |
298 */ | |
299 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
300 eval_to_string_skip( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
301 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
302 char_u **nextcmd, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
303 int skip) // only parse, don't execute |
7 | 304 { |
137 | 305 typval_T tv; |
7 | 306 char_u *retval; |
307 | |
308 if (skip) | |
309 ++emsg_skip; | |
71 | 310 if (eval0(arg, &tv, nextcmd, !skip) == FAIL || skip) |
7 | 311 retval = NULL; |
312 else | |
313 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
314 retval = vim_strsave(tv_get_string(&tv)); |
71 | 315 clear_tv(&tv); |
7 | 316 } |
317 if (skip) | |
318 --emsg_skip; | |
319 | |
320 return retval; | |
321 } | |
322 | |
323 /* | |
9 | 324 * Skip over an expression at "*pp". |
325 * Return FAIL for an error, OK otherwise. | |
326 */ | |
327 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
328 skip_expr(char_u **pp) |
9 | 329 { |
137 | 330 typval_T rettv; |
9 | 331 |
332 *pp = skipwhite(*pp); | |
71 | 333 return eval1(pp, &rettv, FALSE); |
9 | 334 } |
335 | |
336 /* | |
7 | 337 * Top level evaluation function, returning a string. |
1713 | 338 * When "convert" is TRUE convert a List into a sequence of lines and convert |
339 * a Float to a String. | |
7 | 340 * Return pointer to allocated memory, or NULL for failure. |
341 */ | |
342 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
343 eval_to_string( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
344 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
345 char_u **nextcmd, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
346 int convert) |
7 | 347 { |
137 | 348 typval_T tv; |
7 | 349 char_u *retval; |
714 | 350 garray_T ga; |
1851 | 351 #ifdef FEAT_FLOAT |
1713 | 352 char_u numbuf[NUMBUFLEN]; |
1851 | 353 #endif |
7 | 354 |
71 | 355 if (eval0(arg, &tv, nextcmd, TRUE) == FAIL) |
7 | 356 retval = NULL; |
357 else | |
358 { | |
1713 | 359 if (convert && tv.v_type == VAR_LIST) |
714 | 360 { |
361 ga_init2(&ga, (int)sizeof(char), 80); | |
1690 | 362 if (tv.vval.v_list != NULL) |
3000 | 363 { |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
364 list_join(&ga, tv.vval.v_list, (char_u *)"\n", TRUE, FALSE, 0); |
3000 | 365 if (tv.vval.v_list->lv_len > 0) |
366 ga_append(&ga, NL); | |
367 } | |
714 | 368 ga_append(&ga, NUL); |
369 retval = (char_u *)ga.ga_data; | |
370 } | |
1713 | 371 #ifdef FEAT_FLOAT |
372 else if (convert && tv.v_type == VAR_FLOAT) | |
373 { | |
374 vim_snprintf((char *)numbuf, NUMBUFLEN, "%g", tv.vval.v_float); | |
375 retval = vim_strsave(numbuf); | |
376 } | |
377 #endif | |
714 | 378 else |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
379 retval = vim_strsave(tv_get_string(&tv)); |
71 | 380 clear_tv(&tv); |
7 | 381 } |
382 | |
383 return retval; | |
384 } | |
385 | |
386 /* | |
634 | 387 * Call eval_to_string() without using current local variables and using |
388 * textlock. When "use_sandbox" is TRUE use the sandbox. | |
7 | 389 */ |
390 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
391 eval_to_string_safe( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
392 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
393 char_u **nextcmd, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
394 int use_sandbox) |
7 | 395 { |
396 char_u *retval; | |
14927
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14897
diff
changeset
|
397 funccal_entry_T funccal_entry; |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14897
diff
changeset
|
398 |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14897
diff
changeset
|
399 save_funccal(&funccal_entry); |
634 | 400 if (use_sandbox) |
401 ++sandbox; | |
402 ++textlock; | |
714 | 403 retval = eval_to_string(arg, nextcmd, FALSE); |
634 | 404 if (use_sandbox) |
405 --sandbox; | |
406 --textlock; | |
14927
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14897
diff
changeset
|
407 restore_funccal(); |
7 | 408 return retval; |
409 } | |
410 | |
411 /* | |
412 * Top level evaluation function, returning a number. | |
413 * Evaluates "expr" silently. | |
414 * Returns -1 for an error. | |
415 */ | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
416 varnumber_T |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
417 eval_to_number(char_u *expr) |
7 | 418 { |
137 | 419 typval_T rettv; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
420 varnumber_T retval; |
97 | 421 char_u *p = skipwhite(expr); |
7 | 422 |
423 ++emsg_off; | |
424 | |
71 | 425 if (eval1(&p, &rettv, TRUE) == FAIL) |
7 | 426 retval = -1; |
427 else | |
428 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
429 retval = tv_get_number_chk(&rettv, NULL); |
71 | 430 clear_tv(&rettv); |
7 | 431 } |
432 --emsg_off; | |
433 | |
434 return retval; | |
435 } | |
436 | |
446 | 437 /* |
625 | 438 * Top level evaluation function. |
439 * Returns an allocated typval_T with the result. | |
440 * Returns NULL when there is an error. | |
446 | 441 */ |
442 typval_T * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
443 eval_expr(char_u *arg, char_u **nextcmd) |
446 | 444 { |
445 typval_T *tv; | |
446 | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16796
diff
changeset
|
447 tv = ALLOC_ONE(typval_T); |
625 | 448 if (tv != NULL && eval0(arg, tv, nextcmd, TRUE) == FAIL) |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
449 VIM_CLEAR(tv); |
446 | 450 |
451 return tv; | |
452 } | |
453 | |
7 | 454 /* |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10926
diff
changeset
|
455 * Call some Vim script function and return the result in "*rettv". |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13923
diff
changeset
|
456 * Uses argv[0] to argv[argc - 1] for the function arguments. argv[argc] |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13923
diff
changeset
|
457 * should have type VAR_UNKNOWN. |
408 | 458 * Returns OK or FAIL. |
459 */ | |
3078 | 460 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
461 call_vim_function( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
462 char_u *func, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
463 int argc, |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13923
diff
changeset
|
464 typval_T *argv, |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14393
diff
changeset
|
465 typval_T *rettv) |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13923
diff
changeset
|
466 { |
408 | 467 int ret; |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
468 funcexe_T funcexe; |
7 | 469 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
470 rettv->v_type = VAR_UNKNOWN; // clear_tv() uses this |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
471 vim_memset(&funcexe, 0, sizeof(funcexe)); |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
472 funcexe.firstline = curwin->w_cursor.lnum; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
473 funcexe.lastline = curwin->w_cursor.lnum; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
474 funcexe.evaluate = TRUE; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
475 ret = call_func(func, -1, rettv, argc, argv, &funcexe); |
408 | 476 if (ret == FAIL) |
477 clear_tv(rettv); | |
478 | |
479 return ret; | |
480 } | |
481 | |
4133 | 482 /* |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10926
diff
changeset
|
483 * Call Vim script function "func" and return the result as a number. |
4133 | 484 * Returns -1 when calling the function fails. |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13923
diff
changeset
|
485 * Uses argv[0] to argv[argc - 1] for the function arguments. argv[argc] should |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13923
diff
changeset
|
486 * have type VAR_UNKNOWN. |
4133 | 487 */ |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
488 varnumber_T |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
489 call_func_retnr( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
490 char_u *func, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
491 int argc, |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14393
diff
changeset
|
492 typval_T *argv) |
4133 | 493 { |
494 typval_T rettv; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
495 varnumber_T retval; |
4133 | 496 |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14393
diff
changeset
|
497 if (call_vim_function(func, argc, argv, &rettv) == FAIL) |
4133 | 498 return -1; |
499 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
500 retval = tv_get_number_chk(&rettv, NULL); |
4133 | 501 clear_tv(&rettv); |
502 return retval; | |
503 } | |
504 | |
408 | 505 /* |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10926
diff
changeset
|
506 * Call Vim script function "func" and return the result as a string. |
453 | 507 * Returns NULL when calling the function fails. |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13923
diff
changeset
|
508 * Uses argv[0] to argv[argc - 1] for the function arguments. argv[argc] should |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13923
diff
changeset
|
509 * have type VAR_UNKNOWN. |
408 | 510 */ |
511 void * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
512 call_func_retstr( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
513 char_u *func, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
514 int argc, |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14393
diff
changeset
|
515 typval_T *argv) |
408 | 516 { |
517 typval_T rettv; | |
453 | 518 char_u *retval; |
408 | 519 |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14393
diff
changeset
|
520 if (call_vim_function(func, argc, argv, &rettv) == FAIL) |
408 | 521 return NULL; |
522 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
523 retval = vim_strsave(tv_get_string(&rettv)); |
408 | 524 clear_tv(&rettv); |
7 | 525 return retval; |
526 } | |
1322 | 527 |
453 | 528 /* |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10926
diff
changeset
|
529 * Call Vim script function "func" and return the result as a List. |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13923
diff
changeset
|
530 * Uses argv[0] to argv[argc - 1] for the function arguments. argv[argc] should |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13923
diff
changeset
|
531 * have type VAR_UNKNOWN. |
1690 | 532 * Returns NULL when there is something wrong. |
408 | 533 */ |
534 void * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
535 call_func_retlist( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
536 char_u *func, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
537 int argc, |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14393
diff
changeset
|
538 typval_T *argv) |
408 | 539 { |
540 typval_T rettv; | |
541 | |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14393
diff
changeset
|
542 if (call_vim_function(func, argc, argv, &rettv) == FAIL) |
408 | 543 return NULL; |
544 | |
545 if (rettv.v_type != VAR_LIST) | |
546 { | |
547 clear_tv(&rettv); | |
548 return NULL; | |
549 } | |
550 | |
551 return rettv.vval.v_list; | |
552 } | |
1322 | 553 |
7 | 554 #ifdef FEAT_FOLDING |
555 /* | |
556 * Evaluate 'foldexpr'. Returns the foldlevel, and any character preceding | |
557 * it in "*cp". Doesn't give error messages. | |
558 */ | |
559 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
560 eval_foldexpr(char_u *arg, int *cp) |
7 | 561 { |
137 | 562 typval_T tv; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
563 varnumber_T retval; |
7 | 564 char_u *s; |
681 | 565 int use_sandbox = was_set_insecurely((char_u *)"foldexpr", |
566 OPT_LOCAL); | |
7 | 567 |
568 ++emsg_off; | |
634 | 569 if (use_sandbox) |
570 ++sandbox; | |
571 ++textlock; | |
7 | 572 *cp = NUL; |
71 | 573 if (eval0(arg, &tv, NULL, TRUE) == FAIL) |
7 | 574 retval = 0; |
575 else | |
576 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
577 // If the result is a number, just return the number. |
71 | 578 if (tv.v_type == VAR_NUMBER) |
579 retval = tv.vval.v_number; | |
156 | 580 else if (tv.v_type != VAR_STRING || tv.vval.v_string == NULL) |
7 | 581 retval = 0; |
582 else | |
583 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
584 // If the result is a string, check if there is a non-digit before |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
585 // the number. |
71 | 586 s = tv.vval.v_string; |
7 | 587 if (!VIM_ISDIGIT(*s) && *s != '-') |
588 *cp = *s++; | |
589 retval = atol((char *)s); | |
590 } | |
71 | 591 clear_tv(&tv); |
7 | 592 } |
593 --emsg_off; | |
634 | 594 if (use_sandbox) |
595 --sandbox; | |
596 --textlock; | |
7 | 597 |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
598 return (int)retval; |
7 | 599 } |
600 #endif | |
601 | |
602 /* | |
110 | 603 * Get an lval: variable, Dict item or List item that can be assigned a value |
604 * to: "name", "na{me}", "name[expr]", "name[expr:expr]", "name[expr][expr]", | |
605 * "name.key", "name.key[expr]" etc. | |
606 * Indexing only works if "name" is an existing List or Dictionary. | |
607 * "name" points to the start of the name. | |
608 * If "rettv" is not NULL it points to the value to be assigned. | |
609 * "unlet" is TRUE for ":unlet": slightly different behavior when something is | |
610 * wrong; must end in space or cmd separator. | |
611 * | |
5604 | 612 * flags: |
613 * GLV_QUIET: do not give error messages | |
10912
fd1760f8c215
patch 8.0.0345: islocked('d.changedtick') does not work
Christian Brabandt <cb@256bit.org>
parents:
10910
diff
changeset
|
614 * GLV_READ_ONLY: will not change the variable |
5604 | 615 * GLV_NO_AUTOLOAD: do not use script autoloading |
616 * | |
110 | 617 * Returns a pointer to just after the name, including indexes. |
124 | 618 * When an evaluation error occurs "lp->ll_name" is NULL; |
110 | 619 * Returns NULL for a parsing error. Still need to free items in "lp"! |
71 | 620 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
621 char_u * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
622 get_lval( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
623 char_u *name, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
624 typval_T *rettv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
625 lval_T *lp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
626 int unlet, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
627 int skip, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
628 int flags, // GLV_ values |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
629 int fne_flags) // flags for find_name_end() |
110 | 630 { |
631 char_u *p; | |
632 char_u *expr_start, *expr_end; | |
633 int cc; | |
137 | 634 dictitem_T *v; |
635 typval_T var1; | |
636 typval_T var2; | |
110 | 637 int empty1 = FALSE; |
137 | 638 listitem_T *ni; |
100 | 639 char_u *key = NULL; |
640 int len; | |
137 | 641 hashtab_T *ht; |
5604 | 642 int quiet = flags & GLV_QUIET; |
71 | 643 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
644 // Clear everything in "lp". |
137 | 645 vim_memset(lp, 0, sizeof(lval_T)); |
110 | 646 |
647 if (skip) | |
648 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
649 // When skipping just find the end of the name. |
110 | 650 lp->ll_name = name; |
271 | 651 return find_name_end(name, NULL, NULL, FNE_INCL_BR | fne_flags); |
110 | 652 } |
653 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
654 // Find the end of the name. |
271 | 655 p = find_name_end(name, &expr_start, &expr_end, fne_flags); |
110 | 656 if (expr_start != NULL) |
657 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
658 // Don't expand the name when we already know there is an error. |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
659 if (unlet && !VIM_ISWHITE(*p) && !ends_excmd(*p) |
110 | 660 && *p != '[' && *p != '.') |
661 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
662 emsg(_(e_trailing)); |
110 | 663 return NULL; |
664 } | |
665 | |
666 lp->ll_exp_name = make_expanded_name(name, expr_start, expr_end, p); | |
667 if (lp->ll_exp_name == NULL) | |
668 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
669 // Report an invalid expression in braces, unless the |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
670 // expression evaluation has been cancelled due to an |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
671 // aborting error, an interrupt, or an exception. |
110 | 672 if (!aborting() && !quiet) |
673 { | |
121 | 674 emsg_severe = TRUE; |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
675 semsg(_(e_invarg2), name); |
110 | 676 return NULL; |
677 } | |
678 } | |
679 lp->ll_name = lp->ll_exp_name; | |
680 } | |
681 else | |
682 lp->ll_name = name; | |
683 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
684 // Without [idx] or .key we are done. |
110 | 685 if ((*p != '[' && *p != '.') || lp->ll_name == NULL) |
686 return p; | |
687 | |
688 cc = *p; | |
689 *p = NUL; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
690 // Only pass &ht when we would write to the variable, it prevents autoload |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
691 // as well. |
13002
f7b2ecaeb79c
patch 8.0.1377: cannot call a dict function in autoloaded dict
Christian Brabandt <cb@256bit.org>
parents:
12728
diff
changeset
|
692 v = find_var(lp->ll_name, (flags & GLV_READ_ONLY) ? NULL : &ht, |
f7b2ecaeb79c
patch 8.0.1377: cannot call a dict function in autoloaded dict
Christian Brabandt <cb@256bit.org>
parents:
12728
diff
changeset
|
693 flags & GLV_NO_AUTOLOAD); |
110 | 694 if (v == NULL && !quiet) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
695 semsg(_(e_undefvar), lp->ll_name); |
110 | 696 *p = cc; |
71 | 697 if (v == NULL) |
698 return NULL; | |
699 | |
110 | 700 /* |
701 * Loop until no more [idx] or .key is following. | |
702 */ | |
137 | 703 lp->ll_tv = &v->di_tv; |
10926
7dab3a9cb933
patch 8.0.0352: not easy to see when a typval needs to be cleared
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
704 var1.v_type = VAR_UNKNOWN; |
7dab3a9cb933
patch 8.0.0352: not easy to see when a typval needs to be cleared
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
705 var2.v_type = VAR_UNKNOWN; |
110 | 706 while (*p == '[' || (*p == '.' && lp->ll_tv->v_type == VAR_DICT)) |
707 { | |
708 if (!(lp->ll_tv->v_type == VAR_LIST && lp->ll_tv->vval.v_list != NULL) | |
709 && !(lp->ll_tv->v_type == VAR_DICT | |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
710 && lp->ll_tv->vval.v_dict != NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
711 && !(lp->ll_tv->v_type == VAR_BLOB |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
712 && lp->ll_tv->vval.v_blob != NULL)) |
110 | 713 { |
714 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
715 emsg(_("E689: Can only index a List, Dictionary or Blob")); |
110 | 716 return NULL; |
717 } | |
718 if (lp->ll_range) | |
719 { | |
720 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
721 emsg(_("E708: [:] must come last")); |
110 | 722 return NULL; |
71 | 723 } |
88 | 724 |
100 | 725 len = -1; |
726 if (*p == '.') | |
727 { | |
728 key = p + 1; | |
729 for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; ++len) | |
730 ; | |
731 if (len == 0) | |
732 { | |
110 | 733 if (!quiet) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
734 emsg(_(e_emptykey)); |
110 | 735 return NULL; |
88 | 736 } |
100 | 737 p = key + len; |
738 } | |
739 else | |
740 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
741 // Get the index [expr] or the first index [expr: ]. |
88 | 742 p = skipwhite(p + 1); |
100 | 743 if (*p == ':') |
744 empty1 = TRUE; | |
88 | 745 else |
746 { | |
100 | 747 empty1 = FALSE; |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
748 if (eval1(&p, &var1, TRUE) == FAIL) // recursive! |
110 | 749 return NULL; |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
750 if (tv_get_string_chk(&var1) == NULL) |
323 | 751 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
752 // not a number or string |
323 | 753 clear_tv(&var1); |
754 return NULL; | |
755 } | |
100 | 756 } |
757 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
758 // Optionally get the second index [ :expr]. |
100 | 759 if (*p == ':') |
760 { | |
110 | 761 if (lp->ll_tv->v_type == VAR_DICT) |
762 { | |
763 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
764 emsg(_(e_dictrange)); |
10926
7dab3a9cb933
patch 8.0.0352: not easy to see when a typval needs to be cleared
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
765 clear_tv(&var1); |
110 | 766 return NULL; |
767 } | |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
768 if (rettv != NULL |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
769 && !(rettv->v_type == VAR_LIST |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
770 && rettv->vval.v_list != NULL) |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
771 && !(rettv->v_type == VAR_BLOB |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
772 && rettv->vval.v_blob != NULL)) |
110 | 773 { |
774 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
775 emsg(_("E709: [:] requires a List or Blob value")); |
10926
7dab3a9cb933
patch 8.0.0352: not easy to see when a typval needs to be cleared
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
776 clear_tv(&var1); |
110 | 777 return NULL; |
88 | 778 } |
100 | 779 p = skipwhite(p + 1); |
780 if (*p == ']') | |
110 | 781 lp->ll_empty2 = TRUE; |
100 | 782 else |
783 { | |
110 | 784 lp->ll_empty2 = FALSE; |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
785 if (eval1(&p, &var2, TRUE) == FAIL) // recursive! |
100 | 786 { |
10926
7dab3a9cb933
patch 8.0.0352: not easy to see when a typval needs to be cleared
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
787 clear_tv(&var1); |
110 | 788 return NULL; |
100 | 789 } |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
790 if (tv_get_string_chk(&var2) == NULL) |
323 | 791 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
792 // not a number or string |
10926
7dab3a9cb933
patch 8.0.0352: not easy to see when a typval needs to be cleared
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
793 clear_tv(&var1); |
323 | 794 clear_tv(&var2); |
795 return NULL; | |
796 } | |
100 | 797 } |
110 | 798 lp->ll_range = TRUE; |
100 | 799 } |
800 else | |
110 | 801 lp->ll_range = FALSE; |
100 | 802 |
803 if (*p != ']') | |
804 { | |
110 | 805 if (!quiet) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
806 emsg(_(e_missbrac)); |
10926
7dab3a9cb933
patch 8.0.0352: not easy to see when a typval needs to be cleared
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
807 clear_tv(&var1); |
7dab3a9cb933
patch 8.0.0352: not easy to see when a typval needs to be cleared
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
808 clear_tv(&var2); |
110 | 809 return NULL; |
100 | 810 } |
811 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
812 // Skip to past ']'. |
100 | 813 ++p; |
814 } | |
815 | |
110 | 816 if (lp->ll_tv->v_type == VAR_DICT) |
100 | 817 { |
818 if (len == -1) | |
819 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
820 // "[key]": get key from "var1" |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
821 key = tv_get_string_chk(&var1); // is number or string |
8839
9fa567d13551
commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents:
8831
diff
changeset
|
822 if (key == NULL) |
9fa567d13551
commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents:
8831
diff
changeset
|
823 { |
100 | 824 clear_tv(&var1); |
110 | 825 return NULL; |
826 } | |
827 } | |
117 | 828 lp->ll_list = NULL; |
829 lp->ll_dict = lp->ll_tv->vval.v_dict; | |
121 | 830 lp->ll_di = dict_find(lp->ll_dict, key, len); |
2739 | 831 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
832 // When assigning to a scope dictionary check that a function and |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
833 // variable name is valid (only variable name unless it is l: or |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
834 // g: dictionary). Disallow overwriting a builtin function. |
3687 | 835 if (rettv != NULL && lp->ll_dict->dv_scope != 0) |
836 { | |
837 int prevval; | |
838 int wrong; | |
839 | |
840 if (len != -1) | |
841 { | |
842 prevval = key[len]; | |
843 key[len] = NUL; | |
844 } | |
4819
8c4324e6f477
updated for version 7.3.1156
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
845 else |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
846 prevval = 0; // avoid compiler warning |
3687 | 847 wrong = (lp->ll_dict->dv_scope == VAR_DEF_SCOPE |
848 && rettv->v_type == VAR_FUNC | |
2739 | 849 && var_check_func_name(key, lp->ll_di == NULL)) |
3687 | 850 || !valid_varname(key); |
851 if (len != -1) | |
852 key[len] = prevval; | |
853 if (wrong) | |
2739 | 854 return NULL; |
855 } | |
856 | |
110 | 857 if (lp->ll_di == NULL) |
100 | 858 { |
15762
dff66c4670b1
patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
859 // Can't add "v:" or "a:" variable. |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
860 if (lp->ll_dict == get_vimvar_dict() |
15762
dff66c4670b1
patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
861 || &lp->ll_dict->dv_hashtab == get_funccal_args_ht()) |
2739 | 862 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
863 semsg(_(e_illvar), name); |
16013
93b08b92a049
patch 8.1.1012: memory leak with E461
Bram Moolenaar <Bram@vim.org>
parents:
15969
diff
changeset
|
864 clear_tv(&var1); |
2739 | 865 return NULL; |
866 } | |
867 | |
15762
dff66c4670b1
patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
868 // Key does not exist in dict: may need to add it. |
110 | 869 if (*p == '[' || *p == '.' || unlet) |
870 { | |
871 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
872 semsg(_(e_dictkey), key); |
10926
7dab3a9cb933
patch 8.0.0352: not easy to see when a typval needs to be cleared
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
873 clear_tv(&var1); |
110 | 874 return NULL; |
100 | 875 } |
876 if (len == -1) | |
110 | 877 lp->ll_newkey = vim_strsave(key); |
100 | 878 else |
110 | 879 lp->ll_newkey = vim_strnsave(key, len); |
10926
7dab3a9cb933
patch 8.0.0352: not easy to see when a typval needs to be cleared
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
880 clear_tv(&var1); |
110 | 881 if (lp->ll_newkey == NULL) |
100 | 882 p = NULL; |
883 break; | |
884 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
885 // existing variable, need to check if it can be changed |
10912
fd1760f8c215
patch 8.0.0345: islocked('d.changedtick') does not work
Christian Brabandt <cb@256bit.org>
parents:
10910
diff
changeset
|
886 else if ((flags & GLV_READ_ONLY) == 0 |
fd1760f8c215
patch 8.0.0345: islocked('d.changedtick') does not work
Christian Brabandt <cb@256bit.org>
parents:
10910
diff
changeset
|
887 && var_check_ro(lp->ll_di->di_flags, name, FALSE)) |
10910
8bff367672a4
patch 8.0.0344: unlet command leaks memory
Christian Brabandt <cb@256bit.org>
parents:
10908
diff
changeset
|
888 { |
8bff367672a4
patch 8.0.0344: unlet command leaks memory
Christian Brabandt <cb@256bit.org>
parents:
10908
diff
changeset
|
889 clear_tv(&var1); |
2739 | 890 return NULL; |
10910
8bff367672a4
patch 8.0.0344: unlet command leaks memory
Christian Brabandt <cb@256bit.org>
parents:
10908
diff
changeset
|
891 } |
2739 | 892 |
10926
7dab3a9cb933
patch 8.0.0352: not easy to see when a typval needs to be cleared
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
893 clear_tv(&var1); |
110 | 894 lp->ll_tv = &lp->ll_di->di_tv; |
100 | 895 } |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
896 else if (lp->ll_tv->v_type == VAR_BLOB) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
897 { |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
898 long bloblen = blob_len(lp->ll_tv->vval.v_blob); |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
899 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
900 /* |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
901 * Get the number and item for the only or first index of the List. |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
902 */ |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
903 if (empty1) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
904 lp->ll_n1 = 0; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
905 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
906 // is number or string |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
907 lp->ll_n1 = (long)tv_get_number(&var1); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
908 clear_tv(&var1); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
909 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
910 if (lp->ll_n1 < 0 |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
911 || lp->ll_n1 > bloblen |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
912 || (lp->ll_range && lp->ll_n1 == bloblen)) |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
913 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
914 if (!quiet) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
915 semsg(_(e_blobidx), lp->ll_n1); |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
916 clear_tv(&var2); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
917 return NULL; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
918 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
919 if (lp->ll_range && !lp->ll_empty2) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
920 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
921 lp->ll_n2 = (long)tv_get_number(&var2); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
922 clear_tv(&var2); |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
923 if (lp->ll_n2 < 0 |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
924 || lp->ll_n2 >= bloblen |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
925 || lp->ll_n2 < lp->ll_n1) |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
926 { |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
927 if (!quiet) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
928 semsg(_(e_blobidx), lp->ll_n2); |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
929 return NULL; |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
930 } |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
931 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
932 lp->ll_blob = lp->ll_tv->vval.v_blob; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
933 lp->ll_tv = NULL; |
16036
89fb86821b4a
patch 8.1.1023: may use NULL pointer when indexing a blob
Bram Moolenaar <Bram@vim.org>
parents:
16013
diff
changeset
|
934 break; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
935 } |
100 | 936 else |
937 { | |
938 /* | |
939 * Get the number and item for the only or first index of the List. | |
940 */ | |
941 if (empty1) | |
110 | 942 lp->ll_n1 = 0; |
100 | 943 else |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
944 // is number or string |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
945 lp->ll_n1 = (long)tv_get_number(&var1); |
10926
7dab3a9cb933
patch 8.0.0352: not easy to see when a typval needs to be cleared
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
946 clear_tv(&var1); |
7dab3a9cb933
patch 8.0.0352: not easy to see when a typval needs to be cleared
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
947 |
117 | 948 lp->ll_dict = NULL; |
110 | 949 lp->ll_list = lp->ll_tv->vval.v_list; |
950 lp->ll_li = list_find(lp->ll_list, lp->ll_n1); | |
951 if (lp->ll_li == NULL) | |
952 { | |
842 | 953 if (lp->ll_n1 < 0) |
954 { | |
955 lp->ll_n1 = 0; | |
956 lp->ll_li = list_find(lp->ll_list, lp->ll_n1); | |
957 } | |
958 } | |
959 if (lp->ll_li == NULL) | |
960 { | |
10926
7dab3a9cb933
patch 8.0.0352: not easy to see when a typval needs to be cleared
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
961 clear_tv(&var2); |
2772 | 962 if (!quiet) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
963 semsg(_(e_listidx), lp->ll_n1); |
110 | 964 return NULL; |
100 | 965 } |
966 | |
967 /* | |
968 * May need to find the item or absolute index for the second | |
969 * index of a range. | |
110 | 970 * When no index given: "lp->ll_empty2" is TRUE. |
971 * Otherwise "lp->ll_n2" is set to the second index. | |
100 | 972 */ |
110 | 973 if (lp->ll_range && !lp->ll_empty2) |
974 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
975 lp->ll_n2 = (long)tv_get_number(&var2); |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
976 // is number or string |
88 | 977 clear_tv(&var2); |
110 | 978 if (lp->ll_n2 < 0) |
979 { | |
980 ni = list_find(lp->ll_list, lp->ll_n2); | |
100 | 981 if (ni == NULL) |
2772 | 982 { |
983 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
984 semsg(_(e_listidx), lp->ll_n2); |
110 | 985 return NULL; |
2772 | 986 } |
110 | 987 lp->ll_n2 = list_idx_of_item(lp->ll_list, ni); |
988 } | |
989 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
990 // Check that lp->ll_n2 isn't before lp->ll_n1. |
110 | 991 if (lp->ll_n1 < 0) |
992 lp->ll_n1 = list_idx_of_item(lp->ll_list, lp->ll_li); | |
993 if (lp->ll_n2 < lp->ll_n1) | |
2772 | 994 { |
995 if (!quiet) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
996 semsg(_(e_listidx), lp->ll_n2); |
110 | 997 return NULL; |
2772 | 998 } |
110 | 999 } |
1000 | |
1001 lp->ll_tv = &lp->ll_li->li_tv; | |
1002 } | |
1003 } | |
1004 | |
10926
7dab3a9cb933
patch 8.0.0352: not easy to see when a typval needs to be cleared
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
1005 clear_tv(&var1); |
110 | 1006 return p; |
1007 } | |
1008 | |
1009 /* | |
137 | 1010 * Clear lval "lp" that was filled by get_lval(). |
110 | 1011 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1012 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1013 clear_lval(lval_T *lp) |
110 | 1014 { |
1015 vim_free(lp->ll_exp_name); | |
1016 vim_free(lp->ll_newkey); | |
1017 } | |
1018 | |
1019 /* | |
151 | 1020 * Set a variable that was parsed by get_lval() to "rettv". |
110 | 1021 * "endp" points to just after the parsed name. |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1022 * "op" is NULL, "+" for "+=", "-" for "-=", "*" for "*=", "/" for "/=", |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1023 * "%" for "%=", "." for ".=" or "=" for "=". |
117 | 1024 */ |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17833
diff
changeset
|
1025 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1026 set_var_lval( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1027 lval_T *lp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1028 char_u *endp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1029 typval_T *rettv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1030 int copy, |
17079
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1031 int is_const, // Disallow to modify existing variable for :const |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1032 char_u *op) |
110 | 1033 { |
1034 int cc; | |
137 | 1035 listitem_T *ri; |
1036 dictitem_T *di; | |
110 | 1037 |
1038 if (lp->ll_tv == NULL) | |
1039 { | |
10889
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1040 cc = *endp; |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1041 *endp = NUL; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1042 if (lp->ll_blob != NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1043 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1044 int error = FALSE, val; |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1045 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1046 if (op != NULL && *op != '=') |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1047 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1048 semsg(_(e_letwrong), op); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1049 return; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1050 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1051 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1052 if (lp->ll_range && rettv->v_type == VAR_BLOB) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1053 { |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1054 int il, ir; |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1055 |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1056 if (lp->ll_empty2) |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1057 lp->ll_n2 = blob_len(lp->ll_blob) - 1; |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1058 |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1059 if (lp->ll_n2 - lp->ll_n1 + 1 != blob_len(rettv->vval.v_blob)) |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1060 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1061 emsg(_("E972: Blob value does not have the right number of bytes")); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1062 return; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1063 } |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1064 if (lp->ll_empty2) |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1065 lp->ll_n2 = blob_len(lp->ll_blob); |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1066 |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1067 ir = 0; |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1068 for (il = lp->ll_n1; il <= lp->ll_n2; il++) |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1069 blob_set(lp->ll_blob, il, |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1070 blob_get(rettv->vval.v_blob, ir++)); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1071 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1072 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1073 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1074 val = (int)tv_get_number_chk(rettv, &error); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1075 if (!error) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1076 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1077 garray_T *gap = &lp->ll_blob->bv_ga; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1078 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1079 // Allow for appending a byte. Setting a byte beyond |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1080 // the end is an error otherwise. |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1081 if (lp->ll_n1 < gap->ga_len |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1082 || (lp->ll_n1 == gap->ga_len |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1083 && ga_grow(&lp->ll_blob->bv_ga, 1) == OK)) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1084 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1085 blob_set(lp->ll_blob, lp->ll_n1, val); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1086 if (lp->ll_n1 == gap->ga_len) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1087 ++gap->ga_len; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1088 } |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1089 // error for invalid range was already given in get_lval() |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1090 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1091 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1092 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1093 else if (op != NULL && *op != '=') |
10889
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1094 { |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1095 typval_T tv; |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1096 |
17079
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1097 if (is_const) |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1098 { |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1099 emsg(_(e_cannot_mod)); |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1100 *endp = cc; |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1101 return; |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1102 } |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1103 |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1104 // handle +=, -=, *=, /=, %= and .= |
10889
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1105 di = NULL; |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1106 if (get_var_tv(lp->ll_name, (int)STRLEN(lp->ll_name), |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1107 &tv, &di, TRUE, FALSE) == OK) |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1108 { |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1109 if ((di == NULL |
15780
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
1110 || (!var_check_ro(di->di_flags, lp->ll_name, FALSE) |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
1111 && !tv_check_lock(&di->di_tv, lp->ll_name, FALSE))) |
10889
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1112 && tv_op(&tv, rettv, op) == OK) |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1113 set_var(lp->ll_name, &tv, FALSE); |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1114 clear_tv(&tv); |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1115 } |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1116 } |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1117 else |
17079
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1118 set_var_const(lp->ll_name, rettv, copy, is_const); |
10889
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10728
diff
changeset
|
1119 *endp = cc; |
110 | 1120 } |
15780
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
1121 else if (var_check_lock(lp->ll_newkey == NULL |
151 | 1122 ? lp->ll_tv->v_lock |
6773 | 1123 : lp->ll_tv->vval.v_dict->dv_lock, lp->ll_name, FALSE)) |
151 | 1124 ; |
110 | 1125 else if (lp->ll_range) |
1126 { | |
6166 | 1127 listitem_T *ll_li = lp->ll_li; |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1128 int ll_n1 = lp->ll_n1; |
6166 | 1129 |
17079
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1130 if (is_const) |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1131 { |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1132 emsg(_("E996: Cannot lock a range")); |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1133 return; |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1134 } |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1135 |
6166 | 1136 /* |
1137 * Check whether any of the list items is locked | |
1138 */ | |
6422 | 1139 for (ri = rettv->vval.v_list->lv_first; ri != NULL && ll_li != NULL; ) |
6166 | 1140 { |
15780
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
1141 if (var_check_lock(ll_li->li_tv.v_lock, lp->ll_name, FALSE)) |
6166 | 1142 return; |
1143 ri = ri->li_next; | |
1144 if (ri == NULL || (!lp->ll_empty2 && lp->ll_n2 == ll_n1)) | |
1145 break; | |
1146 ll_li = ll_li->li_next; | |
1147 ++ll_n1; | |
1148 } | |
1149 | |
110 | 1150 /* |
1151 * Assign the List values to the list items. | |
1152 */ | |
1153 for (ri = rettv->vval.v_list->lv_first; ri != NULL; ) | |
1154 { | |
117 | 1155 if (op != NULL && *op != '=') |
1156 tv_op(&lp->ll_li->li_tv, &ri->li_tv, op); | |
1157 else | |
1158 { | |
1159 clear_tv(&lp->ll_li->li_tv); | |
1160 copy_tv(&ri->li_tv, &lp->ll_li->li_tv); | |
1161 } | |
110 | 1162 ri = ri->li_next; |
1163 if (ri == NULL || (!lp->ll_empty2 && lp->ll_n2 == lp->ll_n1)) | |
1164 break; | |
1165 if (lp->ll_li->li_next == NULL) | |
1166 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1167 // Need to add an empty item. |
533 | 1168 if (list_append_number(lp->ll_list, 0) == FAIL) |
110 | 1169 { |
1170 ri = NULL; | |
88 | 1171 break; |
110 | 1172 } |
1173 } | |
1174 lp->ll_li = lp->ll_li->li_next; | |
1175 ++lp->ll_n1; | |
1176 } | |
1177 if (ri != NULL) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1178 emsg(_("E710: List value has more items than target")); |
117 | 1179 else if (lp->ll_empty2 |
1180 ? (lp->ll_li != NULL && lp->ll_li->li_next != NULL) | |
110 | 1181 : lp->ll_n1 != lp->ll_n2) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1182 emsg(_("E711: List value has not enough items")); |
110 | 1183 } |
1184 else | |
1185 { | |
1186 /* | |
1187 * Assign to a List or Dictionary item. | |
1188 */ | |
17079
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1189 if (is_const) |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1190 { |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1191 emsg(_("E996: Cannot lock a list or dict")); |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1192 return; |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1193 } |
110 | 1194 if (lp->ll_newkey != NULL) |
1195 { | |
117 | 1196 if (op != NULL && *op != '=') |
1197 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1198 semsg(_(e_letwrong), op); |
117 | 1199 return; |
1200 } | |
1201 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1202 // Need to add an item to the Dictionary. |
121 | 1203 di = dictitem_alloc(lp->ll_newkey); |
110 | 1204 if (di == NULL) |
1205 return; | |
121 | 1206 if (dict_add(lp->ll_tv->vval.v_dict, di) == FAIL) |
1207 { | |
1208 vim_free(di); | |
1209 return; | |
1210 } | |
110 | 1211 lp->ll_tv = &di->di_tv; |
1212 } | |
117 | 1213 else if (op != NULL && *op != '=') |
1214 { | |
1215 tv_op(lp->ll_tv, rettv, op); | |
1216 return; | |
1217 } | |
110 | 1218 else |
1219 clear_tv(lp->ll_tv); | |
1220 | |
1221 /* | |
1222 * Assign the value to the variable or list item. | |
1223 */ | |
1224 if (copy) | |
1225 copy_tv(rettv, lp->ll_tv); | |
1226 else | |
1227 { | |
1228 *lp->ll_tv = *rettv; | |
156 | 1229 lp->ll_tv->v_lock = 0; |
110 | 1230 init_tv(rettv); |
1231 } | |
1232 } | |
7 | 1233 } |
1234 | |
76 | 1235 /* |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1236 * Handle "tv1 += tv2", "tv1 -= tv2", "tv1 *= tv2", "tv1 /= tv2", "tv1 %= tv2" |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1237 * and "tv1 .= tv2" |
117 | 1238 * Returns OK or FAIL. |
1239 */ | |
1240 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1241 tv_op(typval_T *tv1, typval_T *tv2, char_u *op) |
117 | 1242 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1243 varnumber_T n; |
117 | 1244 char_u numbuf[NUMBUFLEN]; |
1245 char_u *s; | |
1246 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1247 // Can't do anything with a Funcref, Dict, v:true on the right. |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
1248 if (tv2->v_type != VAR_FUNC && tv2->v_type != VAR_DICT |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
1249 && tv2->v_type != VAR_SPECIAL) |
117 | 1250 { |
1251 switch (tv1->v_type) | |
1252 { | |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
1253 case VAR_UNKNOWN: |
117 | 1254 case VAR_DICT: |
1255 case VAR_FUNC: | |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
1256 case VAR_PARTIAL: |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
1257 case VAR_SPECIAL: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
1258 case VAR_JOB: |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
1259 case VAR_CHANNEL: |
117 | 1260 break; |
1261 | |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1262 case VAR_BLOB: |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1263 if (*op != '+' || tv2->v_type != VAR_BLOB) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1264 break; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1265 // BLOB += BLOB |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1266 if (tv1->vval.v_blob != NULL && tv2->vval.v_blob != NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1267 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1268 blob_T *b1 = tv1->vval.v_blob; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1269 blob_T *b2 = tv2->vval.v_blob; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1270 int i, len = blob_len(b2); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1271 for (i = 0; i < len; i++) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1272 ga_append(&b1->bv_ga, blob_get(b2, i)); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1273 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1274 return OK; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1275 |
117 | 1276 case VAR_LIST: |
1277 if (*op != '+' || tv2->v_type != VAR_LIST) | |
1278 break; | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1279 // List += List |
117 | 1280 if (tv1->vval.v_list != NULL && tv2->vval.v_list != NULL) |
1281 list_extend(tv1->vval.v_list, tv2->vval.v_list, NULL); | |
1282 return OK; | |
1283 | |
1284 case VAR_NUMBER: | |
1285 case VAR_STRING: | |
1286 if (tv2->v_type == VAR_LIST) | |
1287 break; | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1288 if (vim_strchr((char_u *)"+-*/%", *op) != NULL) |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1289 { |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1290 // nr += nr , nr -= nr , nr *=nr , nr /= nr , nr %= nr |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1291 n = tv_get_number(tv1); |
1624 | 1292 #ifdef FEAT_FLOAT |
1293 if (tv2->v_type == VAR_FLOAT) | |
1294 { | |
1295 float_T f = n; | |
1296 | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1297 if (*op == '%') |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1298 break; |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1299 switch (*op) |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1300 { |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1301 case '+': f += tv2->vval.v_float; break; |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1302 case '-': f -= tv2->vval.v_float; break; |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1303 case '*': f *= tv2->vval.v_float; break; |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1304 case '/': f /= tv2->vval.v_float; break; |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1305 } |
1624 | 1306 clear_tv(tv1); |
1307 tv1->v_type = VAR_FLOAT; | |
1308 tv1->vval.v_float = f; | |
1309 } | |
117 | 1310 else |
1624 | 1311 #endif |
1312 { | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1313 switch (*op) |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1314 { |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1315 case '+': n += tv_get_number(tv2); break; |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1316 case '-': n -= tv_get_number(tv2); break; |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1317 case '*': n *= tv_get_number(tv2); break; |
15969
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
1318 case '/': n = num_divide(n, tv_get_number(tv2)); break; |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
1319 case '%': n = num_modulus(n, tv_get_number(tv2)); break; |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1320 } |
1624 | 1321 clear_tv(tv1); |
1322 tv1->v_type = VAR_NUMBER; | |
1323 tv1->vval.v_number = n; | |
1324 } | |
1325 } | |
1326 else | |
1327 { | |
1328 if (tv2->v_type == VAR_FLOAT) | |
1329 break; | |
1330 | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1331 // str .= str |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1332 s = tv_get_string(tv1); |
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1333 s = concat_str(s, tv_get_string_buf(tv2, numbuf)); |
117 | 1334 clear_tv(tv1); |
1335 tv1->v_type = VAR_STRING; | |
1336 tv1->vval.v_string = s; | |
1337 } | |
1338 return OK; | |
1624 | 1339 |
1340 case VAR_FLOAT: | |
8364
991d8fd4d841
commit https://github.com/vim/vim/commit/5fac467474376a844407cecc0ff481510ead221c
Christian Brabandt <cb@256bit.org>
parents:
8350
diff
changeset
|
1341 #ifdef FEAT_FLOAT |
1624 | 1342 { |
1343 float_T f; | |
1344 | |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1345 if (*op == '%' || *op == '.' |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1346 || (tv2->v_type != VAR_FLOAT |
1624 | 1347 && tv2->v_type != VAR_NUMBER |
1348 && tv2->v_type != VAR_STRING)) | |
1349 break; | |
1350 if (tv2->v_type == VAR_FLOAT) | |
1351 f = tv2->vval.v_float; | |
1352 else | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1353 f = tv_get_number(tv2); |
15790
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1354 switch (*op) |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1355 { |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1356 case '+': tv1->vval.v_float += f; break; |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1357 case '-': tv1->vval.v_float -= f; break; |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1358 case '*': tv1->vval.v_float *= f; break; |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1359 case '/': tv1->vval.v_float /= f; break; |
05d836c8f1c4
patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents:
15784
diff
changeset
|
1360 } |
1624 | 1361 } |
8364
991d8fd4d841
commit https://github.com/vim/vim/commit/5fac467474376a844407cecc0ff481510ead221c
Christian Brabandt <cb@256bit.org>
parents:
8350
diff
changeset
|
1362 #endif |
1624 | 1363 return OK; |
117 | 1364 } |
1365 } | |
1366 | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1367 semsg(_(e_letwrong), op); |
117 | 1368 return FAIL; |
1369 } | |
1370 | |
1371 /* | |
76 | 1372 * Evaluate the expression used in a ":for var in expr" command. |
1373 * "arg" points to "var". | |
1374 * Set "*errp" to TRUE for an error, FALSE otherwise; | |
1375 * Return a pointer that holds the info. Null when there is an error. | |
1376 */ | |
1377 void * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1378 eval_for_line( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1379 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1380 int *errp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1381 char_u **nextcmdp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1382 int skip) |
76 | 1383 { |
137 | 1384 forinfo_T *fi; |
76 | 1385 char_u *expr; |
137 | 1386 typval_T tv; |
1387 list_T *l; | |
76 | 1388 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1389 *errp = TRUE; // default: there is an error |
76 | 1390 |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16796
diff
changeset
|
1391 fi = ALLOC_CLEAR_ONE(forinfo_T); |
76 | 1392 if (fi == NULL) |
1393 return NULL; | |
1394 | |
1395 expr = skip_var_list(arg, &fi->fi_varcount, &fi->fi_semicolon); | |
1396 if (expr == NULL) | |
1397 return fi; | |
1398 | |
1399 expr = skipwhite(expr); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
1400 if (expr[0] != 'i' || expr[1] != 'n' || !VIM_ISWHITE(expr[2])) |
76 | 1401 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1402 emsg(_("E690: Missing \"in\" after :for")); |
76 | 1403 return fi; |
1404 } | |
1405 | |
1406 if (skip) | |
1407 ++emsg_skip; | |
1408 if (eval0(skipwhite(expr + 2), &tv, nextcmdp, !skip) == OK) | |
1409 { | |
1410 *errp = FALSE; | |
1411 if (!skip) | |
1412 { | |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1413 if (tv.v_type == VAR_LIST) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1414 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1415 l = tv.vval.v_list; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1416 if (l == NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1417 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1418 // a null list is like an empty list: do nothing |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1419 clear_tv(&tv); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1420 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1421 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1422 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1423 // No need to increment the refcount, it's already set for |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1424 // the list being used in "tv". |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1425 fi->fi_list = l; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1426 list_add_watch(l, &fi->fi_lw); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1427 fi->fi_lw.lw_item = l->lv_first; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1428 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1429 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1430 else if (tv.v_type == VAR_BLOB) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1431 { |
15581
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1432 fi->fi_bi = 0; |
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1433 if (tv.vval.v_blob != NULL) |
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1434 { |
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1435 typval_T btv; |
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1436 |
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1437 // Make a copy, so that the iteration still works when the |
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1438 // blob is changed. |
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1439 blob_copy(&tv, &btv); |
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1440 fi->fi_blob = btv.vval.v_blob; |
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1441 } |
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1442 clear_tv(&tv); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1443 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1444 else |
359 | 1445 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1446 emsg(_(e_listreq)); |
359 | 1447 clear_tv(&tv); |
1448 } | |
76 | 1449 } |
1450 } | |
1451 if (skip) | |
1452 --emsg_skip; | |
1453 | |
1454 return fi; | |
1455 } | |
1456 | |
1457 /* | |
1458 * Use the first item in a ":for" list. Advance to the next. | |
1459 * Assign the values to the variable (list). "arg" points to the first one. | |
1460 * Return TRUE when a valid item was found, FALSE when at end of list or | |
1461 * something wrong. | |
1462 */ | |
1463 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1464 next_for_item(void *fi_void, char_u *arg) |
76 | 1465 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
1466 forinfo_T *fi = (forinfo_T *)fi_void; |
76 | 1467 int result; |
137 | 1468 listitem_T *item; |
76 | 1469 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1470 if (fi->fi_blob != NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1471 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1472 typval_T tv; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1473 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1474 if (fi->fi_bi >= blob_len(fi->fi_blob)) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1475 return FALSE; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1476 tv.v_type = VAR_NUMBER; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1477 tv.v_lock = VAR_FIXED; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1478 tv.vval.v_number = blob_get(fi->fi_blob, fi->fi_bi); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1479 ++fi->fi_bi; |
17079
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1480 return ex_let_vars(arg, &tv, TRUE, fi->fi_semicolon, |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1481 fi->fi_varcount, FALSE, NULL) == OK; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1482 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1483 |
76 | 1484 item = fi->fi_lw.lw_item; |
1485 if (item == NULL) | |
1486 result = FALSE; | |
1487 else | |
1488 { | |
1489 fi->fi_lw.lw_item = item->li_next; | |
17079
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1490 result = (ex_let_vars(arg, &item->li_tv, TRUE, fi->fi_semicolon, |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
17053
diff
changeset
|
1491 fi->fi_varcount, FALSE, NULL) == OK); |
76 | 1492 } |
1493 return result; | |
1494 } | |
1495 | |
1496 /* | |
1497 * Free the structure used to store info used by ":for". | |
1498 */ | |
1499 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1500 free_for_info(void *fi_void) |
76 | 1501 { |
137 | 1502 forinfo_T *fi = (forinfo_T *)fi_void; |
76 | 1503 |
92 | 1504 if (fi != NULL && fi->fi_list != NULL) |
359 | 1505 { |
76 | 1506 list_rem_watch(fi->fi_list, &fi->fi_lw); |
359 | 1507 list_unref(fi->fi_list); |
1508 } | |
15460
543cff56dd3f
patch 8.1.0738: using freed memory, for loop over blob leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15458
diff
changeset
|
1509 if (fi != NULL && fi->fi_blob != NULL) |
543cff56dd3f
patch 8.1.0738: using freed memory, for loop over blob leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15458
diff
changeset
|
1510 blob_unref(fi->fi_blob); |
76 | 1511 vim_free(fi); |
1512 } | |
1513 | |
7 | 1514 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1515 set_context_for_expression( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1516 expand_T *xp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1517 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1518 cmdidx_T cmdidx) |
7 | 1519 { |
1520 int got_eq = FALSE; | |
1521 int c; | |
76 | 1522 char_u *p; |
1523 | |
18713
baf890fa1621
patch 8.1.2348: :const cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1524 if (cmdidx == CMD_let || cmdidx == CMD_const) |
76 | 1525 { |
1526 xp->xp_context = EXPAND_USER_VARS; | |
159 | 1527 if (vim_strpbrk(arg, (char_u *)"\"'+-*/%.=!?~|&$([<>,#") == NULL) |
76 | 1528 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1529 // ":let var1 var2 ...": find last space. |
159 | 1530 for (p = arg + STRLEN(arg); p >= arg; ) |
76 | 1531 { |
1532 xp->xp_pattern = p; | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10964
diff
changeset
|
1533 MB_PTR_BACK(arg, p); |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
1534 if (VIM_ISWHITE(*p)) |
76 | 1535 break; |
1536 } | |
1537 return; | |
1538 } | |
1539 } | |
1540 else | |
1541 xp->xp_context = cmdidx == CMD_call ? EXPAND_FUNCTIONS | |
1542 : EXPAND_EXPRESSION; | |
7 | 1543 while ((xp->xp_pattern = vim_strpbrk(arg, |
1544 (char_u *)"\"'+-*/%.=!?~|&$([<>,#")) != NULL) | |
1545 { | |
1546 c = *xp->xp_pattern; | |
1547 if (c == '&') | |
1548 { | |
1549 c = xp->xp_pattern[1]; | |
1550 if (c == '&') | |
1551 { | |
1552 ++xp->xp_pattern; | |
1553 xp->xp_context = cmdidx != CMD_let || got_eq | |
1554 ? EXPAND_EXPRESSION : EXPAND_NOTHING; | |
1555 } | |
1556 else if (c != ' ') | |
201 | 1557 { |
7 | 1558 xp->xp_context = EXPAND_SETTINGS; |
201 | 1559 if ((c == 'l' || c == 'g') && xp->xp_pattern[2] == ':') |
1560 xp->xp_pattern += 2; | |
1561 | |
1562 } | |
7 | 1563 } |
1564 else if (c == '$') | |
1565 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1566 // environment variable |
7 | 1567 xp->xp_context = EXPAND_ENV_VARS; |
1568 } | |
1569 else if (c == '=') | |
1570 { | |
1571 got_eq = TRUE; | |
1572 xp->xp_context = EXPAND_EXPRESSION; | |
1573 } | |
8763
4b83af41f5db
commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents:
8749
diff
changeset
|
1574 else if (c == '#' |
4b83af41f5db
commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents:
8749
diff
changeset
|
1575 && xp->xp_context == EXPAND_EXPRESSION) |
4b83af41f5db
commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents:
8749
diff
changeset
|
1576 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1577 // Autoload function/variable contains '#'. |
8763
4b83af41f5db
commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents:
8749
diff
changeset
|
1578 break; |
4b83af41f5db
commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents:
8749
diff
changeset
|
1579 } |
6367 | 1580 else if ((c == '<' || c == '#') |
7 | 1581 && xp->xp_context == EXPAND_FUNCTIONS |
1582 && vim_strchr(xp->xp_pattern, '(') == NULL) | |
1583 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1584 // Function name can start with "<SNR>" and contain '#'. |
7 | 1585 break; |
1586 } | |
1587 else if (cmdidx != CMD_let || got_eq) | |
1588 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1589 if (c == '"') // string |
7 | 1590 { |
1591 while ((c = *++xp->xp_pattern) != NUL && c != '"') | |
1592 if (c == '\\' && xp->xp_pattern[1] != NUL) | |
1593 ++xp->xp_pattern; | |
1594 xp->xp_context = EXPAND_NOTHING; | |
1595 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1596 else if (c == '\'') // literal string |
7 | 1597 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1598 // Trick: '' is like stopping and starting a literal string. |
7 | 1599 while ((c = *++xp->xp_pattern) != NUL && c != '\'') |
1600 /* skip */ ; | |
1601 xp->xp_context = EXPAND_NOTHING; | |
1602 } | |
1603 else if (c == '|') | |
1604 { | |
1605 if (xp->xp_pattern[1] == '|') | |
1606 { | |
1607 ++xp->xp_pattern; | |
1608 xp->xp_context = EXPAND_EXPRESSION; | |
1609 } | |
1610 else | |
1611 xp->xp_context = EXPAND_COMMANDS; | |
1612 } | |
1613 else | |
1614 xp->xp_context = EXPAND_EXPRESSION; | |
1615 } | |
1616 else | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1617 // Doesn't look like something valid, expand as an expression |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1618 // anyway. |
76 | 1619 xp->xp_context = EXPAND_EXPRESSION; |
7 | 1620 arg = xp->xp_pattern; |
1621 if (*arg != NUL) | |
1622 while ((c = *++arg) != NUL && (c == ' ' || c == '\t')) | |
1623 /* skip */ ; | |
1624 } | |
1625 xp->xp_pattern = arg; | |
1626 } | |
1627 | |
1628 /* | |
8749
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1629 * Return TRUE if "pat" matches "text". |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1630 * Does not use 'cpo' and always uses 'magic'. |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1631 */ |
17377
cb008de2a6ec
patch 8.1.1687: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17375
diff
changeset
|
1632 int |
8749
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1633 pattern_match(char_u *pat, char_u *text, int ic) |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1634 { |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1635 int matches = FALSE; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1636 char_u *save_cpo; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1637 regmatch_T regmatch; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1638 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1639 // avoid 'l' flag in 'cpoptions' |
8749
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1640 save_cpo = p_cpo; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1641 p_cpo = (char_u *)""; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1642 regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1643 if (regmatch.regprog != NULL) |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1644 { |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1645 regmatch.rm_ic = ic; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1646 matches = vim_regexec_nl(®match, text, (colnr_T)0); |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1647 vim_regfree(regmatch.regprog); |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1648 } |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1649 p_cpo = save_cpo; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1650 return matches; |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1651 } |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1652 |
65a5a18d3acf
commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents:
8742
diff
changeset
|
1653 /* |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1654 * Handle a name followed by "(". Both for just "name(arg)" and for |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1655 * "expr->name(arg)". |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1656 * Returns OK or FAIL. |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1657 */ |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1658 static int |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1659 eval_func( |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1660 char_u **arg, // points to "(", will be advanced |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1661 char_u *name, |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1662 int name_len, |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1663 typval_T *rettv, |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1664 int evaluate, |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1665 typval_T *basetv) // "expr" for "expr->name(arg)" |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1666 { |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1667 char_u *s = name; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1668 int len = name_len; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1669 partial_T *partial; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1670 int ret = OK; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1671 |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1672 if (!evaluate) |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1673 check_vars(s, len); |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1674 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1675 // If "s" is the name of a variable of type VAR_FUNC |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1676 // use its contents. |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1677 s = deref_func_name(s, &len, &partial, !evaluate); |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1678 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1679 // Need to make a copy, in case evaluating the arguments makes |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1680 // the name invalid. |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1681 s = vim_strsave(s); |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1682 if (s == NULL) |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1683 ret = FAIL; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1684 else |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1685 { |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1686 funcexe_T funcexe; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1687 |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1688 // Invoke the function. |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1689 vim_memset(&funcexe, 0, sizeof(funcexe)); |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1690 funcexe.firstline = curwin->w_cursor.lnum; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1691 funcexe.lastline = curwin->w_cursor.lnum; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1692 funcexe.evaluate = evaluate; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1693 funcexe.partial = partial; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1694 funcexe.basetv = basetv; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1695 ret = get_func_tv(s, len, rettv, arg, &funcexe); |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1696 } |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1697 vim_free(s); |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1698 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1699 // If evaluate is FALSE rettv->v_type was not set in |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1700 // get_func_tv, but it's needed in handle_subscript() to parse |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1701 // what follows. So set it here. |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1702 if (rettv->v_type == VAR_UNKNOWN && !evaluate && **arg == '(') |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1703 { |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1704 rettv->vval.v_string = NULL; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1705 rettv->v_type = VAR_FUNC; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1706 } |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1707 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1708 // Stop the expression evaluation when immediately |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1709 // aborting on error, or when an interrupt occurred or |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1710 // an exception was thrown but not caught. |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1711 if (evaluate && aborting()) |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1712 { |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1713 if (ret == OK) |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1714 clear_tv(rettv); |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1715 ret = FAIL; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1716 } |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1717 return ret; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1718 } |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1719 |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
1720 /* |
7 | 1721 * The "evaluate" argument: When FALSE, the argument is only parsed but not |
71 | 1722 * executed. The function may return OK, but the rettv will be of type |
7 | 1723 * VAR_UNKNOWN. The function still returns FAIL for a syntax error. |
1724 */ | |
1725 | |
1726 /* | |
1727 * Handle zero level expression. | |
1728 * This calls eval1() and handles error message and nextcmd. | |
71 | 1729 * Put the result in "rettv" when returning OK and "evaluate" is TRUE. |
533 | 1730 * Note: "rettv.v_lock" is not set. |
7 | 1731 * Return OK or FAIL. |
1732 */ | |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1733 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1734 eval0( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1735 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1736 typval_T *rettv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1737 char_u **nextcmd, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1738 int evaluate) |
7 | 1739 { |
1740 int ret; | |
1741 char_u *p; | |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1742 int did_emsg_before = did_emsg; |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1743 int called_emsg_before = called_emsg; |
7 | 1744 |
1745 p = skipwhite(arg); | |
71 | 1746 ret = eval1(&p, rettv, evaluate); |
7 | 1747 if (ret == FAIL || !ends_excmd(*p)) |
1748 { | |
1749 if (ret != FAIL) | |
71 | 1750 clear_tv(rettv); |
7 | 1751 /* |
1752 * Report the invalid expression unless the expression evaluation has | |
1753 * been cancelled due to an aborting error, an interrupt, or an | |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1754 * exception, or we already gave a more specific error. |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1755 * Also check called_emsg for when using assert_fails(). |
7 | 1756 */ |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1757 if (!aborting() && did_emsg == did_emsg_before |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
1758 && called_emsg == called_emsg_before) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1759 semsg(_(e_invexpr2), arg); |
7 | 1760 ret = FAIL; |
1761 } | |
1762 if (nextcmd != NULL) | |
1763 *nextcmd = check_nextcmd(p); | |
1764 | |
1765 return ret; | |
1766 } | |
1767 | |
1768 /* | |
1769 * Handle top level expression: | |
1800 | 1770 * expr2 ? expr1 : expr1 |
7 | 1771 * |
1772 * "arg" must point to the first non-white of the expression. | |
1773 * "arg" is advanced to the next non-white after the recognized expression. | |
1774 * | |
533 | 1775 * Note: "rettv.v_lock" is not set. |
1776 * | |
7 | 1777 * Return OK or FAIL. |
1778 */ | |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
1779 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1780 eval1(char_u **arg, typval_T *rettv, int evaluate) |
7 | 1781 { |
1782 int result; | |
137 | 1783 typval_T var2; |
7 | 1784 |
1785 /* | |
1786 * Get the first variable. | |
1787 */ | |
71 | 1788 if (eval2(arg, rettv, evaluate) == FAIL) |
7 | 1789 return FAIL; |
1790 | |
1791 if ((*arg)[0] == '?') | |
1792 { | |
1793 result = FALSE; | |
1794 if (evaluate) | |
1795 { | |
323 | 1796 int error = FALSE; |
1797 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1798 if (tv_get_number_chk(rettv, &error) != 0) |
7 | 1799 result = TRUE; |
71 | 1800 clear_tv(rettv); |
323 | 1801 if (error) |
1802 return FAIL; | |
7 | 1803 } |
1804 | |
1805 /* | |
1806 * Get the second variable. | |
1807 */ | |
1808 *arg = skipwhite(*arg + 1); | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1809 if (eval1(arg, rettv, evaluate && result) == FAIL) // recursive! |
7 | 1810 return FAIL; |
1811 | |
1812 /* | |
1813 * Check for the ":". | |
1814 */ | |
1815 if ((*arg)[0] != ':') | |
1816 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
1817 emsg(_("E109: Missing ':' after '?'")); |
7 | 1818 if (evaluate && result) |
71 | 1819 clear_tv(rettv); |
7 | 1820 return FAIL; |
1821 } | |
1822 | |
1823 /* | |
1824 * Get the third variable. | |
1825 */ | |
1826 *arg = skipwhite(*arg + 1); | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1827 if (eval1(arg, &var2, evaluate && !result) == FAIL) // recursive! |
7 | 1828 { |
1829 if (evaluate && result) | |
71 | 1830 clear_tv(rettv); |
7 | 1831 return FAIL; |
1832 } | |
1833 if (evaluate && !result) | |
71 | 1834 *rettv = var2; |
7 | 1835 } |
1836 | |
1837 return OK; | |
1838 } | |
1839 | |
1840 /* | |
1841 * Handle first level expression: | |
1842 * expr2 || expr2 || expr2 logical OR | |
1843 * | |
1844 * "arg" must point to the first non-white of the expression. | |
1845 * "arg" is advanced to the next non-white after the recognized expression. | |
1846 * | |
1847 * Return OK or FAIL. | |
1848 */ | |
1849 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1850 eval2(char_u **arg, typval_T *rettv, int evaluate) |
7 | 1851 { |
137 | 1852 typval_T var2; |
7 | 1853 long result; |
1854 int first; | |
323 | 1855 int error = FALSE; |
7 | 1856 |
1857 /* | |
1858 * Get the first variable. | |
1859 */ | |
71 | 1860 if (eval3(arg, rettv, evaluate) == FAIL) |
7 | 1861 return FAIL; |
1862 | |
1863 /* | |
1864 * Repeat until there is no following "||". | |
1865 */ | |
1866 first = TRUE; | |
1867 result = FALSE; | |
1868 while ((*arg)[0] == '|' && (*arg)[1] == '|') | |
1869 { | |
1870 if (evaluate && first) | |
1871 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1872 if (tv_get_number_chk(rettv, &error) != 0) |
7 | 1873 result = TRUE; |
71 | 1874 clear_tv(rettv); |
323 | 1875 if (error) |
1876 return FAIL; | |
7 | 1877 first = FALSE; |
1878 } | |
1879 | |
1880 /* | |
1881 * Get the second variable. | |
1882 */ | |
1883 *arg = skipwhite(*arg + 2); | |
1884 if (eval3(arg, &var2, evaluate && !result) == FAIL) | |
1885 return FAIL; | |
1886 | |
1887 /* | |
1888 * Compute the result. | |
1889 */ | |
1890 if (evaluate && !result) | |
1891 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1892 if (tv_get_number_chk(&var2, &error) != 0) |
7 | 1893 result = TRUE; |
71 | 1894 clear_tv(&var2); |
323 | 1895 if (error) |
1896 return FAIL; | |
7 | 1897 } |
1898 if (evaluate) | |
1899 { | |
71 | 1900 rettv->v_type = VAR_NUMBER; |
1901 rettv->vval.v_number = result; | |
7 | 1902 } |
1903 } | |
1904 | |
1905 return OK; | |
1906 } | |
1907 | |
1908 /* | |
1909 * Handle second level expression: | |
1910 * expr3 && expr3 && expr3 logical AND | |
1911 * | |
1912 * "arg" must point to the first non-white of the expression. | |
1913 * "arg" is advanced to the next non-white after the recognized expression. | |
1914 * | |
1915 * Return OK or FAIL. | |
1916 */ | |
1917 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1918 eval3(char_u **arg, typval_T *rettv, int evaluate) |
7 | 1919 { |
137 | 1920 typval_T var2; |
7 | 1921 long result; |
1922 int first; | |
323 | 1923 int error = FALSE; |
7 | 1924 |
1925 /* | |
1926 * Get the first variable. | |
1927 */ | |
71 | 1928 if (eval4(arg, rettv, evaluate) == FAIL) |
7 | 1929 return FAIL; |
1930 | |
1931 /* | |
1932 * Repeat until there is no following "&&". | |
1933 */ | |
1934 first = TRUE; | |
1935 result = TRUE; | |
1936 while ((*arg)[0] == '&' && (*arg)[1] == '&') | |
1937 { | |
1938 if (evaluate && first) | |
1939 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1940 if (tv_get_number_chk(rettv, &error) == 0) |
7 | 1941 result = FALSE; |
71 | 1942 clear_tv(rettv); |
323 | 1943 if (error) |
1944 return FAIL; | |
7 | 1945 first = FALSE; |
1946 } | |
1947 | |
1948 /* | |
1949 * Get the second variable. | |
1950 */ | |
1951 *arg = skipwhite(*arg + 2); | |
1952 if (eval4(arg, &var2, evaluate && result) == FAIL) | |
1953 return FAIL; | |
1954 | |
1955 /* | |
1956 * Compute the result. | |
1957 */ | |
1958 if (evaluate && result) | |
1959 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1960 if (tv_get_number_chk(&var2, &error) == 0) |
7 | 1961 result = FALSE; |
71 | 1962 clear_tv(&var2); |
323 | 1963 if (error) |
1964 return FAIL; | |
7 | 1965 } |
1966 if (evaluate) | |
1967 { | |
71 | 1968 rettv->v_type = VAR_NUMBER; |
1969 rettv->vval.v_number = result; | |
7 | 1970 } |
1971 } | |
1972 | |
1973 return OK; | |
1974 } | |
1975 | |
1976 /* | |
1977 * Handle third level expression: | |
1978 * var1 == var2 | |
1979 * var1 =~ var2 | |
1980 * var1 != var2 | |
1981 * var1 !~ var2 | |
1982 * var1 > var2 | |
1983 * var1 >= var2 | |
1984 * var1 < var2 | |
1985 * var1 <= var2 | |
80 | 1986 * var1 is var2 |
1987 * var1 isnot var2 | |
7 | 1988 * |
1989 * "arg" must point to the first non-white of the expression. | |
1990 * "arg" is advanced to the next non-white after the recognized expression. | |
1991 * | |
1992 * Return OK or FAIL. | |
1993 */ | |
1994 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
1995 eval4(char_u **arg, typval_T *rettv, int evaluate) |
7 | 1996 { |
137 | 1997 typval_T var2; |
7 | 1998 char_u *p; |
1999 int i; | |
2000 exptype_T type = TYPE_UNKNOWN; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2001 int type_is = FALSE; // TRUE for "is" and "isnot" |
7 | 2002 int len = 2; |
2003 int ic; | |
2004 | |
2005 /* | |
2006 * Get the first variable. | |
2007 */ | |
71 | 2008 if (eval5(arg, rettv, evaluate) == FAIL) |
7 | 2009 return FAIL; |
2010 | |
2011 p = *arg; | |
2012 switch (p[0]) | |
2013 { | |
2014 case '=': if (p[1] == '=') | |
2015 type = TYPE_EQUAL; | |
2016 else if (p[1] == '~') | |
2017 type = TYPE_MATCH; | |
2018 break; | |
2019 case '!': if (p[1] == '=') | |
2020 type = TYPE_NEQUAL; | |
2021 else if (p[1] == '~') | |
2022 type = TYPE_NOMATCH; | |
2023 break; | |
2024 case '>': if (p[1] != '=') | |
2025 { | |
2026 type = TYPE_GREATER; | |
2027 len = 1; | |
2028 } | |
2029 else | |
2030 type = TYPE_GEQUAL; | |
2031 break; | |
2032 case '<': if (p[1] != '=') | |
2033 { | |
2034 type = TYPE_SMALLER; | |
2035 len = 1; | |
2036 } | |
2037 else | |
2038 type = TYPE_SEQUAL; | |
2039 break; | |
80 | 2040 case 'i': if (p[1] == 's') |
2041 { | |
2042 if (p[2] == 'n' && p[3] == 'o' && p[4] == 't') | |
2043 len = 5; | |
7064
5fc5c5bf2233
commit https://github.com/vim/vim/commit/37a8de17d4dfd3d463960c38a204ce399c8e19d4
Christian Brabandt <cb@256bit.org>
parents:
7046
diff
changeset
|
2044 i = p[len]; |
5fc5c5bf2233
commit https://github.com/vim/vim/commit/37a8de17d4dfd3d463960c38a204ce399c8e19d4
Christian Brabandt <cb@256bit.org>
parents:
7046
diff
changeset
|
2045 if (!isalnum(i) && i != '_') |
80 | 2046 { |
2047 type = len == 2 ? TYPE_EQUAL : TYPE_NEQUAL; | |
2048 type_is = TRUE; | |
2049 } | |
2050 } | |
2051 break; | |
7 | 2052 } |
2053 | |
2054 /* | |
1624 | 2055 * If there is a comparative operator, use it. |
7 | 2056 */ |
2057 if (type != TYPE_UNKNOWN) | |
2058 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2059 // extra question mark appended: ignore case |
7 | 2060 if (p[len] == '?') |
2061 { | |
2062 ic = TRUE; | |
2063 ++len; | |
2064 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2065 // extra '#' appended: match case |
7 | 2066 else if (p[len] == '#') |
2067 { | |
2068 ic = FALSE; | |
2069 ++len; | |
2070 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2071 // nothing appended: use 'ignorecase' |
7 | 2072 else |
2073 ic = p_ic; | |
2074 | |
2075 /* | |
2076 * Get the second variable. | |
2077 */ | |
2078 *arg = skipwhite(p + len); | |
2079 if (eval5(arg, &var2, evaluate) == FAIL) | |
2080 { | |
71 | 2081 clear_tv(rettv); |
7 | 2082 return FAIL; |
2083 } | |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
2084 if (evaluate) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
2085 { |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
2086 int ret = typval_compare(rettv, &var2, type, type_is, ic); |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
2087 |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
2088 clear_tv(&var2); |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
2089 return ret; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
2090 } |
7 | 2091 } |
2092 | |
2093 return OK; | |
2094 } | |
2095 | |
2096 /* | |
2097 * Handle fourth level expression: | |
2098 * + number addition | |
2099 * - number subtraction | |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2100 * . string concatenation (if script version is 1) |
16219
bd49e1656c72
patch 8.1.1114: confusing overloaded operator "." for string concatenation
Bram Moolenaar <Bram@vim.org>
parents:
16170
diff
changeset
|
2101 * .. string concatenation |
7 | 2102 * |
2103 * "arg" must point to the first non-white of the expression. | |
2104 * "arg" is advanced to the next non-white after the recognized expression. | |
2105 * | |
2106 * Return OK or FAIL. | |
2107 */ | |
2108 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2109 eval5(char_u **arg, typval_T *rettv, int evaluate) |
7 | 2110 { |
137 | 2111 typval_T var2; |
2112 typval_T var3; | |
7 | 2113 int op; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
2114 varnumber_T n1, n2; |
1624 | 2115 #ifdef FEAT_FLOAT |
2116 float_T f1 = 0, f2 = 0; | |
2117 #endif | |
7 | 2118 char_u *s1, *s2; |
2119 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN]; | |
2120 char_u *p; | |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2121 int concat; |
7 | 2122 |
2123 /* | |
2124 * Get the first variable. | |
2125 */ | |
1655 | 2126 if (eval6(arg, rettv, evaluate, FALSE) == FAIL) |
7 | 2127 return FAIL; |
2128 | |
2129 /* | |
2130 * Repeat computing, until no '+', '-' or '.' is following. | |
2131 */ | |
2132 for (;;) | |
2133 { | |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2134 // "." is only string concatenation when scriptversion is 1 |
7 | 2135 op = **arg; |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2136 concat = op == '.' |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2137 && (*(*arg + 1) == '.' || current_sctx.sc_version < 2); |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2138 if (op != '+' && op != '-' && !concat) |
7 | 2139 break; |
2140 | |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2141 if ((op != '+' || (rettv->v_type != VAR_LIST |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2142 && rettv->v_type != VAR_BLOB)) |
1624 | 2143 #ifdef FEAT_FLOAT |
2144 && (op == '.' || rettv->v_type != VAR_FLOAT) | |
2145 #endif | |
2146 ) | |
323 | 2147 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2148 // For "list + ...", an illegal use of the first operand as |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2149 // a number cannot be determined before evaluating the 2nd |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2150 // operand: if this is also a list, all is ok. |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2151 // For "something . ...", "something - ..." or "non-list + ...", |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2152 // we know that the first operand needs to be a string or number |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2153 // without evaluating the 2nd operand. So check before to avoid |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2154 // side effects after an error. |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2155 if (evaluate && tv_get_string_chk(rettv) == NULL) |
323 | 2156 { |
2157 clear_tv(rettv); | |
2158 return FAIL; | |
2159 } | |
2160 } | |
2161 | |
7 | 2162 /* |
2163 * Get the second variable. | |
2164 */ | |
16219
bd49e1656c72
patch 8.1.1114: confusing overloaded operator "." for string concatenation
Bram Moolenaar <Bram@vim.org>
parents:
16170
diff
changeset
|
2165 if (op == '.' && *(*arg + 1) == '.') // .. string concatenation |
bd49e1656c72
patch 8.1.1114: confusing overloaded operator "." for string concatenation
Bram Moolenaar <Bram@vim.org>
parents:
16170
diff
changeset
|
2166 ++*arg; |
7 | 2167 *arg = skipwhite(*arg + 1); |
1655 | 2168 if (eval6(arg, &var2, evaluate, op == '.') == FAIL) |
7 | 2169 { |
71 | 2170 clear_tv(rettv); |
7 | 2171 return FAIL; |
2172 } | |
2173 | |
2174 if (evaluate) | |
2175 { | |
2176 /* | |
2177 * Compute the result. | |
2178 */ | |
2179 if (op == '.') | |
2180 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2181 s1 = tv_get_string_buf(rettv, buf1); // already checked |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2182 s2 = tv_get_string_buf_chk(&var2, buf2); |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2183 if (s2 == NULL) // type error ? |
323 | 2184 { |
2185 clear_tv(rettv); | |
2186 clear_tv(&var2); | |
2187 return FAIL; | |
2188 } | |
117 | 2189 p = concat_str(s1, s2); |
71 | 2190 clear_tv(rettv); |
2191 rettv->v_type = VAR_STRING; | |
2192 rettv->vval.v_string = p; | |
7 | 2193 } |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2194 else if (op == '+' && rettv->v_type == VAR_BLOB |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2195 && var2.v_type == VAR_BLOB) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2196 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2197 blob_T *b1 = rettv->vval.v_blob; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2198 blob_T *b2 = var2.vval.v_blob; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2199 blob_T *b = blob_alloc(); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2200 int i; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2201 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2202 if (b != NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2203 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2204 for (i = 0; i < blob_len(b1); i++) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2205 ga_append(&b->bv_ga, blob_get(b1, i)); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2206 for (i = 0; i < blob_len(b2); i++) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2207 ga_append(&b->bv_ga, blob_get(b2, i)); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2208 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2209 clear_tv(rettv); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2210 rettv_blob_set(rettv, b); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2211 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2212 } |
104 | 2213 else if (op == '+' && rettv->v_type == VAR_LIST |
2214 && var2.v_type == VAR_LIST) | |
80 | 2215 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2216 // concatenate Lists |
80 | 2217 if (list_concat(rettv->vval.v_list, var2.vval.v_list, |
2218 &var3) == FAIL) | |
2219 { | |
2220 clear_tv(rettv); | |
2221 clear_tv(&var2); | |
2222 return FAIL; | |
2223 } | |
2224 clear_tv(rettv); | |
2225 *rettv = var3; | |
2226 } | |
7 | 2227 else |
2228 { | |
323 | 2229 int error = FALSE; |
2230 | |
1624 | 2231 #ifdef FEAT_FLOAT |
2232 if (rettv->v_type == VAR_FLOAT) | |
2233 { | |
2234 f1 = rettv->vval.v_float; | |
2235 n1 = 0; | |
2236 } | |
2237 else | |
2238 #endif | |
2239 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2240 n1 = tv_get_number_chk(rettv, &error); |
1624 | 2241 if (error) |
2242 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2243 // This can only happen for "list + non-list". For |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2244 // "non-list + ..." or "something - ...", we returned |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2245 // before evaluating the 2nd operand. |
1624 | 2246 clear_tv(rettv); |
2247 return FAIL; | |
2248 } | |
2249 #ifdef FEAT_FLOAT | |
2250 if (var2.v_type == VAR_FLOAT) | |
2251 f1 = n1; | |
2252 #endif | |
2253 } | |
2254 #ifdef FEAT_FLOAT | |
2255 if (var2.v_type == VAR_FLOAT) | |
2256 { | |
2257 f2 = var2.vval.v_float; | |
2258 n2 = 0; | |
2259 } | |
2260 else | |
2261 #endif | |
2262 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2263 n2 = tv_get_number_chk(&var2, &error); |
1624 | 2264 if (error) |
2265 { | |
2266 clear_tv(rettv); | |
2267 clear_tv(&var2); | |
2268 return FAIL; | |
2269 } | |
2270 #ifdef FEAT_FLOAT | |
2271 if (rettv->v_type == VAR_FLOAT) | |
2272 f2 = n2; | |
2273 #endif | |
323 | 2274 } |
71 | 2275 clear_tv(rettv); |
1624 | 2276 |
2277 #ifdef FEAT_FLOAT | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2278 // If there is a float on either side the result is a float. |
1624 | 2279 if (rettv->v_type == VAR_FLOAT || var2.v_type == VAR_FLOAT) |
2280 { | |
2281 if (op == '+') | |
2282 f1 = f1 + f2; | |
2283 else | |
2284 f1 = f1 - f2; | |
2285 rettv->v_type = VAR_FLOAT; | |
2286 rettv->vval.v_float = f1; | |
2287 } | |
2288 else | |
2289 #endif | |
2290 { | |
2291 if (op == '+') | |
2292 n1 = n1 + n2; | |
2293 else | |
2294 n1 = n1 - n2; | |
2295 rettv->v_type = VAR_NUMBER; | |
2296 rettv->vval.v_number = n1; | |
2297 } | |
71 | 2298 } |
2299 clear_tv(&var2); | |
7 | 2300 } |
2301 } | |
2302 return OK; | |
2303 } | |
2304 | |
2305 /* | |
2306 * Handle fifth level expression: | |
2307 * * number multiplication | |
2308 * / number division | |
2309 * % number modulo | |
2310 * | |
2311 * "arg" must point to the first non-white of the expression. | |
2312 * "arg" is advanced to the next non-white after the recognized expression. | |
2313 * | |
2314 * Return OK or FAIL. | |
2315 */ | |
2316 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2317 eval6( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2318 char_u **arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2319 typval_T *rettv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2320 int evaluate, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2321 int want_string) // after "." operator |
7 | 2322 { |
137 | 2323 typval_T var2; |
7 | 2324 int op; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
2325 varnumber_T n1, n2; |
1624 | 2326 #ifdef FEAT_FLOAT |
2327 int use_float = FALSE; | |
16405
840fa633ad64
patch 8.1.1207: some compilers give warning messages
Bram Moolenaar <Bram@vim.org>
parents:
16366
diff
changeset
|
2328 float_T f1 = 0, f2 = 0; |
1624 | 2329 #endif |
323 | 2330 int error = FALSE; |
7 | 2331 |
2332 /* | |
2333 * Get the first variable. | |
2334 */ | |
1655 | 2335 if (eval7(arg, rettv, evaluate, want_string) == FAIL) |
7 | 2336 return FAIL; |
2337 | |
2338 /* | |
2339 * Repeat computing, until no '*', '/' or '%' is following. | |
2340 */ | |
2341 for (;;) | |
2342 { | |
2343 op = **arg; | |
17387
2558f90045e5
patch 8.1.1692: using *{} for literal dict is not backwards compatible
Bram Moolenaar <Bram@vim.org>
parents:
17377
diff
changeset
|
2344 if (op != '*' && op != '/' && op != '%') |
7 | 2345 break; |
2346 | |
2347 if (evaluate) | |
2348 { | |
1624 | 2349 #ifdef FEAT_FLOAT |
2350 if (rettv->v_type == VAR_FLOAT) | |
2351 { | |
2352 f1 = rettv->vval.v_float; | |
2353 use_float = TRUE; | |
2354 n1 = 0; | |
2355 } | |
2356 else | |
2357 #endif | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2358 n1 = tv_get_number_chk(rettv, &error); |
71 | 2359 clear_tv(rettv); |
323 | 2360 if (error) |
2361 return FAIL; | |
7 | 2362 } |
2363 else | |
2364 n1 = 0; | |
2365 | |
2366 /* | |
2367 * Get the second variable. | |
2368 */ | |
2369 *arg = skipwhite(*arg + 1); | |
1655 | 2370 if (eval7(arg, &var2, evaluate, FALSE) == FAIL) |
7 | 2371 return FAIL; |
2372 | |
2373 if (evaluate) | |
2374 { | |
1624 | 2375 #ifdef FEAT_FLOAT |
2376 if (var2.v_type == VAR_FLOAT) | |
2377 { | |
2378 if (!use_float) | |
2379 { | |
2380 f1 = n1; | |
2381 use_float = TRUE; | |
2382 } | |
2383 f2 = var2.vval.v_float; | |
2384 n2 = 0; | |
2385 } | |
2386 else | |
2387 #endif | |
2388 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
2389 n2 = tv_get_number_chk(&var2, &error); |
1624 | 2390 clear_tv(&var2); |
2391 if (error) | |
2392 return FAIL; | |
2393 #ifdef FEAT_FLOAT | |
2394 if (use_float) | |
2395 f2 = n2; | |
2396 #endif | |
2397 } | |
7 | 2398 |
2399 /* | |
2400 * Compute the result. | |
1624 | 2401 * When either side is a float the result is a float. |
7 | 2402 */ |
1624 | 2403 #ifdef FEAT_FLOAT |
2404 if (use_float) | |
2405 { | |
2406 if (op == '*') | |
2407 f1 = f1 * f2; | |
2408 else if (op == '/') | |
2409 { | |
2441
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2410 # ifdef VMS |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2411 // VMS crashes on divide by zero, work around it |
2441
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2412 if (f2 == 0.0) |
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2413 { |
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2414 if (f1 == 0) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2415 f1 = -1 * __F_FLT_MAX - 1L; // similar to NaN |
2441
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2416 else if (f1 < 0) |
2529
2aaa88366cbb
Fix for float values on VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2513
diff
changeset
|
2417 f1 = -1 * __F_FLT_MAX; |
2441
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2418 else |
2529
2aaa88366cbb
Fix for float values on VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2513
diff
changeset
|
2419 f1 = __F_FLT_MAX; |
2441
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2420 } |
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2421 else |
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2422 f1 = f1 / f2; |
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2423 # else |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2424 // We rely on the floating point library to handle divide |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2425 // by zero to result in "inf" and not a crash. |
1624 | 2426 f1 = f1 / f2; |
2441
620a42739426
Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents:
2427
diff
changeset
|
2427 # endif |
1624 | 2428 } |
2429 else | |
2430 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
2431 emsg(_("E804: Cannot use '%' with Float")); |
1624 | 2432 return FAIL; |
2433 } | |
2434 rettv->v_type = VAR_FLOAT; | |
2435 rettv->vval.v_float = f1; | |
2436 } | |
2437 else | |
2438 #endif | |
2439 { | |
2440 if (op == '*') | |
2441 n1 = n1 * n2; | |
2442 else if (op == '/') | |
15969
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
2443 n1 = num_divide(n1, n2); |
1624 | 2444 else |
15969
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
2445 n1 = num_modulus(n1, n2); |
9cc42db77a54
patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
2446 |
1624 | 2447 rettv->v_type = VAR_NUMBER; |
2448 rettv->vval.v_number = n1; | |
2449 } | |
7 | 2450 } |
2451 } | |
2452 | |
2453 return OK; | |
2454 } | |
2455 | |
2456 /* | |
2457 * Handle sixth level expression: | |
2458 * number number constant | |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2459 * 0zFFFFFFFF Blob constant |
1228 | 2460 * "string" string constant |
2461 * 'string' literal string constant | |
7 | 2462 * &option-name option value |
2463 * @r register contents | |
2464 * identifier variable value | |
2465 * function() function call | |
2466 * $VAR environment variable | |
2467 * (expression) nested expression | |
151 | 2468 * [expr, expr] List |
17368
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2469 * {key: val, key: val} Dictionary |
17413
40417757dffd
patch 8.1.1705: using ~{} for a literal dict is not nice
Bram Moolenaar <Bram@vim.org>
parents:
17387
diff
changeset
|
2470 * #{key: val, key: val} Dictionary with literal keys |
7 | 2471 * |
2472 * Also handle: | |
2473 * ! in front logical NOT | |
2474 * - in front unary minus | |
2475 * + in front unary plus (ignored) | |
100 | 2476 * trailing [] subscript in String or List |
2477 * trailing .name entry in Dictionary | |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2478 * trailing ->name() method call |
7 | 2479 * |
2480 * "arg" must point to the first non-white of the expression. | |
2481 * "arg" is advanced to the next non-white after the recognized expression. | |
2482 * | |
2483 * Return OK or FAIL. | |
2484 */ | |
2485 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2486 eval7( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2487 char_u **arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2488 typval_T *rettv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2489 int evaluate, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2490 int want_string UNUSED) // after "." operator |
7 | 2491 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
2492 varnumber_T n; |
7 | 2493 int len; |
2494 char_u *s; | |
2495 char_u *start_leader, *end_leader; | |
2496 int ret = OK; | |
2497 char_u *alias; | |
2498 | |
2499 /* | |
71 | 2500 * Initialise variable so that clear_tv() can't mistake this for a |
56 | 2501 * string and free a string that isn't there. |
7 | 2502 */ |
71 | 2503 rettv->v_type = VAR_UNKNOWN; |
7 | 2504 |
2505 /* | |
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
10000
diff
changeset
|
2506 * Skip '!', '-' and '+' characters. They are handled later. |
7 | 2507 */ |
2508 start_leader = *arg; | |
2509 while (**arg == '!' || **arg == '-' || **arg == '+') | |
2510 *arg = skipwhite(*arg + 1); | |
2511 end_leader = *arg; | |
2512 | |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2513 if (**arg == '.' && (!isdigit(*(*arg + 1)) |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2514 #ifdef FEAT_FLOAT |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2515 || current_sctx.sc_version < 2 |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2516 #endif |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2517 )) |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2518 { |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2519 semsg(_(e_invexpr2), *arg); |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2520 ++*arg; |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2521 return FAIL; |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2522 } |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2523 |
7 | 2524 switch (**arg) |
2525 { | |
2526 /* | |
2527 * Number constant. | |
2528 */ | |
2529 case '0': | |
2530 case '1': | |
2531 case '2': | |
2532 case '3': | |
2533 case '4': | |
2534 case '5': | |
2535 case '6': | |
2536 case '7': | |
2537 case '8': | |
2538 case '9': | |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2539 case '.': |
1624 | 2540 { |
2541 #ifdef FEAT_FLOAT | |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2542 char_u *p; |
1624 | 2543 int get_float = FALSE; |
2544 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2545 // We accept a float when the format matches |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2546 // "[0-9]\+\.[0-9]\+\([eE][+-]\?[0-9]\+\)\?". This is very |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2547 // strict to avoid backwards compatibility problems. |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2548 // With script version 2 and later the leading digit can be |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2549 // omitted. |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2550 // Don't look for a float after the "." operator, so that |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2551 // ":let vers = 1.2.3" doesn't fail. |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2552 if (**arg == '.') |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2553 p = *arg; |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2554 else |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16219
diff
changeset
|
2555 p = skipdigits(*arg + 1); |
1655 | 2556 if (!want_string && p[0] == '.' && vim_isdigit(p[1])) |
1624 | 2557 { |
2558 get_float = TRUE; | |
2559 p = skipdigits(p + 2); | |
2560 if (*p == 'e' || *p == 'E') | |
2561 { | |
2562 ++p; | |
2563 if (*p == '-' || *p == '+') | |
2564 ++p; | |
2565 if (!vim_isdigit(*p)) | |
2566 get_float = FALSE; | |
2567 else | |
2568 p = skipdigits(p + 1); | |
2569 } | |
2570 if (ASCII_ISALPHA(*p) || *p == '.') | |
2571 get_float = FALSE; | |
2572 } | |
2573 if (get_float) | |
2574 { | |
2575 float_T f; | |
2576 | |
2577 *arg += string2float(*arg, &f); | |
2578 if (evaluate) | |
2579 { | |
2580 rettv->v_type = VAR_FLOAT; | |
2581 rettv->vval.v_float = f; | |
2582 } | |
2583 } | |
2584 else | |
2585 #endif | |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2586 if (**arg == '0' && ((*arg)[1] == 'z' || (*arg)[1] == 'Z')) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2587 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2588 char_u *bp; |
15458
0f8065d7d68c
patch 8.1.0737: compiler warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
15456
diff
changeset
|
2589 blob_T *blob = NULL; // init for gcc |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2590 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2591 // Blob constant: 0z0123456789abcdef |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2592 if (evaluate) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2593 blob = blob_alloc(); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2594 for (bp = *arg + 2; vim_isxdigit(bp[0]); bp += 2) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2595 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2596 if (!vim_isxdigit(bp[1])) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2597 { |
15460
543cff56dd3f
patch 8.1.0738: using freed memory, for loop over blob leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15458
diff
changeset
|
2598 if (blob != NULL) |
543cff56dd3f
patch 8.1.0738: using freed memory, for loop over blob leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15458
diff
changeset
|
2599 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
2600 emsg(_("E973: Blob literal should have an even number of hex characters")); |
15460
543cff56dd3f
patch 8.1.0738: using freed memory, for loop over blob leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15458
diff
changeset
|
2601 ga_clear(&blob->bv_ga); |
543cff56dd3f
patch 8.1.0738: using freed memory, for loop over blob leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15458
diff
changeset
|
2602 VIM_CLEAR(blob); |
543cff56dd3f
patch 8.1.0738: using freed memory, for loop over blob leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15458
diff
changeset
|
2603 } |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2604 ret = FAIL; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2605 break; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2606 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2607 if (blob != NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2608 ga_append(&blob->bv_ga, |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2609 (hex2nr(*bp) << 4) + hex2nr(*(bp+1))); |
15515
99a4cc4782ac
patch 8.1.0765: string format of a Blob can't be parsed back
Bram Moolenaar <Bram@vim.org>
parents:
15496
diff
changeset
|
2610 if (bp[2] == '.' && vim_isxdigit(bp[3])) |
99a4cc4782ac
patch 8.1.0765: string format of a Blob can't be parsed back
Bram Moolenaar <Bram@vim.org>
parents:
15496
diff
changeset
|
2611 ++bp; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2612 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2613 if (blob != NULL) |
15460
543cff56dd3f
patch 8.1.0738: using freed memory, for loop over blob leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15458
diff
changeset
|
2614 rettv_blob_set(rettv, blob); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2615 *arg = bp; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2616 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2617 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2618 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
2619 // decimal, hex or octal number |
18080
a6d218f99ff7
patch 8.1.2035: recognizing octal numbers is confusing
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2620 vim_str2nr(*arg, NULL, &len, current_sctx.sc_version >= 4 |
a6d218f99ff7
patch 8.1.2035: recognizing octal numbers is confusing
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2621 ? STR2NR_NO_OCT + STR2NR_QUOTE |
a6d218f99ff7
patch 8.1.2035: recognizing octal numbers is confusing
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2622 : STR2NR_ALL, &n, NULL, 0, TRUE); |
16706
77bcb5055fec
patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents:
16704
diff
changeset
|
2623 if (len == 0) |
77bcb5055fec
patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents:
16704
diff
changeset
|
2624 { |
77bcb5055fec
patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents:
16704
diff
changeset
|
2625 semsg(_(e_invexpr2), *arg); |
77bcb5055fec
patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents:
16704
diff
changeset
|
2626 ret = FAIL; |
77bcb5055fec
patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents:
16704
diff
changeset
|
2627 break; |
77bcb5055fec
patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents:
16704
diff
changeset
|
2628 } |
1624 | 2629 *arg += len; |
2630 if (evaluate) | |
2631 { | |
2632 rettv->v_type = VAR_NUMBER; | |
2633 rettv->vval.v_number = n; | |
2634 } | |
2635 } | |
2636 break; | |
2637 } | |
7 | 2638 |
2639 /* | |
2640 * String constant: "string". | |
2641 */ | |
71 | 2642 case '"': ret = get_string_tv(arg, rettv, evaluate); |
7 | 2643 break; |
2644 | |
2645 /* | |
100 | 2646 * Literal string constant: 'str''ing'. |
7 | 2647 */ |
71 | 2648 case '\'': ret = get_lit_string_tv(arg, rettv, evaluate); |
56 | 2649 break; |
2650 | |
2651 /* | |
2652 * List: [expr, expr] | |
2653 */ | |
71 | 2654 case '[': ret = get_list_tv(arg, rettv, evaluate); |
7 | 2655 break; |
2656 | |
2657 /* | |
17413
40417757dffd
patch 8.1.1705: using ~{} for a literal dict is not nice
Bram Moolenaar <Bram@vim.org>
parents:
17387
diff
changeset
|
2658 * Dictionary: #{key: val, key: val} |
17368
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2659 */ |
17413
40417757dffd
patch 8.1.1705: using ~{} for a literal dict is not nice
Bram Moolenaar <Bram@vim.org>
parents:
17387
diff
changeset
|
2660 case '#': if ((*arg)[1] == '{') |
17368
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2661 { |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2662 ++*arg; |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2663 ret = dict_get_tv(arg, rettv, evaluate, TRUE); |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2664 } |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2665 else |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2666 ret = NOTDONE; |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2667 break; |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2668 |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2669 /* |
9527
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
9525
diff
changeset
|
2670 * Lambda: {arg, arg -> expr} |
17368
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2671 * Dictionary: {'key': val, 'key': val} |
100 | 2672 */ |
9527
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
9525
diff
changeset
|
2673 case '{': ret = get_lambda_tv(arg, rettv, evaluate); |
e8b3db8e2d30
commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents:
9525
diff
changeset
|
2674 if (ret == NOTDONE) |
17368
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17322
diff
changeset
|
2675 ret = dict_get_tv(arg, rettv, evaluate, FALSE); |
100 | 2676 break; |
2677 | |
2678 /* | |
104 | 2679 * Option value: &name |
7 | 2680 */ |
104 | 2681 case '&': ret = get_option_tv(arg, rettv, evaluate); |
7 | 2682 break; |
2683 | |
2684 /* | |
2685 * Environment variable: $VAR. | |
2686 */ | |
71 | 2687 case '$': ret = get_env_tv(arg, rettv, evaluate); |
7 | 2688 break; |
2689 | |
2690 /* | |
2691 * Register contents: @r. | |
2692 */ | |
2693 case '@': ++*arg; | |
2694 if (evaluate) | |
2695 { | |
71 | 2696 rettv->v_type = VAR_STRING; |
5796 | 2697 rettv->vval.v_string = get_reg_contents(**arg, |
2698 GREG_EXPR_SRC); | |
7 | 2699 } |
2700 if (**arg != NUL) | |
2701 ++*arg; | |
2702 break; | |
2703 | |
2704 /* | |
2705 * nested expression: (expression). | |
2706 */ | |
2707 case '(': *arg = skipwhite(*arg + 1); | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2708 ret = eval1(arg, rettv, evaluate); // recursive! |
7 | 2709 if (**arg == ')') |
2710 ++*arg; | |
2711 else if (ret == OK) | |
2712 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
2713 emsg(_("E110: Missing ')'")); |
71 | 2714 clear_tv(rettv); |
7 | 2715 ret = FAIL; |
2716 } | |
2717 break; | |
2718 | |
100 | 2719 default: ret = NOTDONE; |
2720 break; | |
2721 } | |
2722 | |
2723 if (ret == NOTDONE) | |
2724 { | |
2725 /* | |
2726 * Must be a variable or function name. | |
2727 * Can also be a curly-braces kind of name: {expr}. | |
2728 */ | |
2729 s = *arg; | |
159 | 2730 len = get_name_len(arg, &alias, evaluate, TRUE); |
100 | 2731 if (alias != NULL) |
2732 s = alias; | |
2733 | |
159 | 2734 if (len <= 0) |
100 | 2735 ret = FAIL; |
2736 else | |
2737 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2738 if (**arg == '(') // recursive! |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2739 ret = eval_func(arg, s, len, rettv, evaluate, NULL); |
100 | 2740 else if (evaluate) |
6791 | 2741 ret = get_var_tv(s, len, rettv, NULL, TRUE, FALSE); |
117 | 2742 else |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
2743 { |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
2744 check_vars(s, len); |
117 | 2745 ret = OK; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
2746 } |
100 | 2747 } |
2690 | 2748 vim_free(alias); |
100 | 2749 } |
2750 | |
7 | 2751 *arg = skipwhite(*arg); |
2752 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2753 // Handle following '[', '(' and '.' for expr[expr], expr.name, |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2754 // expr(expr), expr->name(expr) |
159 | 2755 if (ret == OK) |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2756 ret = handle_subscript(arg, rettv, evaluate, TRUE, |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2757 start_leader, &end_leader); |
7 | 2758 |
2759 /* | |
2760 * Apply logical NOT and unary '-', from right to left, ignore '+'. | |
2761 */ | |
2762 if (ret == OK && evaluate && end_leader > start_leader) | |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2763 ret = eval7_leader(rettv, start_leader, &end_leader); |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2764 return ret; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2765 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2766 |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2767 /* |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2768 * Apply the leading "!" and "-" before an eval7 expression to "rettv". |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2769 * Adjusts "end_leaderp" until it is at "start_leader". |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2770 */ |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2771 static int |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2772 eval7_leader(typval_T *rettv, char_u *start_leader, char_u **end_leaderp) |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2773 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2774 char_u *end_leader = *end_leaderp; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2775 int ret = OK; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2776 int error = FALSE; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2777 varnumber_T val = 0; |
1624 | 2778 #ifdef FEAT_FLOAT |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2779 float_T f = 0.0; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2780 |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2781 if (rettv->v_type == VAR_FLOAT) |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2782 f = rettv->vval.v_float; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2783 else |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2784 #endif |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2785 val = tv_get_number_chk(rettv, &error); |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2786 if (error) |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2787 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2788 clear_tv(rettv); |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2789 ret = FAIL; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2790 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2791 else |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2792 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2793 while (end_leader > start_leader) |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2794 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2795 --end_leader; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2796 if (*end_leader == '!') |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2797 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2798 #ifdef FEAT_FLOAT |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2799 if (rettv->v_type == VAR_FLOAT) |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2800 f = !f; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2801 else |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2802 #endif |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2803 val = !val; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2804 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2805 else if (*end_leader == '-') |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2806 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2807 #ifdef FEAT_FLOAT |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2808 if (rettv->v_type == VAR_FLOAT) |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2809 f = -f; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2810 else |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2811 #endif |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2812 val = -val; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2813 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2814 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2815 #ifdef FEAT_FLOAT |
1624 | 2816 if (rettv->v_type == VAR_FLOAT) |
323 | 2817 { |
2818 clear_tv(rettv); | |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2819 rettv->vval.v_float = f; |
323 | 2820 } |
2821 else | |
1624 | 2822 #endif |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2823 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2824 clear_tv(rettv); |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2825 rettv->v_type = VAR_NUMBER; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2826 rettv->vval.v_number = val; |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2827 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2828 } |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
2829 *end_leaderp = end_leader; |
7 | 2830 return ret; |
2831 } | |
2832 | |
2833 /* | |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2834 * Call the function referred to in "rettv". |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2835 */ |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2836 static int |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2837 call_func_rettv( |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2838 char_u **arg, |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2839 typval_T *rettv, |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2840 int evaluate, |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2841 dict_T *selfdict, |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2842 typval_T *basetv) |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2843 { |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2844 partial_T *pt = NULL; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2845 funcexe_T funcexe; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2846 typval_T functv; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2847 char_u *s; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2848 int ret; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2849 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2850 // need to copy the funcref so that we can clear rettv |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2851 if (evaluate) |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2852 { |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2853 functv = *rettv; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2854 rettv->v_type = VAR_UNKNOWN; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2855 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2856 // Invoke the function. Recursive! |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2857 if (functv.v_type == VAR_PARTIAL) |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2858 { |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2859 pt = functv.vval.v_partial; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2860 s = partial_name(pt); |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2861 } |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2862 else |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2863 s = functv.vval.v_string; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2864 } |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2865 else |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2866 s = (char_u *)""; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2867 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2868 vim_memset(&funcexe, 0, sizeof(funcexe)); |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2869 funcexe.firstline = curwin->w_cursor.lnum; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2870 funcexe.lastline = curwin->w_cursor.lnum; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2871 funcexe.evaluate = evaluate; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2872 funcexe.partial = pt; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2873 funcexe.selfdict = selfdict; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2874 funcexe.basetv = basetv; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2875 ret = get_func_tv(s, -1, rettv, arg, &funcexe); |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2876 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2877 // Clear the funcref afterwards, so that deleting it while |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2878 // evaluating the arguments is possible (see test55). |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2879 if (evaluate) |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2880 clear_tv(&functv); |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2881 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2882 return ret; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2883 } |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2884 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2885 /* |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2886 * Evaluate "->method()". |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2887 * "*arg" points to the '-'. |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2888 * Returns FAIL or OK. "*arg" is advanced to after the ')'. |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2889 */ |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2890 static int |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2891 eval_lambda( |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2892 char_u **arg, |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2893 typval_T *rettv, |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2894 int evaluate, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2895 int verbose) // give error messages |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2896 { |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2897 typval_T base = *rettv; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2898 int ret; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2899 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2900 // Skip over the ->. |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2901 *arg += 2; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2902 rettv->v_type = VAR_UNKNOWN; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2903 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2904 ret = get_lambda_tv(arg, rettv, evaluate); |
18851
3cf9529b3a4a
patch 8.1.2412: crash when evaluating expression with error
Bram Moolenaar <Bram@vim.org>
parents:
18777
diff
changeset
|
2905 if (ret != OK) |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2906 return FAIL; |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2907 else if (**arg != '(') |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2908 { |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2909 if (verbose) |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2910 { |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2911 if (*skipwhite(*arg) == '(') |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2912 semsg(_(e_nowhitespace)); |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2913 else |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2914 semsg(_(e_missingparen), "lambda"); |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2915 } |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2916 clear_tv(rettv); |
18225
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
2917 ret = FAIL; |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2918 } |
18225
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
2919 else |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
2920 ret = call_func_rettv(arg, rettv, evaluate, NULL, &base); |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
2921 |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
2922 // Clear the funcref afterwards, so that deleting it while |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
2923 // evaluating the arguments is possible (see test55). |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
2924 if (evaluate) |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
2925 clear_tv(&base); |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
2926 |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
2927 return ret; |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2928 } |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2929 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2930 /* |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2931 * Evaluate "->method()". |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2932 * "*arg" points to the '-'. |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2933 * Returns FAIL or OK. "*arg" is advanced to after the ')'. |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2934 */ |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2935 static int |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2936 eval_method( |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2937 char_u **arg, |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2938 typval_T *rettv, |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2939 int evaluate, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2940 int verbose) // give error messages |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2941 { |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2942 char_u *name; |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2943 long len; |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2944 char_u *alias; |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2945 typval_T base = *rettv; |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2946 int ret; |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2947 |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2948 // Skip over the ->. |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2949 *arg += 2; |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2950 rettv->v_type = VAR_UNKNOWN; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2951 |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2952 name = *arg; |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2953 len = get_name_len(arg, &alias, evaluate, TRUE); |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2954 if (alias != NULL) |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2955 name = alias; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2956 |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2957 if (len <= 0) |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2958 { |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2959 if (verbose) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2960 emsg(_("E260: Missing name after ->")); |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2961 ret = FAIL; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2962 } |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2963 else |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2964 { |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2965 if (**arg != '(') |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2966 { |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2967 if (verbose) |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2968 semsg(_(e_missingparen), name); |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2969 ret = FAIL; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2970 } |
17661
da7890e3359b
patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
2971 else if (VIM_ISWHITE((*arg)[-1])) |
da7890e3359b
patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
2972 { |
da7890e3359b
patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
2973 if (verbose) |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2974 semsg(_(e_nowhitespace)); |
17661
da7890e3359b
patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
2975 ret = FAIL; |
da7890e3359b
patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
2976 } |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2977 else |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2978 ret = eval_func(arg, name, len, rettv, evaluate, &base); |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
2979 } |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2980 |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2981 // Clear the funcref afterwards, so that deleting it while |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
2982 // evaluating the arguments is possible (see test55). |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2983 if (evaluate) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2984 clear_tv(&base); |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2985 |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2986 return ret; |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2987 } |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2988 |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2989 /* |
829 | 2990 * Evaluate an "[expr]" or "[expr:expr]" index. Also "dict.key". |
2991 * "*arg" points to the '[' or '.'. | |
56 | 2992 * Returns FAIL or OK. "*arg" is advanced to after the ']'. |
2993 */ | |
2994 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2995 eval_index( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2996 char_u **arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2997 typval_T *rettv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
2998 int evaluate, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2999 int verbose) // give error messages |
56 | 3000 { |
3001 int empty1 = FALSE, empty2 = FALSE; | |
137 | 3002 typval_T var1, var2; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3003 long i; |
56 | 3004 long n1, n2 = 0; |
100 | 3005 long len = -1; |
3006 int range = FALSE; | |
56 | 3007 char_u *s; |
100 | 3008 char_u *key = NULL; |
56 | 3009 |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3010 switch (rettv->v_type) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3011 { |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3012 case VAR_FUNC: |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
3013 case VAR_PARTIAL: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3014 if (verbose) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3015 emsg(_("E695: Cannot index a Funcref")); |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3016 return FAIL; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3017 case VAR_FLOAT: |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3018 #ifdef FEAT_FLOAT |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3019 if (verbose) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3020 emsg(_(e_float_as_string)); |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3021 return FAIL; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3022 #endif |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3023 case VAR_SPECIAL: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3024 case VAR_JOB: |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
3025 case VAR_CHANNEL: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3026 if (verbose) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3027 emsg(_("E909: Cannot index a special variable")); |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3028 return FAIL; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3029 case VAR_UNKNOWN: |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3030 if (evaluate) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3031 return FAIL; |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3032 // FALLTHROUGH |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3033 |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3034 case VAR_STRING: |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3035 case VAR_NUMBER: |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3036 case VAR_LIST: |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3037 case VAR_DICT: |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3038 case VAR_BLOB: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3039 break; |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3040 } |
56 | 3041 |
7046
fd409a0800fd
commit https://github.com/vim/vim/commit/0a38dd29d6f65aa601162542a5ab0ba7f308fc8e
Christian Brabandt <cb@256bit.org>
parents:
7042
diff
changeset
|
3042 init_tv(&var1); |
fd409a0800fd
commit https://github.com/vim/vim/commit/0a38dd29d6f65aa601162542a5ab0ba7f308fc8e
Christian Brabandt <cb@256bit.org>
parents:
7042
diff
changeset
|
3043 init_tv(&var2); |
100 | 3044 if (**arg == '.') |
3045 { | |
3046 /* | |
3047 * dict.name | |
3048 */ | |
3049 key = *arg + 1; | |
3050 for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; ++len) | |
3051 ; | |
3052 if (len == 0) | |
3053 return FAIL; | |
3054 *arg = skipwhite(key + len); | |
3055 } | |
3056 else | |
3057 { | |
3058 /* | |
3059 * something[idx] | |
3060 * | |
3061 * Get the (first) variable from inside the []. | |
3062 */ | |
56 | 3063 *arg = skipwhite(*arg + 1); |
100 | 3064 if (**arg == ':') |
3065 empty1 = TRUE; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3066 else if (eval1(arg, &var1, evaluate) == FAIL) // recursive! |
56 | 3067 return FAIL; |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
3068 else if (evaluate && tv_get_string_chk(&var1) == NULL) |
323 | 3069 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3070 // not a number or string |
323 | 3071 clear_tv(&var1); |
3072 return FAIL; | |
3073 } | |
100 | 3074 |
3075 /* | |
3076 * Get the second variable from inside the [:]. | |
3077 */ | |
3078 if (**arg == ':') | |
3079 { | |
3080 range = TRUE; | |
3081 *arg = skipwhite(*arg + 1); | |
3082 if (**arg == ']') | |
3083 empty2 = TRUE; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3084 else if (eval1(arg, &var2, evaluate) == FAIL) // recursive! |
100 | 3085 { |
323 | 3086 if (!empty1) |
3087 clear_tv(&var1); | |
3088 return FAIL; | |
3089 } | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
3090 else if (evaluate && tv_get_string_chk(&var2) == NULL) |
323 | 3091 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3092 // not a number or string |
323 | 3093 if (!empty1) |
3094 clear_tv(&var1); | |
3095 clear_tv(&var2); | |
100 | 3096 return FAIL; |
3097 } | |
3098 } | |
3099 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3100 // Check for the ']'. |
100 | 3101 if (**arg != ']') |
3102 { | |
159 | 3103 if (verbose) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3104 emsg(_(e_missbrac)); |
100 | 3105 clear_tv(&var1); |
3106 if (range) | |
3107 clear_tv(&var2); | |
3108 return FAIL; | |
3109 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3110 *arg = skipwhite(*arg + 1); // skip the ']' |
56 | 3111 } |
3112 | |
3113 if (evaluate) | |
3114 { | |
100 | 3115 n1 = 0; |
3116 if (!empty1 && rettv->v_type != VAR_DICT) | |
56 | 3117 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
3118 n1 = tv_get_number(&var1); |
71 | 3119 clear_tv(&var1); |
56 | 3120 } |
3121 if (range) | |
3122 { | |
3123 if (empty2) | |
3124 n2 = -1; | |
3125 else | |
3126 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
3127 n2 = tv_get_number(&var2); |
71 | 3128 clear_tv(&var2); |
3129 } | |
3130 } | |
3131 | |
3132 switch (rettv->v_type) | |
56 | 3133 { |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3134 case VAR_UNKNOWN: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3135 case VAR_FUNC: |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
3136 case VAR_PARTIAL: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3137 case VAR_FLOAT: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3138 case VAR_SPECIAL: |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3139 case VAR_JOB: |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
3140 case VAR_CHANNEL: |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3141 break; // not evaluating, skipping over subscript |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3142 |
56 | 3143 case VAR_NUMBER: |
3144 case VAR_STRING: | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
3145 s = tv_get_string(rettv); |
56 | 3146 len = (long)STRLEN(s); |
3147 if (range) | |
3148 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3149 // The resulting variable is a substring. If the indexes |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3150 // are out of range the result is empty. |
56 | 3151 if (n1 < 0) |
3152 { | |
3153 n1 = len + n1; | |
3154 if (n1 < 0) | |
3155 n1 = 0; | |
3156 } | |
3157 if (n2 < 0) | |
3158 n2 = len + n2; | |
3159 else if (n2 >= len) | |
3160 n2 = len; | |
3161 if (n1 >= len || n2 < 0 || n1 > n2) | |
3162 s = NULL; | |
3163 else | |
3164 s = vim_strnsave(s + n1, (int)(n2 - n1 + 1)); | |
3165 } | |
3166 else | |
3167 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3168 // The resulting variable is a string of a single |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3169 // character. If the index is too big or negative the |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3170 // result is empty. |
56 | 3171 if (n1 >= len || n1 < 0) |
3172 s = NULL; | |
3173 else | |
3174 s = vim_strnsave(s + n1, 1); | |
3175 } | |
71 | 3176 clear_tv(rettv); |
3177 rettv->v_type = VAR_STRING; | |
3178 rettv->vval.v_string = s; | |
56 | 3179 break; |
3180 | |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3181 case VAR_BLOB: |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3182 len = blob_len(rettv->vval.v_blob); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3183 if (range) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3184 { |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
3185 // The resulting variable is a sub-blob. If the indexes |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3186 // are out of range the result is empty. |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3187 if (n1 < 0) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3188 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3189 n1 = len + n1; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3190 if (n1 < 0) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3191 n1 = 0; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3192 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3193 if (n2 < 0) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3194 n2 = len + n2; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3195 else if (n2 >= len) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3196 n2 = len - 1; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3197 if (n1 >= len || n2 < 0 || n1 > n2) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3198 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3199 clear_tv(rettv); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3200 rettv->v_type = VAR_BLOB; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3201 rettv->vval.v_blob = NULL; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3202 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3203 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3204 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3205 blob_T *blob = blob_alloc(); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3206 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3207 if (blob != NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3208 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3209 if (ga_grow(&blob->bv_ga, n2 - n1 + 1) == FAIL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3210 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3211 blob_free(blob); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3212 return FAIL; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3213 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3214 blob->bv_ga.ga_len = n2 - n1 + 1; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3215 for (i = n1; i <= n2; i++) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3216 blob_set(blob, i - n1, |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3217 blob_get(rettv->vval.v_blob, i)); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3218 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3219 clear_tv(rettv); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3220 rettv_blob_set(rettv, blob); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3221 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3222 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3223 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3224 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3225 { |
15589
44ea60ca593b
patch 8.1.0802: negative index doesn't work for Blob
Bram Moolenaar <Bram@vim.org>
parents:
15581
diff
changeset
|
3226 // The resulting variable is a byte value. |
44ea60ca593b
patch 8.1.0802: negative index doesn't work for Blob
Bram Moolenaar <Bram@vim.org>
parents:
15581
diff
changeset
|
3227 // If the index is too big or negative that is an error. |
44ea60ca593b
patch 8.1.0802: negative index doesn't work for Blob
Bram Moolenaar <Bram@vim.org>
parents:
15581
diff
changeset
|
3228 if (n1 < 0) |
44ea60ca593b
patch 8.1.0802: negative index doesn't work for Blob
Bram Moolenaar <Bram@vim.org>
parents:
15581
diff
changeset
|
3229 n1 = len + n1; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3230 if (n1 < len && n1 >= 0) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3231 { |
15589
44ea60ca593b
patch 8.1.0802: negative index doesn't work for Blob
Bram Moolenaar <Bram@vim.org>
parents:
15581
diff
changeset
|
3232 int v = blob_get(rettv->vval.v_blob, n1); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3233 |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3234 clear_tv(rettv); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3235 rettv->v_type = VAR_NUMBER; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3236 rettv->vval.v_number = v; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3237 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3238 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3239 semsg(_(e_blobidx), n1); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3240 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3241 break; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3242 |
56 | 3243 case VAR_LIST: |
71 | 3244 len = list_len(rettv->vval.v_list); |
56 | 3245 if (n1 < 0) |
3246 n1 = len + n1; | |
3247 if (!empty1 && (n1 < 0 || n1 >= len)) | |
3248 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3249 // For a range we allow invalid values and return an empty |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3250 // list. A list index out of range is an error. |
842 | 3251 if (!range) |
3252 { | |
3253 if (verbose) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3254 semsg(_(e_listidx), n1); |
842 | 3255 return FAIL; |
3256 } | |
3257 n1 = len; | |
56 | 3258 } |
3259 if (range) | |
3260 { | |
137 | 3261 list_T *l; |
3262 listitem_T *item; | |
56 | 3263 |
3264 if (n2 < 0) | |
3265 n2 = len + n2; | |
829 | 3266 else if (n2 >= len) |
3267 n2 = len - 1; | |
3268 if (!empty2 && (n2 < 0 || n2 + 1 < n1)) | |
842 | 3269 n2 = -1; |
56 | 3270 l = list_alloc(); |
3271 if (l == NULL) | |
3272 return FAIL; | |
71 | 3273 for (item = list_find(rettv->vval.v_list, n1); |
56 | 3274 n1 <= n2; ++n1) |
3275 { | |
3276 if (list_append_tv(l, &item->li_tv) == FAIL) | |
3277 { | |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3278 list_free(l); |
56 | 3279 return FAIL; |
3280 } | |
3281 item = item->li_next; | |
3282 } | |
71 | 3283 clear_tv(rettv); |
11418
162bcd0debd7
patch 8.0.0593: duplication of code for adding a list or dict return value
Christian Brabandt <cb@256bit.org>
parents:
11412
diff
changeset
|
3284 rettv_list_set(rettv, l); |
56 | 3285 } |
3286 else | |
3287 { | |
842 | 3288 copy_tv(&list_find(rettv->vval.v_list, n1)->li_tv, &var1); |
71 | 3289 clear_tv(rettv); |
3290 *rettv = var1; | |
56 | 3291 } |
3292 break; | |
100 | 3293 |
3294 case VAR_DICT: | |
3295 if (range) | |
3296 { | |
159 | 3297 if (verbose) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3298 emsg(_(e_dictrange)); |
100 | 3299 if (len == -1) |
3300 clear_tv(&var1); | |
3301 return FAIL; | |
3302 } | |
3303 { | |
137 | 3304 dictitem_T *item; |
100 | 3305 |
3306 if (len == -1) | |
3307 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
3308 key = tv_get_string_chk(&var1); |
8839
9fa567d13551
commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents:
8831
diff
changeset
|
3309 if (key == NULL) |
100 | 3310 { |
3311 clear_tv(&var1); | |
3312 return FAIL; | |
3313 } | |
3314 } | |
3315 | |
121 | 3316 item = dict_find(rettv->vval.v_dict, key, (int)len); |
100 | 3317 |
159 | 3318 if (item == NULL && verbose) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3319 semsg(_(e_dictkey), key); |
100 | 3320 if (len == -1) |
3321 clear_tv(&var1); | |
3322 if (item == NULL) | |
3323 return FAIL; | |
3324 | |
3325 copy_tv(&item->di_tv, &var1); | |
3326 clear_tv(rettv); | |
3327 *rettv = var1; | |
3328 } | |
3329 break; | |
3330 } | |
3331 } | |
3332 | |
56 | 3333 return OK; |
3334 } | |
3335 | |
3336 /* | |
7 | 3337 * Get an option value. |
3338 * "arg" points to the '&' or '+' before the option name. | |
3339 * "arg" is advanced to character after the option name. | |
3340 * Return OK or FAIL. | |
3341 */ | |
9571
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9562
diff
changeset
|
3342 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3343 get_option_tv( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3344 char_u **arg, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3345 typval_T *rettv, // when NULL, only check if option exists |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3346 int evaluate) |
7 | 3347 { |
3348 char_u *option_end; | |
3349 long numval; | |
3350 char_u *stringval; | |
3351 int opt_type; | |
3352 int c; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3353 int working = (**arg == '+'); // has("+option") |
7 | 3354 int ret = OK; |
3355 int opt_flags; | |
3356 | |
3357 /* | |
3358 * Isolate the option name and find its value. | |
3359 */ | |
3360 option_end = find_option_end(arg, &opt_flags); | |
3361 if (option_end == NULL) | |
3362 { | |
71 | 3363 if (rettv != NULL) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3364 semsg(_("E112: Option name missing: %s"), *arg); |
7 | 3365 return FAIL; |
3366 } | |
3367 | |
3368 if (!evaluate) | |
3369 { | |
3370 *arg = option_end; | |
3371 return OK; | |
3372 } | |
3373 | |
3374 c = *option_end; | |
3375 *option_end = NUL; | |
3376 opt_type = get_option_value(*arg, &numval, | |
71 | 3377 rettv == NULL ? NULL : &stringval, opt_flags); |
7 | 3378 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3379 if (opt_type == -3) // invalid name |
7 | 3380 { |
71 | 3381 if (rettv != NULL) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3382 semsg(_("E113: Unknown option: %s"), *arg); |
7 | 3383 ret = FAIL; |
3384 } | |
71 | 3385 else if (rettv != NULL) |
7 | 3386 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3387 if (opt_type == -2) // hidden string option |
7 | 3388 { |
71 | 3389 rettv->v_type = VAR_STRING; |
3390 rettv->vval.v_string = NULL; | |
7 | 3391 } |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3392 else if (opt_type == -1) // hidden number option |
7 | 3393 { |
71 | 3394 rettv->v_type = VAR_NUMBER; |
3395 rettv->vval.v_number = 0; | |
7 | 3396 } |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3397 else if (opt_type == 1) // number option |
7 | 3398 { |
71 | 3399 rettv->v_type = VAR_NUMBER; |
3400 rettv->vval.v_number = numval; | |
7 | 3401 } |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3402 else // string option |
7 | 3403 { |
71 | 3404 rettv->v_type = VAR_STRING; |
3405 rettv->vval.v_string = stringval; | |
7 | 3406 } |
3407 } | |
3408 else if (working && (opt_type == -2 || opt_type == -1)) | |
3409 ret = FAIL; | |
3410 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3411 *option_end = c; // put back for error messages |
7 | 3412 *arg = option_end; |
3413 | |
3414 return ret; | |
3415 } | |
3416 | |
3417 /* | |
3418 * Allocate a variable for a string constant. | |
3419 * Return OK or FAIL. | |
3420 */ | |
3421 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3422 get_string_tv(char_u **arg, typval_T *rettv, int evaluate) |
7 | 3423 { |
3424 char_u *p; | |
3425 char_u *name; | |
3426 int extra = 0; | |
3427 | |
3428 /* | |
3429 * Find the end of the string, skipping backslashed characters. | |
3430 */ | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10964
diff
changeset
|
3431 for (p = *arg + 1; *p != NUL && *p != '"'; MB_PTR_ADV(p)) |
7 | 3432 { |
3433 if (*p == '\\' && p[1] != NUL) | |
3434 { | |
3435 ++p; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3436 // A "\<x>" form occupies at least 4 characters, and produces up |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3437 // to 6 characters: reserve space for 2 extra |
7 | 3438 if (*p == '<') |
3439 extra += 2; | |
3440 } | |
3441 } | |
3442 | |
3443 if (*p != '"') | |
3444 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3445 semsg(_("E114: Missing quote: %s"), *arg); |
7 | 3446 return FAIL; |
3447 } | |
3448 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3449 // If only parsing, set *arg and return here |
7 | 3450 if (!evaluate) |
3451 { | |
3452 *arg = p + 1; | |
3453 return OK; | |
3454 } | |
3455 | |
3456 /* | |
3457 * Copy the string into allocated memory, handling backslashed | |
3458 * characters. | |
3459 */ | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
3460 name = alloc(p - *arg + extra); |
7 | 3461 if (name == NULL) |
3462 return FAIL; | |
100 | 3463 rettv->v_type = VAR_STRING; |
3464 rettv->vval.v_string = name; | |
3465 | |
3466 for (p = *arg + 1; *p != NUL && *p != '"'; ) | |
7 | 3467 { |
3468 if (*p == '\\') | |
3469 { | |
3470 switch (*++p) | |
3471 { | |
100 | 3472 case 'b': *name++ = BS; ++p; break; |
3473 case 'e': *name++ = ESC; ++p; break; | |
3474 case 'f': *name++ = FF; ++p; break; | |
3475 case 'n': *name++ = NL; ++p; break; | |
3476 case 'r': *name++ = CAR; ++p; break; | |
3477 case 't': *name++ = TAB; ++p; break; | |
7 | 3478 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3479 case 'X': // hex: "\x1", "\x12" |
7 | 3480 case 'x': |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3481 case 'u': // Unicode: "\u0023" |
7 | 3482 case 'U': |
3483 if (vim_isxdigit(p[1])) | |
3484 { | |
3485 int n, nr; | |
3486 int c = toupper(*p); | |
3487 | |
3488 if (c == 'X') | |
3489 n = 2; | |
6836 | 3490 else if (*p == 'u') |
3491 n = 4; | |
7 | 3492 else |
6836 | 3493 n = 8; |
7 | 3494 nr = 0; |
3495 while (--n >= 0 && vim_isxdigit(p[1])) | |
3496 { | |
3497 ++p; | |
3498 nr = (nr << 4) + hex2nr(*p); | |
3499 } | |
100 | 3500 ++p; |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3501 // For "\u" store the number according to |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3502 // 'encoding'. |
7 | 3503 if (c != 'X') |
100 | 3504 name += (*mb_char2bytes)(nr, name); |
7 | 3505 else |
100 | 3506 *name++ = nr; |
7 | 3507 } |
3508 break; | |
3509 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3510 // octal: "\1", "\12", "\123" |
7 | 3511 case '0': |
3512 case '1': | |
3513 case '2': | |
3514 case '3': | |
3515 case '4': | |
3516 case '5': | |
3517 case '6': | |
100 | 3518 case '7': *name = *p++ - '0'; |
3519 if (*p >= '0' && *p <= '7') | |
7 | 3520 { |
100 | 3521 *name = (*name << 3) + *p++ - '0'; |
3522 if (*p >= '0' && *p <= '7') | |
3523 *name = (*name << 3) + *p++ - '0'; | |
7 | 3524 } |
100 | 3525 ++name; |
7 | 3526 break; |
3527 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3528 // Special key, e.g.: "\<C-W>" |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
3529 case '<': extra = trans_special(&p, name, TRUE, TRUE, |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
3530 TRUE, NULL); |
7 | 3531 if (extra != 0) |
3532 { | |
100 | 3533 name += extra; |
7 | 3534 break; |
3535 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3536 // FALLTHROUGH |
7 | 3537 |
100 | 3538 default: MB_COPY_CHAR(p, name); |
7 | 3539 break; |
3540 } | |
3541 } | |
3542 else | |
100 | 3543 MB_COPY_CHAR(p, name); |
3544 | |
3545 } | |
3546 *name = NUL; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3547 if (*p != NUL) // just in case |
9965
b329e3ca0dcb
commit https://github.com/vim/vim/commit/db249f26edf7a5f88d1f4468d08ec5b84f5ab7ad
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
3548 ++p; |
b329e3ca0dcb
commit https://github.com/vim/vim/commit/db249f26edf7a5f88d1f4468d08ec5b84f5ab7ad
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
3549 *arg = p; |
7 | 3550 |
3551 return OK; | |
3552 } | |
3553 | |
3554 /* | |
100 | 3555 * Allocate a variable for a 'str''ing' constant. |
7 | 3556 * Return OK or FAIL. |
3557 */ | |
3558 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3559 get_lit_string_tv(char_u **arg, typval_T *rettv, int evaluate) |
7 | 3560 { |
3561 char_u *p; | |
100 | 3562 char_u *str; |
3563 int reduce = 0; | |
7 | 3564 |
3565 /* | |
100 | 3566 * Find the end of the string, skipping ''. |
7 | 3567 */ |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10964
diff
changeset
|
3568 for (p = *arg + 1; *p != NUL; MB_PTR_ADV(p)) |
100 | 3569 { |
3570 if (*p == '\'') | |
3571 { | |
3572 if (p[1] != '\'') | |
3573 break; | |
3574 ++reduce; | |
3575 ++p; | |
3576 } | |
3577 } | |
3578 | |
3579 if (*p != '\'') | |
7 | 3580 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
3581 semsg(_("E115: Missing quote: %s"), *arg); |
7 | 3582 return FAIL; |
3583 } | |
3584 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3585 // If only parsing return after setting "*arg" |
97 | 3586 if (!evaluate) |
3587 { | |
3588 *arg = p + 1; | |
3589 return OK; | |
3590 } | |
3591 | |
3592 /* | |
100 | 3593 * Copy the string into allocated memory, handling '' to ' reduction. |
97 | 3594 */ |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
3595 str = alloc((p - *arg) - reduce); |
97 | 3596 if (str == NULL) |
3597 return FAIL; | |
100 | 3598 rettv->v_type = VAR_STRING; |
3599 rettv->vval.v_string = str; | |
3600 | |
3601 for (p = *arg + 1; *p != NUL; ) | |
3602 { | |
3603 if (*p == '\'') | |
3604 { | |
3605 if (p[1] != '\'') | |
97 | 3606 break; |
3607 ++p; | |
3608 } | |
100 | 3609 MB_COPY_CHAR(p, str); |
3610 } | |
3611 *str = NUL; | |
97 | 3612 *arg = p + 1; |
3613 | |
3614 return OK; | |
3615 } | |
3616 | |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3617 /* |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3618 * Return the function name of the partial. |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3619 */ |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3620 char_u * |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3621 partial_name(partial_T *pt) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3622 { |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3623 if (pt->pt_name != NULL) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3624 return pt->pt_name; |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3625 return pt->pt_func->uf_name; |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3626 } |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3627 |
8855
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3628 static void |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3629 partial_free(partial_T *pt) |
8855
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3630 { |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3631 int i; |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3632 |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3633 for (i = 0; i < pt->pt_argc; ++i) |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3634 clear_tv(&pt->pt_argv[i]); |
8855
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3635 vim_free(pt->pt_argv); |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3636 dict_unref(pt->pt_dict); |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3637 if (pt->pt_name != NULL) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3638 { |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3639 func_unref(pt->pt_name); |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3640 vim_free(pt->pt_name); |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3641 } |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3642 else |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3643 func_ptr_unref(pt->pt_func); |
8855
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3644 vim_free(pt); |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3645 } |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3646 |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3647 /* |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3648 * Unreference a closure: decrement the reference count and free it when it |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3649 * becomes zero. |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3650 */ |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3651 void |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3652 partial_unref(partial_T *pt) |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3653 { |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3654 if (pt != NULL && --pt->pt_refcount <= 0) |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3655 partial_free(pt); |
8855
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3656 } |
b76195a1e38e
commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents:
8839
diff
changeset
|
3657 |
2634 | 3658 static int tv_equal_recurse_limit; |
3659 | |
9183
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3660 static int |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3661 func_equal( |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3662 typval_T *tv1, |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3663 typval_T *tv2, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3664 int ic) // ignore case |
9183
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3665 { |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3666 char_u *s1, *s2; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3667 dict_T *d1, *d2; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3668 int a1, a2; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3669 int i; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3670 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3671 // empty and NULL function name considered the same |
9183
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3672 s1 = tv1->v_type == VAR_FUNC ? tv1->vval.v_string |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3673 : partial_name(tv1->vval.v_partial); |
9183
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3674 if (s1 != NULL && *s1 == NUL) |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3675 s1 = NULL; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3676 s2 = tv2->v_type == VAR_FUNC ? tv2->vval.v_string |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
3677 : partial_name(tv2->vval.v_partial); |
9183
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3678 if (s2 != NULL && *s2 == NUL) |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3679 s2 = NULL; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3680 if (s1 == NULL || s2 == NULL) |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3681 { |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3682 if (s1 != s2) |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3683 return FALSE; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3684 } |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3685 else if (STRCMP(s1, s2) != 0) |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3686 return FALSE; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3687 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3688 // empty dict and NULL dict is different |
9183
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3689 d1 = tv1->v_type == VAR_FUNC ? NULL : tv1->vval.v_partial->pt_dict; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3690 d2 = tv2->v_type == VAR_FUNC ? NULL : tv2->vval.v_partial->pt_dict; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3691 if (d1 == NULL || d2 == NULL) |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3692 { |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3693 if (d1 != d2) |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3694 return FALSE; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3695 } |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3696 else if (!dict_equal(d1, d2, ic, TRUE)) |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3697 return FALSE; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3698 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3699 // empty list and no list considered the same |
9183
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3700 a1 = tv1->v_type == VAR_FUNC ? 0 : tv1->vval.v_partial->pt_argc; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3701 a2 = tv2->v_type == VAR_FUNC ? 0 : tv2->vval.v_partial->pt_argc; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3702 if (a1 != a2) |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3703 return FALSE; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3704 for (i = 0; i < a1; ++i) |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3705 if (!tv_equal(tv1->vval.v_partial->pt_argv + i, |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3706 tv2->vval.v_partial->pt_argv + i, ic, TRUE)) |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3707 return FALSE; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3708 |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3709 return TRUE; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3710 } |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3711 |
117 | 3712 /* |
80 | 3713 * Return TRUE if "tv1" and "tv2" have the same value. |
388 | 3714 * Compares the items just like "==" would compare them, but strings and |
1624 | 3715 * numbers are different. Floats and numbers are also different. |
80 | 3716 */ |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
3717 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3718 tv_equal( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3719 typval_T *tv1, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3720 typval_T *tv2, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3721 int ic, // ignore case |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3722 int recursive) // TRUE when used recursively |
80 | 3723 { |
3724 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN]; | |
323 | 3725 char_u *s1, *s2; |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3726 static int recursive_cnt = 0; // catch recursive loops |
1008 | 3727 int r; |
3728 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3729 // Catch lists and dicts that have an endless loop by limiting |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3730 // recursiveness to a limit. We guess they are equal then. |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3731 // A fixed limit has the problem of still taking an awful long time. |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3732 // Reduce the limit every time running into it. That should work fine for |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3733 // deeply linked structures that are not recursively linked and catch |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3734 // recursiveness quickly. |
2634 | 3735 if (!recursive) |
3736 tv_equal_recurse_limit = 1000; | |
3737 if (recursive_cnt >= tv_equal_recurse_limit) | |
3738 { | |
3739 --tv_equal_recurse_limit; | |
1014 | 3740 return TRUE; |
2634 | 3741 } |
388 | 3742 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3743 // For VAR_FUNC and VAR_PARTIAL compare the function name, bound dict and |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3744 // arguments. |
9183
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3745 if ((tv1->v_type == VAR_FUNC |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3746 || (tv1->v_type == VAR_PARTIAL && tv1->vval.v_partial != NULL)) |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3747 && (tv2->v_type == VAR_FUNC |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3748 || (tv2->v_type == VAR_PARTIAL && tv2->vval.v_partial != NULL))) |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3749 { |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3750 ++recursive_cnt; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3751 r = func_equal(tv1, tv2, ic); |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3752 --recursive_cnt; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3753 return r; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3754 } |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3755 |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3756 if (tv1->v_type != tv2->v_type) |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3757 return FALSE; |
988c8ab557bf
commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents:
9169
diff
changeset
|
3758 |
388 | 3759 switch (tv1->v_type) |
3760 { | |
3761 case VAR_LIST: | |
2634 | 3762 ++recursive_cnt; |
3763 r = list_equal(tv1->vval.v_list, tv2->vval.v_list, ic, TRUE); | |
3764 --recursive_cnt; | |
1008 | 3765 return r; |
388 | 3766 |
3767 case VAR_DICT: | |
2634 | 3768 ++recursive_cnt; |
3769 r = dict_equal(tv1->vval.v_dict, tv2->vval.v_dict, ic, TRUE); | |
3770 --recursive_cnt; | |
1008 | 3771 return r; |
388 | 3772 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3773 case VAR_BLOB: |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3774 return blob_equal(tv1->vval.v_blob, tv2->vval.v_blob); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3775 |
388 | 3776 case VAR_NUMBER: |
3777 return tv1->vval.v_number == tv2->vval.v_number; | |
3778 | |
3779 case VAR_STRING: | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
3780 s1 = tv_get_string_buf(tv1, buf1); |
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
3781 s2 = tv_get_string_buf(tv2, buf2); |
388 | 3782 return ((ic ? MB_STRICMP(s1, s2) : STRCMP(s1, s2)) == 0); |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3783 |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3784 case VAR_SPECIAL: |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3785 return tv1->vval.v_number == tv2->vval.v_number; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3786 |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3787 case VAR_FLOAT: |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3788 #ifdef FEAT_FLOAT |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3789 return tv1->vval.v_float == tv2->vval.v_float; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3790 #endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3791 case VAR_JOB: |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
3792 #ifdef FEAT_JOB_CHANNEL |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3793 return tv1->vval.v_job == tv2->vval.v_job; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3794 #endif |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
3795 case VAR_CHANNEL: |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
3796 #ifdef FEAT_JOB_CHANNEL |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
3797 return tv1->vval.v_channel == tv2->vval.v_channel; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
3798 #endif |
8635
3a38d465f731
commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
8633
diff
changeset
|
3799 case VAR_FUNC: |
3a38d465f731
commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
8633
diff
changeset
|
3800 case VAR_PARTIAL: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3801 case VAR_UNKNOWN: |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
3802 break; |
388 | 3803 } |
3804 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3805 // VAR_UNKNOWN can be the result of a invalid expression, let's say it |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3806 // does not equal anything, not even itself. |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
3807 return FALSE; |
80 | 3808 } |
3809 | |
3810 /* | |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3811 * Return the next (unique) copy ID. |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3812 * Used for serializing nested structures. |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3813 */ |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3814 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3815 get_copyID(void) |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3816 { |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3817 current_copyID += COPYID_INC; |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3818 return current_copyID; |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3819 } |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3820 |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3821 /* |
371 | 3822 * Garbage collection for lists and dictionaries. |
3823 * | |
3824 * We use reference counts to be able to free most items right away when they | |
3825 * are no longer used. But for composite items it's possible that it becomes | |
3826 * unused while the reference count is > 0: When there is a recursive | |
3827 * reference. Example: | |
3828 * :let l = [1, 2, 3] | |
3829 * :let d = {9: l} | |
3830 * :let l[1] = d | |
3831 * | |
3832 * Since this is quite unusual we handle this with garbage collection: every | |
3833 * once in a while find out which lists and dicts are not referenced from any | |
3834 * variable. | |
3835 * | |
3836 * Here is a good reference text about garbage collection (refers to Python | |
3837 * but it applies to all reference-counting mechanisms): | |
3838 * http://python.ca/nas/python/gc/ | |
3839 */ | |
3840 | |
3841 /* | |
3842 * Do garbage collection for lists and dicts. | |
9108
d319453f62b3
commit https://github.com/vim/vim/commit/574860b5ee9da281c875dad07a607454e135eaee
Christian Brabandt <cb@256bit.org>
parents:
9104
diff
changeset
|
3843 * When "testing" is TRUE this is called from test_garbagecollect_now(). |
371 | 3844 * Return TRUE if some memory was freed. |
3845 */ | |
3846 int | |
8881
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
3847 garbage_collect(int testing) |
371 | 3848 { |
1891 | 3849 int copyID; |
6565 | 3850 int abort = FALSE; |
371 | 3851 buf_T *buf; |
3852 win_T *wp; | |
6588 | 3853 int did_free = FALSE; |
819 | 3854 tabpage_T *tp; |
371 | 3855 |
8881
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
3856 if (!testing) |
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
3857 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3858 // Only do this once. |
8881
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
3859 want_garbage_collect = FALSE; |
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
3860 may_garbage_collect = FALSE; |
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
3861 garbage_collect_at_exit = FALSE; |
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
3862 } |
958 | 3863 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3864 // We advance by two because we add one for items referenced through |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3865 // previous_funccal. |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
3866 copyID = get_copyID(); |
1891 | 3867 |
371 | 3868 /* |
3869 * 1. Go through all accessible variables and mark all lists and dicts | |
3870 * with copyID. | |
3871 */ | |
1891 | 3872 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3873 // Don't free variables in the previous_funccal list unless they are only |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3874 // referenced through previous_funccal. This must be first, because if |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3875 // the item is referenced elsewhere the funccal must not be freed. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
3876 abort = abort || set_ref_in_previous_funccal(copyID); |
1891 | 3877 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3878 // script-local variables |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3879 abort = abort || garbage_collect_scriptvars(copyID); |
371 | 3880 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3881 // buffer-local variables |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9636
diff
changeset
|
3882 FOR_ALL_BUFFERS(buf) |
6565 | 3883 abort = abort || set_ref_in_item(&buf->b_bufvar.di_tv, copyID, |
3884 NULL, NULL); | |
371 | 3885 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3886 // window-local variables |
819 | 3887 FOR_ALL_TAB_WINDOWS(tp, wp) |
6565 | 3888 abort = abort || set_ref_in_item(&wp->w_winvar.di_tv, copyID, |
3889 NULL, NULL); | |
4309 | 3890 if (aucmd_win != NULL) |
6565 | 3891 abort = abort || set_ref_in_item(&aucmd_win->w_winvar.di_tv, copyID, |
3892 NULL, NULL); | |
18763
49b78d6465e5
patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents:
18713
diff
changeset
|
3893 #ifdef FEAT_PROP_POPUP |
16778
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
3894 for (wp = first_popupwin; wp != NULL; wp = wp->w_next) |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
3895 abort = abort || set_ref_in_item(&wp->w_winvar.di_tv, copyID, |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
3896 NULL, NULL); |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
3897 FOR_ALL_TABPAGES(tp) |
16796
5f98d80d116a
patch 8.1.1400: using global pointer for tab-local popups is clumsy
Bram Moolenaar <Bram@vim.org>
parents:
16778
diff
changeset
|
3898 for (wp = tp->tp_first_popupwin; wp != NULL; wp = wp->w_next) |
16778
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
3899 abort = abort || set_ref_in_item(&wp->w_winvar.di_tv, copyID, |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
3900 NULL, NULL); |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
3901 #endif |
371 | 3902 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3903 // tabpage-local variables |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9636
diff
changeset
|
3904 FOR_ALL_TABPAGES(tp) |
6565 | 3905 abort = abort || set_ref_in_item(&tp->tp_winvar.di_tv, copyID, |
3906 NULL, NULL); | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3907 // global variables |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3908 abort = abort || garbage_collect_globvars(copyID); |
371 | 3909 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3910 // function-local variables |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
3911 abort = abort || set_ref_in_call_stack(copyID); |
371 | 3912 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3913 // named functions (matters for closures) |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
3914 abort = abort || set_ref_in_functions(copyID); |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
3915 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3916 // function call arguments, if v:testing is set. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
3917 abort = abort || set_ref_in_func_args(copyID); |
8881
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8877
diff
changeset
|
3918 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3919 // v: vars |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3920 abort = abort || garbage_collect_vimvars(copyID); |
1733 | 3921 |
17151
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
17085
diff
changeset
|
3922 // callbacks in buffers |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
17085
diff
changeset
|
3923 abort = abort || set_ref_in_buffers(copyID); |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
17085
diff
changeset
|
3924 |
3450 | 3925 #ifdef FEAT_LUA |
6565 | 3926 abort = abort || set_ref_in_lua(copyID); |
3450 | 3927 #endif |
3928 | |
3618 | 3929 #ifdef FEAT_PYTHON |
6565 | 3930 abort = abort || set_ref_in_python(copyID); |
3618 | 3931 #endif |
3932 | |
3933 #ifdef FEAT_PYTHON3 | |
6565 | 3934 abort = abort || set_ref_in_python3(copyID); |
3935 #endif | |
3936 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
3937 #ifdef FEAT_JOB_CHANNEL |
8877
50e40f322e78
commit https://github.com/vim/vim/commit/3780bb923a688e0051a9a23474eeb38a8acb695a
Christian Brabandt <cb@256bit.org>
parents:
8870
diff
changeset
|
3938 abort = abort || set_ref_in_channel(copyID); |
9058
87c2e43a4a12
commit https://github.com/vim/vim/commit/b8d4905592fc26fcd09180d7d6bfefd899f2f6c6
Christian Brabandt <cb@256bit.org>
parents:
9052
diff
changeset
|
3939 abort = abort || set_ref_in_job(copyID); |
7931
2679e636e862
commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents:
7895
diff
changeset
|
3940 #endif |
9052
3a6b66c02d6d
commit https://github.com/vim/vim/commit/3266c85a44a637862b0ed6e531680c6ab2897ab5
Christian Brabandt <cb@256bit.org>
parents:
9027
diff
changeset
|
3941 #ifdef FEAT_NETBEANS_INTG |
3a6b66c02d6d
commit https://github.com/vim/vim/commit/3266c85a44a637862b0ed6e531680c6ab2897ab5
Christian Brabandt <cb@256bit.org>
parents:
9027
diff
changeset
|
3942 abort = abort || set_ref_in_nb_channel(copyID); |
3a6b66c02d6d
commit https://github.com/vim/vim/commit/3266c85a44a637862b0ed6e531680c6ab2897ab5
Christian Brabandt <cb@256bit.org>
parents:
9027
diff
changeset
|
3943 #endif |
7931
2679e636e862
commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents:
7895
diff
changeset
|
3944 |
9153
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9127
diff
changeset
|
3945 #ifdef FEAT_TIMERS |
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9127
diff
changeset
|
3946 abort = abort || set_ref_in_timer(copyID); |
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9127
diff
changeset
|
3947 #endif |
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9127
diff
changeset
|
3948 |
11412
84baca75b7f2
patch 8.0.0590: cannot add a context to locations
Christian Brabandt <cb@256bit.org>
parents:
11323
diff
changeset
|
3949 #ifdef FEAT_QUICKFIX |
84baca75b7f2
patch 8.0.0590: cannot add a context to locations
Christian Brabandt <cb@256bit.org>
parents:
11323
diff
changeset
|
3950 abort = abort || set_ref_in_quickfix(copyID); |
84baca75b7f2
patch 8.0.0590: cannot add a context to locations
Christian Brabandt <cb@256bit.org>
parents:
11323
diff
changeset
|
3951 #endif |
84baca75b7f2
patch 8.0.0590: cannot add a context to locations
Christian Brabandt <cb@256bit.org>
parents:
11323
diff
changeset
|
3952 |
11804
5630978ae089
patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
3953 #ifdef FEAT_TERMINAL |
5630978ae089
patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
3954 abort = abort || set_ref_in_term(copyID); |
5630978ae089
patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
3955 #endif |
5630978ae089
patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
3956 |
18763
49b78d6465e5
patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents:
18713
diff
changeset
|
3957 #ifdef FEAT_PROP_POPUP |
17151
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
17085
diff
changeset
|
3958 abort = abort || set_ref_in_popups(copyID); |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
17085
diff
changeset
|
3959 #endif |
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
17085
diff
changeset
|
3960 |
6565 | 3961 if (!abort) |
3962 { | |
3963 /* | |
3964 * 2. Free lists and dictionaries that are not referenced. | |
3965 */ | |
3966 did_free = free_unref_items(copyID); | |
3967 | |
3968 /* | |
3969 * 3. Check if any funccal can be freed now. | |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
3970 * This may call us back recursively. |
6565 | 3971 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
3972 free_unref_funccal(copyID, testing); |
6565 | 3973 } |
3974 else if (p_verbose > 0) | |
3975 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
3976 verb_msg(_("Not enough memory to set references, garbage collection aborted!")); |
6565 | 3977 } |
1891 | 3978 |
3979 return did_free; | |
3980 } | |
3981 | |
3982 /* | |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3983 * Free lists, dictionaries, channels and jobs that are no longer referenced. |
1891 | 3984 */ |
3985 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
3986 free_unref_items(int copyID) |
1891 | 3987 { |
3988 int did_free = FALSE; | |
3989 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3990 // Let all "free" functions know that we are here. This means no |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3991 // dictionaries, lists, channels or jobs are to be freed, because we will |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3992 // do that here. |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3993 in_free_unref_items = TRUE; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3994 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3995 /* |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3996 * PASS 1: free the contents of the items. We don't free the items |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3997 * themselves yet, so that it is possible to decrement refcount counters |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3998 */ |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
3999 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4000 // Go through the list of dicts and free items without the copyID. |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
4001 did_free |= dict_free_nonref(copyID); |
371 | 4002 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4003 // Go through the list of lists and free items without the copyID. |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
9556
diff
changeset
|
4004 did_free |= list_free_nonref(copyID); |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4005 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4006 #ifdef FEAT_JOB_CHANNEL |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4007 // Go through the list of jobs and free items without the copyID. This |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4008 // must happen before doing channels, because jobs refer to channels, but |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4009 // the reference from the channel to the job isn't tracked. |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4010 did_free |= free_unused_jobs_contents(copyID, COPYID_MASK); |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4011 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4012 // Go through the list of channels and free items without the copyID. |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4013 did_free |= free_unused_channels_contents(copyID, COPYID_MASK); |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4014 #endif |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4015 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4016 /* |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4017 * PASS 2: free the items themselves. |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4018 */ |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
4019 dict_free_items(copyID); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
9556
diff
changeset
|
4020 list_free_items(copyID); |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4021 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4022 #ifdef FEAT_JOB_CHANNEL |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4023 // Go through the list of jobs and free items without the copyID. This |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4024 // must happen before doing channels, because jobs refer to channels, but |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4025 // the reference from the channel to the job isn't tracked. |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4026 free_unused_jobs(copyID, COPYID_MASK); |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4027 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4028 // Go through the list of channels and free items without the copyID. |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4029 free_unused_channels(copyID, COPYID_MASK); |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4030 #endif |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4031 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4032 in_free_unref_items = FALSE; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
4033 |
371 | 4034 return did_free; |
4035 } | |
4036 | |
4037 /* | |
4038 * Mark all lists and dicts referenced through hashtab "ht" with "copyID". | |
6565 | 4039 * "list_stack" is used to add lists to be marked. Can be NULL. |
4040 * | |
4041 * Returns TRUE if setting references failed somehow. | |
4042 */ | |
4043 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4044 set_ref_in_ht(hashtab_T *ht, int copyID, list_stack_T **list_stack) |
364 | 4045 { |
4046 int todo; | |
6565 | 4047 int abort = FALSE; |
364 | 4048 hashitem_T *hi; |
6565 | 4049 hashtab_T *cur_ht; |
4050 ht_stack_T *ht_stack = NULL; | |
4051 ht_stack_T *tempitem; | |
4052 | |
4053 cur_ht = ht; | |
4054 for (;;) | |
4055 { | |
4056 if (!abort) | |
4057 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4058 // Mark each item in the hashtab. If the item contains a hashtab |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4059 // it is added to ht_stack, if it contains a list it is added to |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4060 // list_stack. |
6565 | 4061 todo = (int)cur_ht->ht_used; |
4062 for (hi = cur_ht->ht_array; todo > 0; ++hi) | |
4063 if (!HASHITEM_EMPTY(hi)) | |
4064 { | |
4065 --todo; | |
4066 abort = abort || set_ref_in_item(&HI2DI(hi)->di_tv, copyID, | |
4067 &ht_stack, list_stack); | |
4068 } | |
4069 } | |
4070 | |
4071 if (ht_stack == NULL) | |
4072 break; | |
4073 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4074 // take an item from the stack |
6565 | 4075 cur_ht = ht_stack->ht; |
4076 tempitem = ht_stack; | |
4077 ht_stack = ht_stack->prev; | |
4078 free(tempitem); | |
4079 } | |
4080 | |
4081 return abort; | |
371 | 4082 } |
4083 | |
4084 /* | |
17168
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4085 * Mark a dict and its items with "copyID". |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4086 * Returns TRUE if setting references failed somehow. |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4087 */ |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4088 int |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4089 set_ref_in_dict(dict_T *d, int copyID) |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4090 { |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4091 if (d != NULL && d->dv_copyID != copyID) |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4092 { |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4093 d->dv_copyID = copyID; |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4094 return set_ref_in_ht(&d->dv_hashtab, copyID, NULL); |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4095 } |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4096 return FALSE; |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4097 } |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4098 |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4099 /* |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4100 * Mark a list and its items with "copyID". |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4101 * Returns TRUE if setting references failed somehow. |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4102 */ |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4103 int |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4104 set_ref_in_list(list_T *ll, int copyID) |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4105 { |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4106 if (ll != NULL && ll->lv_copyID != copyID) |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4107 { |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4108 ll->lv_copyID = copyID; |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4109 return set_ref_in_list_items(ll, copyID, NULL); |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4110 } |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4111 return FALSE; |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4112 } |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4113 |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4114 /* |
371 | 4115 * Mark all lists and dicts referenced through list "l" with "copyID". |
6565 | 4116 * "ht_stack" is used to add hashtabs to be marked. Can be NULL. |
4117 * | |
4118 * Returns TRUE if setting references failed somehow. | |
4119 */ | |
4120 int | |
17168
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4121 set_ref_in_list_items(list_T *l, int copyID, ht_stack_T **ht_stack) |
6565 | 4122 { |
4123 listitem_T *li; | |
4124 int abort = FALSE; | |
4125 list_T *cur_l; | |
4126 list_stack_T *list_stack = NULL; | |
4127 list_stack_T *tempitem; | |
4128 | |
4129 cur_l = l; | |
4130 for (;;) | |
4131 { | |
4132 if (!abort) | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4133 // Mark each item in the list. If the item contains a hashtab |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4134 // it is added to ht_stack, if it contains a list it is added to |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4135 // list_stack. |
6565 | 4136 for (li = cur_l->lv_first; !abort && li != NULL; li = li->li_next) |
4137 abort = abort || set_ref_in_item(&li->li_tv, copyID, | |
4138 ht_stack, &list_stack); | |
4139 if (list_stack == NULL) | |
4140 break; | |
4141 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4142 // take an item from the stack |
6565 | 4143 cur_l = list_stack->list; |
4144 tempitem = list_stack; | |
4145 list_stack = list_stack->prev; | |
4146 free(tempitem); | |
4147 } | |
4148 | |
4149 return abort; | |
371 | 4150 } |
4151 | |
4152 /* | |
4153 * Mark all lists and dicts referenced through typval "tv" with "copyID". | |
6565 | 4154 * "list_stack" is used to add lists to be marked. Can be NULL. |
4155 * "ht_stack" is used to add hashtabs to be marked. Can be NULL. | |
4156 * | |
4157 * Returns TRUE if setting references failed somehow. | |
4158 */ | |
4159 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4160 set_ref_in_item( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4161 typval_T *tv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4162 int copyID, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4163 ht_stack_T **ht_stack, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4164 list_stack_T **list_stack) |
364 | 4165 { |
6565 | 4166 int abort = FALSE; |
364 | 4167 |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4168 if (tv->v_type == VAR_DICT) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4169 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4170 dict_T *dd = tv->vval.v_dict; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4171 |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4172 if (dd != NULL && dd->dv_copyID != copyID) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4173 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4174 // Didn't see this dict yet. |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4175 dd->dv_copyID = copyID; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4176 if (ht_stack == NULL) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4177 { |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4178 abort = set_ref_in_ht(&dd->dv_hashtab, copyID, list_stack); |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4179 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4180 else |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4181 { |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4182 ht_stack_T *newitem = (ht_stack_T*)malloc(sizeof(ht_stack_T)); |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4183 if (newitem == NULL) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4184 abort = TRUE; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4185 else |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4186 { |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4187 newitem->ht = &dd->dv_hashtab; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4188 newitem->prev = *ht_stack; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4189 *ht_stack = newitem; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4190 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4191 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4192 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4193 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4194 else if (tv->v_type == VAR_LIST) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4195 { |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4196 list_T *ll = tv->vval.v_list; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4197 |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4198 if (ll != NULL && ll->lv_copyID != copyID) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4199 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4200 // Didn't see this list yet. |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4201 ll->lv_copyID = copyID; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4202 if (list_stack == NULL) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4203 { |
17168
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
4204 abort = set_ref_in_list_items(ll, copyID, ht_stack); |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4205 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4206 else |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4207 { |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4208 list_stack_T *newitem = (list_stack_T*)malloc( |
6565 | 4209 sizeof(list_stack_T)); |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4210 if (newitem == NULL) |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4211 abort = TRUE; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4212 else |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4213 { |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4214 newitem->list = ll; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4215 newitem->prev = *list_stack; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4216 *list_stack = newitem; |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4217 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4218 } |
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4219 } |
6565 | 4220 } |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
4221 else if (tv->v_type == VAR_FUNC) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
4222 { |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
4223 abort = set_ref_in_func(tv->vval.v_string, NULL, copyID); |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
4224 } |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4225 else if (tv->v_type == VAR_PARTIAL) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4226 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4227 partial_T *pt = tv->vval.v_partial; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4228 int i; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4229 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4230 // A partial does not have a copyID, because it cannot contain itself. |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4231 if (pt != NULL) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4232 { |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
4233 abort = set_ref_in_func(pt->pt_name, pt->pt_func, copyID); |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
4234 |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4235 if (pt->pt_dict != NULL) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4236 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4237 typval_T dtv; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4238 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4239 dtv.v_type = VAR_DICT; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4240 dtv.vval.v_dict = pt->pt_dict; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4241 set_ref_in_item(&dtv, copyID, ht_stack, list_stack); |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4242 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4243 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4244 for (i = 0; i < pt->pt_argc; ++i) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4245 abort = abort || set_ref_in_item(&pt->pt_argv[i], copyID, |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4246 ht_stack, list_stack); |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4247 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4248 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4249 #ifdef FEAT_JOB_CHANNEL |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4250 else if (tv->v_type == VAR_JOB) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4251 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4252 job_T *job = tv->vval.v_job; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4253 typval_T dtv; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4254 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4255 if (job != NULL && job->jv_copyID != copyID) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4256 { |
8870
30988ffb7498
commit https://github.com/vim/vim/commit/0239acb11fe4bfe9b525ea90b782759da5eb7704
Christian Brabandt <cb@256bit.org>
parents:
8863
diff
changeset
|
4257 job->jv_copyID = copyID; |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4258 if (job->jv_channel != NULL) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4259 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4260 dtv.v_type = VAR_CHANNEL; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4261 dtv.vval.v_channel = job->jv_channel; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4262 set_ref_in_item(&dtv, copyID, ht_stack, list_stack); |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4263 } |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4264 if (job->jv_exit_cb.cb_partial != NULL) |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4265 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4266 dtv.v_type = VAR_PARTIAL; |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4267 dtv.vval.v_partial = job->jv_exit_cb.cb_partial; |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4268 set_ref_in_item(&dtv, copyID, ht_stack, list_stack); |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4269 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4270 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4271 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4272 else if (tv->v_type == VAR_CHANNEL) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4273 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4274 channel_T *ch =tv->vval.v_channel; |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10235
diff
changeset
|
4275 ch_part_T part; |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4276 typval_T dtv; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4277 jsonq_T *jq; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4278 cbq_T *cq; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4279 |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4280 if (ch != NULL && ch->ch_copyID != copyID) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4281 { |
8870
30988ffb7498
commit https://github.com/vim/vim/commit/0239acb11fe4bfe9b525ea90b782759da5eb7704
Christian Brabandt <cb@256bit.org>
parents:
8863
diff
changeset
|
4282 ch->ch_copyID = copyID; |
10259
a09db7a4afe0
commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents:
10235
diff
changeset
|
4283 for (part = PART_SOCK; part < PART_COUNT; ++part) |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4284 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4285 for (jq = ch->ch_part[part].ch_json_head.jq_next; jq != NULL; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4286 jq = jq->jq_next) |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4287 set_ref_in_item(jq->jq_value, copyID, ht_stack, list_stack); |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4288 for (cq = ch->ch_part[part].ch_cb_head.cq_next; cq != NULL; |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4289 cq = cq->cq_next) |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4290 if (cq->cq_callback.cb_partial != NULL) |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4291 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4292 dtv.v_type = VAR_PARTIAL; |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4293 dtv.vval.v_partial = cq->cq_callback.cb_partial; |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4294 set_ref_in_item(&dtv, copyID, ht_stack, list_stack); |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4295 } |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4296 if (ch->ch_part[part].ch_callback.cb_partial != NULL) |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4297 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4298 dtv.v_type = VAR_PARTIAL; |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4299 dtv.vval.v_partial = |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4300 ch->ch_part[part].ch_callback.cb_partial; |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4301 set_ref_in_item(&dtv, copyID, ht_stack, list_stack); |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4302 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4303 } |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4304 if (ch->ch_callback.cb_partial != NULL) |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4305 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4306 dtv.v_type = VAR_PARTIAL; |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4307 dtv.vval.v_partial = ch->ch_callback.cb_partial; |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4308 set_ref_in_item(&dtv, copyID, ht_stack, list_stack); |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4309 } |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4310 if (ch->ch_close_cb.cb_partial != NULL) |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4311 { |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4312 dtv.v_type = VAR_PARTIAL; |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4313 dtv.vval.v_partial = ch->ch_close_cb.cb_partial; |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4314 set_ref_in_item(&dtv, copyID, ht_stack, list_stack); |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4315 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4316 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4317 } |
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8861
diff
changeset
|
4318 #endif |
6565 | 4319 return abort; |
364 | 4320 } |
4321 | |
100 | 4322 /* |
56 | 4323 * Return a string with the string representation of a variable. |
4324 * If the memory is allocated "tofree" is set to it, otherwise NULL. | |
80 | 4325 * "numbuf" is used for a number. |
634 | 4326 * When "copyID" is not NULL replace recursive lists and dicts with "...". |
11973
aec3df2af27c
patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents:
11848
diff
changeset
|
4327 * When both "echo_style" and "composite_val" are FALSE, put quotes around |
aec3df2af27c
patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents:
11848
diff
changeset
|
4328 * stings as "string()", otherwise does not put quotes around strings, as |
aec3df2af27c
patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents:
11848
diff
changeset
|
4329 * ":echo" displays values. |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4330 * When "restore_copyID" is FALSE, repeated items in dictionaries and lists |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4331 * are replaced with "...". |
1360 | 4332 * May return NULL. |
56 | 4333 */ |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
4334 char_u * |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4335 echo_string_core( |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4336 typval_T *tv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4337 char_u **tofree, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4338 char_u *numbuf, |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4339 int copyID, |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4340 int echo_style, |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4341 int restore_copyID, |
11973
aec3df2af27c
patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents:
11848
diff
changeset
|
4342 int composite_val) |
56 | 4343 { |
104 | 4344 static int recurse = 0; |
4345 char_u *r = NULL; | |
4346 | |
137 | 4347 if (recurse >= DICT_MAXNEST) |
104 | 4348 { |
5973 | 4349 if (!did_echo_string_emsg) |
4350 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4351 // Only give this message once for a recursive call to avoid |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4352 // flooding the user with errors. And stop iterating over lists |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4353 // and dicts. |
5973 | 4354 did_echo_string_emsg = TRUE; |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
4355 emsg(_("E724: variable nested too deep for displaying")); |
5973 | 4356 } |
104 | 4357 *tofree = NULL; |
5973 | 4358 return (char_u *)"{E724}"; |
104 | 4359 } |
4360 ++recurse; | |
4361 | |
56 | 4362 switch (tv->v_type) |
4363 { | |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4364 case VAR_STRING: |
11973
aec3df2af27c
patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents:
11848
diff
changeset
|
4365 if (echo_style && !composite_val) |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4366 { |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4367 *tofree = NULL; |
11973
aec3df2af27c
patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents:
11848
diff
changeset
|
4368 r = tv->vval.v_string; |
aec3df2af27c
patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents:
11848
diff
changeset
|
4369 if (r == NULL) |
aec3df2af27c
patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents:
11848
diff
changeset
|
4370 r = (char_u *)""; |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4371 } |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4372 else |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4373 { |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4374 *tofree = string_quote(tv->vval.v_string, FALSE); |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4375 r = *tofree; |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4376 } |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4377 break; |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4378 |
56 | 4379 case VAR_FUNC: |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4380 if (echo_style) |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4381 { |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4382 *tofree = NULL; |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4383 r = tv->vval.v_string; |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4384 } |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4385 else |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4386 { |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4387 *tofree = string_quote(tv->vval.v_string, TRUE); |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4388 r = *tofree; |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4389 } |
104 | 4390 break; |
634 | 4391 |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
4392 case VAR_PARTIAL: |
8710
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4393 { |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4394 partial_T *pt = tv->vval.v_partial; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4395 char_u *fname = string_quote(pt == NULL ? NULL |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
4396 : partial_name(pt), FALSE); |
8710
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4397 garray_T ga; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4398 int i; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4399 char_u *tf; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4400 |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4401 ga_init2(&ga, 1, 100); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4402 ga_concat(&ga, (char_u *)"function("); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4403 if (fname != NULL) |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4404 { |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4405 ga_concat(&ga, fname); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4406 vim_free(fname); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4407 } |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4408 if (pt != NULL && pt->pt_argc > 0) |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4409 { |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4410 ga_concat(&ga, (char_u *)", ["); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4411 for (i = 0; i < pt->pt_argc; ++i) |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4412 { |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4413 if (i > 0) |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4414 ga_concat(&ga, (char_u *)", "); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4415 ga_concat(&ga, |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4416 tv2string(&pt->pt_argv[i], &tf, numbuf, copyID)); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4417 vim_free(tf); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4418 } |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4419 ga_concat(&ga, (char_u *)"]"); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4420 } |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4421 if (pt != NULL && pt->pt_dict != NULL) |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4422 { |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4423 typval_T dtv; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4424 |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4425 ga_concat(&ga, (char_u *)", "); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4426 dtv.v_type = VAR_DICT; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4427 dtv.vval.v_dict = pt->pt_dict; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4428 ga_concat(&ga, tv2string(&dtv, &tf, numbuf, copyID)); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4429 vim_free(tf); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4430 } |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4431 ga_concat(&ga, (char_u *)")"); |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4432 |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4433 *tofree = ga.ga_data; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4434 r = *tofree; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4435 break; |
af3cb5c068fd
commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents:
8708
diff
changeset
|
4436 } |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
4437 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
4438 case VAR_BLOB: |
15466
435fcefd2c8e
patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents:
15464
diff
changeset
|
4439 r = blob2string(tv->vval.v_blob, tofree, numbuf); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
4440 break; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
4441 |
56 | 4442 case VAR_LIST: |
634 | 4443 if (tv->vval.v_list == NULL) |
4444 { | |
4445 *tofree = NULL; | |
4446 r = NULL; | |
4447 } | |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4448 else if (copyID != 0 && tv->vval.v_list->lv_copyID == copyID |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4449 && tv->vval.v_list->lv_len > 0) |
634 | 4450 { |
4451 *tofree = NULL; | |
4452 r = (char_u *)"[...]"; | |
4453 } | |
4454 else | |
4455 { | |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4456 int old_copyID = tv->vval.v_list->lv_copyID; |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4457 |
634 | 4458 tv->vval.v_list->lv_copyID = copyID; |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4459 *tofree = list2string(tv, copyID, restore_copyID); |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4460 if (restore_copyID) |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4461 tv->vval.v_list->lv_copyID = old_copyID; |
634 | 4462 r = *tofree; |
4463 } | |
4464 break; | |
4465 | |
100 | 4466 case VAR_DICT: |
634 | 4467 if (tv->vval.v_dict == NULL) |
4468 { | |
4469 *tofree = NULL; | |
4470 r = NULL; | |
4471 } | |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4472 else if (copyID != 0 && tv->vval.v_dict->dv_copyID == copyID |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4473 && tv->vval.v_dict->dv_hashtab.ht_used != 0) |
634 | 4474 { |
4475 *tofree = NULL; | |
4476 r = (char_u *)"{...}"; | |
4477 } | |
4478 else | |
4479 { | |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4480 int old_copyID = tv->vval.v_dict->dv_copyID; |
634 | 4481 tv->vval.v_dict->dv_copyID = copyID; |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4482 *tofree = dict2string(tv, copyID, restore_copyID); |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4483 if (restore_copyID) |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4484 tv->vval.v_dict->dv_copyID = old_copyID; |
634 | 4485 r = *tofree; |
4486 } | |
4487 break; | |
4488 | |
71 | 4489 case VAR_NUMBER: |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
4490 case VAR_UNKNOWN: |
11973
aec3df2af27c
patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents:
11848
diff
changeset
|
4491 *tofree = NULL; |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
4492 r = tv_get_string_buf(tv, numbuf); |
11973
aec3df2af27c
patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents:
11848
diff
changeset
|
4493 break; |
aec3df2af27c
patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents:
11848
diff
changeset
|
4494 |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
4495 case VAR_JOB: |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
4496 case VAR_CHANNEL: |
104 | 4497 *tofree = NULL; |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
4498 r = tv_get_string_buf(tv, numbuf); |
11973
aec3df2af27c
patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents:
11848
diff
changeset
|
4499 if (composite_val) |
aec3df2af27c
patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents:
11848
diff
changeset
|
4500 { |
aec3df2af27c
patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents:
11848
diff
changeset
|
4501 *tofree = string_quote(r, FALSE); |
aec3df2af27c
patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents:
11848
diff
changeset
|
4502 r = *tofree; |
aec3df2af27c
patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents:
11848
diff
changeset
|
4503 } |
71 | 4504 break; |
634 | 4505 |
1624 | 4506 case VAR_FLOAT: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
4507 #ifdef FEAT_FLOAT |
1624 | 4508 *tofree = NULL; |
4509 vim_snprintf((char *)numbuf, NUMBUFLEN, "%g", tv->vval.v_float); | |
4510 r = numbuf; | |
4511 break; | |
4512 #endif | |
4513 | |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
4514 case VAR_SPECIAL: |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
4515 *tofree = NULL; |
7730
80ce794827c4
commit https://github.com/vim/vim/commit/17a13437c9414a8693369a97f3be2fc8ad48c12e
Christian Brabandt <cb@256bit.org>
parents:
7720
diff
changeset
|
4516 r = (char_u *)get_var_special_name(tv->vval.v_number); |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
4517 break; |
104 | 4518 } |
4519 | |
5973 | 4520 if (--recurse == 0) |
4521 did_echo_string_emsg = FALSE; | |
104 | 4522 return r; |
97 | 4523 } |
4524 | |
4525 /* | |
4526 * Return a string with the string representation of a variable. | |
4527 * If the memory is allocated "tofree" is set to it, otherwise NULL. | |
4528 * "numbuf" is used for a number. | |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4529 * Does not put quotes around strings, as ":echo" displays values. |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4530 * When "copyID" is not NULL replace recursive lists and dicts with "...". |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4531 * May return NULL. |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4532 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
4533 char_u * |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4534 echo_string( |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4535 typval_T *tv, |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4536 char_u **tofree, |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4537 char_u *numbuf, |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4538 int copyID) |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4539 { |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4540 return echo_string_core(tv, tofree, numbuf, copyID, TRUE, FALSE, FALSE); |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4541 } |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4542 |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4543 /* |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4544 * Return a string with the string representation of a variable. |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4545 * If the memory is allocated "tofree" is set to it, otherwise NULL. |
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4546 * "numbuf" is used for a number. |
97 | 4547 * Puts quotes around strings, so that they can be parsed back by eval(). |
1360 | 4548 * May return NULL. |
97 | 4549 */ |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8887
diff
changeset
|
4550 char_u * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4551 tv2string( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4552 typval_T *tv, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4553 char_u **tofree, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4554 char_u *numbuf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4555 int copyID) |
97 | 4556 { |
9157
e316b83892c1
commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
4557 return echo_string_core(tv, tofree, numbuf, copyID, FALSE, TRUE, FALSE); |
56 | 4558 } |
4559 | |
4560 /* | |
137 | 4561 * Return string "str" in ' quotes, doubling ' characters. |
4562 * If "str" is NULL an empty string is assumed. | |
100 | 4563 * If "function" is TRUE make it function('string'). |
97 | 4564 */ |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
4565 char_u * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4566 string_quote(char_u *str, int function) |
97 | 4567 { |
137 | 4568 unsigned len; |
97 | 4569 char_u *p, *r, *s; |
4570 | |
137 | 4571 len = (function ? 13 : 3); |
4572 if (str != NULL) | |
4573 { | |
835 | 4574 len += (unsigned)STRLEN(str); |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10964
diff
changeset
|
4575 for (p = str; *p != NUL; MB_PTR_ADV(p)) |
137 | 4576 if (*p == '\'') |
4577 ++len; | |
4578 } | |
97 | 4579 s = r = alloc(len); |
4580 if (r != NULL) | |
4581 { | |
4582 if (function) | |
4583 { | |
100 | 4584 STRCPY(r, "function('"); |
97 | 4585 r += 10; |
4586 } | |
4587 else | |
100 | 4588 *r++ = '\''; |
137 | 4589 if (str != NULL) |
4590 for (p = str; *p != NUL; ) | |
4591 { | |
4592 if (*p == '\'') | |
4593 *r++ = '\''; | |
4594 MB_COPY_CHAR(p, r); | |
4595 } | |
100 | 4596 *r++ = '\''; |
97 | 4597 if (function) |
4598 *r++ = ')'; | |
4599 *r++ = NUL; | |
4600 } | |
4601 return s; | |
4602 } | |
4603 | |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
4604 #if defined(FEAT_FLOAT) || defined(PROTO) |
1624 | 4605 /* |
4606 * Convert the string "text" to a floating point number. | |
4607 * This uses strtod(). setlocale(LC_NUMERIC, "C") has been used to make sure | |
4608 * this always uses a decimal point. | |
4609 * Returns the length of the text that was consumed. | |
4610 */ | |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
4611 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4612 string2float( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4613 char_u *text, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4614 float_T *value) // result stored here |
1624 | 4615 { |
4616 char *s = (char *)text; | |
4617 float_T f; | |
4618 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4619 // MS-Windows does not deal with "inf" and "nan" properly. |
10536
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4620 if (STRNICMP(text, "inf", 3) == 0) |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4621 { |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4622 *value = INFINITY; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4623 return 3; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4624 } |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4625 if (STRNICMP(text, "-inf", 3) == 0) |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4626 { |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4627 *value = -INFINITY; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4628 return 4; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4629 } |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4630 if (STRNICMP(text, "nan", 3) == 0) |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4631 { |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4632 *value = NAN; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4633 return 3; |
6ddf322ff7cf
patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4634 } |
1624 | 4635 f = strtod(s, &s); |
4636 *value = f; | |
4637 return (int)((char_u *)s - text); | |
4638 } | |
4639 #endif | |
4640 | |
97 | 4641 /* |
7 | 4642 * Get the value of an environment variable. |
4643 * "arg" is pointing to the '$'. It is advanced to after the name. | |
4644 * If the environment variable was not set, silently assume it is empty. | |
5858 | 4645 * Return FAIL if the name is invalid. |
7 | 4646 */ |
4647 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4648 get_env_tv(char_u **arg, typval_T *rettv, int evaluate) |
7 | 4649 { |
4650 char_u *string = NULL; | |
4651 int len; | |
4652 int cc; | |
4653 char_u *name; | |
170 | 4654 int mustfree = FALSE; |
7 | 4655 |
4656 ++*arg; | |
4657 name = *arg; | |
4658 len = get_env_len(arg); | |
4659 if (evaluate) | |
4660 { | |
5858 | 4661 if (len == 0) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4662 return FAIL; // invalid empty name |
5858 | 4663 |
4664 cc = name[len]; | |
4665 name[len] = NUL; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4666 // first try vim_getenv(), fast for normal environment vars |
5858 | 4667 string = vim_getenv(name, &mustfree); |
4668 if (string != NULL && *string != NUL) | |
4669 { | |
4670 if (!mustfree) | |
4671 string = vim_strsave(string); | |
4672 } | |
4673 else | |
4674 { | |
4675 if (mustfree) | |
4676 vim_free(string); | |
4677 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4678 // next try expanding things like $VIM and ${HOME} |
5858 | 4679 string = expand_env_save(name - 1); |
4680 if (string != NULL && *string == '$') | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
4681 VIM_CLEAR(string); |
5858 | 4682 } |
4683 name[len] = cc; | |
4684 | |
71 | 4685 rettv->v_type = VAR_STRING; |
4686 rettv->vval.v_string = string; | |
7 | 4687 } |
4688 | |
4689 return OK; | |
4690 } | |
4691 | |
3214 | 4692 /* |
7 | 4693 * Translate a String variable into a position. |
685 | 4694 * Returns NULL when there is an error. |
7 | 4695 */ |
9571
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9562
diff
changeset
|
4696 pos_T * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4697 var2fpos( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4698 typval_T *varp, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4699 int dollar_lnum, // TRUE when $ is last line |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4700 int *fnum) // set to fnum for '0, 'A, etc. |
7 | 4701 { |
700 | 4702 char_u *name; |
7 | 4703 static pos_T pos; |
700 | 4704 pos_T *pp; |
7 | 4705 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4706 // Argument can be [lnum, col, coladd]. |
685 | 4707 if (varp->v_type == VAR_LIST) |
4708 { | |
4709 list_T *l; | |
4710 int len; | |
705 | 4711 int error = FALSE; |
1317 | 4712 listitem_T *li; |
685 | 4713 |
4714 l = varp->vval.v_list; | |
4715 if (l == NULL) | |
4716 return NULL; | |
4717 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4718 // Get the line number |
705 | 4719 pos.lnum = list_find_nr(l, 0L, &error); |
4720 if (error || pos.lnum <= 0 || pos.lnum > curbuf->b_ml.ml_line_count) | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4721 return NULL; // invalid line number |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4722 |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4723 // Get the column number |
705 | 4724 pos.col = list_find_nr(l, 1L, &error); |
4725 if (error) | |
685 | 4726 return NULL; |
4727 len = (long)STRLEN(ml_get(pos.lnum)); | |
1317 | 4728 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4729 // We accept "$" for the column number: last column. |
1317 | 4730 li = list_find(l, 1L); |
4731 if (li != NULL && li->li_tv.v_type == VAR_STRING | |
4732 && li->li_tv.vval.v_string != NULL | |
4733 && STRCMP(li->li_tv.vval.v_string, "$") == 0) | |
4734 pos.col = len + 1; | |
4735 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4736 // Accept a position up to the NUL after the line. |
826 | 4737 if (pos.col == 0 || (int)pos.col > len + 1) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4738 return NULL; // invalid column number |
705 | 4739 --pos.col; |
4740 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4741 // Get the virtual offset. Defaults to zero. |
705 | 4742 pos.coladd = list_find_nr(l, 2L, &error); |
4743 if (error) | |
4744 pos.coladd = 0; | |
4745 | |
685 | 4746 return &pos; |
4747 } | |
4748 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
4749 name = tv_get_string_chk(varp); |
323 | 4750 if (name == NULL) |
4751 return NULL; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4752 if (name[0] == '.') // cursor |
7 | 4753 return &curwin->w_cursor; |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4754 if (name[0] == 'v' && name[1] == NUL) // Visual start |
1609 | 4755 { |
4756 if (VIsual_active) | |
4757 return &VIsual; | |
4758 return &curwin->w_cursor; | |
4759 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4760 if (name[0] == '\'') // mark |
7 | 4761 { |
4043 | 4762 pp = getmark_buf_fnum(curbuf, name[1], FALSE, fnum); |
7 | 4763 if (pp == NULL || pp == (pos_T *)-1 || pp->lnum <= 0) |
4764 return NULL; | |
4765 return pp; | |
4766 } | |
705 | 4767 |
4768 pos.coladd = 0; | |
4769 | |
1317 | 4770 if (name[0] == 'w' && dollar_lnum) |
666 | 4771 { |
4772 pos.col = 0; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4773 if (name[1] == '0') // "w0": first visible line |
666 | 4774 { |
671 | 4775 update_topline(); |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4776 // In silent Ex mode topline is zero, but that's not a valid line |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4777 // number; use one instead. |
11313
327a04a762f6
patch 8.0.0542: getpos() can return a negative line number
Christian Brabandt <cb@256bit.org>
parents:
11181
diff
changeset
|
4778 pos.lnum = curwin->w_topline > 0 ? curwin->w_topline : 1; |
666 | 4779 return &pos; |
4780 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4781 else if (name[1] == '$') // "w$": last visible line |
666 | 4782 { |
671 | 4783 validate_botline(); |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4784 // In silent Ex mode botline is zero, return zero then. |
11313
327a04a762f6
patch 8.0.0542: getpos() can return a negative line number
Christian Brabandt <cb@256bit.org>
parents:
11181
diff
changeset
|
4785 pos.lnum = curwin->w_botline > 0 ? curwin->w_botline - 1 : 0; |
666 | 4786 return &pos; |
4787 } | |
4788 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4789 else if (name[0] == '$') // last column or line |
7 | 4790 { |
1317 | 4791 if (dollar_lnum) |
7 | 4792 { |
4793 pos.lnum = curbuf->b_ml.ml_line_count; | |
4794 pos.col = 0; | |
4795 } | |
4796 else | |
4797 { | |
4798 pos.lnum = curwin->w_cursor.lnum; | |
4799 pos.col = (colnr_T)STRLEN(ml_get_curline()); | |
4800 } | |
4801 return &pos; | |
4802 } | |
4803 return NULL; | |
4804 } | |
4805 | |
4806 /* | |
709 | 4807 * Convert list in "arg" into a position and optional file number. |
4808 * When "fnump" is NULL there is no file number, only 3 items. | |
4809 * Note that the column is passed on as-is, the caller may want to decrement | |
4810 * it to use 1 for the first column. | |
4811 * Return FAIL when conversion is not possible, doesn't check the position for | |
4812 * validity. | |
4813 */ | |
9571
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9562
diff
changeset
|
4814 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4815 list2fpos( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4816 typval_T *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4817 pos_T *posp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4818 int *fnump, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4819 colnr_T *curswantp) |
709 | 4820 { |
4821 list_T *l = arg->vval.v_list; | |
4822 long i = 0; | |
4823 long n; | |
4824 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4825 // List must be: [fnum, lnum, col, coladd, curswant], where "fnum" is only |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4826 // there when "fnump" isn't NULL; "coladd" and "curswant" are optional. |
915 | 4827 if (arg->v_type != VAR_LIST |
4828 || l == NULL | |
4829 || l->lv_len < (fnump == NULL ? 2 : 3) | |
5938 | 4830 || l->lv_len > (fnump == NULL ? 4 : 5)) |
709 | 4831 return FAIL; |
4832 | |
4833 if (fnump != NULL) | |
4834 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4835 n = list_find_nr(l, i++, NULL); // fnum |
709 | 4836 if (n < 0) |
4837 return FAIL; | |
4838 if (n == 0) | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4839 n = curbuf->b_fnum; // current buffer |
709 | 4840 *fnump = n; |
4841 } | |
4842 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4843 n = list_find_nr(l, i++, NULL); // lnum |
709 | 4844 if (n < 0) |
4845 return FAIL; | |
4846 posp->lnum = n; | |
4847 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4848 n = list_find_nr(l, i++, NULL); // col |
709 | 4849 if (n < 0) |
4850 return FAIL; | |
4851 posp->col = n; | |
4852 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4853 n = list_find_nr(l, i, NULL); // off |
709 | 4854 if (n < 0) |
915 | 4855 posp->coladd = 0; |
4856 else | |
4857 posp->coladd = n; | |
709 | 4858 |
5938 | 4859 if (curswantp != NULL) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4860 *curswantp = list_find_nr(l, i + 1, NULL); // curswant |
5938 | 4861 |
709 | 4862 return OK; |
4863 } | |
4864 | |
4865 /* | |
7 | 4866 * Get the length of an environment variable name. |
4867 * Advance "arg" to the first character after the name. | |
4868 * Return 0 for error. | |
4869 */ | |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17833
diff
changeset
|
4870 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4871 get_env_len(char_u **arg) |
7 | 4872 { |
4873 char_u *p; | |
4874 int len; | |
4875 | |
4876 for (p = *arg; vim_isIDc(*p); ++p) | |
4877 ; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4878 if (p == *arg) // no name found |
7 | 4879 return 0; |
4880 | |
4881 len = (int)(p - *arg); | |
4882 *arg = p; | |
4883 return len; | |
4884 } | |
4885 | |
4886 /* | |
4887 * Get the length of the name of a function or internal variable. | |
4888 * "arg" is advanced to the first non-white character after the name. | |
4889 * Return 0 if something is wrong. | |
4890 */ | |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
4891 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4892 get_id_len(char_u **arg) |
7 | 4893 { |
4894 char_u *p; | |
4895 int len; | |
4896 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4897 // Find the end of the name. |
7 | 4898 for (p = *arg; eval_isnamec(*p); ++p) |
7611
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4899 { |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4900 if (*p == ':') |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4901 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4902 // "s:" is start of "s:var", but "n:" is not and can be used in |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4903 // slice "[n:]". Also "xx:" is not a namespace. |
7611
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4904 len = (int)(p - *arg); |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4905 if ((len == 1 && vim_strchr(NAMESPACE_CHAR, **arg) == NULL) |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4906 || len > 1) |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4907 break; |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4908 } |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
4909 } |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4910 if (p == *arg) // no name found |
7 | 4911 return 0; |
4912 | |
4913 len = (int)(p - *arg); | |
4914 *arg = skipwhite(p); | |
4915 | |
4916 return len; | |
4917 } | |
4918 | |
4919 /* | |
124 | 4920 * Get the length of the name of a variable or function. |
4921 * Only the name is recognized, does not handle ".key" or "[idx]". | |
7 | 4922 * "arg" is advanced to the first non-white character after the name. |
159 | 4923 * Return -1 if curly braces expansion failed. |
4924 * Return 0 if something else is wrong. | |
7 | 4925 * If the name contains 'magic' {}'s, expand them and return the |
4926 * expanded name in an allocated string via 'alias' - caller must free. | |
4927 */ | |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17833
diff
changeset
|
4928 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4929 get_name_len( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4930 char_u **arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4931 char_u **alias, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4932 int evaluate, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
4933 int verbose) |
7 | 4934 { |
4935 int len; | |
4936 char_u *p; | |
4937 char_u *expr_start; | |
4938 char_u *expr_end; | |
4939 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4940 *alias = NULL; // default to no alias |
7 | 4941 |
4942 if ((*arg)[0] == K_SPECIAL && (*arg)[1] == KS_EXTRA | |
4943 && (*arg)[2] == (int)KE_SNR) | |
4944 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4945 // hard coded <SNR>, already translated |
7 | 4946 *arg += 3; |
4947 return get_id_len(arg) + 3; | |
4948 } | |
4949 len = eval_fname_script(*arg); | |
4950 if (len > 0) | |
4951 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
4952 // literal "<SID>", "s:" or "<SNR>" |
7 | 4953 *arg += len; |
4954 } | |
4955 | |
4956 /* | |
71 | 4957 * Find the end of the name; check for {} construction. |
7 | 4958 */ |
271 | 4959 p = find_name_end(*arg, &expr_start, &expr_end, |
4960 len > 0 ? 0 : FNE_CHECK_START); | |
7 | 4961 if (expr_start != NULL) |
4962 { | |
4963 char_u *temp_string; | |
4964 | |
4965 if (!evaluate) | |
4966 { | |
4967 len += (int)(p - *arg); | |
4968 *arg = skipwhite(p); | |
4969 return len; | |
4970 } | |
4971 | |
4972 /* | |
4973 * Include any <SID> etc in the expanded string: | |
4974 * Thus the -len here. | |
4975 */ | |
4976 temp_string = make_expanded_name(*arg - len, expr_start, expr_end, p); | |
4977 if (temp_string == NULL) | |
159 | 4978 return -1; |
7 | 4979 *alias = temp_string; |
4980 *arg = skipwhite(p); | |
4981 return (int)STRLEN(temp_string); | |
4982 } | |
4983 | |
4984 len += get_id_len(arg); | |
15464
3faa7cc8207c
patch 8.1.0740: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents:
15460
diff
changeset
|
4985 // Only give an error when there is something, otherwise it will be |
3faa7cc8207c
patch 8.1.0740: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents:
15460
diff
changeset
|
4986 // reported at a higher level. |
3faa7cc8207c
patch 8.1.0740: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents:
15460
diff
changeset
|
4987 if (len == 0 && verbose && **arg != NUL) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
4988 semsg(_(e_invexpr2), *arg); |
7 | 4989 |
4990 return len; | |
4991 } | |
4992 | |
71 | 4993 /* |
4994 * Find the end of a variable or function name, taking care of magic braces. | |
4995 * If "expr_start" is not NULL then "expr_start" and "expr_end" are set to the | |
4996 * start and end of the first magic braces item. | |
271 | 4997 * "flags" can have FNE_INCL_BR and FNE_CHECK_START. |
71 | 4998 * Return a pointer to just after the name. Equal to "arg" if there is no |
4999 * valid name. | |
5000 */ | |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
5001 char_u * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5002 find_name_end( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5003 char_u *arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5004 char_u **expr_start, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5005 char_u **expr_end, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5006 int flags) |
71 | 5007 { |
5008 int mb_nest = 0; | |
5009 int br_nest = 0; | |
7 | 5010 char_u *p; |
7611
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
5011 int len; |
7 | 5012 |
71 | 5013 if (expr_start != NULL) |
5014 { | |
5015 *expr_start = NULL; | |
5016 *expr_end = NULL; | |
5017 } | |
5018 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5019 // Quick check for valid starting character. |
271 | 5020 if ((flags & FNE_CHECK_START) && !eval_isnamec1(*arg) && *arg != '{') |
5021 return arg; | |
5022 | |
71 | 5023 for (p = arg; *p != NUL |
5024 && (eval_isnamec(*p) | |
104 | 5025 || *p == '{' |
271 | 5026 || ((flags & FNE_INCL_BR) && (*p == '[' || *p == '.')) |
71 | 5027 || mb_nest != 0 |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10964
diff
changeset
|
5028 || br_nest != 0); MB_PTR_ADV(p)) |
468 | 5029 { |
5030 if (*p == '\'') | |
5031 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5032 // skip over 'string' to avoid counting [ and ] inside it. |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10964
diff
changeset
|
5033 for (p = p + 1; *p != NUL && *p != '\''; MB_PTR_ADV(p)) |
468 | 5034 ; |
5035 if (*p == NUL) | |
5036 break; | |
5037 } | |
5038 else if (*p == '"') | |
5039 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5040 // skip over "str\"ing" to avoid counting [ and ] inside it. |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10964
diff
changeset
|
5041 for (p = p + 1; *p != NUL && *p != '"'; MB_PTR_ADV(p)) |
468 | 5042 if (*p == '\\' && p[1] != NUL) |
5043 ++p; | |
5044 if (*p == NUL) | |
5045 break; | |
5046 } | |
7611
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
5047 else if (br_nest == 0 && mb_nest == 0 && *p == ':') |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
5048 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5049 // "s:" is start of "s:var", but "n:" is not and can be used in |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5050 // slice "[n:]". Also "xx:" is not a namespace. But {ns}: is. |
7611
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
5051 len = (int)(p - arg); |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
5052 if ((len == 1 && vim_strchr(NAMESPACE_CHAR, *arg) == NULL) |
7627
d9ec7d22494d
commit https://github.com/vim/vim/commit/4119cf80e1e534057680f9543e73edf7967c2440
Christian Brabandt <cb@256bit.org>
parents:
7615
diff
changeset
|
5053 || (len > 1 && p[-1] != '}')) |
7611
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
5054 break; |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
5055 } |
468 | 5056 |
71 | 5057 if (mb_nest == 0) |
5058 { | |
5059 if (*p == '[') | |
5060 ++br_nest; | |
5061 else if (*p == ']') | |
5062 --br_nest; | |
5063 } | |
468 | 5064 |
71 | 5065 if (br_nest == 0) |
5066 { | |
5067 if (*p == '{') | |
5068 { | |
5069 mb_nest++; | |
5070 if (expr_start != NULL && *expr_start == NULL) | |
5071 *expr_start = p; | |
5072 } | |
5073 else if (*p == '}') | |
5074 { | |
5075 mb_nest--; | |
5076 if (expr_start != NULL && mb_nest == 0 && *expr_end == NULL) | |
5077 *expr_end = p; | |
5078 } | |
5079 } | |
7 | 5080 } |
5081 | |
5082 return p; | |
5083 } | |
5084 | |
5085 /* | |
159 | 5086 * Expands out the 'magic' {}'s in a variable/function name. |
5087 * Note that this can call itself recursively, to deal with | |
5088 * constructs like foo{bar}{baz}{bam} | |
5089 * The four pointer arguments point to "foo{expre}ss{ion}bar" | |
5090 * "in_start" ^ | |
5091 * "expr_start" ^ | |
5092 * "expr_end" ^ | |
5093 * "in_end" ^ | |
5094 * | |
5095 * Returns a new allocated string, which the caller must free. | |
5096 * Returns NULL for failure. | |
5097 */ | |
5098 static char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5099 make_expanded_name( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5100 char_u *in_start, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5101 char_u *expr_start, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5102 char_u *expr_end, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5103 char_u *in_end) |
159 | 5104 { |
5105 char_u c1; | |
5106 char_u *retval = NULL; | |
5107 char_u *temp_result; | |
5108 char_u *nextcmd = NULL; | |
5109 | |
5110 if (expr_end == NULL || in_end == NULL) | |
5111 return NULL; | |
5112 *expr_start = NUL; | |
5113 *expr_end = NUL; | |
5114 c1 = *in_end; | |
5115 *in_end = NUL; | |
5116 | |
714 | 5117 temp_result = eval_to_string(expr_start + 1, &nextcmd, FALSE); |
159 | 5118 if (temp_result != NULL && nextcmd == NULL) |
5119 { | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
5120 retval = alloc(STRLEN(temp_result) + (expr_start - in_start) |
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
5121 + (in_end - expr_end) + 1); |
159 | 5122 if (retval != NULL) |
5123 { | |
5124 STRCPY(retval, in_start); | |
5125 STRCAT(retval, temp_result); | |
5126 STRCAT(retval, expr_end + 1); | |
5127 } | |
5128 } | |
5129 vim_free(temp_result); | |
5130 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5131 *in_end = c1; // put char back for error messages |
159 | 5132 *expr_start = '{'; |
5133 *expr_end = '}'; | |
5134 | |
5135 if (retval != NULL) | |
5136 { | |
271 | 5137 temp_result = find_name_end(retval, &expr_start, &expr_end, 0); |
159 | 5138 if (expr_start != NULL) |
5139 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5140 // Further expansion! |
159 | 5141 temp_result = make_expanded_name(retval, expr_start, |
5142 expr_end, temp_result); | |
5143 vim_free(retval); | |
5144 retval = temp_result; | |
5145 } | |
5146 } | |
5147 | |
5148 return retval; | |
5149 } | |
5150 | |
5151 /* | |
7 | 5152 * Return TRUE if character "c" can be used in a variable or function name. |
104 | 5153 * Does not include '{' or '}' for magic braces. |
7 | 5154 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
5155 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5156 eval_isnamec(int c) |
7 | 5157 { |
271 | 5158 return (ASCII_ISALNUM(c) || c == '_' || c == ':' || c == AUTOLOAD_CHAR); |
5159 } | |
5160 | |
5161 /* | |
5162 * Return TRUE if character "c" can be used as the first character in a | |
5163 * variable or function name (excluding '{' and '}'). | |
5164 */ | |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
5165 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5166 eval_isnamec1(int c) |
271 | 5167 { |
5168 return (ASCII_ISALPHA(c) || c == '_'); | |
7 | 5169 } |
5170 | |
5171 /* | |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5172 * Handle: |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5173 * - expr[expr], expr[expr:expr] subscript |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5174 * - ".name" lookup |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5175 * - function call with Funcref variable: func(expr) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5176 * - method call: var->method() |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5177 * |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5178 * Can all be combined in any order: dict.func(expr)[idx]['func'](expr)->len() |
159 | 5179 */ |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
5180 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5181 handle_subscript( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5182 char_u **arg, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5183 typval_T *rettv, |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5184 int evaluate, // do more than finding the end |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5185 int verbose, // give error messages |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5186 char_u *start_leader, // start of '!' and '-' prefixes |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5187 char_u **end_leaderp) // end of '!' and '-' prefixes |
159 | 5188 { |
5189 int ret = OK; | |
5190 dict_T *selfdict = NULL; | |
5191 | |
17448
f8cd16838434
patch 8.1.1722: error when scriptversion is 2 a making a dictionary access
Bram Moolenaar <Bram@vim.org>
parents:
17413
diff
changeset
|
5192 // "." is ".name" lookup when we found a dict or when evaluating and |
f8cd16838434
patch 8.1.1722: error when scriptversion is 2 a making a dictionary access
Bram Moolenaar <Bram@vim.org>
parents:
17413
diff
changeset
|
5193 // scriptversion is at least 2, where string concatenation is "..". |
159 | 5194 while (ret == OK |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5195 && (((**arg == '[' |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5196 || (**arg == '.' && (rettv->v_type == VAR_DICT |
17448
f8cd16838434
patch 8.1.1722: error when scriptversion is 2 a making a dictionary access
Bram Moolenaar <Bram@vim.org>
parents:
17413
diff
changeset
|
5197 || (!evaluate |
f8cd16838434
patch 8.1.1722: error when scriptversion is 2 a making a dictionary access
Bram Moolenaar <Bram@vim.org>
parents:
17413
diff
changeset
|
5198 && (*arg)[1] != '.' |
f8cd16838434
patch 8.1.1722: error when scriptversion is 2 a making a dictionary access
Bram Moolenaar <Bram@vim.org>
parents:
17413
diff
changeset
|
5199 && current_sctx.sc_version >= 2))) |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5200 || (**arg == '(' && (!evaluate || rettv->v_type == VAR_FUNC |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5201 || rettv->v_type == VAR_PARTIAL))) |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5202 && !VIM_ISWHITE(*(*arg - 1))) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5203 || (**arg == '-' && (*arg)[1] == '>'))) |
159 | 5204 { |
5205 if (**arg == '(') | |
5206 { | |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
5207 ret = call_func_rettv(arg, rettv, evaluate, selfdict, NULL); |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
5208 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
5209 // Stop the expression evaluation when immediately aborting on |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
5210 // error, or when an interrupt occurred or an exception was thrown |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
5211 // but not caught. |
159 | 5212 if (aborting()) |
5213 { | |
5214 if (ret == OK) | |
5215 clear_tv(rettv); | |
5216 ret = FAIL; | |
5217 } | |
5218 dict_unref(selfdict); | |
5219 selfdict = NULL; | |
5220 } | |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5221 else if (**arg == '-') |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5222 { |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5223 // Expression "-1.0->method()" applies the leader "-" before |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5224 // applying ->. |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5225 if (evaluate && *end_leaderp > start_leader) |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5226 ret = eval7_leader(rettv, start_leader, end_leaderp); |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5227 if (ret == OK) |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5228 { |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5229 if ((*arg)[2] == '{') |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5230 // expr->{lambda}() |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5231 ret = eval_lambda(arg, rettv, evaluate, verbose); |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5232 else |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5233 // expr->name() |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5234 ret = eval_method(arg, rettv, evaluate, verbose); |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
5235 } |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5236 } |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5237 else // **arg == '[' || **arg == '.' |
159 | 5238 { |
5239 dict_unref(selfdict); | |
5240 if (rettv->v_type == VAR_DICT) | |
5241 { | |
5242 selfdict = rettv->vval.v_dict; | |
5243 if (selfdict != NULL) | |
5244 ++selfdict->dv_refcount; | |
5245 } | |
5246 else | |
5247 selfdict = NULL; | |
5248 if (eval_index(arg, rettv, evaluate, verbose) == FAIL) | |
5249 { | |
5250 clear_tv(rettv); | |
5251 ret = FAIL; | |
5252 } | |
5253 } | |
5254 } | |
8575
b5209a4e5baf
commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents:
8554
diff
changeset
|
5255 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5256 // Turn "dict.Func" into a partial for "Func" bound to "dict". |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5257 // Don't do this when "Func" is already a partial that was bound |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5258 // explicitly (pt_auto is FALSE). |
9104
2242a5766417
commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents:
9093
diff
changeset
|
5259 if (selfdict != NULL |
2242a5766417
commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents:
9093
diff
changeset
|
5260 && (rettv->v_type == VAR_FUNC |
2242a5766417
commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents:
9093
diff
changeset
|
5261 || (rettv->v_type == VAR_PARTIAL |
2242a5766417
commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents:
9093
diff
changeset
|
5262 && (rettv->vval.v_partial->pt_auto |
2242a5766417
commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents:
9093
diff
changeset
|
5263 || rettv->vval.v_partial->pt_dict == NULL)))) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
5264 selfdict = make_partial(selfdict, rettv); |
8575
b5209a4e5baf
commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents:
8554
diff
changeset
|
5265 |
159 | 5266 dict_unref(selfdict); |
5267 return ret; | |
5268 } | |
5269 | |
5270 /* | |
1624 | 5271 * Allocate memory for a variable type-value, and make it empty (0 or NULL |
56 | 5272 * value). |
5273 */ | |
7877
7fbd2de703a9
commit https://github.com/vim/vim/commit/11e0afa00a8e6c0aa1d50f760b5d5cb62dade038
Christian Brabandt <cb@256bit.org>
parents:
7864
diff
changeset
|
5274 typval_T * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5275 alloc_tv(void) |
56 | 5276 { |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16796
diff
changeset
|
5277 return ALLOC_CLEAR_ONE(typval_T); |
56 | 5278 } |
5279 | |
5280 /* | |
5281 * Allocate memory for a variable type-value, and assign a string to it. | |
7 | 5282 * The string "s" must have been allocated, it is consumed. |
5283 * Return NULL for out of memory, the variable otherwise. | |
5284 */ | |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
5285 typval_T * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5286 alloc_string_tv(char_u *s) |
7 | 5287 { |
137 | 5288 typval_T *rettv; |
71 | 5289 |
5290 rettv = alloc_tv(); | |
5291 if (rettv != NULL) | |
5292 { | |
5293 rettv->v_type = VAR_STRING; | |
5294 rettv->vval.v_string = s; | |
7 | 5295 } |
5296 else | |
5297 vim_free(s); | |
71 | 5298 return rettv; |
7 | 5299 } |
5300 | |
5301 /* | |
56 | 5302 * Free the memory for a variable type-value. |
5303 */ | |
625 | 5304 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5305 free_tv(typval_T *varp) |
7 | 5306 { |
5307 if (varp != NULL) | |
5308 { | |
56 | 5309 switch (varp->v_type) |
5310 { | |
117 | 5311 case VAR_FUNC: |
5312 func_unref(varp->vval.v_string); | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5313 // FALLTHROUGH |
56 | 5314 case VAR_STRING: |
5315 vim_free(varp->vval.v_string); | |
5316 break; | |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5317 case VAR_PARTIAL: |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5318 partial_unref(varp->vval.v_partial); |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5319 break; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5320 case VAR_BLOB: |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5321 blob_unref(varp->vval.v_blob); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5322 break; |
56 | 5323 case VAR_LIST: |
5324 list_unref(varp->vval.v_list); | |
5325 break; | |
117 | 5326 case VAR_DICT: |
5327 dict_unref(varp->vval.v_dict); | |
5328 break; | |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5329 case VAR_JOB: |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5330 #ifdef FEAT_JOB_CHANNEL |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5331 job_unref(varp->vval.v_job); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5332 break; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5333 #endif |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5334 case VAR_CHANNEL: |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5335 #ifdef FEAT_JOB_CHANNEL |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5336 channel_unref(varp->vval.v_channel); |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5337 break; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5338 #endif |
156 | 5339 case VAR_NUMBER: |
1624 | 5340 case VAR_FLOAT: |
156 | 5341 case VAR_UNKNOWN: |
7768
3d8e4e0d7127
commit https://github.com/vim/vim/commit/6650a694547eb744afa060ec62dd8270e99db9f2
Christian Brabandt <cb@256bit.org>
parents:
7765
diff
changeset
|
5342 case VAR_SPECIAL: |
156 | 5343 break; |
56 | 5344 } |
7 | 5345 vim_free(varp); |
5346 } | |
5347 } | |
5348 | |
5349 /* | |
5350 * Free the memory for a variable value and set the value to NULL or 0. | |
5351 */ | |
446 | 5352 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5353 clear_tv(typval_T *varp) |
7 | 5354 { |
5355 if (varp != NULL) | |
5356 { | |
56 | 5357 switch (varp->v_type) |
5358 { | |
117 | 5359 case VAR_FUNC: |
5360 func_unref(varp->vval.v_string); | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5361 // FALLTHROUGH |
56 | 5362 case VAR_STRING: |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
5363 VIM_CLEAR(varp->vval.v_string); |
56 | 5364 break; |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5365 case VAR_PARTIAL: |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5366 partial_unref(varp->vval.v_partial); |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5367 varp->vval.v_partial = NULL; |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5368 break; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5369 case VAR_BLOB: |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5370 blob_unref(varp->vval.v_blob); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5371 varp->vval.v_blob = NULL; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5372 break; |
56 | 5373 case VAR_LIST: |
5374 list_unref(varp->vval.v_list); | |
121 | 5375 varp->vval.v_list = NULL; |
56 | 5376 break; |
100 | 5377 case VAR_DICT: |
5378 dict_unref(varp->vval.v_dict); | |
121 | 5379 varp->vval.v_dict = NULL; |
100 | 5380 break; |
71 | 5381 case VAR_NUMBER: |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
5382 case VAR_SPECIAL: |
56 | 5383 varp->vval.v_number = 0; |
5384 break; | |
1624 | 5385 case VAR_FLOAT: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5386 #ifdef FEAT_FLOAT |
1624 | 5387 varp->vval.v_float = 0.0; |
5388 break; | |
5389 #endif | |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5390 case VAR_JOB: |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5391 #ifdef FEAT_JOB_CHANNEL |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5392 job_unref(varp->vval.v_job); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5393 varp->vval.v_job = NULL; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5394 #endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5395 break; |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5396 case VAR_CHANNEL: |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5397 #ifdef FEAT_JOB_CHANNEL |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5398 channel_unref(varp->vval.v_channel); |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5399 varp->vval.v_channel = NULL; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5400 #endif |
71 | 5401 case VAR_UNKNOWN: |
5402 break; | |
5403 } | |
151 | 5404 varp->v_lock = 0; |
71 | 5405 } |
5406 } | |
5407 | |
5408 /* | |
5409 * Set the value of a variable to NULL without freeing items. | |
5410 */ | |
9571
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9562
diff
changeset
|
5411 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5412 init_tv(typval_T *varp) |
71 | 5413 { |
5414 if (varp != NULL) | |
137 | 5415 vim_memset(varp, 0, sizeof(typval_T)); |
7 | 5416 } |
5417 | |
5418 /* | |
5419 * Get the number value of a variable. | |
5420 * If it is a String variable, uses vim_str2nr(). | |
323 | 5421 * For incompatible types, return 0. |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5422 * tv_get_number_chk() is similar to tv_get_number(), but informs the |
323 | 5423 * caller of incompatible types: it sets *denote to TRUE if "denote" |
5424 * is not NULL or returns -1 otherwise. | |
7 | 5425 */ |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
5426 varnumber_T |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5427 tv_get_number(typval_T *varp) |
56 | 5428 { |
323 | 5429 int error = FALSE; |
5430 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5431 return tv_get_number_chk(varp, &error); // return 0L on error |
323 | 5432 } |
5433 | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
5434 varnumber_T |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5435 tv_get_number_chk(typval_T *varp, int *denote) |
323 | 5436 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
5437 varnumber_T n = 0L; |
56 | 5438 |
5439 switch (varp->v_type) | |
5440 { | |
5441 case VAR_NUMBER: | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
5442 return varp->vval.v_number; |
1624 | 5443 case VAR_FLOAT: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5444 #ifdef FEAT_FLOAT |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5445 emsg(_("E805: Using a Float as a Number")); |
1624 | 5446 break; |
5447 #endif | |
56 | 5448 case VAR_FUNC: |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5449 case VAR_PARTIAL: |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5450 emsg(_("E703: Using a Funcref as a Number")); |
56 | 5451 break; |
5452 case VAR_STRING: | |
5453 if (varp->vval.v_string != NULL) | |
5454 vim_str2nr(varp->vval.v_string, NULL, NULL, | |
16706
77bcb5055fec
patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents:
16704
diff
changeset
|
5455 STR2NR_ALL, &n, NULL, 0, FALSE); |
323 | 5456 return n; |
97 | 5457 case VAR_LIST: |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5458 emsg(_("E745: Using a List as a Number")); |
97 | 5459 break; |
117 | 5460 case VAR_DICT: |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5461 emsg(_("E728: Using a Dictionary as a Number")); |
117 | 5462 break; |
7730
80ce794827c4
commit https://github.com/vim/vim/commit/17a13437c9414a8693369a97f3be2fc8ad48c12e
Christian Brabandt <cb@256bit.org>
parents:
7720
diff
changeset
|
5463 case VAR_SPECIAL: |
80ce794827c4
commit https://github.com/vim/vim/commit/17a13437c9414a8693369a97f3be2fc8ad48c12e
Christian Brabandt <cb@256bit.org>
parents:
7720
diff
changeset
|
5464 return varp->vval.v_number == VVAL_TRUE ? 1 : 0; |
80ce794827c4
commit https://github.com/vim/vim/commit/17a13437c9414a8693369a97f3be2fc8ad48c12e
Christian Brabandt <cb@256bit.org>
parents:
7720
diff
changeset
|
5465 break; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5466 case VAR_JOB: |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5467 #ifdef FEAT_JOB_CHANNEL |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5468 emsg(_("E910: Using a Job as a Number")); |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5469 break; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5470 #endif |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5471 case VAR_CHANNEL: |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5472 #ifdef FEAT_JOB_CHANNEL |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5473 emsg(_("E913: Using a Channel as a Number")); |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5474 break; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5475 #endif |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5476 case VAR_BLOB: |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5477 emsg(_("E974: Using a Blob as a Number")); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5478 break; |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
5479 case VAR_UNKNOWN: |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5480 internal_error("tv_get_number(UNKNOWN)"); |
56 | 5481 break; |
5482 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5483 if (denote == NULL) // useful for values that must be unsigned |
323 | 5484 n = -1; |
5485 else | |
5486 *denote = TRUE; | |
56 | 5487 return n; |
7 | 5488 } |
5489 | |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5490 #ifdef FEAT_FLOAT |
9571
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9562
diff
changeset
|
5491 float_T |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5492 tv_get_float(typval_T *varp) |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5493 { |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5494 switch (varp->v_type) |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5495 { |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5496 case VAR_NUMBER: |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5497 return (float_T)(varp->vval.v_number); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5498 case VAR_FLOAT: |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5499 return varp->vval.v_float; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5500 case VAR_FUNC: |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5501 case VAR_PARTIAL: |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5502 emsg(_("E891: Using a Funcref as a Float")); |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5503 break; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5504 case VAR_STRING: |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5505 emsg(_("E892: Using a String as a Float")); |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5506 break; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5507 case VAR_LIST: |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5508 emsg(_("E893: Using a List as a Float")); |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5509 break; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5510 case VAR_DICT: |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5511 emsg(_("E894: Using a Dictionary as a Float")); |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5512 break; |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
5513 case VAR_SPECIAL: |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5514 emsg(_("E907: Using a special value as a Float")); |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
5515 break; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5516 case VAR_JOB: |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5517 # ifdef FEAT_JOB_CHANNEL |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5518 emsg(_("E911: Using a Job as a Float")); |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5519 break; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5520 # endif |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5521 case VAR_CHANNEL: |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5522 # ifdef FEAT_JOB_CHANNEL |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5523 emsg(_("E914: Using a Channel as a Float")); |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5524 break; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5525 # endif |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5526 case VAR_BLOB: |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5527 emsg(_("E975: Using a Blob as a Float")); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5528 break; |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
5529 case VAR_UNKNOWN: |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5530 internal_error("tv_get_float(UNKNOWN)"); |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5531 break; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5532 } |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5533 return 0; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5534 } |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5535 #endif |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7683
diff
changeset
|
5536 |
7 | 5537 /* |
5538 * Get the string value of a variable. | |
5539 * If it is a Number variable, the number is converted into a string. | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5540 * tv_get_string() uses a single, static buffer. YOU CAN ONLY USE IT ONCE! |
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5541 * tv_get_string_buf() uses a given buffer. |
7 | 5542 * If the String variable has never been set, return an empty string. |
5543 * Never returns NULL; | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5544 * tv_get_string_chk() and tv_get_string_buf_chk() are similar, but return |
323 | 5545 * NULL on error. |
7 | 5546 */ |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5547 char_u * |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5548 tv_get_string(typval_T *varp) |
7 | 5549 { |
5550 static char_u mybuf[NUMBUFLEN]; | |
5551 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5552 return tv_get_string_buf(varp, mybuf); |
7 | 5553 } |
5554 | |
8498
42277980a76d
commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5555 char_u * |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5556 tv_get_string_buf(typval_T *varp, char_u *buf) |
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5557 { |
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5558 char_u *res = tv_get_string_buf_chk(varp, buf); |
323 | 5559 |
5560 return res != NULL ? res : (char_u *)""; | |
5561 } | |
5562 | |
5810 | 5563 /* |
5564 * Careful: This uses a single, static buffer. YOU CAN ONLY USE IT ONCE! | |
5565 */ | |
449 | 5566 char_u * |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5567 tv_get_string_chk(typval_T *varp) |
323 | 5568 { |
5569 static char_u mybuf[NUMBUFLEN]; | |
5570 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5571 return tv_get_string_buf_chk(varp, mybuf); |
323 | 5572 } |
5573 | |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
5574 char_u * |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
5575 tv_get_string_buf_chk(typval_T *varp, char_u *buf) |
323 | 5576 { |
56 | 5577 switch (varp->v_type) |
5578 { | |
5579 case VAR_NUMBER: | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
5580 vim_snprintf((char *)buf, NUMBUFLEN, "%lld", |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15515
diff
changeset
|
5581 (long_long_T)varp->vval.v_number); |
56 | 5582 return buf; |
5583 case VAR_FUNC: | |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5584 case VAR_PARTIAL: |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5585 emsg(_("E729: using Funcref as a String")); |
56 | 5586 break; |
5587 case VAR_LIST: | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5588 emsg(_("E730: using List as a String")); |
100 | 5589 break; |
5590 case VAR_DICT: | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5591 emsg(_("E731: using Dictionary as a String")); |
56 | 5592 break; |
1624 | 5593 case VAR_FLOAT: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5594 #ifdef FEAT_FLOAT |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5595 emsg(_(e_float_as_string)); |
1624 | 5596 break; |
5597 #endif | |
56 | 5598 case VAR_STRING: |
5599 if (varp->vval.v_string != NULL) | |
5600 return varp->vval.v_string; | |
323 | 5601 return (char_u *)""; |
7730
80ce794827c4
commit https://github.com/vim/vim/commit/17a13437c9414a8693369a97f3be2fc8ad48c12e
Christian Brabandt <cb@256bit.org>
parents:
7720
diff
changeset
|
5602 case VAR_SPECIAL: |
80ce794827c4
commit https://github.com/vim/vim/commit/17a13437c9414a8693369a97f3be2fc8ad48c12e
Christian Brabandt <cb@256bit.org>
parents:
7720
diff
changeset
|
5603 STRCPY(buf, get_var_special_name(varp->vval.v_number)); |
80ce794827c4
commit https://github.com/vim/vim/commit/17a13437c9414a8693369a97f3be2fc8ad48c12e
Christian Brabandt <cb@256bit.org>
parents:
7720
diff
changeset
|
5604 return buf; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5605 case VAR_BLOB: |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5606 emsg(_("E976: using Blob as a String")); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5607 break; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5608 case VAR_JOB: |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5609 #ifdef FEAT_JOB_CHANNEL |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5610 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5611 job_T *job = varp->vval.v_job; |
8424
be45d4921f1f
commit https://github.com/vim/vim/commit/839fd11d7ed1a96bace3159c4d1861658864aae3
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5612 char *status; |
be45d4921f1f
commit https://github.com/vim/vim/commit/839fd11d7ed1a96bace3159c4d1861658864aae3
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5613 |
be45d4921f1f
commit https://github.com/vim/vim/commit/839fd11d7ed1a96bace3159c4d1861658864aae3
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5614 if (job == NULL) |
be45d4921f1f
commit https://github.com/vim/vim/commit/839fd11d7ed1a96bace3159c4d1861658864aae3
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5615 return (char_u *)"no process"; |
be45d4921f1f
commit https://github.com/vim/vim/commit/839fd11d7ed1a96bace3159c4d1861658864aae3
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5616 status = job->jv_status == JOB_FAILED ? "fail" |
10386
d3f0946b4a80
commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents:
10381
diff
changeset
|
5617 : job->jv_status >= JOB_ENDED ? "dead" |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5618 : "run"; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5619 # ifdef UNIX |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5620 vim_snprintf((char *)buf, NUMBUFLEN, |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5621 "process %ld %s", (long)job->jv_pid, status); |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15790
diff
changeset
|
5622 # elif defined(MSWIN) |
8001
e5dbeb923ce6
commit https://github.com/vim/vim/commit/4d8747cdfc13843a5680dc8340fbeb6d32e7b626
Christian Brabandt <cb@256bit.org>
parents:
7995
diff
changeset
|
5623 vim_snprintf((char *)buf, NUMBUFLEN, |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8019
diff
changeset
|
5624 "process %ld %s", |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8019
diff
changeset
|
5625 (long)job->jv_proc_info.dwProcessId, |
8001
e5dbeb923ce6
commit https://github.com/vim/vim/commit/4d8747cdfc13843a5680dc8340fbeb6d32e7b626
Christian Brabandt <cb@256bit.org>
parents:
7995
diff
changeset
|
5626 status); |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5627 # else |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5628 // fall-back |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5629 vim_snprintf((char *)buf, NUMBUFLEN, "process ? %s", status); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5630 # endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5631 return buf; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5632 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5633 #endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5634 break; |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5635 case VAR_CHANNEL: |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5636 #ifdef FEAT_JOB_CHANNEL |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5637 { |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5638 channel_T *channel = varp->vval.v_channel; |
10235
ad6851687158
commit https://github.com/vim/vim/commit/0e77b7691ee7c477facb4c9d9162c8603ada2d84
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5639 char *status = channel_status(channel, -1); |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5640 |
8070
e4c3f6720b03
commit https://github.com/vim/vim/commit/5cefd4098204b4677387511b586673649f2fab48
Christian Brabandt <cb@256bit.org>
parents:
8062
diff
changeset
|
5641 if (channel == NULL) |
e4c3f6720b03
commit https://github.com/vim/vim/commit/5cefd4098204b4677387511b586673649f2fab48
Christian Brabandt <cb@256bit.org>
parents:
8062
diff
changeset
|
5642 vim_snprintf((char *)buf, NUMBUFLEN, "channel %s", status); |
e4c3f6720b03
commit https://github.com/vim/vim/commit/5cefd4098204b4677387511b586673649f2fab48
Christian Brabandt <cb@256bit.org>
parents:
8062
diff
changeset
|
5643 else |
e4c3f6720b03
commit https://github.com/vim/vim/commit/5cefd4098204b4677387511b586673649f2fab48
Christian Brabandt <cb@256bit.org>
parents:
8062
diff
changeset
|
5644 vim_snprintf((char *)buf, NUMBUFLEN, |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5645 "channel %d %s", channel->ch_id, status); |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5646 return buf; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5647 } |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5648 #endif |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5649 break; |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
5650 case VAR_UNKNOWN: |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5651 emsg(_("E908: using an invalid value as a String")); |
56 | 5652 break; |
5653 } | |
323 | 5654 return NULL; |
7 | 5655 } |
5656 | |
5657 /* | |
15219
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5658 * Turn a typeval into a string. Similar to tv_get_string_buf() but uses |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5659 * string() on Dict, List, etc. |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5660 */ |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
5661 static char_u * |
15219
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5662 tv_stringify(typval_T *varp, char_u *buf) |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5663 { |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5664 if (varp->v_type == VAR_LIST |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5665 || varp->v_type == VAR_DICT |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5666 || varp->v_type == VAR_FUNC |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5667 || varp->v_type == VAR_PARTIAL |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5668 || varp->v_type == VAR_FLOAT) |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5669 { |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5670 typval_T tmp; |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5671 |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5672 f_string(varp, &tmp); |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5673 tv_get_string_buf(&tmp, buf); |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5674 clear_tv(varp); |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5675 *varp = tmp; |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5676 return tmp.vval.v_string; |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5677 } |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5678 return tv_get_string_buf(varp, buf); |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5679 } |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5680 |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5681 /* |
15780
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5682 * Return TRUE if typeval "tv" and its value are set to be locked (immutable). |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5683 * Also give an error message, using "name" or _("name") when use_gettext is |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5684 * TRUE. |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5685 */ |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5686 static int |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5687 tv_check_lock(typval_T *tv, char_u *name, int use_gettext) |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5688 { |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5689 int lock = 0; |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5690 |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5691 switch (tv->v_type) |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5692 { |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5693 case VAR_BLOB: |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5694 if (tv->vval.v_blob != NULL) |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5695 lock = tv->vval.v_blob->bv_lock; |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5696 break; |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5697 case VAR_LIST: |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5698 if (tv->vval.v_list != NULL) |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5699 lock = tv->vval.v_list->lv_lock; |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5700 break; |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5701 case VAR_DICT: |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5702 if (tv->vval.v_dict != NULL) |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5703 lock = tv->vval.v_dict->dv_lock; |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5704 break; |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5705 default: |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5706 break; |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5707 } |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5708 return var_check_lock(tv->v_lock, name, use_gettext) |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5709 || (lock != 0 && var_check_lock(lock, name, use_gettext)); |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5710 } |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5711 |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15770
diff
changeset
|
5712 /* |
137 | 5713 * Copy the values from typval_T "from" to typval_T "to". |
56 | 5714 * When needed allocates string or increases reference count. |
15581
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5715 * Does not make a copy of a list, blob or dict but copies the reference! |
1772 | 5716 * It is OK for "from" and "to" to point to the same item. This is used to |
5717 * make a copy later. | |
56 | 5718 */ |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2045
diff
changeset
|
5719 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5720 copy_tv(typval_T *from, typval_T *to) |
56 | 5721 { |
5722 to->v_type = from->v_type; | |
151 | 5723 to->v_lock = 0; |
56 | 5724 switch (from->v_type) |
5725 { | |
5726 case VAR_NUMBER: | |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
5727 case VAR_SPECIAL: |
56 | 5728 to->vval.v_number = from->vval.v_number; |
5729 break; | |
1624 | 5730 case VAR_FLOAT: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5731 #ifdef FEAT_FLOAT |
1624 | 5732 to->vval.v_float = from->vval.v_float; |
5733 break; | |
5734 #endif | |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5735 case VAR_JOB: |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5736 #ifdef FEAT_JOB_CHANNEL |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5737 to->vval.v_job = from->vval.v_job; |
8174
f2286ff0c102
commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents:
8170
diff
changeset
|
5738 if (to->vval.v_job != NULL) |
f2286ff0c102
commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents:
8170
diff
changeset
|
5739 ++to->vval.v_job->jv_refcount; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5740 break; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5741 #endif |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5742 case VAR_CHANNEL: |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5743 #ifdef FEAT_JOB_CHANNEL |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5744 to->vval.v_channel = from->vval.v_channel; |
8070
e4c3f6720b03
commit https://github.com/vim/vim/commit/5cefd4098204b4677387511b586673649f2fab48
Christian Brabandt <cb@256bit.org>
parents:
8062
diff
changeset
|
5745 if (to->vval.v_channel != NULL) |
e4c3f6720b03
commit https://github.com/vim/vim/commit/5cefd4098204b4677387511b586673649f2fab48
Christian Brabandt <cb@256bit.org>
parents:
8062
diff
changeset
|
5746 ++to->vval.v_channel->ch_refcount; |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5747 break; |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5748 #endif |
56 | 5749 case VAR_STRING: |
5750 case VAR_FUNC: | |
5751 if (from->vval.v_string == NULL) | |
5752 to->vval.v_string = NULL; | |
5753 else | |
117 | 5754 { |
56 | 5755 to->vval.v_string = vim_strsave(from->vval.v_string); |
117 | 5756 if (from->v_type == VAR_FUNC) |
5757 func_ref(to->vval.v_string); | |
5758 } | |
56 | 5759 break; |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5760 case VAR_PARTIAL: |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5761 if (from->vval.v_partial == NULL) |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5762 to->vval.v_partial = NULL; |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5763 else |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5764 { |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5765 to->vval.v_partial = from->vval.v_partial; |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5766 ++to->vval.v_partial->pt_refcount; |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5767 } |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5768 break; |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5769 case VAR_BLOB: |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5770 if (from->vval.v_blob == NULL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5771 to->vval.v_blob = NULL; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5772 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5773 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5774 to->vval.v_blob = from->vval.v_blob; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5775 ++to->vval.v_blob->bv_refcount; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5776 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5777 break; |
56 | 5778 case VAR_LIST: |
5779 if (from->vval.v_list == NULL) | |
5780 to->vval.v_list = NULL; | |
5781 else | |
5782 { | |
5783 to->vval.v_list = from->vval.v_list; | |
5784 ++to->vval.v_list->lv_refcount; | |
5785 } | |
5786 break; | |
100 | 5787 case VAR_DICT: |
5788 if (from->vval.v_dict == NULL) | |
5789 to->vval.v_dict = NULL; | |
5790 else | |
5791 { | |
5792 to->vval.v_dict = from->vval.v_dict; | |
5793 ++to->vval.v_dict->dv_refcount; | |
5794 } | |
5795 break; | |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
5796 case VAR_UNKNOWN: |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10259
diff
changeset
|
5797 internal_error("copy_tv(UNKNOWN)"); |
56 | 5798 break; |
5799 } | |
7 | 5800 } |
5801 | |
5802 /* | |
104 | 5803 * Make a copy of an item. |
5804 * Lists and Dictionaries are also copied. A deep copy if "deep" is set. | |
165 | 5805 * For deepcopy() "copyID" is zero for a full copy or the ID for when a |
5806 * reference to an already copied list/dict can be used. | |
5807 * Returns FAIL or OK. | |
5808 */ | |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
9527
diff
changeset
|
5809 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5810 item_copy( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5811 typval_T *from, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5812 typval_T *to, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5813 int deep, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5814 int copyID) |
104 | 5815 { |
5816 static int recurse = 0; | |
165 | 5817 int ret = OK; |
104 | 5818 |
137 | 5819 if (recurse >= DICT_MAXNEST) |
104 | 5820 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5821 emsg(_("E698: variable nested too deep for making a copy")); |
165 | 5822 return FAIL; |
104 | 5823 } |
5824 ++recurse; | |
5825 | |
5826 switch (from->v_type) | |
5827 { | |
5828 case VAR_NUMBER: | |
1624 | 5829 case VAR_FLOAT: |
104 | 5830 case VAR_STRING: |
5831 case VAR_FUNC: | |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8536
diff
changeset
|
5832 case VAR_PARTIAL: |
7862
d4fec9208e7e
commit https://github.com/vim/vim/commit/155500077c80cdb5d9c63996000c011b66a676bf
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5833 case VAR_SPECIAL: |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7955
diff
changeset
|
5834 case VAR_JOB: |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
8031
diff
changeset
|
5835 case VAR_CHANNEL: |
104 | 5836 copy_tv(from, to); |
5837 break; | |
5838 case VAR_LIST: | |
5839 to->v_type = VAR_LIST; | |
151 | 5840 to->v_lock = 0; |
165 | 5841 if (from->vval.v_list == NULL) |
5842 to->vval.v_list = NULL; | |
5843 else if (copyID != 0 && from->vval.v_list->lv_copyID == copyID) | |
5844 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5845 // use the copy made earlier |
165 | 5846 to->vval.v_list = from->vval.v_list->lv_copylist; |
5847 ++to->vval.v_list->lv_refcount; | |
5848 } | |
5849 else | |
5850 to->vval.v_list = list_copy(from->vval.v_list, deep, copyID); | |
5851 if (to->vval.v_list == NULL) | |
5852 ret = FAIL; | |
104 | 5853 break; |
15496
f1c33409e908
patch 8.1.0756: copy() does not make a copy of a Blob
Bram Moolenaar <Bram@vim.org>
parents:
15490
diff
changeset
|
5854 case VAR_BLOB: |
15581
c2382f0d1279
patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5855 ret = blob_copy(from, to); |
15496
f1c33409e908
patch 8.1.0756: copy() does not make a copy of a Blob
Bram Moolenaar <Bram@vim.org>
parents:
15490
diff
changeset
|
5856 break; |
104 | 5857 case VAR_DICT: |
5858 to->v_type = VAR_DICT; | |
151 | 5859 to->v_lock = 0; |
165 | 5860 if (from->vval.v_dict == NULL) |
5861 to->vval.v_dict = NULL; | |
5862 else if (copyID != 0 && from->vval.v_dict->dv_copyID == copyID) | |
5863 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5864 // use the copy made earlier |
165 | 5865 to->vval.v_dict = from->vval.v_dict->dv_copydict; |
5866 ++to->vval.v_dict->dv_refcount; | |
5867 } | |
5868 else | |
5869 to->vval.v_dict = dict_copy(from->vval.v_dict, deep, copyID); | |
5870 if (to->vval.v_dict == NULL) | |
5871 ret = FAIL; | |
104 | 5872 break; |
7943
e875f0fbd9c0
commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents:
7937
diff
changeset
|
5873 case VAR_UNKNOWN: |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10259
diff
changeset
|
5874 internal_error("item_copy(UNKNOWN)"); |
165 | 5875 ret = FAIL; |
104 | 5876 } |
5877 --recurse; | |
165 | 5878 return ret; |
104 | 5879 } |
5880 | |
5881 /* | |
7 | 5882 * ":echo expr1 ..." print each argument separated with a space, add a |
5883 * newline at the end. | |
5884 * ":echon expr1 ..." print each argument plain. | |
5885 */ | |
5886 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5887 ex_echo(exarg_T *eap) |
7 | 5888 { |
5889 char_u *arg = eap->arg; | |
137 | 5890 typval_T rettv; |
56 | 5891 char_u *tofree; |
7 | 5892 char_u *p; |
5893 int needclr = TRUE; | |
5894 int atstart = TRUE; | |
80 | 5895 char_u numbuf[NUMBUFLEN]; |
15079
a527110d5f56
patch 8.1.0550: expression evaluation may repeat an error message
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
5896 int did_emsg_before = did_emsg; |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
5897 int called_emsg_before = called_emsg; |
7 | 5898 |
5899 if (eap->skip) | |
5900 ++emsg_skip; | |
5901 while (*arg != NUL && *arg != '|' && *arg != '\n' && !got_int) | |
5902 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5903 // If eval1() causes an error message the text from the command may |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5904 // still need to be cleared. E.g., "echo 22,44". |
1624 | 5905 need_clr_eos = needclr; |
5906 | |
7 | 5907 p = arg; |
71 | 5908 if (eval1(&arg, &rettv, !eap->skip) == FAIL) |
7 | 5909 { |
5910 /* | |
5911 * Report the invalid expression unless the expression evaluation | |
5912 * has been cancelled due to an aborting error, an interrupt, or an | |
5913 * exception. | |
5914 */ | |
15456
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
5915 if (!aborting() && did_emsg == did_emsg_before |
f01eb1aed348
patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
5916 && called_emsg == called_emsg_before) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
5917 semsg(_(e_invexpr2), p); |
1624 | 5918 need_clr_eos = FALSE; |
5919 break; | |
5920 } | |
5921 need_clr_eos = FALSE; | |
5922 | |
7 | 5923 if (!eap->skip) |
5924 { | |
5925 if (atstart) | |
5926 { | |
5927 atstart = FALSE; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5928 // Call msg_start() after eval1(), evaluating the expression |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5929 // may cause a message to appear. |
7 | 5930 if (eap->cmdidx == CMD_echo) |
3423 | 5931 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5932 // Mark the saved text as finishing the line, so that what |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5933 // follows is displayed on a new line when scrolling back |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5934 // at the more prompt. |
3435 | 5935 msg_sb_eol(); |
7 | 5936 msg_start(); |
3423 | 5937 } |
7 | 5938 } |
5939 else if (eap->cmdidx == CMD_echo) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
5940 msg_puts_attr(" ", echo_attr); |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7705
diff
changeset
|
5941 p = echo_string(&rettv, &tofree, numbuf, get_copyID()); |
165 | 5942 if (p != NULL) |
5943 for ( ; *p != NUL && !got_int; ++p) | |
5944 { | |
5945 if (*p == '\n' || *p == '\r' || *p == TAB) | |
7 | 5946 { |
165 | 5947 if (*p != TAB && needclr) |
5948 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5949 // remove any text still there from the command |
165 | 5950 msg_clr_eos(); |
5951 needclr = FALSE; | |
5952 } | |
5953 msg_putchar_attr(*p, echo_attr); | |
7 | 5954 } |
5955 else | |
165 | 5956 { |
5957 if (has_mbyte) | |
5958 { | |
474 | 5959 int i = (*mb_ptr2len)(p); |
165 | 5960 |
5961 (void)msg_outtrans_len_attr(p, i, echo_attr); | |
5962 p += i - 1; | |
5963 } | |
5964 else | |
5965 (void)msg_outtrans_len_attr(p, 1, echo_attr); | |
5966 } | |
7 | 5967 } |
56 | 5968 vim_free(tofree); |
5969 } | |
71 | 5970 clear_tv(&rettv); |
7 | 5971 arg = skipwhite(arg); |
5972 } | |
5973 eap->nextcmd = check_nextcmd(arg); | |
5974 | |
5975 if (eap->skip) | |
5976 --emsg_skip; | |
5977 else | |
5978 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
5979 // remove text that may still be there from the command |
7 | 5980 if (needclr) |
5981 msg_clr_eos(); | |
5982 if (eap->cmdidx == CMD_echo) | |
5983 msg_end(); | |
5984 } | |
5985 } | |
5986 | |
5987 /* | |
5988 * ":echohl {name}". | |
5989 */ | |
5990 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
5991 ex_echohl(exarg_T *eap) |
7 | 5992 { |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
5993 echo_attr = syn_name2attr(eap->arg); |
7 | 5994 } |
5995 | |
5996 /* | |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
5997 * Returns the :echo attribute |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
5998 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
5999 int |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
6000 get_echo_attr(void) |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
6001 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
6002 return echo_attr; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
6003 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
6004 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
6005 /* |
7 | 6006 * ":execute expr1 ..." execute the result of an expression. |
6007 * ":echomsg expr1 ..." Print a message | |
6008 * ":echoerr expr1 ..." Print an error | |
6009 * Each gets spaces around each argument and a newline at the end for | |
6010 * echo commands | |
6011 */ | |
6012 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
6013 ex_execute(exarg_T *eap) |
7 | 6014 { |
6015 char_u *arg = eap->arg; | |
137 | 6016 typval_T rettv; |
7 | 6017 int ret = OK; |
6018 char_u *p; | |
6019 garray_T ga; | |
6020 int len; | |
16054
78faa25f9698
patch 8.1.1032: warnings from clang static analyzer
Bram Moolenaar <Bram@vim.org>
parents:
16036
diff
changeset
|
6021 int save_did_emsg; |
7 | 6022 |
6023 ga_init2(&ga, 1, 80); | |
6024 | |
6025 if (eap->skip) | |
6026 ++emsg_skip; | |
6027 while (*arg != NUL && *arg != '|' && *arg != '\n') | |
6028 { | |
15478
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6029 ret = eval1_emsg(&arg, &rettv, !eap->skip); |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6030 if (ret == FAIL) |
7 | 6031 break; |
6032 | |
6033 if (!eap->skip) | |
6034 { | |
15219
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
6035 char_u buf[NUMBUFLEN]; |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
6036 |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
6037 if (eap->cmdidx == CMD_execute) |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
6038 p = tv_get_string_buf(&rettv, buf); |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
6039 else |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
6040 p = tv_stringify(&rettv, buf); |
7 | 6041 len = (int)STRLEN(p); |
6042 if (ga_grow(&ga, len + 2) == FAIL) | |
6043 { | |
71 | 6044 clear_tv(&rettv); |
7 | 6045 ret = FAIL; |
6046 break; | |
6047 } | |
6048 if (ga.ga_len) | |
6049 ((char_u *)(ga.ga_data))[ga.ga_len++] = ' '; | |
6050 STRCPY((char_u *)(ga.ga_data) + ga.ga_len, p); | |
6051 ga.ga_len += len; | |
6052 } | |
6053 | |
71 | 6054 clear_tv(&rettv); |
7 | 6055 arg = skipwhite(arg); |
6056 } | |
6057 | |
6058 if (ret != FAIL && ga.ga_data != NULL) | |
6059 { | |
11161
404e98047f0b
patch 8.0.0467: using g< after :for does not show the right output
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
6060 if (eap->cmdidx == CMD_echomsg || eap->cmdidx == CMD_echoerr) |
404e98047f0b
patch 8.0.0467: using g< after :for does not show the right output
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
6061 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6062 // Mark the already saved text as finishing the line, so that what |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6063 // follows is displayed on a new line when scrolling back at the |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6064 // more prompt. |
11161
404e98047f0b
patch 8.0.0467: using g< after :for does not show the right output
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
6065 msg_sb_eol(); |
404e98047f0b
patch 8.0.0467: using g< after :for does not show the right output
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
6066 } |
404e98047f0b
patch 8.0.0467: using g< after :for does not show the right output
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
6067 |
7 | 6068 if (eap->cmdidx == CMD_echomsg) |
625 | 6069 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
6070 msg_attr(ga.ga_data, echo_attr); |
625 | 6071 out_flush(); |
6072 } | |
7 | 6073 else if (eap->cmdidx == CMD_echoerr) |
6074 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6075 // We don't want to abort following commands, restore did_emsg. |
7 | 6076 save_did_emsg = did_emsg; |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
6077 emsg(ga.ga_data); |
7 | 6078 if (!force_abort) |
6079 did_emsg = save_did_emsg; | |
6080 } | |
6081 else if (eap->cmdidx == CMD_execute) | |
6082 do_cmdline((char_u *)ga.ga_data, | |
6083 eap->getline, eap->cookie, DOCMD_NOWAIT|DOCMD_VERBOSE); | |
6084 } | |
6085 | |
6086 ga_clear(&ga); | |
6087 | |
6088 if (eap->skip) | |
6089 --emsg_skip; | |
6090 | |
6091 eap->nextcmd = check_nextcmd(arg); | |
6092 } | |
6093 | |
6094 /* | |
6095 * Skip over the name of an option: "&option", "&g:option" or "&l:option". | |
6096 * "arg" points to the "&" or '+' when called, to "option" when returning. | |
6097 * Returns NULL when no option name found. Otherwise pointer to the char | |
6098 * after the option name. | |
6099 */ | |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17833
diff
changeset
|
6100 char_u * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
6101 find_option_end(char_u **arg, int *opt_flags) |
7 | 6102 { |
6103 char_u *p = *arg; | |
6104 | |
6105 ++p; | |
6106 if (*p == 'g' && p[1] == ':') | |
6107 { | |
6108 *opt_flags = OPT_GLOBAL; | |
6109 p += 2; | |
6110 } | |
6111 else if (*p == 'l' && p[1] == ':') | |
6112 { | |
6113 *opt_flags = OPT_LOCAL; | |
6114 p += 2; | |
6115 } | |
6116 else | |
6117 *opt_flags = 0; | |
6118 | |
6119 if (!ASCII_ISALPHA(*p)) | |
6120 return NULL; | |
6121 *arg = p; | |
6122 | |
6123 if (p[0] == 't' && p[1] == '_' && p[2] != NUL && p[3] != NUL) | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6124 p += 4; // termcap option |
7 | 6125 else |
6126 while (ASCII_ISALPHA(*p)) | |
6127 ++p; | |
6128 return p; | |
6129 } | |
6130 | |
6131 /* | |
448 | 6132 * Display script name where an item was last set. |
6133 * Should only be invoked when 'verbose' is non-zero. | |
6134 */ | |
6135 void | |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
6136 last_set_msg(sctx_T script_ctx) |
448 | 6137 { |
507 | 6138 char_u *p; |
6139 | |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
6140 if (script_ctx.sc_sid != 0) |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
6141 { |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
6142 p = home_replace_save(NULL, get_scriptname(script_ctx.sc_sid)); |
507 | 6143 if (p != NULL) |
6144 { | |
6145 verbose_enter(); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
6146 msg_puts(_("\n\tLast set from ")); |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
6147 msg_puts((char *)p); |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
6148 if (script_ctx.sc_lnum > 0) |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
6149 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
6150 msg_puts(_(" line ")); |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
6151 msg_outnum((long)script_ctx.sc_lnum); |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
6152 } |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
6153 verbose_leave(); |
507 | 6154 vim_free(p); |
6155 } | |
448 | 6156 } |
6157 } | |
6158 | |
16036
89fb86821b4a
patch 8.1.1023: may use NULL pointer when indexing a blob
Bram Moolenaar <Bram@vim.org>
parents:
16013
diff
changeset
|
6159 /* |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6160 * Compare "typ1" and "typ2". Put the result in "typ1". |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6161 */ |
13262
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6162 int |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6163 typval_compare( |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6164 typval_T *typ1, // first operand |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6165 typval_T *typ2, // second operand |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6166 exptype_T type, // operator |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6167 int type_is, // TRUE for "is" and "isnot" |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6168 int ic) // ignore case |
13262
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6169 { |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6170 int i; |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6171 varnumber_T n1, n2; |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6172 char_u *s1, *s2; |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6173 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN]; |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6174 |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6175 if (type_is && typ1->v_type != typ2->v_type) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6176 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6177 // For "is" a different type always means FALSE, for "notis" |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6178 // it means TRUE. |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6179 n1 = (type == TYPE_NEQUAL); |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6180 } |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6181 else if (typ1->v_type == VAR_BLOB || typ2->v_type == VAR_BLOB) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6182 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6183 if (type_is) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6184 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6185 n1 = (typ1->v_type == typ2->v_type |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6186 && typ1->vval.v_blob == typ2->vval.v_blob); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6187 if (type == TYPE_NEQUAL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6188 n1 = !n1; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6189 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6190 else if (typ1->v_type != typ2->v_type |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6191 || (type != TYPE_EQUAL && type != TYPE_NEQUAL)) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6192 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6193 if (typ1->v_type != typ2->v_type) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
6194 emsg(_("E977: Can only compare Blob with Blob")); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6195 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
6196 emsg(_(e_invalblob)); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6197 clear_tv(typ1); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6198 return FAIL; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6199 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6200 else |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6201 { |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6202 // Compare two Blobs for being equal or unequal. |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6203 n1 = blob_equal(typ1->vval.v_blob, typ2->vval.v_blob); |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6204 if (type == TYPE_NEQUAL) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6205 n1 = !n1; |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6206 } |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
6207 } |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6208 else if (typ1->v_type == VAR_LIST || typ2->v_type == VAR_LIST) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6209 { |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6210 if (type_is) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6211 { |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6212 n1 = (typ1->v_type == typ2->v_type |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6213 && typ1->vval.v_list == typ2->vval.v_list); |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6214 if (type == TYPE_NEQUAL) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6215 n1 = !n1; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6216 } |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6217 else if (typ1->v_type != typ2->v_type |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6218 || (type != TYPE_EQUAL && type != TYPE_NEQUAL)) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6219 { |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6220 if (typ1->v_type != typ2->v_type) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
6221 emsg(_("E691: Can only compare List with List")); |
13262
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6222 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
6223 emsg(_("E692: Invalid operation for List")); |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6224 clear_tv(typ1); |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6225 return FAIL; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6226 } |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6227 else |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6228 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6229 // Compare two Lists for being equal or unequal. |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6230 n1 = list_equal(typ1->vval.v_list, typ2->vval.v_list, |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6231 ic, FALSE); |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6232 if (type == TYPE_NEQUAL) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6233 n1 = !n1; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6234 } |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6235 } |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6236 |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6237 else if (typ1->v_type == VAR_DICT || typ2->v_type == VAR_DICT) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6238 { |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6239 if (type_is) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6240 { |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6241 n1 = (typ1->v_type == typ2->v_type |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6242 && typ1->vval.v_dict == typ2->vval.v_dict); |
13262
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6243 if (type == TYPE_NEQUAL) |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6244 n1 = !n1; |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6245 } |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6246 else if (typ1->v_type != typ2->v_type |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6247 || (type != TYPE_EQUAL && type != TYPE_NEQUAL)) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6248 { |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6249 if (typ1->v_type != typ2->v_type) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
6250 emsg(_("E735: Can only compare Dictionary with Dictionary")); |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6251 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
6252 emsg(_("E736: Invalid operation for Dictionary")); |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6253 clear_tv(typ1); |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6254 return FAIL; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6255 } |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6256 else |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6257 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6258 // Compare two Dictionaries for being equal or unequal. |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6259 n1 = dict_equal(typ1->vval.v_dict, typ2->vval.v_dict, |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6260 ic, FALSE); |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6261 if (type == TYPE_NEQUAL) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6262 n1 = !n1; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6263 } |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6264 } |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6265 |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6266 else if (typ1->v_type == VAR_FUNC || typ2->v_type == VAR_FUNC |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6267 || typ1->v_type == VAR_PARTIAL || typ2->v_type == VAR_PARTIAL) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6268 { |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6269 if (type != TYPE_EQUAL && type != TYPE_NEQUAL) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6270 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15466
diff
changeset
|
6271 emsg(_("E694: Invalid operation for Funcrefs")); |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6272 clear_tv(typ1); |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6273 return FAIL; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6274 } |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6275 if ((typ1->v_type == VAR_PARTIAL |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6276 && typ1->vval.v_partial == NULL) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6277 || (typ2->v_type == VAR_PARTIAL |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6278 && typ2->vval.v_partial == NULL)) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6279 // when a partial is NULL assume not equal |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6280 n1 = FALSE; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6281 else if (type_is) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6282 { |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6283 if (typ1->v_type == VAR_FUNC && typ2->v_type == VAR_FUNC) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6284 // strings are considered the same if their value is |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6285 // the same |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6286 n1 = tv_equal(typ1, typ2, ic, FALSE); |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6287 else if (typ1->v_type == VAR_PARTIAL |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6288 && typ2->v_type == VAR_PARTIAL) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6289 n1 = (typ1->vval.v_partial == typ2->vval.v_partial); |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6290 else |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6291 n1 = FALSE; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6292 } |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6293 else |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6294 n1 = tv_equal(typ1, typ2, ic, FALSE); |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6295 if (type == TYPE_NEQUAL) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6296 n1 = !n1; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6297 } |
13262
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6298 |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6299 #ifdef FEAT_FLOAT |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6300 /* |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6301 * If one of the two variables is a float, compare as a float. |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6302 * When using "=~" or "!~", always compare as string. |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6303 */ |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6304 else if ((typ1->v_type == VAR_FLOAT || typ2->v_type == VAR_FLOAT) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6305 && type != TYPE_MATCH && type != TYPE_NOMATCH) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6306 { |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6307 float_T f1, f2; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6308 |
15904
fec4416adb80
patch 8.1.0958: compiling weird regexp pattern is very slow
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
6309 f1 = tv_get_float(typ1); |
fec4416adb80
patch 8.1.0958: compiling weird regexp pattern is very slow
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
6310 f2 = tv_get_float(typ2); |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6311 n1 = FALSE; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6312 switch (type) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6313 { |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6314 case TYPE_EQUAL: n1 = (f1 == f2); break; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6315 case TYPE_NEQUAL: n1 = (f1 != f2); break; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6316 case TYPE_GREATER: n1 = (f1 > f2); break; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6317 case TYPE_GEQUAL: n1 = (f1 >= f2); break; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6318 case TYPE_SMALLER: n1 = (f1 < f2); break; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6319 case TYPE_SEQUAL: n1 = (f1 <= f2); break; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6320 case TYPE_UNKNOWN: |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6321 case TYPE_MATCH: |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6322 case TYPE_NOMATCH: break; // avoid gcc warning |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6323 } |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6324 } |
13262
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6325 #endif |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6326 |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6327 /* |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6328 * If one of the two variables is a number, compare as a number. |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6329 * When using "=~" or "!~", always compare as string. |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6330 */ |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6331 else if ((typ1->v_type == VAR_NUMBER || typ2->v_type == VAR_NUMBER) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6332 && type != TYPE_MATCH && type != TYPE_NOMATCH) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6333 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
6334 n1 = tv_get_number(typ1); |
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
6335 n2 = tv_get_number(typ2); |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6336 switch (type) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6337 { |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6338 case TYPE_EQUAL: n1 = (n1 == n2); break; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6339 case TYPE_NEQUAL: n1 = (n1 != n2); break; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6340 case TYPE_GREATER: n1 = (n1 > n2); break; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6341 case TYPE_GEQUAL: n1 = (n1 >= n2); break; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6342 case TYPE_SMALLER: n1 = (n1 < n2); break; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6343 case TYPE_SEQUAL: n1 = (n1 <= n2); break; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6344 case TYPE_UNKNOWN: |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6345 case TYPE_MATCH: |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6346 case TYPE_NOMATCH: break; // avoid gcc warning |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6347 } |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6348 } |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6349 else |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6350 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
6351 s1 = tv_get_string_buf(typ1, buf1); |
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
6352 s2 = tv_get_string_buf(typ2, buf2); |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6353 if (type != TYPE_MATCH && type != TYPE_NOMATCH) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6354 i = ic ? MB_STRICMP(s1, s2) : STRCMP(s1, s2); |
13262
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6355 else |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6356 i = 0; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6357 n1 = FALSE; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6358 switch (type) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6359 { |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6360 case TYPE_EQUAL: n1 = (i == 0); break; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6361 case TYPE_NEQUAL: n1 = (i != 0); break; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6362 case TYPE_GREATER: n1 = (i > 0); break; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6363 case TYPE_GEQUAL: n1 = (i >= 0); break; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6364 case TYPE_SMALLER: n1 = (i < 0); break; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6365 case TYPE_SEQUAL: n1 = (i <= 0); break; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6366 |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6367 case TYPE_MATCH: |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6368 case TYPE_NOMATCH: |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6369 n1 = pattern_match(s2, s1, ic); |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6370 if (type == TYPE_NOMATCH) |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6371 n1 = !n1; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6372 break; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6373 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6374 case TYPE_UNKNOWN: break; // avoid gcc warning |
13274
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6375 } |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6376 } |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6377 clear_tv(typ1); |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6378 typ1->v_type = VAR_NUMBER; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6379 typ1->vval.v_number = n1; |
f4b4162264b1
patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
6380 |
13262
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6381 return OK; |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6382 } |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6383 |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6384 char_u * |
14391
46f14852a919
patch 8.1.0210: still a few K&R function declarations
Christian Brabandt <cb@256bit.org>
parents:
14331
diff
changeset
|
6385 typval_tostring(typval_T *arg) |
13262
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6386 { |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6387 char_u *tofree; |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6388 char_u numbuf[NUMBUFLEN]; |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6389 char_u *ret = NULL; |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6390 |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6391 if (arg == NULL) |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6392 return vim_strsave((char_u *)"(does not exist)"); |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6393 ret = tv2string(arg, &tofree, numbuf, 0); |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6394 // Make a copy if we have a value but it's not in allocated memory. |
13262
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6395 if (ret != NULL && tofree == NULL) |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6396 ret = vim_strsave(ret); |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6397 return ret; |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6398 } |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6399 |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
6400 #endif // FEAT_EVAL |
7 | 6401 |
6402 /* | |
6403 * Perform a substitution on "str" with pattern "pat" and substitute "sub". | |
9589
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9587
diff
changeset
|
6404 * When "sub" is NULL "expr" is used, must be a VAR_FUNC or VAR_PARTIAL. |
7 | 6405 * "flags" can be "g" to do a global substitute. |
6406 * Returns an allocated string, NULL for error. | |
6407 */ | |
6408 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
6409 do_string_sub( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
6410 char_u *str, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
6411 char_u *pat, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
6412 char_u *sub, |
9589
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9587
diff
changeset
|
6413 typval_T *expr, |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7788
diff
changeset
|
6414 char_u *flags) |
7 | 6415 { |
6416 int sublen; | |
6417 regmatch_T regmatch; | |
6418 int i; | |
6419 int do_all; | |
6420 char_u *tail; | |
6332 | 6421 char_u *end; |
7 | 6422 garray_T ga; |
6423 char_u *ret; | |
6424 char_u *save_cpo; | |
5623 | 6425 char_u *zero_width = NULL; |
7 | 6426 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6427 // Make 'cpoptions' empty, so that the 'l' flag doesn't work here |
7 | 6428 save_cpo = p_cpo; |
1672 | 6429 p_cpo = empty_option; |
7 | 6430 |
6431 ga_init2(&ga, 1, 200); | |
6432 | |
6433 do_all = (flags[0] == 'g'); | |
6434 | |
6435 regmatch.rm_ic = p_ic; | |
6436 regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); | |
6437 if (regmatch.regprog != NULL) | |
6438 { | |
6439 tail = str; | |
6332 | 6440 end = str + STRLEN(str); |
7 | 6441 while (vim_regexec_nl(®match, str, (colnr_T)(tail - str))) |
6442 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6443 // Skip empty match except for first match. |
5623 | 6444 if (regmatch.startp[0] == regmatch.endp[0]) |
6445 { | |
6446 if (zero_width == regmatch.startp[0]) | |
6447 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6448 // avoid getting stuck on a match with an empty string |
18251
c8a53c0daeed
patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
6449 i = mb_ptr2len(tail); |
5964 | 6450 mch_memmove((char_u *)ga.ga_data + ga.ga_len, tail, |
6451 (size_t)i); | |
6452 ga.ga_len += i; | |
6453 tail += i; | |
5623 | 6454 continue; |
6455 } | |
6456 zero_width = regmatch.startp[0]; | |
6457 } | |
6458 | |
7 | 6459 /* |
6460 * Get some space for a temporary buffer to do the substitution | |
6461 * into. It will contain: | |
6462 * - The text up to where the match is. | |
6463 * - The substituted text. | |
6464 * - The text after the match. | |
6465 */ | |
9589
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9587
diff
changeset
|
6466 sublen = vim_regsub(®match, sub, expr, tail, FALSE, TRUE, FALSE); |
6332 | 6467 if (ga_grow(&ga, (int)((end - tail) + sublen - |
7 | 6468 (regmatch.endp[0] - regmatch.startp[0]))) == FAIL) |
6469 { | |
6470 ga_clear(&ga); | |
6471 break; | |
6472 } | |
6473 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6474 // copy the text up to where the match is |
7 | 6475 i = (int)(regmatch.startp[0] - tail); |
6476 mch_memmove((char_u *)ga.ga_data + ga.ga_len, tail, (size_t)i); | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6477 // add the substituted text |
9589
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9587
diff
changeset
|
6478 (void)vim_regsub(®match, sub, expr, (char_u *)ga.ga_data |
7 | 6479 + ga.ga_len + i, TRUE, TRUE, FALSE); |
6480 ga.ga_len += i + sublen - 1; | |
5388 | 6481 tail = regmatch.endp[0]; |
6482 if (*tail == NUL) | |
6483 break; | |
7 | 6484 if (!do_all) |
6485 break; | |
6486 } | |
6487 | |
6488 if (ga.ga_data != NULL) | |
6489 STRCPY((char *)ga.ga_data + ga.ga_len, tail); | |
6490 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4778
diff
changeset
|
6491 vim_regfree(regmatch.regprog); |
7 | 6492 } |
6493 | |
6494 ret = vim_strsave(ga.ga_data == NULL ? str : (char_u *)ga.ga_data); | |
6495 ga_clear(&ga); | |
1672 | 6496 if (p_cpo == empty_option) |
6497 p_cpo = save_cpo; | |
6498 else | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
6499 // Darn, evaluating {sub} expression or {expr} changed the value. |
1672 | 6500 free_string_option(save_cpo); |
7 | 6501 |
6502 return ret; | |
6503 } |