annotate src/eval.c @ 19760:9daed26b788b v8.2.0436

patch 8.2.0436: no warnings for incorrect printf arguments Commit: https://github.com/vim/vim/commit/db99f9f29a248b84742b6779c3343123f72065e7 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Mar 23 22:12:22 2020 +0100 patch 8.2.0436: no warnings for incorrect printf arguments Problem: No warnings for incorrect printf arguments. Solution: Fix attribute in declaration. Fix uncovered mistakes. (Dominique Pelle, closes #5834)
author Bram Moolenaar <Bram@vim.org>
date Mon, 23 Mar 2020 22:15:05 +0100
parents c0749ad6c699
children f92435f0f449
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 * eval.c: Expression evaluation.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
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
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 #include "vim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
17 #if defined(FEAT_EVAL) || defined(PROTO)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
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
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
23 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
24 #ifdef FEAT_FLOAT
4870
b7bb20390111 updated for version 7.3.1181
Bram Moolenaar <bram@vim.org>
parents: 4859
diff changeset
25 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
26 #endif
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
27
7611
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
28 #define NAMESPACE_CHAR (char_u *)"abglstvw"
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
29
142
0ef5b70c3eaf updated for version 7.0045
vimboss
parents: 137
diff changeset
30 /*
364
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
31 * When recursively copying lists and dicts we need to remember which ones we
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
32 * have done to avoid endless recursiveness. This unique ID is used for that.
1891
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
33 * The last bit is used for previous_funccal, ignored when comparing.
364
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
34 */
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
35 static int current_copyID = 0;
5973
99d8f2d72dcd updated for version 7.4.327
Bram Moolenaar <bram@vim.org>
parents: 5964
diff changeset
36
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
37 static int echo_attr = 0; // attributes used for ":echo"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 /*
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
40 * Info used by a ":for" loop.
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
41 */
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
42 typedef struct
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
43 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
44 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
45 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
46 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
47 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
48 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
49 blob_T *fi_blob; // blob being used
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
50 } forinfo_T;
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
51
7720
7c52f11e6df3 commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
52 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
53 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
54 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
55 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
56 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
57 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
58 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
59 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
60
7c52f11e6df3 commit https://github.com/vim/vim/commit/48e697e4b6b6b490c58ec9393da9b2d2ea47c6d8
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
61 static int free_unref_items(int copyID);
17789
0f7ae8010787 patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents: 17781
diff changeset
62 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
63 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
64
15969
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
65 /*
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
66 * 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
67 */
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17833
diff changeset
68 varnumber_T
15969
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
69 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
70 {
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
71 varnumber_T result;
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
72
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
73 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
74 {
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
75 if (n1 == 0)
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
76 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
77 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
78 result = -VARNUM_MAX;
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
79 else
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
80 result = VARNUM_MAX;
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
81 }
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
82 else
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
83 result = n1 / n2;
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
84
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
85 return result;
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
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
88 /*
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
89 * 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
90 */
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17833
diff changeset
91 varnumber_T
15969
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
92 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
93 {
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
94 // 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
95 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
96 }
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
97
10567
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
98 #if defined(EBCDIC) || defined(PROTO)
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
99 /*
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
100 * 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
101 */
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
102 static int
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
103 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
104 {
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
105 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
106 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
107
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
108 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
109 }
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
110
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
111 /*
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
112 * 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
113 * 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
114 * 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
115 */
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
116 static void
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
117 sortFunctions(void)
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
118 {
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
119 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
120
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
121 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
122 }
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
123 #endif
82c2c450dad0 patch 8.0.0173: build fails with EBCDIC defined
Christian Brabandt <cb@256bit.org>
parents: 10540
diff changeset
124
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
125 /*
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
126 * Initialize the global and v: variables.
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
127 */
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
128 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
129 eval_init(void)
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
130 {
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
131 evalvars_init();
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
132 func_init();
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
133
2247
c40cd9aad546 Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
134 #ifdef EBCDIC
c40cd9aad546 Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
135 /*
3178
b7f0f23bf906 updated for version 7.3.359
Bram Moolenaar <bram@vim.org>
parents: 3160
diff changeset
136 * 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
137 */
c40cd9aad546 Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
138 sortFunctions();
c40cd9aad546 Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
139 #endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
140 }
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
141
357
25dd5036f2b0 updated for version 7.0092
vimboss
parents: 344
diff changeset
142 #if defined(EXITFREE) || defined(PROTO)
25dd5036f2b0 updated for version 7.0092
vimboss
parents: 344
diff changeset
143 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
144 eval_clear(void)
357
25dd5036f2b0 updated for version 7.0092
vimboss
parents: 344
diff changeset
145 {
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
146 evalvars_clear();
19108
44c6498535c9 patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents: 19102
diff changeset
147 free_scriptnames(); // must come after evalvars_clear().
2849
b0190e93e601 updated for version 7.3.198
Bram Moolenaar <bram@vim.org>
parents: 2845
diff changeset
148 free_locales();
357
25dd5036f2b0 updated for version 7.0092
vimboss
parents: 344
diff changeset
149
17922
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
150 // 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
151 free_autoload_scriptnames();
855
d2a4f08396fe updated for version 7.0f05
vimboss
parents: 846
diff changeset
152
16967
586d625e21b4 patch 8.1.1484: some tests are slow
Bram Moolenaar <Bram@vim.org>
parents: 16872
diff changeset
153 // unreferenced lists and dicts
8881
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8877
diff changeset
154 (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
155
8c794a694d66 patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents: 16967
diff changeset
156 // 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
157 free_all_functions();
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
158 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
159 #endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
160
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 * Top level evaluation function, returning a boolean.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 * Sets "error" to TRUE if there was an error.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 * Return TRUE or FALSE.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
167 eval_to_bool(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
168 char_u *arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
169 int *error,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
170 char_u **nextcmd,
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
171 int skip) // only parse, don't execute
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
173 typval_T tv;
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
174 varnumber_T retval = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 if (skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 ++emsg_skip;
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
178 if (eval0(arg, &tv, nextcmd, !skip) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 *error = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 *error = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 if (!skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
185 retval = (tv_get_number_chk(&tv, error) != 0);
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
186 clear_tv(&tv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 if (skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 --emsg_skip;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
192 return (int)retval;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194
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
195 /*
051937ebaf22 patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
196 * 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
197 */
051937ebaf22 patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
198 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
199 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
200 {
15482
18dd04f7c4a1 patch 8.1.0749: error message contains garbage
Bram Moolenaar <Bram@vim.org>
parents: 15478
diff changeset
201 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
202 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
203 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
204 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
205
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 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
207 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
208 {
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 // 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
210 // 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
211 // 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
212 // 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
213 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
214 && called_emsg == called_emsg_before)
15482
18dd04f7c4a1 patch 8.1.0749: error message contains garbage
Bram Moolenaar <Bram@vim.org>
parents: 15478
diff changeset
215 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
216 }
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 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
218 }
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
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
220 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
221 * Evaluate an expression, which can be a function, partial or string.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
222 * Pass arguments "argv[argc]".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
223 * Return the result in "rettv" and OK or FAIL.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
224 */
16231
0761a4c111a7 patch 8.1.1120: cannot easily get directory entry matches
Bram Moolenaar <Bram@vim.org>
parents: 16223
diff changeset
225 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
226 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
227 {
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 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
229 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
230 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
231
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 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
233 {
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 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
235 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
236 return FAIL;
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17536
diff changeset
237 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
238 funcexe.evaluate = TRUE;
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17536
diff changeset
239 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
240 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
241 }
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 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
243 {
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 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
245
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
246 if (partial->pt_func != NULL && partial->pt_func->uf_dfunc_idx >= 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
247 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
248 if (call_def_function(partial->pt_func, argc, argv, rettv) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
249 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
250 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
251 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
252 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
253 s = partial_name(partial);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
254 if (s == NULL || *s == NUL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
255 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
256 vim_memset(&funcexe, 0, sizeof(funcexe));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
257 funcexe.evaluate = TRUE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
258 funcexe.partial = partial;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
259 if (call_func(s, -1, rettv, argc, argv, &funcexe) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
260 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
261 }
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
262 }
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 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
264 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
265 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
266 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
267 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
268 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
269 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
270 return FAIL;
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
271 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
272 {
14331
f8280e1bfc84 patch 8.1.0181: memory leak with trailing characters in skip expression
Christian Brabandt <cb@256bit.org>
parents: 14071
diff changeset
273 clear_tv(rettv);
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
274 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
275 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
276 }
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 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
279 }
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 /*
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 * 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
283 * 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
284 */
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 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
286 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
287 {
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 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
289 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
290
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 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
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 *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
294 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
295 }
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
296 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
297 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
298 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
299 }
7749260f261c patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()
Christian Brabandt <cb@256bit.org>
parents: 12674
diff changeset
300
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302 * Top level evaluation function, returning a string. If "skip" is TRUE,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 * only parsing to "nextcmd" is done, without reporting errors. Return
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 * pointer to allocated memory, or NULL for failure or when "skip" is TRUE.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 char_u *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
307 eval_to_string_skip(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
308 char_u *arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
309 char_u **nextcmd,
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
310 int skip) // only parse, don't execute
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
312 typval_T tv;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313 char_u *retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 if (skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 ++emsg_skip;
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
317 if (eval0(arg, &tv, nextcmd, !skip) == FAIL || skip)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 retval = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
321 retval = vim_strsave(tv_get_string(&tv));
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
322 clear_tv(&tv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 if (skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325 --emsg_skip;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 /*
9
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
331 * Skip over an expression at "*pp".
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
332 * Return FAIL for an error, OK otherwise.
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
333 */
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
334 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
335 skip_expr(char_u **pp)
9
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
336 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
337 typval_T rettv;
9
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
338
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
339 *pp = skipwhite(*pp);
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
340 return eval1(pp, &rettv, FALSE);
9
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
341 }
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
342
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
343 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 * Top level evaluation function, returning a string.
1713
7781fcd2b74f updated for version 7.2-011
vimboss
parents: 1707
diff changeset
345 * When "convert" is TRUE convert a List into a sequence of lines and convert
7781fcd2b74f updated for version 7.2-011
vimboss
parents: 1707
diff changeset
346 * a Float to a String.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347 * Return pointer to allocated memory, or NULL for failure.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 char_u *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
350 eval_to_string(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
351 char_u *arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
352 char_u **nextcmd,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
353 int convert)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
355 typval_T tv;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 char_u *retval;
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 713
diff changeset
357 garray_T ga;
1851
e7f6ca5594cf updated for version 7.2-149
vimboss
parents: 1800
diff changeset
358 #ifdef FEAT_FLOAT
1713
7781fcd2b74f updated for version 7.2-011
vimboss
parents: 1707
diff changeset
359 char_u numbuf[NUMBUFLEN];
1851
e7f6ca5594cf updated for version 7.2-149
vimboss
parents: 1800
diff changeset
360 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
362 if (eval0(arg, &tv, nextcmd, TRUE) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 retval = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 {
1713
7781fcd2b74f updated for version 7.2-011
vimboss
parents: 1707
diff changeset
366 if (convert && tv.v_type == VAR_LIST)
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 713
diff changeset
367 {
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 713
diff changeset
368 ga_init2(&ga, (int)sizeof(char), 80);
1690
c6b06a4a8f92 updated for version 7.2b-023
vimboss
parents: 1683
diff changeset
369 if (tv.vval.v_list != NULL)
3000
02f5abca10ae updated for version 7.3.272
Bram Moolenaar <bram@vim.org>
parents: 2963
diff changeset
370 {
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
371 list_join(&ga, tv.vval.v_list, (char_u *)"\n", TRUE, FALSE, 0);
3000
02f5abca10ae updated for version 7.3.272
Bram Moolenaar <bram@vim.org>
parents: 2963
diff changeset
372 if (tv.vval.v_list->lv_len > 0)
02f5abca10ae updated for version 7.3.272
Bram Moolenaar <bram@vim.org>
parents: 2963
diff changeset
373 ga_append(&ga, NL);
02f5abca10ae updated for version 7.3.272
Bram Moolenaar <bram@vim.org>
parents: 2963
diff changeset
374 }
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 713
diff changeset
375 ga_append(&ga, NUL);
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 713
diff changeset
376 retval = (char_u *)ga.ga_data;
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 713
diff changeset
377 }
1713
7781fcd2b74f updated for version 7.2-011
vimboss
parents: 1707
diff changeset
378 #ifdef FEAT_FLOAT
7781fcd2b74f updated for version 7.2-011
vimboss
parents: 1707
diff changeset
379 else if (convert && tv.v_type == VAR_FLOAT)
7781fcd2b74f updated for version 7.2-011
vimboss
parents: 1707
diff changeset
380 {
7781fcd2b74f updated for version 7.2-011
vimboss
parents: 1707
diff changeset
381 vim_snprintf((char *)numbuf, NUMBUFLEN, "%g", tv.vval.v_float);
7781fcd2b74f updated for version 7.2-011
vimboss
parents: 1707
diff changeset
382 retval = vim_strsave(numbuf);
7781fcd2b74f updated for version 7.2-011
vimboss
parents: 1707
diff changeset
383 }
7781fcd2b74f updated for version 7.2-011
vimboss
parents: 1707
diff changeset
384 #endif
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 713
diff changeset
385 else
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
386 retval = vim_strsave(tv_get_string(&tv));
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
387 clear_tv(&tv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 /*
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
394 * Call eval_to_string() without using current local variables and using
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
395 * textlock. When "use_sandbox" is TRUE use the sandbox.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 char_u *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
398 eval_to_string_safe(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
399 char_u *arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
400 char_u **nextcmd,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
401 int use_sandbox)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403 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
404 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
405
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14897
diff changeset
406 save_funccal(&funccal_entry);
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
407 if (use_sandbox)
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
408 ++sandbox;
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
409 ++textlock;
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 713
diff changeset
410 retval = eval_to_string(arg, nextcmd, FALSE);
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
411 if (use_sandbox)
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
412 --sandbox;
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
413 --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
414 restore_funccal();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 * Top level evaluation function, returning a number.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420 * Evaluates "expr" silently.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 * Returns -1 for an error.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 */
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
423 varnumber_T
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
424 eval_to_number(char_u *expr)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
426 typval_T rettv;
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
427 varnumber_T retval;
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
428 char_u *p = skipwhite(expr);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
430 ++emsg_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
432 if (eval1(&p, &rettv, TRUE) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433 retval = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
434 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
435 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
436 retval = tv_get_number_chk(&rettv, NULL);
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
437 clear_tv(&rettv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
438 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439 --emsg_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
443
446
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
444 /*
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 615
diff changeset
445 * Top level evaluation function.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 615
diff changeset
446 * Returns an allocated typval_T with the result.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 615
diff changeset
447 * Returns NULL when there is an error.
446
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
448 */
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
449 typval_T *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
450 eval_expr(char_u *arg, char_u **nextcmd)
446
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
451 {
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
452 typval_T *tv;
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
453
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
454 tv = ALLOC_ONE(typval_T);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 615
diff changeset
455 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
456 VIM_CLEAR(tv);
446
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
457
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
458 return tv;
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
459 }
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
460
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 /*
10942
e05695e59f6d patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents: 10926
diff changeset
462 * 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
463 * 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
464 * should have type VAR_UNKNOWN.
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
465 * Returns OK or FAIL.
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
466 */
3078
2cbde6bcc623 updated for version 7.3.311
Bram Moolenaar <bram@vim.org>
parents: 3066
diff changeset
467 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
468 call_vim_function(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
469 char_u *func,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
470 int argc,
14071
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13923
diff changeset
471 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
472 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
473 {
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
474 int ret;
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17536
diff changeset
475 funcexe_T funcexe;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
477 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
478 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
479 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
480 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
481 funcexe.evaluate = TRUE;
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17536
diff changeset
482 ret = call_func(func, -1, rettv, argc, argv, &funcexe);
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
483 if (ret == FAIL)
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
484 clear_tv(rettv);
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
485
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
486 return ret;
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
487 }
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
488
4133
36fd800b8c6c updated for version 7.3.819
Bram Moolenaar <bram@vim.org>
parents: 4126
diff changeset
489 /*
10942
e05695e59f6d patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents: 10926
diff changeset
490 * Call Vim script function "func" and return the result as a number.
4133
36fd800b8c6c updated for version 7.3.819
Bram Moolenaar <bram@vim.org>
parents: 4126
diff changeset
491 * 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
492 * 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
493 * have type VAR_UNKNOWN.
4133
36fd800b8c6c updated for version 7.3.819
Bram Moolenaar <bram@vim.org>
parents: 4126
diff changeset
494 */
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
495 varnumber_T
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
496 call_func_retnr(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
497 char_u *func,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
498 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
499 typval_T *argv)
4133
36fd800b8c6c updated for version 7.3.819
Bram Moolenaar <bram@vim.org>
parents: 4126
diff changeset
500 {
36fd800b8c6c updated for version 7.3.819
Bram Moolenaar <bram@vim.org>
parents: 4126
diff changeset
501 typval_T rettv;
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
502 varnumber_T retval;
4133
36fd800b8c6c updated for version 7.3.819
Bram Moolenaar <bram@vim.org>
parents: 4126
diff changeset
503
14439
e4c553e9132b patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents: 14393
diff changeset
504 if (call_vim_function(func, argc, argv, &rettv) == FAIL)
4133
36fd800b8c6c updated for version 7.3.819
Bram Moolenaar <bram@vim.org>
parents: 4126
diff changeset
505 return -1;
36fd800b8c6c updated for version 7.3.819
Bram Moolenaar <bram@vim.org>
parents: 4126
diff changeset
506
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
507 retval = tv_get_number_chk(&rettv, NULL);
4133
36fd800b8c6c updated for version 7.3.819
Bram Moolenaar <bram@vim.org>
parents: 4126
diff changeset
508 clear_tv(&rettv);
36fd800b8c6c updated for version 7.3.819
Bram Moolenaar <bram@vim.org>
parents: 4126
diff changeset
509 return retval;
36fd800b8c6c updated for version 7.3.819
Bram Moolenaar <bram@vim.org>
parents: 4126
diff changeset
510 }
36fd800b8c6c updated for version 7.3.819
Bram Moolenaar <bram@vim.org>
parents: 4126
diff changeset
511
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
512 /*
10942
e05695e59f6d patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents: 10926
diff changeset
513 * Call Vim script function "func" and return the result as a string.
453
3ffdc64af1e5 updated for version 7.0120
vimboss
parents: 449
diff changeset
514 * 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
515 * 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
516 * have type VAR_UNKNOWN.
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
517 */
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
518 void *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
519 call_func_retstr(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
520 char_u *func,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
521 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
522 typval_T *argv)
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
523 {
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
524 typval_T rettv;
453
3ffdc64af1e5 updated for version 7.0120
vimboss
parents: 449
diff changeset
525 char_u *retval;
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
526
14439
e4c553e9132b patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents: 14393
diff changeset
527 if (call_vim_function(func, argc, argv, &rettv) == FAIL)
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
528 return NULL;
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
529
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
530 retval = vim_strsave(tv_get_string(&rettv));
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
531 clear_tv(&rettv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533 }
1322
4ce0a7e4c6b3 updated for version 7.1-036
vimboss
parents: 1320
diff changeset
534
453
3ffdc64af1e5 updated for version 7.0120
vimboss
parents: 449
diff changeset
535 /*
10942
e05695e59f6d patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents: 10926
diff changeset
536 * 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
537 * 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
538 * have type VAR_UNKNOWN.
1690
c6b06a4a8f92 updated for version 7.2b-023
vimboss
parents: 1683
diff changeset
539 * Returns NULL when there is something wrong.
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
540 */
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
541 void *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
542 call_func_retlist(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
543 char_u *func,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
544 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
545 typval_T *argv)
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
546 {
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
547 typval_T rettv;
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
548
14439
e4c553e9132b patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents: 14393
diff changeset
549 if (call_vim_function(func, argc, argv, &rettv) == FAIL)
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
550 return NULL;
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
551
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
552 if (rettv.v_type != VAR_LIST)
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
553 {
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
554 clear_tv(&rettv);
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
555 return NULL;
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
556 }
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
557
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
558 return rettv.vval.v_list;
06234af3a8b7 updated for version 7.0106
vimboss
parents: 388
diff changeset
559 }
1322
4ce0a7e4c6b3 updated for version 7.1-036
vimboss
parents: 1320
diff changeset
560
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
561 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
562 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
563 * Evaluate 'foldexpr'. Returns the foldlevel, and any character preceding
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
564 * it in "*cp". Doesn't give error messages.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
565 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
566 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
567 eval_foldexpr(char_u *arg, int *cp)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
568 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
569 typval_T tv;
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
570 varnumber_T retval;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
571 char_u *s;
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 680
diff changeset
572 int use_sandbox = was_set_insecurely((char_u *)"foldexpr",
9364d114ed8d updated for version 7.0204
vimboss
parents: 680
diff changeset
573 OPT_LOCAL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575 ++emsg_off;
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
576 if (use_sandbox)
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
577 ++sandbox;
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
578 ++textlock;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
579 *cp = NUL;
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
580 if (eval0(arg, &tv, NULL, TRUE) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581 retval = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
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 number, just return the number.
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
585 if (tv.v_type == VAR_NUMBER)
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
586 retval = tv.vval.v_number;
156
c5b05f6de1ad updated for version 7.0047
vimboss
parents: 151
diff changeset
587 else if (tv.v_type != VAR_STRING || tv.vval.v_string == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588 retval = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
591 // 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
592 // the number.
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
593 s = tv.vval.v_string;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
594 if (!VIM_ISDIGIT(*s) && *s != '-')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595 *cp = *s++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596 retval = atol((char *)s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597 }
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
598 clear_tv(&tv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
599 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600 --emsg_off;
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
601 if (use_sandbox)
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
602 --sandbox;
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
603 --textlock;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
604
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
605 return (int)retval;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
606 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
607 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
608
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609 /*
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
610 * Get an lval: variable, Dict item or List item that can be assigned a value
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
611 * to: "name", "na{me}", "name[expr]", "name[expr:expr]", "name[expr][expr]",
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
612 * "name.key", "name.key[expr]" etc.
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
613 * Indexing only works if "name" is an existing List or Dictionary.
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
614 * "name" points to the start of the name.
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
615 * If "rettv" is not NULL it points to the value to be assigned.
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
616 * "unlet" is TRUE for ":unlet": slightly different behavior when something is
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
617 * wrong; must end in space or cmd separator.
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
618 *
5604
b43363a7b4c7 updated for version 7.4.149
Bram Moolenaar <bram@vim.org>
parents: 5571
diff changeset
619 * flags:
b43363a7b4c7 updated for version 7.4.149
Bram Moolenaar <bram@vim.org>
parents: 5571
diff changeset
620 * 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
621 * GLV_READ_ONLY: will not change the variable
5604
b43363a7b4c7 updated for version 7.4.149
Bram Moolenaar <bram@vim.org>
parents: 5571
diff changeset
622 * GLV_NO_AUTOLOAD: do not use script autoloading
b43363a7b4c7 updated for version 7.4.149
Bram Moolenaar <bram@vim.org>
parents: 5571
diff changeset
623 *
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
624 * Returns a pointer to just after the name, including indexes.
124
f455396f3c3f updated for version 7.0043
vimboss
parents: 121
diff changeset
625 * When an evaluation error occurs "lp->ll_name" is NULL;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
626 * Returns NULL for a parsing error. Still need to free items in "lp"!
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
627 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
628 char_u *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
629 get_lval(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
630 char_u *name,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
631 typval_T *rettv,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
632 lval_T *lp,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
633 int unlet,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
634 int skip,
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
635 int flags, // GLV_ values
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
636 int fne_flags) // flags for find_name_end()
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
637 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
638 char_u *p;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
639 char_u *expr_start, *expr_end;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
640 int cc;
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
641 dictitem_T *v;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
642 typval_T var1;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
643 typval_T var2;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
644 int empty1 = FALSE;
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
645 listitem_T *ni;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
646 char_u *key = NULL;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
647 int len;
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
648 hashtab_T *ht;
5604
b43363a7b4c7 updated for version 7.4.149
Bram Moolenaar <bram@vim.org>
parents: 5571
diff changeset
649 int quiet = flags & GLV_QUIET;
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
650
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
651 // Clear everything in "lp".
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
652 vim_memset(lp, 0, sizeof(lval_T));
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
653
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
654 if (skip)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
655 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
656 // When skipping just find the end of the name.
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
657 lp->ll_name = name;
271
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
658 return find_name_end(name, NULL, NULL, FNE_INCL_BR | fne_flags);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
659 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
660
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
661 // Find the end of the name.
271
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
662 p = find_name_end(name, &expr_start, &expr_end, fne_flags);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
663 lp->ll_name_end = p;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
664 if (expr_start != NULL)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
665 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
666 // 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
667 if (unlet && !VIM_ISWHITE(*p) && !ends_excmd(*p)
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
668 && *p != '[' && *p != '.')
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
669 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
670 emsg(_(e_trailing));
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
671 return NULL;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
672 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
673
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
674 lp->ll_exp_name = make_expanded_name(name, expr_start, expr_end, p);
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
675 if (lp->ll_exp_name == NULL)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
676 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
677 // 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
678 // 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
679 // aborting error, an interrupt, or an exception.
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
680 if (!aborting() && !quiet)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
681 {
121
86d71ae0c85a updated for version 7.0042
vimboss
parents: 117
diff changeset
682 emsg_severe = TRUE;
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
683 semsg(_(e_invarg2), name);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
684 return NULL;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
685 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
686 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
687 lp->ll_name = lp->ll_exp_name;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
688 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
689 else
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
690 {
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
691 lp->ll_name = name;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
692
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
693 if (current_sctx.sc_version == SCRIPT_VERSION_VIM9 && *p == ':')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
694 {
19191
133ef7ba4e4e patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
695 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
696 char_u *tp = skipwhite(p + 1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
697
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
698 // parse the type after the name
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
699 lp->ll_type = parse_type(&tp, &si->sn_type_list);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
700 lp->ll_name_end = tp;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
701 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
702 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
703
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
704 // Without [idx] or .key we are done.
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
705 if ((*p != '[' && *p != '.') || lp->ll_name == NULL)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
706 return p;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
707
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
708 cc = *p;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
709 *p = NUL;
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
710 // 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
711 // 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
712 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
713 flags & GLV_NO_AUTOLOAD);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
714 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
715 semsg(_(e_undefvar), lp->ll_name);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
716 *p = cc;
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
717 if (v == NULL)
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
718 return NULL;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
719
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
720 /*
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
721 * Loop until no more [idx] or .key is following.
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
722 */
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
723 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
724 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
725 var2.v_type = VAR_UNKNOWN;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
726 while (*p == '[' || (*p == '.' && lp->ll_tv->v_type == VAR_DICT))
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
727 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
728 if (!(lp->ll_tv->v_type == VAR_LIST && lp->ll_tv->vval.v_list != NULL)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
729 && !(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
730 && 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
731 && !(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
732 && lp->ll_tv->vval.v_blob != NULL))
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
733 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
734 if (!quiet)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
735 emsg(_("E689: Can only index a List, Dictionary or Blob"));
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
736 return NULL;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
737 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
738 if (lp->ll_range)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
739 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
740 if (!quiet)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
741 emsg(_("E708: [:] must come last"));
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
742 return NULL;
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
743 }
88
2b4debdc8d2c updated for version 7.0035
vimboss
parents: 86
diff changeset
744
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
745 len = -1;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
746 if (*p == '.')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
747 {
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
748 key = p + 1;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
749 for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; ++len)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
750 ;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
751 if (len == 0)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
752 {
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
753 if (!quiet)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
754 emsg(_(e_emptykey));
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
755 return NULL;
88
2b4debdc8d2c updated for version 7.0035
vimboss
parents: 86
diff changeset
756 }
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
757 p = key + len;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
758 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
759 else
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
760 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
761 // Get the index [expr] or the first index [expr: ].
88
2b4debdc8d2c updated for version 7.0035
vimboss
parents: 86
diff changeset
762 p = skipwhite(p + 1);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
763 if (*p == ':')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
764 empty1 = TRUE;
88
2b4debdc8d2c updated for version 7.0035
vimboss
parents: 86
diff changeset
765 else
2b4debdc8d2c updated for version 7.0035
vimboss
parents: 86
diff changeset
766 {
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
767 empty1 = FALSE;
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
768 if (eval1(&p, &var1, TRUE) == FAIL) // recursive!
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
769 return NULL;
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
770 if (tv_get_string_chk(&var1) == NULL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
771 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
772 // not a number or string
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
773 clear_tv(&var1);
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
774 return NULL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
775 }
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
776 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
777
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
778 // Optionally get the second index [ :expr].
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
779 if (*p == ':')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
780 {
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
781 if (lp->ll_tv->v_type == VAR_DICT)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
782 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
783 if (!quiet)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
784 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
785 clear_tv(&var1);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
786 return NULL;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
787 }
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
788 if (rettv != NULL
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
789 && !(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
790 && rettv->vval.v_list != NULL)
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
791 && !(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
792 && rettv->vval.v_blob != NULL))
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
793 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
794 if (!quiet)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
795 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
796 clear_tv(&var1);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
797 return NULL;
88
2b4debdc8d2c updated for version 7.0035
vimboss
parents: 86
diff changeset
798 }
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
799 p = skipwhite(p + 1);
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
800 if (*p == ']')
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
801 lp->ll_empty2 = TRUE;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
802 else
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
803 {
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
804 lp->ll_empty2 = FALSE;
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
805 if (eval1(&p, &var2, TRUE) == FAIL) // recursive!
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
806 {
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);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
808 return NULL;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
809 }
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
810 if (tv_get_string_chk(&var2) == NULL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
811 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
812 // 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
813 clear_tv(&var1);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
814 clear_tv(&var2);
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
815 return NULL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
816 }
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
817 }
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
818 lp->ll_range = TRUE;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
819 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
820 else
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
821 lp->ll_range = FALSE;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
822
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
823 if (*p != ']')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
824 {
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
825 if (!quiet)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
826 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
827 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
828 clear_tv(&var2);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
829 return NULL;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
830 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
831
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
832 // Skip to past ']'.
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
833 ++p;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
834 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
835
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
836 if (lp->ll_tv->v_type == VAR_DICT)
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
837 {
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
838 if (len == -1)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
839 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
840 // "[key]": get key from "var1"
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
841 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
842 if (key == NULL)
9fa567d13551 commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents: 8831
diff changeset
843 {
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
844 clear_tv(&var1);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
845 return NULL;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
846 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
847 }
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
848 lp->ll_list = NULL;
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
849 lp->ll_dict = lp->ll_tv->vval.v_dict;
121
86d71ae0c85a updated for version 7.0042
vimboss
parents: 117
diff changeset
850 lp->ll_di = dict_find(lp->ll_dict, key, len);
2739
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
851
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
852 // 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
853 // 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
854 // g: dictionary). Disallow overwriting a builtin function.
3687
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
855 if (rettv != NULL && lp->ll_dict->dv_scope != 0)
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
856 {
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
857 int prevval;
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
858 int wrong;
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
859
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
860 if (len != -1)
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
861 {
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
862 prevval = key[len];
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
863 key[len] = NUL;
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
864 }
4819
8c4324e6f477 updated for version 7.3.1156
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
865 else
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
866 prevval = 0; // avoid compiler warning
3687
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
867 wrong = (lp->ll_dict->dv_scope == VAR_DEF_SCOPE
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
868 && rettv->v_type == VAR_FUNC
2739
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
869 && var_check_func_name(key, lp->ll_di == NULL))
3687
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
870 || !valid_varname(key);
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
871 if (len != -1)
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
872 key[len] = prevval;
085f14642fe8 updated for version 7.3.603
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
873 if (wrong)
2739
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
874 return NULL;
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
875 }
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
876
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
877 if (lp->ll_di == NULL)
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
878 {
15762
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15636
diff changeset
879 // 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
880 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
881 || &lp->ll_dict->dv_hashtab == get_funccal_args_ht())
2739
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
882 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
883 semsg(_(e_illvar), name);
16013
93b08b92a049 patch 8.1.1012: memory leak with E461
Bram Moolenaar <Bram@vim.org>
parents: 15969
diff changeset
884 clear_tv(&var1);
2739
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
885 return NULL;
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
886 }
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
887
15762
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15636
diff changeset
888 // Key does not exist in dict: may need to add it.
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
889 if (*p == '[' || *p == '.' || unlet)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
890 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
891 if (!quiet)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
892 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
893 clear_tv(&var1);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
894 return NULL;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
895 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
896 if (len == -1)
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
897 lp->ll_newkey = vim_strsave(key);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
898 else
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
899 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
900 clear_tv(&var1);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
901 if (lp->ll_newkey == NULL)
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
902 p = NULL;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
903 break;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
904 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
905 // 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
906 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
907 && 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
908 {
8bff367672a4 patch 8.0.0344: unlet command leaks memory
Christian Brabandt <cb@256bit.org>
parents: 10908
diff changeset
909 clear_tv(&var1);
2739
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
910 return NULL;
10910
8bff367672a4 patch 8.0.0344: unlet command leaks memory
Christian Brabandt <cb@256bit.org>
parents: 10908
diff changeset
911 }
2739
2bd574a2ef1c updated for version 7.3.146
Bram Moolenaar <bram@vim.org>
parents: 2690
diff changeset
912
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
913 clear_tv(&var1);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
914 lp->ll_tv = &lp->ll_di->di_tv;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
915 }
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
916 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
917 {
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
918 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
919
15454
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 * 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
922 */
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
923 if (empty1)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
924 lp->ll_n1 = 0;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
925 else
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
926 // is number or string
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
927 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
928 clear_tv(&var1);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
929
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
930 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
931 || lp->ll_n1 > bloblen
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
932 || (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
933 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
934 if (!quiet)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
935 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
936 clear_tv(&var2);
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
937 return NULL;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
938 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
939 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
940 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
941 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
942 clear_tv(&var2);
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
943 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
944 || lp->ll_n2 >= bloblen
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
945 || 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
946 {
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
947 if (!quiet)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
948 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
949 return NULL;
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
950 }
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
951 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
952 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
953 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
954 break;
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
955 }
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
956 else
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
957 {
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
958 /*
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
959 * Get the number and item for the only or first index of the List.
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
960 */
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
961 if (empty1)
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
962 lp->ll_n1 = 0;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
963 else
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
964 // 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
965 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
966 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
967
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
968 lp->ll_dict = NULL;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
969 lp->ll_list = lp->ll_tv->vval.v_list;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
970 lp->ll_li = list_find(lp->ll_list, lp->ll_n1);
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
971 if (lp->ll_li == NULL)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
972 {
842
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
973 if (lp->ll_n1 < 0)
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
974 {
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
975 lp->ll_n1 = 0;
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
976 lp->ll_li = list_find(lp->ll_list, lp->ll_n1);
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
977 }
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
978 }
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
979 if (lp->ll_li == NULL)
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
980 {
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
981 clear_tv(&var2);
2772
18ad854f5dcd updated for version 7.3.162
Bram Moolenaar <bram@vim.org>
parents: 2770
diff changeset
982 if (!quiet)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
983 semsg(_(e_listidx), lp->ll_n1);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
984 return NULL;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
985 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
986
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
987 /*
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
988 * May need to find the item or absolute index for the second
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
989 * index of a range.
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
990 * When no index given: "lp->ll_empty2" is TRUE.
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
991 * Otherwise "lp->ll_n2" is set to the second index.
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
992 */
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
993 if (lp->ll_range && !lp->ll_empty2)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
994 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
995 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
996 // is number or string
88
2b4debdc8d2c updated for version 7.0035
vimboss
parents: 86
diff changeset
997 clear_tv(&var2);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
998 if (lp->ll_n2 < 0)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
999 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1000 ni = list_find(lp->ll_list, lp->ll_n2);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
1001 if (ni == NULL)
2772
18ad854f5dcd updated for version 7.3.162
Bram Moolenaar <bram@vim.org>
parents: 2770
diff changeset
1002 {
18ad854f5dcd updated for version 7.3.162
Bram Moolenaar <bram@vim.org>
parents: 2770
diff changeset
1003 if (!quiet)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
1004 semsg(_(e_listidx), lp->ll_n2);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1005 return NULL;
2772
18ad854f5dcd updated for version 7.3.162
Bram Moolenaar <bram@vim.org>
parents: 2770
diff changeset
1006 }
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1007 lp->ll_n2 = list_idx_of_item(lp->ll_list, ni);
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1008 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1009
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1010 // Check that lp->ll_n2 isn't before lp->ll_n1.
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1011 if (lp->ll_n1 < 0)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1012 lp->ll_n1 = list_idx_of_item(lp->ll_list, lp->ll_li);
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1013 if (lp->ll_n2 < lp->ll_n1)
2772
18ad854f5dcd updated for version 7.3.162
Bram Moolenaar <bram@vim.org>
parents: 2770
diff changeset
1014 {
18ad854f5dcd updated for version 7.3.162
Bram Moolenaar <bram@vim.org>
parents: 2770
diff changeset
1015 if (!quiet)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
1016 semsg(_(e_listidx), lp->ll_n2);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1017 return NULL;
2772
18ad854f5dcd updated for version 7.3.162
Bram Moolenaar <bram@vim.org>
parents: 2770
diff changeset
1018 }
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1019 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1020
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1021 lp->ll_tv = &lp->ll_li->li_tv;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1022 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1023 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1024
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
1025 clear_tv(&var1);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
1026 lp->ll_name_end = p;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1027 return p;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1028 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1029
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1030 /*
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
1031 * Clear lval "lp" that was filled by get_lval().
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1032 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1033 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1034 clear_lval(lval_T *lp)
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1035 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1036 vim_free(lp->ll_exp_name);
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1037 vim_free(lp->ll_newkey);
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1038 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1039
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1040 /*
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 142
diff changeset
1041 * Set a variable that was parsed by get_lval() to "rettv".
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1042 * "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
1043 * "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
1044 * "%" for "%=", "." for ".=" or "=" for "=".
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1045 */
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17833
diff changeset
1046 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1047 set_var_lval(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1048 lval_T *lp,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1049 char_u *endp,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1050 typval_T *rettv,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1051 int copy,
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
1052 int flags, // LET_IS_CONST and/or LET_NO_COMMAND
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1053 char_u *op)
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1054 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1055 int cc;
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
1056 listitem_T *ri;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
1057 dictitem_T *di;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1058
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1059 if (lp->ll_tv == NULL)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1060 {
10889
5780bd3a5a7e patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents: 10728
diff changeset
1061 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
1062 *endp = NUL;
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1063 if (lp->ll_blob != NULL)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1064 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1065 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
1066
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1067 if (op != NULL && *op != '=')
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1068 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
1069 semsg(_(e_letwrong), op);
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1070 return;
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
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1073 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
1074 {
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1075 int il, ir;
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1076
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1077 if (lp->ll_empty2)
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1078 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
1079
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1080 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
1081 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
1082 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
1083 return;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1084 }
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1085 if (lp->ll_empty2)
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1086 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
1087
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1088 ir = 0;
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1089 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
1090 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
1091 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
1092 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1093 else
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1094 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1095 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
1096 if (!error)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1097 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1098 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
1099
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1100 // 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
1101 // the end is an error otherwise.
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1102 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
1103 || (lp->ll_n1 == gap->ga_len
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1104 && 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
1105 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1106 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
1107 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
1108 ++gap->ga_len;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1109 }
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1110 // 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
1111 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1112 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1113 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1114 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
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 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
1117
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
1118 if (flags & LET_IS_CONST)
17079
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1119 {
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1120 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
1121 *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
1122 return;
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1123 }
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1124
15790
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1125 // 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
1126 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
1127 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
1128 &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
1129 {
5780bd3a5a7e patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents: 10728
diff changeset
1130 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
1131 || (!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
1132 && !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
1133 && 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
1134 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
1135 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
1136 }
5780bd3a5a7e patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents: 10728
diff changeset
1137 }
5780bd3a5a7e patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents: 10728
diff changeset
1138 else
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
1139 set_var_const(lp->ll_name, lp->ll_type, rettv, copy, flags);
10889
5780bd3a5a7e patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents: 10728
diff changeset
1140 *endp = cc;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1141 }
15780
5b6c3c7feba8 patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents: 15770
diff changeset
1142 else if (var_check_lock(lp->ll_newkey == NULL
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 142
diff changeset
1143 ? lp->ll_tv->v_lock
6773
eb4b705a5d6a patch 7.4.708
Bram Moolenaar <bram@vim.org>
parents: 6761
diff changeset
1144 : lp->ll_tv->vval.v_dict->dv_lock, lp->ll_name, FALSE))
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 142
diff changeset
1145 ;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1146 else if (lp->ll_range)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1147 {
6166
0a42938f449c updated for version 7.4.419
Bram Moolenaar <bram@vim.org>
parents: 6147
diff changeset
1148 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
1149 int ll_n1 = lp->ll_n1;
6166
0a42938f449c updated for version 7.4.419
Bram Moolenaar <bram@vim.org>
parents: 6147
diff changeset
1150
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
1151 if (flags & LET_IS_CONST)
17079
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1152 {
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1153 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
1154 return;
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1155 }
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1156
6166
0a42938f449c updated for version 7.4.419
Bram Moolenaar <bram@vim.org>
parents: 6147
diff changeset
1157 /*
0a42938f449c updated for version 7.4.419
Bram Moolenaar <bram@vim.org>
parents: 6147
diff changeset
1158 * Check whether any of the list items is locked
0a42938f449c updated for version 7.4.419
Bram Moolenaar <bram@vim.org>
parents: 6147
diff changeset
1159 */
6422
9fbb9c60ab41 updated for version 7.4.541
Bram Moolenaar <bram@vim.org>
parents: 6388
diff changeset
1160 for (ri = rettv->vval.v_list->lv_first; ri != NULL && ll_li != NULL; )
6166
0a42938f449c updated for version 7.4.419
Bram Moolenaar <bram@vim.org>
parents: 6147
diff changeset
1161 {
15780
5b6c3c7feba8 patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents: 15770
diff changeset
1162 if (var_check_lock(ll_li->li_tv.v_lock, lp->ll_name, FALSE))
6166
0a42938f449c updated for version 7.4.419
Bram Moolenaar <bram@vim.org>
parents: 6147
diff changeset
1163 return;
0a42938f449c updated for version 7.4.419
Bram Moolenaar <bram@vim.org>
parents: 6147
diff changeset
1164 ri = ri->li_next;
0a42938f449c updated for version 7.4.419
Bram Moolenaar <bram@vim.org>
parents: 6147
diff changeset
1165 if (ri == NULL || (!lp->ll_empty2 && lp->ll_n2 == ll_n1))
0a42938f449c updated for version 7.4.419
Bram Moolenaar <bram@vim.org>
parents: 6147
diff changeset
1166 break;
0a42938f449c updated for version 7.4.419
Bram Moolenaar <bram@vim.org>
parents: 6147
diff changeset
1167 ll_li = ll_li->li_next;
0a42938f449c updated for version 7.4.419
Bram Moolenaar <bram@vim.org>
parents: 6147
diff changeset
1168 ++ll_n1;
0a42938f449c updated for version 7.4.419
Bram Moolenaar <bram@vim.org>
parents: 6147
diff changeset
1169 }
0a42938f449c updated for version 7.4.419
Bram Moolenaar <bram@vim.org>
parents: 6147
diff changeset
1170
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1171 /*
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1172 * Assign the List values to the list items.
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1173 */
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1174 for (ri = rettv->vval.v_list->lv_first; ri != NULL; )
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1175 {
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1176 if (op != NULL && *op != '=')
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1177 tv_op(&lp->ll_li->li_tv, &ri->li_tv, op);
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1178 else
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1179 {
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1180 clear_tv(&lp->ll_li->li_tv);
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1181 copy_tv(&ri->li_tv, &lp->ll_li->li_tv);
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1182 }
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1183 ri = ri->li_next;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1184 if (ri == NULL || (!lp->ll_empty2 && lp->ll_n2 == lp->ll_n1))
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1185 break;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1186 if (lp->ll_li->li_next == NULL)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1187 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1188 // Need to add an empty item.
533
c8b6b7e1005d updated for version 7.0150
vimboss
parents: 531
diff changeset
1189 if (list_append_number(lp->ll_list, 0) == FAIL)
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1190 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1191 ri = NULL;
88
2b4debdc8d2c updated for version 7.0035
vimboss
parents: 86
diff changeset
1192 break;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1193 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1194 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1195 lp->ll_li = lp->ll_li->li_next;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1196 ++lp->ll_n1;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1197 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1198 if (ri != NULL)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
1199 emsg(_("E710: List value has more items than target"));
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1200 else if (lp->ll_empty2
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1201 ? (lp->ll_li != NULL && lp->ll_li->li_next != NULL)
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1202 : 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
1203 emsg(_("E711: List value has not enough items"));
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1204 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1205 else
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1206 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1207 /*
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1208 * Assign to a List or Dictionary item.
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1209 */
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
1210 if (flags & LET_IS_CONST)
17079
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1211 {
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1212 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
1213 return;
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents: 17053
diff changeset
1214 }
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1215 if (lp->ll_newkey != NULL)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1216 {
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1217 if (op != NULL && *op != '=')
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1218 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
1219 semsg(_(e_letwrong), op);
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1220 return;
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1221 }
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1222
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1223 // Need to add an item to the Dictionary.
121
86d71ae0c85a updated for version 7.0042
vimboss
parents: 117
diff changeset
1224 di = dictitem_alloc(lp->ll_newkey);
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1225 if (di == NULL)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1226 return;
121
86d71ae0c85a updated for version 7.0042
vimboss
parents: 117
diff changeset
1227 if (dict_add(lp->ll_tv->vval.v_dict, di) == FAIL)
86d71ae0c85a updated for version 7.0042
vimboss
parents: 117
diff changeset
1228 {
86d71ae0c85a updated for version 7.0042
vimboss
parents: 117
diff changeset
1229 vim_free(di);
86d71ae0c85a updated for version 7.0042
vimboss
parents: 117
diff changeset
1230 return;
86d71ae0c85a updated for version 7.0042
vimboss
parents: 117
diff changeset
1231 }
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1232 lp->ll_tv = &di->di_tv;
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1233 }
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1234 else if (op != NULL && *op != '=')
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1235 {
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1236 tv_op(lp->ll_tv, rettv, op);
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1237 return;
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1238 }
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1239 else
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1240 clear_tv(lp->ll_tv);
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1241
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1242 /*
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1243 * Assign the value to the variable or list item.
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1244 */
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1245 if (copy)
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1246 copy_tv(rettv, lp->ll_tv);
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1247 else
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1248 {
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1249 *lp->ll_tv = *rettv;
156
c5b05f6de1ad updated for version 7.0047
vimboss
parents: 151
diff changeset
1250 lp->ll_tv->v_lock = 0;
110
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1251 init_tv(rettv);
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1252 }
3b1d692e5a2c updated for version 7.0040
vimboss
parents: 104
diff changeset
1253 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1254 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1255
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1256 /*
15790
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1257 * 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
1258 * and "tv1 .= tv2"
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1259 * Returns OK or FAIL.
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1260 */
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1261 static int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1262 tv_op(typval_T *tv1, typval_T *tv2, char_u *op)
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1263 {
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
1264 varnumber_T n;
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1265 char_u numbuf[NUMBUFLEN];
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1266 char_u *s;
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1267
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1268 // 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
1269 if (tv2->v_type != VAR_FUNC && tv2->v_type != VAR_DICT
19102
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 19087
diff changeset
1270 && tv2->v_type != VAR_BOOL && tv2->v_type != VAR_SPECIAL)
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1271 {
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1272 switch (tv1->v_type)
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1273 {
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
1274 case VAR_UNKNOWN:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
1275 case VAR_VOID:
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1276 case VAR_DICT:
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1277 case VAR_FUNC:
8538
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
1278 case VAR_PARTIAL:
19102
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 19087
diff changeset
1279 case VAR_BOOL:
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
1280 case VAR_SPECIAL:
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
1281 case VAR_JOB:
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
1282 case VAR_CHANNEL:
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1283 break;
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1284
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1285 case VAR_BLOB:
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1286 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
1287 break;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1288 // BLOB += BLOB
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1289 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
1290 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1291 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
1292 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
1293 int i, len = blob_len(b2);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1294 for (i = 0; i < len; i++)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1295 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
1296 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1297 return OK;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1298
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1299 case VAR_LIST:
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1300 if (*op != '+' || tv2->v_type != VAR_LIST)
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1301 break;
15790
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1302 // List += List
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1303 if (tv1->vval.v_list != NULL && tv2->vval.v_list != NULL)
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1304 list_extend(tv1->vval.v_list, tv2->vval.v_list, NULL);
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1305 return OK;
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1306
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1307 case VAR_NUMBER:
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1308 case VAR_STRING:
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1309 if (tv2->v_type == VAR_LIST)
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1310 break;
15790
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1311 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
1312 {
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1313 // 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
1314 n = tv_get_number(tv1);
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1315 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1316 if (tv2->v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1317 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1318 float_T f = n;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1319
15790
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1320 if (*op == '%')
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1321 break;
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1322 switch (*op)
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1323 {
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1324 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
1325 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
1326 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
1327 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
1328 }
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1329 clear_tv(tv1);
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1330 tv1->v_type = VAR_FLOAT;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1331 tv1->vval.v_float = f;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1332 }
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1333 else
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1334 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1335 {
15790
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1336 switch (*op)
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1337 {
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1338 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
1339 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
1340 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
1341 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
1342 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
1343 }
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1344 clear_tv(tv1);
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1345 tv1->v_type = VAR_NUMBER;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1346 tv1->vval.v_number = n;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1347 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1348 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1349 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1350 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1351 if (tv2->v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1352 break;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1353
15790
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1354 // str .= str
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
1355 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
1356 s = concat_str(s, tv_get_string_buf(tv2, numbuf));
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1357 clear_tv(tv1);
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1358 tv1->v_type = VAR_STRING;
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1359 tv1->vval.v_string = s;
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1360 }
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1361 return OK;
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1362
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1363 case VAR_FLOAT:
8364
991d8fd4d841 commit https://github.com/vim/vim/commit/5fac467474376a844407cecc0ff481510ead221c
Christian Brabandt <cb@256bit.org>
parents: 8350
diff changeset
1364 #ifdef FEAT_FLOAT
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1365 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1366 float_T f;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1367
15790
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1368 if (*op == '%' || *op == '.'
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1369 || (tv2->v_type != VAR_FLOAT
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1370 && tv2->v_type != VAR_NUMBER
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1371 && tv2->v_type != VAR_STRING))
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1372 break;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1373 if (tv2->v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1374 f = tv2->vval.v_float;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1375 else
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
1376 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
1377 switch (*op)
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1378 {
05d836c8f1c4 patch 8.1.0902: incomplete set of assignment operators
Bram Moolenaar <Bram@vim.org>
parents: 15784
diff changeset
1379 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
1380 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
1381 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
1382 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
1383 }
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1384 }
8364
991d8fd4d841 commit https://github.com/vim/vim/commit/5fac467474376a844407cecc0ff481510ead221c
Christian Brabandt <cb@256bit.org>
parents: 8350
diff changeset
1385 #endif
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
1386 return OK;
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1387 }
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1388 }
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1389
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
1390 semsg(_(e_letwrong), op);
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1391 return FAIL;
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1392 }
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1393
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
1394 /*
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1395 * Evaluate the expression used in a ":for var in expr" command.
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1396 * "arg" points to "var".
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1397 * Set "*errp" to TRUE for an error, FALSE otherwise;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1398 * Return a pointer that holds the info. Null when there is an error.
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1399 */
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1400 void *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1401 eval_for_line(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1402 char_u *arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1403 int *errp,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1404 char_u **nextcmdp,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1405 int skip)
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1406 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
1407 forinfo_T *fi;
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1408 char_u *expr;
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
1409 typval_T tv;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
1410 list_T *l;
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1411
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1412 *errp = TRUE; // default: there is an error
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1413
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
1414 fi = ALLOC_CLEAR_ONE(forinfo_T);
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1415 if (fi == NULL)
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1416 return NULL;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1417
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
1418 expr = skip_var_list(arg, TRUE, &fi->fi_varcount, &fi->fi_semicolon);
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1419 if (expr == NULL)
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1420 return fi;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1421
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1422 expr = skipwhite(expr);
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
1423 if (expr[0] != 'i' || expr[1] != 'n' || !VIM_ISWHITE(expr[2]))
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1424 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
1425 emsg(_(e_missing_in));
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1426 return fi;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1427 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1428
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1429 if (skip)
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1430 ++emsg_skip;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1431 if (eval0(skipwhite(expr + 2), &tv, nextcmdp, !skip) == OK)
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1432 {
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1433 *errp = FALSE;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1434 if (!skip)
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1435 {
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1436 if (tv.v_type == VAR_LIST)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1437 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1438 l = tv.vval.v_list;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1439 if (l == NULL)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1440 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1441 // 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
1442 clear_tv(&tv);
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
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1445 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
1446 // Need a real list here.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
1447 range_list_materialize(l);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
1448
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1449 // 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
1450 // the list being used in "tv".
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1451 fi->fi_list = l;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1452 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
1453 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
1454 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1455 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1456 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
1457 {
15581
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
1458 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
1459 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
1460 {
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
1461 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
1462
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
1463 // 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
1464 // blob is changed.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
1465 blob_copy(tv.vval.v_blob, &btv);
15581
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
1466 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
1467 }
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
1468 clear_tv(&tv);
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1469 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1470 else
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 357
diff changeset
1471 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
1472 emsg(_(e_listreq));
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 357
diff changeset
1473 clear_tv(&tv);
6c62b9b939bd updated for version 7.0093
vimboss
parents: 357
diff changeset
1474 }
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1475 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1476 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1477 if (skip)
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1478 --emsg_skip;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1479
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1480 return fi;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1481 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1482
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1483 /*
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1484 * Use the first item in a ":for" list. Advance to the next.
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1485 * Assign the values to the variable (list). "arg" points to the first one.
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1486 * Return TRUE when a valid item was found, FALSE when at end of list or
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1487 * something wrong.
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1488 */
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1489 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1490 next_for_item(void *fi_void, char_u *arg)
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1491 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4936
diff changeset
1492 forinfo_T *fi = (forinfo_T *)fi_void;
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1493 int result;
19568
c0749ad6c699 patch 8.2.0341: using ":for" in Vim9 script gives an error
Bram Moolenaar <Bram@vim.org>
parents: 19554
diff changeset
1494 int flag = current_sctx.sc_version == SCRIPT_VERSION_VIM9 ?
c0749ad6c699 patch 8.2.0341: using ":for" in Vim9 script gives an error
Bram Moolenaar <Bram@vim.org>
parents: 19554
diff changeset
1495 LET_NO_COMMAND : 0;
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
1496 listitem_T *item;
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1497
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1498 if (fi->fi_blob != NULL)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1499 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1500 typval_T tv;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1501
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1502 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
1503 return FALSE;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1504 tv.v_type = VAR_NUMBER;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1505 tv.v_lock = VAR_FIXED;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1506 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
1507 ++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
1508 return ex_let_vars(arg, &tv, TRUE, fi->fi_semicolon,
19568
c0749ad6c699 patch 8.2.0341: using ":for" in Vim9 script gives an error
Bram Moolenaar <Bram@vim.org>
parents: 19554
diff changeset
1509 fi->fi_varcount, flag, NULL) == OK;
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1510 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
1511
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1512 item = fi->fi_lw.lw_item;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1513 if (item == NULL)
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1514 result = FALSE;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1515 else
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1516 {
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1517 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
1518 result = (ex_let_vars(arg, &item->li_tv, TRUE, fi->fi_semicolon,
19568
c0749ad6c699 patch 8.2.0341: using ":for" in Vim9 script gives an error
Bram Moolenaar <Bram@vim.org>
parents: 19554
diff changeset
1519 fi->fi_varcount, flag, NULL) == OK);
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1520 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1521 return result;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1522 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1523
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1524 /*
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1525 * Free the structure used to store info used by ":for".
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1526 */
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1527 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1528 free_for_info(void *fi_void)
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1529 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
1530 forinfo_T *fi = (forinfo_T *)fi_void;
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1531
92
a9e90b3356b6 updated for version 7.0036
vimboss
parents: 88
diff changeset
1532 if (fi != NULL && fi->fi_list != NULL)
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 357
diff changeset
1533 {
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1534 list_rem_watch(fi->fi_list, &fi->fi_lw);
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 357
diff changeset
1535 list_unref(fi->fi_list);
6c62b9b939bd updated for version 7.0093
vimboss
parents: 357
diff changeset
1536 }
15460
543cff56dd3f patch 8.1.0738: using freed memory, for loop over blob leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 15458
diff changeset
1537 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
1538 blob_unref(fi->fi_blob);
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1539 vim_free(fi);
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1540 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1541
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1542 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1543 set_context_for_expression(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1544 expand_T *xp,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1545 char_u *arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1546 cmdidx_T cmdidx)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1547 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1548 int got_eq = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1549 int c;
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1550 char_u *p;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1551
18713
baf890fa1621 patch 8.1.2348: :const cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents: 18301
diff changeset
1552 if (cmdidx == CMD_let || cmdidx == CMD_const)
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1553 {
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1554 xp->xp_context = EXPAND_USER_VARS;
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
1555 if (vim_strpbrk(arg, (char_u *)"\"'+-*/%.=!?~|&$([<>,#") == NULL)
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1556 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1557 // ":let var1 var2 ...": find last space.
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
1558 for (p = arg + STRLEN(arg); p >= arg; )
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1559 {
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1560 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
1561 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
1562 if (VIM_ISWHITE(*p))
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1563 break;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1564 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1565 return;
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1566 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1567 }
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1568 else
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1569 xp->xp_context = cmdidx == CMD_call ? EXPAND_FUNCTIONS
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1570 : EXPAND_EXPRESSION;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1571 while ((xp->xp_pattern = vim_strpbrk(arg,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1572 (char_u *)"\"'+-*/%.=!?~|&$([<>,#")) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1573 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1574 c = *xp->xp_pattern;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1575 if (c == '&')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1576 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1577 c = xp->xp_pattern[1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1578 if (c == '&')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1579 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1580 ++xp->xp_pattern;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1581 xp->xp_context = cmdidx != CMD_let || got_eq
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1582 ? EXPAND_EXPRESSION : EXPAND_NOTHING;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1583 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1584 else if (c != ' ')
201
300fac7c5a2b updated for version 7.0059
vimboss
parents: 192
diff changeset
1585 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1586 xp->xp_context = EXPAND_SETTINGS;
201
300fac7c5a2b updated for version 7.0059
vimboss
parents: 192
diff changeset
1587 if ((c == 'l' || c == 'g') && xp->xp_pattern[2] == ':')
300fac7c5a2b updated for version 7.0059
vimboss
parents: 192
diff changeset
1588 xp->xp_pattern += 2;
300fac7c5a2b updated for version 7.0059
vimboss
parents: 192
diff changeset
1589
300fac7c5a2b updated for version 7.0059
vimboss
parents: 192
diff changeset
1590 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1591 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1592 else if (c == '$')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1593 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1594 // environment variable
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1595 xp->xp_context = EXPAND_ENV_VARS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1596 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1597 else if (c == '=')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1598 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1599 got_eq = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1600 xp->xp_context = EXPAND_EXPRESSION;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1601 }
8763
4b83af41f5db commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents: 8749
diff changeset
1602 else if (c == '#'
4b83af41f5db commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents: 8749
diff changeset
1603 && xp->xp_context == EXPAND_EXPRESSION)
4b83af41f5db commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents: 8749
diff changeset
1604 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1605 // Autoload function/variable contains '#'.
8763
4b83af41f5db commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents: 8749
diff changeset
1606 break;
4b83af41f5db commit https://github.com/vim/vim/commit/a32095fc8fdf5fe3d487c86d9cc54adb1236731e
Christian Brabandt <cb@256bit.org>
parents: 8749
diff changeset
1607 }
6367
81c9b19ee0fb updated for version 7.4.516
Bram Moolenaar <bram@vim.org>
parents: 6361
diff changeset
1608 else if ((c == '<' || c == '#')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1609 && xp->xp_context == EXPAND_FUNCTIONS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1610 && vim_strchr(xp->xp_pattern, '(') == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1611 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1612 // Function name can start with "<SNR>" and contain '#'.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1613 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1614 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1615 else if (cmdidx != CMD_let || got_eq)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1616 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1617 if (c == '"') // string
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1618 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1619 while ((c = *++xp->xp_pattern) != NUL && c != '"')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1620 if (c == '\\' && xp->xp_pattern[1] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1621 ++xp->xp_pattern;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1622 xp->xp_context = EXPAND_NOTHING;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1623 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1624 else if (c == '\'') // literal string
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1625 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1626 // Trick: '' is like stopping and starting a literal string.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1627 while ((c = *++xp->xp_pattern) != NUL && c != '\'')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1628 /* skip */ ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1629 xp->xp_context = EXPAND_NOTHING;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1630 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1631 else if (c == '|')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1632 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1633 if (xp->xp_pattern[1] == '|')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1634 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1635 ++xp->xp_pattern;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1636 xp->xp_context = EXPAND_EXPRESSION;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1637 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1638 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1639 xp->xp_context = EXPAND_COMMANDS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1640 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1641 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1642 xp->xp_context = EXPAND_EXPRESSION;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1643 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1644 else
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1645 // 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
1646 // anyway.
76
0ef9cebc4f5d updated for version 7.0031
vimboss
parents: 71
diff changeset
1647 xp->xp_context = EXPAND_EXPRESSION;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1648 arg = xp->xp_pattern;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1649 if (*arg != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1650 while ((c = *++arg) != NUL && (c == ' ' || c == '\t'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1651 /* skip */ ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1652 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1653 xp->xp_pattern = arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1654 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1655
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1656 /*
8749
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1657 * Return TRUE if "pat" matches "text".
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1658 * 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
1659 */
17377
cb008de2a6ec patch 8.1.1687: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17375
diff changeset
1660 int
8749
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1661 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
1662 {
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1663 int matches = FALSE;
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1664 char_u *save_cpo;
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1665 regmatch_T regmatch;
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1666
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1667 // avoid 'l' flag in 'cpoptions'
8749
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1668 save_cpo = p_cpo;
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1669 p_cpo = (char_u *)"";
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1670 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
1671 if (regmatch.regprog != NULL)
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1672 {
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1673 regmatch.rm_ic = ic;
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1674 matches = vim_regexec_nl(&regmatch, text, (colnr_T)0);
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1675 vim_regfree(regmatch.regprog);
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1676 }
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1677 p_cpo = save_cpo;
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1678 return matches;
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1679 }
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1680
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
1681 /*
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1682 * 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
1683 * "expr->name(arg)".
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1684 * Returns OK or FAIL.
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 static int
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1687 eval_func(
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1688 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
1689 char_u *name,
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1690 int name_len,
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1691 typval_T *rettv,
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1692 int evaluate,
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1693 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
1694 {
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1695 char_u *s = name;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1696 int len = name_len;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1697 partial_T *partial;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1698 int ret = OK;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1699
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1700 if (!evaluate)
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1701 check_vars(s, len);
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1702
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1703 // 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
1704 // use its contents.
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1705 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
1706
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1707 // 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
1708 // the name invalid.
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1709 s = vim_strsave(s);
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1710 if (s == NULL)
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1711 ret = FAIL;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1712 else
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1713 {
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1714 funcexe_T funcexe;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1715
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1716 // Invoke the function.
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1717 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
1718 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
1719 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
1720 funcexe.evaluate = evaluate;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1721 funcexe.partial = partial;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1722 funcexe.basetv = basetv;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1723 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
1724 }
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1725 vim_free(s);
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1726
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1727 // 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
1728 // 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
1729 // 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
1730 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
1731 {
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1732 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
1733 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
1734 }
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1735
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1736 // 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
1737 // 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
1738 // 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
1739 if (evaluate && aborting())
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1740 {
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1741 if (ret == OK)
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1742 clear_tv(rettv);
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1743 ret = FAIL;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1744 }
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1745 return ret;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1746 }
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1747
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1748 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1749 * The "evaluate" argument: When FALSE, the argument is only parsed but not
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
1750 * executed. The function may return OK, but the rettv will be of type
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1751 * VAR_UNKNOWN. The function still returns FAIL for a syntax error.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1752 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1753
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1754 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1755 * Handle zero level expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1756 * This calls eval1() and handles error message and nextcmd.
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
1757 * Put the result in "rettv" when returning OK and "evaluate" is TRUE.
533
c8b6b7e1005d updated for version 7.0150
vimboss
parents: 531
diff changeset
1758 * Note: "rettv.v_lock" is not set.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1759 * Return OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1760 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1761 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1762 eval0(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1763 char_u *arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1764 typval_T *rettv,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1765 char_u **nextcmd,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1766 int evaluate)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1767 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1768 int ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1769 char_u *p;
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1770 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
1771 int called_emsg_before = called_emsg;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1772
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1773 p = skipwhite(arg);
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
1774 ret = eval1(&p, rettv, evaluate);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1775 if (ret == FAIL || !ends_excmd(*p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1776 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1777 if (ret != FAIL)
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
1778 clear_tv(rettv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1779 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1780 * Report the invalid expression unless the expression evaluation has
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1781 * 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
1782 * 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
1783 * Also check called_emsg for when using assert_fails().
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1784 */
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
1785 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
1786 && 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
1787 semsg(_(e_invexpr2), arg);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1788 ret = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1789 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1790 if (nextcmd != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1791 *nextcmd = check_nextcmd(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1792
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1793 return ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1794 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1795
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1796 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1797 * Handle top level expression:
1800
e7633eb32cfd updated for version 7.2-098
vimboss
parents: 1794
diff changeset
1798 * expr2 ? expr1 : expr1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1799 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1800 * "arg" must point to the first non-white of the expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1801 * "arg" is advanced to the next non-white after the recognized expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1802 *
533
c8b6b7e1005d updated for version 7.0150
vimboss
parents: 531
diff changeset
1803 * Note: "rettv.v_lock" is not set.
c8b6b7e1005d updated for version 7.0150
vimboss
parents: 531
diff changeset
1804 *
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1805 * Return OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1806 */
9556
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents: 9527
diff changeset
1807 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1808 eval1(char_u **arg, typval_T *rettv, int evaluate)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1809 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1810 int result;
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
1811 typval_T var2;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1812
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1813 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1814 * Get the first variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1815 */
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
1816 if (eval2(arg, rettv, evaluate) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1817 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1818
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1819 if ((*arg)[0] == '?')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1820 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1821 result = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1822 if (evaluate)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1823 {
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
1824 int error = FALSE;
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
1825
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
1826 if (tv_get_number_chk(rettv, &error) != 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1827 result = TRUE;
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
1828 clear_tv(rettv);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
1829 if (error)
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
1830 return FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1831 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1832
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1833 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1834 * Get the second variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1835 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1836 *arg = skipwhite(*arg + 1);
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1837 if (eval1(arg, rettv, evaluate && result) == FAIL) // recursive!
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1838 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1839
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1840 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1841 * Check for the ":".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1842 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1843 if ((*arg)[0] != ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1844 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
1845 emsg(_(e_missing_colon));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1846 if (evaluate && result)
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
1847 clear_tv(rettv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1848 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1849 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1850
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1851 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1852 * Get the third variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1853 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1854 *arg = skipwhite(*arg + 1);
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1855 if (eval1(arg, &var2, evaluate && !result) == FAIL) // recursive!
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1856 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1857 if (evaluate && result)
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
1858 clear_tv(rettv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1859 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1860 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1861 if (evaluate && !result)
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
1862 *rettv = var2;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1863 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1864
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1865 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1866 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1867
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1868 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1869 * Handle first level expression:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1870 * expr2 || expr2 || expr2 logical OR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1871 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1872 * "arg" must point to the first non-white of the expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1873 * "arg" is advanced to the next non-white after the recognized expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1874 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1875 * Return OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1876 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1877 static int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1878 eval2(char_u **arg, typval_T *rettv, int evaluate)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1879 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
1880 typval_T var2;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1881 long result;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1882 int first;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
1883 int error = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1884
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1885 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1886 * Get the first variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1887 */
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
1888 if (eval3(arg, rettv, evaluate) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1889 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1890
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1891 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1892 * Repeat until there is no following "||".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1893 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1894 first = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1895 result = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1896 while ((*arg)[0] == '|' && (*arg)[1] == '|')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1897 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1898 if (evaluate && first)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1899 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
1900 if (tv_get_number_chk(rettv, &error) != 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1901 result = TRUE;
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
1902 clear_tv(rettv);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
1903 if (error)
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
1904 return FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1905 first = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1906 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1907
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1908 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1909 * Get the second variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1910 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1911 *arg = skipwhite(*arg + 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1912 if (eval3(arg, &var2, evaluate && !result) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1913 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1914
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1915 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1916 * Compute the result.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1917 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1918 if (evaluate && !result)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1919 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
1920 if (tv_get_number_chk(&var2, &error) != 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1921 result = TRUE;
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
1922 clear_tv(&var2);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
1923 if (error)
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
1924 return FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1925 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1926 if (evaluate)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1927 {
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
1928 rettv->v_type = VAR_NUMBER;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
1929 rettv->vval.v_number = result;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1930 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1931 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1932
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1933 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1934 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1935
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1936 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1937 * Handle second level expression:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1938 * expr3 && expr3 && expr3 logical AND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1939 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1940 * "arg" must point to the first non-white of the expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1941 * "arg" is advanced to the next non-white after the recognized expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1942 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1943 * Return OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1944 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1945 static int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
1946 eval3(char_u **arg, typval_T *rettv, int evaluate)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1947 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
1948 typval_T var2;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1949 long result;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1950 int first;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
1951 int error = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1952
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1953 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1954 * Get the first variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1955 */
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
1956 if (eval4(arg, rettv, evaluate) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1957 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1958
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1959 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1960 * Repeat until there is no following "&&".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1961 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1962 first = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1963 result = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1964 while ((*arg)[0] == '&' && (*arg)[1] == '&')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1965 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1966 if (evaluate && first)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1967 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
1968 if (tv_get_number_chk(rettv, &error) == 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1969 result = FALSE;
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
1970 clear_tv(rettv);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
1971 if (error)
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
1972 return FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1973 first = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1974 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1975
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1976 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1977 * Get the second variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1978 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1979 *arg = skipwhite(*arg + 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1980 if (eval4(arg, &var2, evaluate && result) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1981 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1982
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1983 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1984 * Compute the result.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1985 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1986 if (evaluate && result)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1987 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
1988 if (tv_get_number_chk(&var2, &error) == 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1989 result = FALSE;
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
1990 clear_tv(&var2);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
1991 if (error)
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
1992 return FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1993 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1994 if (evaluate)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1995 {
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
1996 rettv->v_type = VAR_NUMBER;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
1997 rettv->vval.v_number = result;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1998 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1999 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2000
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2001 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2002 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2003
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2004 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2005 * Handle third level expression:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2006 * var1 == var2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2007 * var1 =~ var2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2008 * var1 != var2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2009 * var1 !~ var2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2010 * var1 > var2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2011 * var1 >= var2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2012 * var1 < var2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2013 * var1 <= var2
80
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
2014 * var1 is var2
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
2015 * var1 isnot var2
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2016 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2017 * "arg" must point to the first non-white of the expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2018 * "arg" is advanced to the next non-white after the recognized expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2019 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2020 * Return OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2021 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2022 static int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
2023 eval4(char_u **arg, typval_T *rettv, int evaluate)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2024 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
2025 typval_T var2;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2026 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2027 int i;
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
2028 exptype_T type = EXPR_UNKNOWN;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2029 int len = 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2030 int ic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2031
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2032 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2033 * Get the first variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2034 */
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2035 if (eval5(arg, rettv, evaluate) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2036 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2037
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2038 p = *arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2039 switch (p[0])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2040 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2041 case '=': if (p[1] == '=')
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
2042 type = EXPR_EQUAL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2043 else if (p[1] == '~')
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
2044 type = EXPR_MATCH;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2045 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2046 case '!': if (p[1] == '=')
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
2047 type = EXPR_NEQUAL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2048 else if (p[1] == '~')
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
2049 type = EXPR_NOMATCH;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2050 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2051 case '>': if (p[1] != '=')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2052 {
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
2053 type = EXPR_GREATER;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2054 len = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2055 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2056 else
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
2057 type = EXPR_GEQUAL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2058 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2059 case '<': if (p[1] != '=')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2060 {
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
2061 type = EXPR_SMALLER;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2062 len = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2063 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2064 else
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
2065 type = EXPR_SEQUAL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2066 break;
80
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
2067 case 'i': if (p[1] == 's')
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
2068 {
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
2069 if (p[2] == 'n' && p[3] == 'o' && p[4] == 't')
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
2070 len = 5;
7064
5fc5c5bf2233 commit https://github.com/vim/vim/commit/37a8de17d4dfd3d463960c38a204ce399c8e19d4
Christian Brabandt <cb@256bit.org>
parents: 7046
diff changeset
2071 i = p[len];
5fc5c5bf2233 commit https://github.com/vim/vim/commit/37a8de17d4dfd3d463960c38a204ce399c8e19d4
Christian Brabandt <cb@256bit.org>
parents: 7046
diff changeset
2072 if (!isalnum(i) && i != '_')
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
2073 type = len == 2 ? EXPR_IS : EXPR_ISNOT;
80
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
2074 }
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
2075 break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2076 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2077
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2078 /*
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2079 * If there is a comparative operator, use it.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2080 */
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
2081 if (type != EXPR_UNKNOWN)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2082 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2083 // extra question mark appended: ignore case
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2084 if (p[len] == '?')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2085 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2086 ic = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2087 ++len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2088 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2089 // extra '#' appended: match case
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2090 else if (p[len] == '#')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2091 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2092 ic = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2093 ++len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2094 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2095 // nothing appended: use 'ignorecase'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2096 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2097 ic = p_ic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2098
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2099 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2100 * Get the second variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2101 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2102 *arg = skipwhite(p + len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2103 if (eval5(arg, &var2, evaluate) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2104 {
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2105 clear_tv(rettv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2106 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2107 }
13274
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
2108 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
2109 {
18966
6bd715870e32 patch 8.2.0044: expression type is used inconsistently
Bram Moolenaar <Bram@vim.org>
parents: 18939
diff changeset
2110 int ret = typval_compare(rettv, &var2, type, ic);
13274
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
2111
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
2112 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
2113 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
2114 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2115 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2116
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2117 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2118 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2119
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2120 void
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2121 eval_addblob(typval_T *tv1, typval_T *tv2)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2122 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2123 blob_T *b1 = tv1->vval.v_blob;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2124 blob_T *b2 = tv2->vval.v_blob;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2125 blob_T *b = blob_alloc();
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2126 int i;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2127
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2128 if (b != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2129 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2130 for (i = 0; i < blob_len(b1); i++)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2131 ga_append(&b->bv_ga, blob_get(b1, i));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2132 for (i = 0; i < blob_len(b2); i++)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2133 ga_append(&b->bv_ga, blob_get(b2, i));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2134
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2135 clear_tv(tv1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2136 rettv_blob_set(tv1, b);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2137 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2138 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2139
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2140 int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2141 eval_addlist(typval_T *tv1, typval_T *tv2)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2142 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2143 typval_T var3;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2144
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2145 // concatenate Lists
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2146 if (list_concat(tv1->vval.v_list, tv2->vval.v_list, &var3) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2147 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2148 clear_tv(tv1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2149 clear_tv(tv2);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2150 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2151 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2152 clear_tv(tv1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2153 *tv1 = var3;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2154 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2155 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2156
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2157 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2158 * Handle fourth level expression:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2159 * + number addition
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2160 * - number subtraction
16223
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
2161 * . 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
2162 * .. string concatenation
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2163 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2164 * "arg" must point to the first non-white of the expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2165 * "arg" is advanced to the next non-white after the recognized expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2166 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2167 * Return OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2168 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2169 static int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
2170 eval5(char_u **arg, typval_T *rettv, int evaluate)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2171 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
2172 typval_T var2;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2173 int op;
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
2174 varnumber_T n1, n2;
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2175 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2176 float_T f1 = 0, f2 = 0;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2177 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2178 char_u *s1, *s2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2179 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2180 char_u *p;
16223
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
2181 int concat;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2182
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2183 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2184 * Get the first variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2185 */
1655
6412b0befebc updated for version 7.2a-007
vimboss
parents: 1653
diff changeset
2186 if (eval6(arg, rettv, evaluate, FALSE) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2187 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2188
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2189 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2190 * Repeat computing, until no '+', '-' or '.' is following.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2191 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2192 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2193 {
16223
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
2194 // "." is only string concatenation when scriptversion is 1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2195 op = **arg;
16223
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
2196 concat = op == '.'
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
2197 && (*(*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
2198 if (op != '+' && op != '-' && !concat)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2199 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2200
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
2201 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
2202 && rettv->v_type != VAR_BLOB))
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2203 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2204 && (op == '.' || rettv->v_type != VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2205 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2206 )
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2207 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2208 // 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
2209 // 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
2210 // 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
2211 // 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
2212 // 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
2213 // 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
2214 // 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
2215 if (evaluate && tv_get_string_chk(rettv) == NULL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2216 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2217 clear_tv(rettv);
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2218 return FAIL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2219 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2220 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2221
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2222 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2223 * Get the second variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2224 */
16219
bd49e1656c72 patch 8.1.1114: confusing overloaded operator "." for string concatenation
Bram Moolenaar <Bram@vim.org>
parents: 16170
diff changeset
2225 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
2226 ++*arg;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2227 *arg = skipwhite(*arg + 1);
1655
6412b0befebc updated for version 7.2a-007
vimboss
parents: 1653
diff changeset
2228 if (eval6(arg, &var2, evaluate, op == '.') == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2229 {
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2230 clear_tv(rettv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2231 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2232 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2233
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2234 if (evaluate)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2235 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2236 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2237 * Compute the result.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2238 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2239 if (op == '.')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2240 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2241 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
2242 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
2243 if (s2 == NULL) // type error ?
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2244 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2245 clear_tv(rettv);
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2246 clear_tv(&var2);
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2247 return FAIL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2248 }
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
2249 p = concat_str(s1, s2);
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2250 clear_tv(rettv);
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2251 rettv->v_type = VAR_STRING;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2252 rettv->vval.v_string = p;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2253 }
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
2254 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
2255 && var2.v_type == VAR_BLOB)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2256 eval_addblob(rettv, &var2);
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
2257 else if (op == '+' && rettv->v_type == VAR_LIST
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
2258 && var2.v_type == VAR_LIST)
80
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
2259 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2260 if (eval_addlist(rettv, &var2) == FAIL)
80
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
2261 return FAIL;
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
2262 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2263 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2264 {
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2265 int error = FALSE;
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2266
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2267 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2268 if (rettv->v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2269 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2270 f1 = rettv->vval.v_float;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2271 n1 = 0;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2272 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2273 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2274 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2275 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
2276 n1 = tv_get_number_chk(rettv, &error);
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2277 if (error)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2278 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2279 // 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
2280 // "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
2281 // before evaluating the 2nd operand.
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2282 clear_tv(rettv);
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2283 return FAIL;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2284 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2285 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2286 if (var2.v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2287 f1 = n1;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2288 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2289 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2290 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2291 if (var2.v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2292 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2293 f2 = var2.vval.v_float;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2294 n2 = 0;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2295 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2296 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2297 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2298 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
2299 n2 = tv_get_number_chk(&var2, &error);
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2300 if (error)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2301 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2302 clear_tv(rettv);
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2303 clear_tv(&var2);
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2304 return FAIL;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2305 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2306 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2307 if (rettv->v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2308 f2 = n2;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2309 #endif
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2310 }
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2311 clear_tv(rettv);
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2312
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2313 #ifdef FEAT_FLOAT
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2314 // If there is a float on either side the result is a float.
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2315 if (rettv->v_type == VAR_FLOAT || var2.v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2316 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2317 if (op == '+')
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2318 f1 = f1 + f2;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2319 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2320 f1 = f1 - f2;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2321 rettv->v_type = VAR_FLOAT;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2322 rettv->vval.v_float = f1;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2323 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2324 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2325 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2326 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2327 if (op == '+')
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2328 n1 = n1 + n2;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2329 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2330 n1 = n1 - n2;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2331 rettv->v_type = VAR_NUMBER;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2332 rettv->vval.v_number = n1;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2333 }
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2334 }
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2335 clear_tv(&var2);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2336 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2337 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2338 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2339 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2340
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2341 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2342 * Handle fifth level expression:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2343 * * number multiplication
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2344 * / number division
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2345 * % number modulo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2346 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2347 * "arg" must point to the first non-white of the expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2348 * "arg" is advanced to the next non-white after the recognized expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2349 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2350 * Return OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2351 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2352 static int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
2353 eval6(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
2354 char_u **arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
2355 typval_T *rettv,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
2356 int evaluate,
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2357 int want_string) // after "." operator
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2358 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
2359 typval_T var2;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2360 int op;
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
2361 varnumber_T n1, n2;
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2362 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2363 int use_float = FALSE;
16405
840fa633ad64 patch 8.1.1207: some compilers give warning messages
Bram Moolenaar <Bram@vim.org>
parents: 16366
diff changeset
2364 float_T f1 = 0, f2 = 0;
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2365 #endif
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2366 int error = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2367
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2368 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2369 * Get the first variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2370 */
1655
6412b0befebc updated for version 7.2a-007
vimboss
parents: 1653
diff changeset
2371 if (eval7(arg, rettv, evaluate, want_string) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2372 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2373
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2374 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2375 * Repeat computing, until no '*', '/' or '%' is following.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2376 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2377 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2378 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2379 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
2380 if (op != '*' && op != '/' && op != '%')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2381 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2382
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2383 if (evaluate)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2384 {
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2385 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2386 if (rettv->v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2387 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2388 f1 = rettv->vval.v_float;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2389 use_float = TRUE;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2390 n1 = 0;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2391 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2392 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2393 #endif
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
2394 n1 = tv_get_number_chk(rettv, &error);
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2395 clear_tv(rettv);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2396 if (error)
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2397 return FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2398 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2399 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2400 n1 = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2401
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2402 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2403 * Get the second variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2404 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2405 *arg = skipwhite(*arg + 1);
1655
6412b0befebc updated for version 7.2a-007
vimboss
parents: 1653
diff changeset
2406 if (eval7(arg, &var2, evaluate, FALSE) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2407 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2408
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2409 if (evaluate)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2410 {
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2411 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2412 if (var2.v_type == VAR_FLOAT)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2413 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2414 if (!use_float)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2415 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2416 f1 = n1;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2417 use_float = TRUE;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2418 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2419 f2 = var2.vval.v_float;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2420 n2 = 0;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2421 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2422 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2423 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2424 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
2425 n2 = tv_get_number_chk(&var2, &error);
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2426 clear_tv(&var2);
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2427 if (error)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2428 return FAIL;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2429 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2430 if (use_float)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2431 f2 = n2;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2432 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2433 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2434
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2435 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2436 * Compute the result.
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2437 * When either side is a float the result is a float.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2438 */
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2439 #ifdef FEAT_FLOAT
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2440 if (use_float)
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2441 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2442 if (op == '*')
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2443 f1 = f1 * f2;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2444 else if (op == '/')
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2445 {
2441
620a42739426 Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2427
diff changeset
2446 # ifdef VMS
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2447 // 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
2448 if (f2 == 0.0)
620a42739426 Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2427
diff changeset
2449 {
620a42739426 Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2427
diff changeset
2450 if (f1 == 0)
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2451 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
2452 else if (f1 < 0)
2529
2aaa88366cbb Fix for float values on VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2513
diff changeset
2453 f1 = -1 * __F_FLT_MAX;
2441
620a42739426 Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2427
diff changeset
2454 else
2529
2aaa88366cbb Fix for float values on VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2513
diff changeset
2455 f1 = __F_FLT_MAX;
2441
620a42739426 Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2427
diff changeset
2456 }
620a42739426 Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2427
diff changeset
2457 else
620a42739426 Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2427
diff changeset
2458 f1 = f1 / f2;
620a42739426 Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2427
diff changeset
2459 # else
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2460 // 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
2461 // by zero to result in "inf" and not a crash.
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2462 f1 = f1 / f2;
2441
620a42739426 Improvements for VMS. (Zoltan Arpadffy)
Bram Moolenaar <bram@vim.org>
parents: 2427
diff changeset
2463 # endif
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2464 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2465 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2466 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2467 emsg(_(e_modulus));
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2468 return FAIL;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2469 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2470 rettv->v_type = VAR_FLOAT;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2471 rettv->vval.v_float = f1;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2472 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2473 else
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2474 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2475 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2476 if (op == '*')
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2477 n1 = n1 * n2;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2478 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
2479 n1 = num_divide(n1, n2);
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2480 else
15969
9cc42db77a54 patch 8.1.0990: floating point exception with "%= 0" and "/= 0"
Bram Moolenaar <Bram@vim.org>
parents: 15904
diff changeset
2481 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
2482
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2483 rettv->v_type = VAR_NUMBER;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2484 rettv->vval.v_number = n1;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2485 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2486 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2487 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2488
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2489 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2490 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2491
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2492 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2493 * Handle sixth level expression:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2494 * number number constant
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
2495 * 0zFFFFFFFF Blob constant
1228
5eb1ac6f92ad updated for version 7.1b
vimboss
parents: 1109
diff changeset
2496 * "string" string constant
5eb1ac6f92ad updated for version 7.1b
vimboss
parents: 1109
diff changeset
2497 * 'string' literal string constant
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2498 * &option-name option value
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2499 * @r register contents
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2500 * identifier variable value
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2501 * function() function call
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2502 * $VAR environment variable
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2503 * (expression) nested expression
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 142
diff changeset
2504 * [expr, expr] List
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2505 * {arg, arg -> expr} Lambda
17368
6604ecb7a615 patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents: 17322
diff changeset
2506 * {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
2507 * #{key: val, key: val} Dictionary with literal keys
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2508 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2509 * Also handle:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2510 * ! in front logical NOT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2511 * - in front unary minus
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2512 * + in front unary plus (ignored)
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2513 * trailing [] subscript in String or List
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2514 * 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
2515 * trailing ->name() method call
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2516 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2517 * "arg" must point to the first non-white of the expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2518 * "arg" is advanced to the next non-white after the recognized expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2519 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2520 * Return OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2521 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2522 static int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
2523 eval7(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
2524 char_u **arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
2525 typval_T *rettv,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
2526 int evaluate,
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2527 int want_string) // after "." operator
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2528 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2529 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2530 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2531 char_u *start_leader, *end_leader;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2532 int ret = OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2533 char_u *alias;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2534
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2535 /*
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2536 * Initialise variable so that clear_tv() can't mistake this for a
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
2537 * string and free a string that isn't there.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2538 */
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2539 rettv->v_type = VAR_UNKNOWN;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2540
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2541 /*
10042
4aead6a9b7a9 commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents: 10000
diff changeset
2542 * Skip '!', '-' and '+' characters. They are handled later.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2543 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2544 start_leader = *arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2545 while (**arg == '!' || **arg == '-' || **arg == '+')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2546 *arg = skipwhite(*arg + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2547 end_leader = *arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2548
16223
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
2549 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
2550 #ifdef FEAT_FLOAT
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
2551 || 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
2552 #endif
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
2553 ))
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
2554 {
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
2555 semsg(_(e_invexpr2), *arg);
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
2556 ++*arg;
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
2557 return FAIL;
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
2558 }
abb67309c1ca patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents: 16219
diff changeset
2559
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2560 switch (**arg)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2561 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2562 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2563 * Number constant.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2564 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2565 case '0':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2566 case '1':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2567 case '2':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2568 case '3':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2569 case '4':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2570 case '5':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2571 case '6':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2572 case '7':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2573 case '8':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2574 case '9':
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2575 case '.': ret = get_number_tv(arg, rettv, evaluate, want_string);
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2576 break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2577
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2578 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2579 * String constant: "string".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2580 */
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2581 case '"': ret = get_string_tv(arg, rettv, evaluate);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2582 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2583
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2584 /*
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2585 * Literal string constant: 'str''ing'.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2586 */
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2587 case '\'': ret = get_lit_string_tv(arg, rettv, evaluate);
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
2588 break;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
2589
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
2590 /*
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
2591 * List: [expr, expr]
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
2592 */
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2593 case '[': ret = get_list_tv(arg, rettv, evaluate, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2594 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2595
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2596 /*
17413
40417757dffd patch 8.1.1705: using ~{} for a literal dict is not nice
Bram Moolenaar <Bram@vim.org>
parents: 17387
diff changeset
2597 * 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
2598 */
17413
40417757dffd patch 8.1.1705: using ~{} for a literal dict is not nice
Bram Moolenaar <Bram@vim.org>
parents: 17387
diff changeset
2599 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
2600 {
6604ecb7a615 patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents: 17322
diff changeset
2601 ++*arg;
19047
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 19017
diff changeset
2602 ret = eval_dict(arg, rettv, evaluate, TRUE);
17368
6604ecb7a615 patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents: 17322
diff changeset
2603 }
6604ecb7a615 patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents: 17322
diff changeset
2604 else
6604ecb7a615 patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents: 17322
diff changeset
2605 ret = NOTDONE;
6604ecb7a615 patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents: 17322
diff changeset
2606 break;
6604ecb7a615 patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents: 17322
diff changeset
2607
6604ecb7a615 patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents: 17322
diff changeset
2608 /*
9527
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9525
diff changeset
2609 * 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
2610 * Dictionary: {'key': val, 'key': val}
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2611 */
9527
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9525
diff changeset
2612 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
2613 if (ret == NOTDONE)
19047
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 19017
diff changeset
2614 ret = eval_dict(arg, rettv, evaluate, FALSE);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2615 break;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2616
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2617 /*
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
2618 * Option value: &name
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2619 */
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
2620 case '&': ret = get_option_tv(arg, rettv, evaluate);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2621 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2622
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2623 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2624 * Environment variable: $VAR.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2625 */
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2626 case '$': ret = get_env_tv(arg, rettv, evaluate);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2627 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2628
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2629 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2630 * Register contents: @r.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2631 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2632 case '@': ++*arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2633 if (evaluate)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2634 {
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2635 rettv->v_type = VAR_STRING;
5796
f084024c0ddb updated for version 7.4.242
Bram Moolenaar <bram@vim.org>
parents: 5794
diff changeset
2636 rettv->vval.v_string = get_reg_contents(**arg,
f084024c0ddb updated for version 7.4.242
Bram Moolenaar <bram@vim.org>
parents: 5794
diff changeset
2637 GREG_EXPR_SRC);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2638 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2639 if (**arg != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2640 ++*arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2641 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2642
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2643 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2644 * nested expression: (expression).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2645 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2646 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
2647 ret = eval1(arg, rettv, evaluate); // recursive!
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2648 if (**arg == ')')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2649 ++*arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2650 else if (ret == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2651 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2652 emsg(_(e_missing_close));
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
2653 clear_tv(rettv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2654 ret = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2655 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2656 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2657
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2658 default: ret = NOTDONE;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2659 break;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2660 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2661
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2662 if (ret == NOTDONE)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2663 {
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2664 /*
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2665 * Must be a variable or function name.
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2666 * Can also be a curly-braces kind of name: {expr}.
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2667 */
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2668 s = *arg;
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
2669 len = get_name_len(arg, &alias, evaluate, TRUE);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2670 if (alias != NULL)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2671 s = alias;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2672
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
2673 if (len <= 0)
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2674 ret = FAIL;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2675 else
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2676 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2677 if (**arg == '(') // recursive!
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2678 ret = eval_func(arg, s, len, rettv, evaluate, NULL);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2679 else if (evaluate)
6791
1805e45ce4d6 patch 7.4.717
Bram Moolenaar <bram@vim.org>
parents: 6773
diff changeset
2680 ret = get_var_tv(s, len, rettv, NULL, TRUE, FALSE);
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
2681 else
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
2682 {
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
2683 check_vars(s, len);
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
2684 ret = OK;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
2685 }
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2686 }
2690
3ea3dcbf2cd6 updated for version 7.3.108
Bram Moolenaar <bram@vim.org>
parents: 2687
diff changeset
2687 vim_free(alias);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2688 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2689
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2690 *arg = skipwhite(*arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2691
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2692 // 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
2693 // expr(expr), expr->name(expr)
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
2694 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
2695 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
2696 start_leader, &end_leader);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2697
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2698 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2699 * Apply logical NOT and unary '-', from right to left, ignore '+'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2700 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2701 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
2702 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
2703 return ret;
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2704 }
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2705
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2706 /*
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2707 * 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
2708 * 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
2709 */
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2710 static int
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2711 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
2712 {
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2713 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
2714 int ret = OK;
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2715 int error = FALSE;
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2716 varnumber_T val = 0;
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2717 #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
2718 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
2719
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2720 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
2721 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
2722 else
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2723 #endif
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2724 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
2725 if (error)
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2726 {
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2727 clear_tv(rettv);
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2728 ret = FAIL;
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2729 }
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2730 else
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2731 {
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2732 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
2733 {
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2734 --end_leader;
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2735 if (*end_leader == '!')
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2736 {
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2737 #ifdef FEAT_FLOAT
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2738 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
2739 f = !f;
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2740 else
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2741 #endif
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2742 val = !val;
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2743 }
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2744 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
2745 {
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2746 #ifdef FEAT_FLOAT
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2747 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
2748 f = -f;
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2749 else
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2750 #endif
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2751 val = -val;
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2752 }
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2753 }
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2754 #ifdef FEAT_FLOAT
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2755 if (rettv->v_type == VAR_FLOAT)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2756 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2757 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
2758 rettv->vval.v_float = f;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2759 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
2760 else
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
2761 #endif
17763
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2762 {
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2763 clear_tv(rettv);
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
2764 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
2765 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
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 *end_leaderp = end_leader;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2769 return ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2770 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2771
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2772 /*
17674
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2773 * 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
2774 */
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2775 static int
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2776 call_func_rettv(
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2777 char_u **arg,
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2778 typval_T *rettv,
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2779 int evaluate,
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2780 dict_T *selfdict,
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2781 typval_T *basetv)
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2782 {
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2783 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
2784 funcexe_T funcexe;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2785 typval_T functv;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2786 char_u *s;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2787 int ret;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2788
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2789 // 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
2790 if (evaluate)
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2791 {
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2792 functv = *rettv;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2793 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
2794
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2795 // 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
2796 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
2797 {
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2798 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
2799 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
2800 }
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2801 else
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2802 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
2803 }
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2804 else
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2805 s = (char_u *)"";
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2806
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2807 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
2808 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
2809 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
2810 funcexe.evaluate = evaluate;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2811 funcexe.partial = pt;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2812 funcexe.selfdict = selfdict;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2813 funcexe.basetv = basetv;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2814 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
2815
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2816 // 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
2817 // 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
2818 if (evaluate)
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2819 clear_tv(&functv);
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2820
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2821 return ret;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2822 }
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2823
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2824 /*
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2825 * Evaluate "->method()".
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2826 * "*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
2827 * 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
2828 */
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2829 static int
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2830 eval_lambda(
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2831 char_u **arg,
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2832 typval_T *rettv,
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2833 int evaluate,
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2834 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
2835 {
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2836 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
2837 int ret;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2838
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2839 // Skip over the ->.
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2840 *arg += 2;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2841 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
2842
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2843 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
2844 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
2845 return FAIL;
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2846 else if (**arg != '(')
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2847 {
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2848 if (verbose)
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 if (*skipwhite(*arg) == '(')
19760
9daed26b788b patch 8.2.0436: no warnings for incorrect printf arguments
Bram Moolenaar <Bram@vim.org>
parents: 19568
diff changeset
2851 emsg(_(e_nowhitespace));
17674
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2852 else
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2853 semsg(_(e_missing_paren), "lambda");
17674
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2854 }
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2855 clear_tv(rettv);
18225
6c3a8312486d patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents: 18080
diff changeset
2856 ret = FAIL;
17674
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2857 }
18225
6c3a8312486d patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents: 18080
diff changeset
2858 else
6c3a8312486d patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents: 18080
diff changeset
2859 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
2860
6c3a8312486d patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents: 18080
diff changeset
2861 // 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
2862 // 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
2863 if (evaluate)
6c3a8312486d patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents: 18080
diff changeset
2864 clear_tv(&base);
6c3a8312486d patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents: 18080
diff changeset
2865
6c3a8312486d patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents: 18080
diff changeset
2866 return ret;
17674
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
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2869 /*
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2870 * Evaluate "->method()".
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2871 * "*arg" points to the '-'.
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2872 * 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
2873 */
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2874 static int
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2875 eval_method(
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2876 char_u **arg,
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2877 typval_T *rettv,
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2878 int evaluate,
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2879 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
2880 {
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2881 char_u *name;
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2882 long len;
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2883 char_u *alias;
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2884 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
2885 int ret;
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2886
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2887 // Skip over the ->.
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2888 *arg += 2;
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2889 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
2890
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2891 name = *arg;
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2892 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
2893 if (alias != NULL)
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2894 name = alias;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2895
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2896 if (len <= 0)
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2897 {
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2898 if (verbose)
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2899 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
2900 ret = FAIL;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2901 }
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2902 else
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2903 {
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2904 if (**arg != '(')
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2905 {
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2906 if (verbose)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2907 semsg(_(e_missing_paren), name);
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2908 ret = FAIL;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2909 }
17661
da7890e3359b patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents: 17646
diff changeset
2910 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
2911 {
da7890e3359b patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents: 17646
diff changeset
2912 if (verbose)
19760
9daed26b788b patch 8.2.0436: no warnings for incorrect printf arguments
Bram Moolenaar <Bram@vim.org>
parents: 19568
diff changeset
2913 emsg(_(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
2914 ret = FAIL;
da7890e3359b patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents: 17646
diff changeset
2915 }
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2916 else
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
2917 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
2918 }
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2919
17674
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
2920 // 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
2921 // 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
2922 if (evaluate)
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2923 clear_tv(&base);
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2924
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2925 return ret;
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2926 }
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2927
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2928 /*
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 826
diff changeset
2929 * Evaluate an "[expr]" or "[expr:expr]" index. Also "dict.key".
dc8197342755 updated for version 7.0d04
vimboss
parents: 826
diff changeset
2930 * "*arg" points to the '[' or '.'.
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
2931 * Returns FAIL or OK. "*arg" is advanced to after the ']'.
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
2932 */
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
2933 static int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
2934 eval_index(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
2935 char_u **arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
2936 typval_T *rettv,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
2937 int evaluate,
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2938 int verbose) // give error messages
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
2939 {
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
2940 int empty1 = FALSE, empty2 = FALSE;
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
2941 typval_T var1, var2;
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
2942 long i;
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
2943 long n1, n2 = 0;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2944 long len = -1;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2945 int range = FALSE;
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
2946 char_u *s;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2947 char_u *key = NULL;
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
2948
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
2949 switch (rettv->v_type)
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
2950 {
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
2951 case VAR_FUNC:
8538
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
2952 case VAR_PARTIAL:
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
2953 if (verbose)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
2954 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
2955 return FAIL;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
2956 case VAR_FLOAT:
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
2957 #ifdef FEAT_FLOAT
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
2958 if (verbose)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
2959 emsg(_(e_float_as_string));
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
2960 return FAIL;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
2961 #endif
19102
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 19087
diff changeset
2962 case VAR_BOOL:
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
2963 case VAR_SPECIAL:
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
2964 case VAR_JOB:
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
2965 case VAR_CHANNEL:
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
2966 if (verbose)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
2967 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
2968 return FAIL;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
2969 case VAR_UNKNOWN:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
2970 case VAR_VOID:
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
2971 if (evaluate)
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
2972 return FAIL;
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2973 // FALLTHROUGH
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
2974
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
2975 case VAR_STRING:
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
2976 case VAR_NUMBER:
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
2977 case VAR_LIST:
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
2978 case VAR_DICT:
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
2979 case VAR_BLOB:
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
2980 break;
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
2981 }
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
2982
7046
fd409a0800fd commit https://github.com/vim/vim/commit/0a38dd29d6f65aa601162542a5ab0ba7f308fc8e
Christian Brabandt <cb@256bit.org>
parents: 7042
diff changeset
2983 init_tv(&var1);
fd409a0800fd commit https://github.com/vim/vim/commit/0a38dd29d6f65aa601162542a5ab0ba7f308fc8e
Christian Brabandt <cb@256bit.org>
parents: 7042
diff changeset
2984 init_tv(&var2);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2985 if (**arg == '.')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2986 {
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2987 /*
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2988 * dict.name
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2989 */
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2990 key = *arg + 1;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2991 for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; ++len)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2992 ;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2993 if (len == 0)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2994 return FAIL;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2995 *arg = skipwhite(key + len);
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2996 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2997 else
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2998 {
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
2999 /*
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3000 * something[idx]
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3001 *
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3002 * Get the (first) variable from inside the [].
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3003 */
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3004 *arg = skipwhite(*arg + 1);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3005 if (**arg == ':')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3006 empty1 = TRUE;
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3007 else if (eval1(arg, &var1, evaluate) == FAIL) // recursive!
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3008 return FAIL;
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
3009 else if (evaluate && tv_get_string_chk(&var1) == NULL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3010 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3011 // not a number or string
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3012 clear_tv(&var1);
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3013 return FAIL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3014 }
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3015
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3016 /*
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3017 * Get the second variable from inside the [:].
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3018 */
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3019 if (**arg == ':')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3020 {
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3021 range = TRUE;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3022 *arg = skipwhite(*arg + 1);
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3023 if (**arg == ']')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3024 empty2 = TRUE;
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3025 else if (eval1(arg, &var2, evaluate) == FAIL) // recursive!
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3026 {
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3027 if (!empty1)
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3028 clear_tv(&var1);
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3029 return FAIL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3030 }
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
3031 else if (evaluate && tv_get_string_chk(&var2) == NULL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3032 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3033 // not a number or string
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3034 if (!empty1)
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3035 clear_tv(&var1);
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3036 clear_tv(&var2);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3037 return FAIL;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3038 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3039 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3040
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3041 // Check for the ']'.
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3042 if (**arg != ']')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3043 {
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
3044 if (verbose)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
3045 emsg(_(e_missbrac));
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3046 clear_tv(&var1);
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3047 if (range)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3048 clear_tv(&var2);
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3049 return FAIL;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3050 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3051 *arg = skipwhite(*arg + 1); // skip the ']'
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3052 }
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3053
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3054 if (evaluate)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3055 {
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3056 n1 = 0;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3057 if (!empty1 && rettv->v_type != VAR_DICT)
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3058 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
3059 n1 = tv_get_number(&var1);
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3060 clear_tv(&var1);
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3061 }
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3062 if (range)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3063 {
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3064 if (empty2)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3065 n2 = -1;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3066 else
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3067 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
3068 n2 = tv_get_number(&var2);
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3069 clear_tv(&var2);
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3070 }
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3071 }
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3072
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3073 switch (rettv->v_type)
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3074 {
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
3075 case VAR_UNKNOWN:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3076 case VAR_VOID:
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
3077 case VAR_FUNC:
8538
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
3078 case VAR_PARTIAL:
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
3079 case VAR_FLOAT:
19102
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 19087
diff changeset
3080 case VAR_BOOL:
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
3081 case VAR_SPECIAL:
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
3082 case VAR_JOB:
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
3083 case VAR_CHANNEL:
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3084 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
3085
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3086 case VAR_NUMBER:
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3087 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
3088 s = tv_get_string(rettv);
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3089 len = (long)STRLEN(s);
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3090 if (range)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3091 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3092 // 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
3093 // are out of range the result is empty.
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3094 if (n1 < 0)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3095 {
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3096 n1 = len + n1;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3097 if (n1 < 0)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3098 n1 = 0;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3099 }
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3100 if (n2 < 0)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3101 n2 = len + n2;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3102 else if (n2 >= len)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3103 n2 = len;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3104 if (n1 >= len || n2 < 0 || n1 > n2)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3105 s = NULL;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3106 else
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3107 s = vim_strnsave(s + n1, (int)(n2 - n1 + 1));
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3108 }
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3109 else
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3110 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3111 // 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
3112 // 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
3113 // result is empty.
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3114 if (n1 >= len || n1 < 0)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3115 s = NULL;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3116 else
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3117 s = vim_strnsave(s + n1, 1);
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3118 }
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3119 clear_tv(rettv);
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3120 rettv->v_type = VAR_STRING;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3121 rettv->vval.v_string = s;
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3122 break;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3123
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3124 case VAR_BLOB:
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3125 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
3126 if (range)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3127 {
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
3128 // 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
3129 // 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
3130 if (n1 < 0)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3131 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3132 n1 = len + n1;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3133 if (n1 < 0)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3134 n1 = 0;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3135 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3136 if (n2 < 0)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3137 n2 = len + n2;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3138 else if (n2 >= len)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3139 n2 = len - 1;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3140 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
3141 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3142 clear_tv(rettv);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3143 rettv->v_type = VAR_BLOB;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3144 rettv->vval.v_blob = NULL;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3145 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3146 else
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3147 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3148 blob_T *blob = blob_alloc();
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3149
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3150 if (blob != NULL)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3151 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3152 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
3153 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3154 blob_free(blob);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3155 return FAIL;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3156 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3157 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
3158 for (i = n1; i <= n2; i++)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3159 blob_set(blob, i - n1,
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3160 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
3161
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3162 clear_tv(rettv);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3163 rettv_blob_set(rettv, blob);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3164 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3165 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3166 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3167 else
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3168 {
15589
44ea60ca593b patch 8.1.0802: negative index doesn't work for Blob
Bram Moolenaar <Bram@vim.org>
parents: 15581
diff changeset
3169 // 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
3170 // 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
3171 if (n1 < 0)
44ea60ca593b patch 8.1.0802: negative index doesn't work for Blob
Bram Moolenaar <Bram@vim.org>
parents: 15581
diff changeset
3172 n1 = len + n1;
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3173 if (n1 < len && n1 >= 0)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3174 {
15589
44ea60ca593b patch 8.1.0802: negative index doesn't work for Blob
Bram Moolenaar <Bram@vim.org>
parents: 15581
diff changeset
3175 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
3176
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3177 clear_tv(rettv);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3178 rettv->v_type = VAR_NUMBER;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3179 rettv->vval.v_number = v;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3180 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3181 else
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
3182 semsg(_(e_blobidx), n1);
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3183 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3184 break;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3185
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3186 case VAR_LIST:
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3187 len = list_len(rettv->vval.v_list);
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3188 if (n1 < 0)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3189 n1 = len + n1;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3190 if (!empty1 && (n1 < 0 || n1 >= len))
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3191 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3192 // 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
3193 // list. A list index out of range is an error.
842
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
3194 if (!range)
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
3195 {
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
3196 if (verbose)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
3197 semsg(_(e_listidx), n1);
842
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
3198 return FAIL;
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
3199 }
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
3200 n1 = len;
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3201 }
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3202 if (range)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3203 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
3204 list_T *l;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
3205 listitem_T *item;
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3206
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3207 if (n2 < 0)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3208 n2 = len + n2;
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 826
diff changeset
3209 else if (n2 >= len)
dc8197342755 updated for version 7.0d04
vimboss
parents: 826
diff changeset
3210 n2 = len - 1;
dc8197342755 updated for version 7.0d04
vimboss
parents: 826
diff changeset
3211 if (!empty2 && (n2 < 0 || n2 + 1 < n1))
842
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
3212 n2 = -1;
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3213 l = list_alloc();
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3214 if (l == NULL)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3215 return FAIL;
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3216 for (item = list_find(rettv->vval.v_list, n1);
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3217 n1 <= n2; ++n1)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3218 {
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3219 if (list_append_tv(l, &item->li_tv) == FAIL)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3220 {
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
3221 list_free(l);
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3222 return FAIL;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3223 }
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3224 item = item->li_next;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3225 }
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3226 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
3227 rettv_list_set(rettv, l);
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3228 }
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3229 else
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3230 {
842
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
3231 copy_tv(&list_find(rettv->vval.v_list, n1)->li_tv, &var1);
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3232 clear_tv(rettv);
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3233 *rettv = var1;
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3234 }
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3235 break;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3236
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3237 case VAR_DICT:
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3238 if (range)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3239 {
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
3240 if (verbose)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
3241 emsg(_(e_dictrange));
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3242 if (len == -1)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3243 clear_tv(&var1);
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3244 return FAIL;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3245 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3246 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
3247 dictitem_T *item;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3248
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3249 if (len == -1)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3250 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
3251 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
3252 if (key == NULL)
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3253 {
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3254 clear_tv(&var1);
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3255 return FAIL;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3256 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3257 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3258
121
86d71ae0c85a updated for version 7.0042
vimboss
parents: 117
diff changeset
3259 item = dict_find(rettv->vval.v_dict, key, (int)len);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3260
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
3261 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
3262 semsg(_(e_dictkey), key);
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3263 if (len == -1)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3264 clear_tv(&var1);
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3265 if (item == NULL)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3266 return FAIL;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3267
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3268 copy_tv(&item->di_tv, &var1);
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3269 clear_tv(rettv);
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3270 *rettv = var1;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3271 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3272 break;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3273 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3274 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3275
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3276 return OK;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3277 }
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3278
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
3279 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3280 * Get an option value.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3281 * "arg" points to the '&' or '+' before the option name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3282 * "arg" is advanced to character after the option name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3283 * Return OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3284 */
9571
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9562
diff changeset
3285 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
3286 get_option_tv(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
3287 char_u **arg,
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3288 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
3289 int evaluate)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3290 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3291 char_u *option_end;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3292 long numval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3293 char_u *stringval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3294 int opt_type;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3295 int c;
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3296 int working = (**arg == '+'); // has("+option")
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3297 int ret = OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3298 int opt_flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3299
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3300 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3301 * Isolate the option name and find its value.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3302 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3303 option_end = find_option_end(arg, &opt_flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3304 if (option_end == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3305 {
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3306 if (rettv != NULL)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
3307 semsg(_("E112: Option name missing: %s"), *arg);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3308 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3309 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3310
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3311 if (!evaluate)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3312 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3313 *arg = option_end;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3314 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3315 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3316
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3317 c = *option_end;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3318 *option_end = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3319 opt_type = get_option_value(*arg, &numval,
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3320 rettv == NULL ? NULL : &stringval, opt_flags);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3321
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3322 if (opt_type == -3) // invalid name
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3323 {
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3324 if (rettv != NULL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3325 semsg(_(e_unknown_option), *arg);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3326 ret = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3327 }
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3328 else if (rettv != NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3329 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3330 if (opt_type == -2) // hidden string option
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3331 {
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3332 rettv->v_type = VAR_STRING;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3333 rettv->vval.v_string = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3334 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3335 else if (opt_type == -1) // hidden number option
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3336 {
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3337 rettv->v_type = VAR_NUMBER;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3338 rettv->vval.v_number = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3339 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3340 else if (opt_type == 1) // number option
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3341 {
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3342 rettv->v_type = VAR_NUMBER;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3343 rettv->vval.v_number = numval;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3344 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3345 else // string option
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3346 {
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3347 rettv->v_type = VAR_STRING;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
3348 rettv->vval.v_string = stringval;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3349 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3350 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3351 else if (working && (opt_type == -2 || opt_type == -1))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3352 ret = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3353
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3354 *option_end = c; // put back for error messages
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3355 *arg = option_end;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3356
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3357 return ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3358 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3359
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3360 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3361 * Allocate a variable for a number constant. Also deals with "0z" for blob.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3362 * Return OK or FAIL.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3363 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3364 int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3365 get_number_tv(
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3366 char_u **arg,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3367 typval_T *rettv,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3368 int evaluate,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3369 int want_string UNUSED)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3370 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3371 int len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3372 #ifdef FEAT_FLOAT
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3373 char_u *p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3374 int get_float = FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3375
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3376 // We accept a float when the format matches
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3377 // "[0-9]\+\.[0-9]\+\([eE][+-]\?[0-9]\+\)\?". This is very
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3378 // strict to avoid backwards compatibility problems.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3379 // With script version 2 and later the leading digit can be
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3380 // omitted.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3381 // Don't look for a float after the "." operator, so that
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3382 // ":let vers = 1.2.3" doesn't fail.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3383 if (**arg == '.')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3384 p = *arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3385 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3386 p = skipdigits(*arg + 1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3387 if (!want_string && p[0] == '.' && vim_isdigit(p[1]))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3388 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3389 get_float = TRUE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3390 p = skipdigits(p + 2);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3391 if (*p == 'e' || *p == 'E')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3392 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3393 ++p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3394 if (*p == '-' || *p == '+')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3395 ++p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3396 if (!vim_isdigit(*p))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3397 get_float = FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3398 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3399 p = skipdigits(p + 1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3400 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3401 if (ASCII_ISALPHA(*p) || *p == '.')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3402 get_float = FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3403 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3404 if (get_float)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3405 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3406 float_T f;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3407
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3408 *arg += string2float(*arg, &f);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3409 if (evaluate)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3410 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3411 rettv->v_type = VAR_FLOAT;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3412 rettv->vval.v_float = f;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3413 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3414 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3415 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3416 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3417 if (**arg == '0' && ((*arg)[1] == 'z' || (*arg)[1] == 'Z'))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3418 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3419 char_u *bp;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3420 blob_T *blob = NULL; // init for gcc
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3421
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3422 // Blob constant: 0z0123456789abcdef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3423 if (evaluate)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3424 blob = blob_alloc();
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3425 for (bp = *arg + 2; vim_isxdigit(bp[0]); bp += 2)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3426 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3427 if (!vim_isxdigit(bp[1]))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3428 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3429 if (blob != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3430 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3431 emsg(_("E973: Blob literal should have an even number of hex characters"));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3432 ga_clear(&blob->bv_ga);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3433 VIM_CLEAR(blob);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3434 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3435 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3436 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3437 if (blob != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3438 ga_append(&blob->bv_ga,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3439 (hex2nr(*bp) << 4) + hex2nr(*(bp+1)));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3440 if (bp[2] == '.' && vim_isxdigit(bp[3]))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3441 ++bp;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3442 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3443 if (blob != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3444 rettv_blob_set(rettv, blob);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3445 *arg = bp;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3446 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3447 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3448 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3449 varnumber_T n;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3450
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3451 // decimal, hex or octal number
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3452 vim_str2nr(*arg, NULL, &len, current_sctx.sc_version >= 4
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3453 ? STR2NR_NO_OCT + STR2NR_QUOTE
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3454 : STR2NR_ALL, &n, NULL, 0, TRUE);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3455 if (len == 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3456 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3457 semsg(_(e_invexpr2), *arg);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3458 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3459 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3460 *arg += len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3461 if (evaluate)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3462 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3463 rettv->v_type = VAR_NUMBER;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3464 rettv->vval.v_number = n;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3465 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3466 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3467 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3468 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3469
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3470 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3471 * Allocate a variable for a string constant.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3472 * Return OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3473 */
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3474 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
3475 get_string_tv(char_u **arg, typval_T *rettv, int evaluate)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3476 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3477 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3478 char_u *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3479 int extra = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3480
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3481 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3482 * Find the end of the string, skipping backslashed characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3483 */
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 10964
diff changeset
3484 for (p = *arg + 1; *p != NUL && *p != '"'; MB_PTR_ADV(p))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3485 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3486 if (*p == '\\' && p[1] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3487 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3488 ++p;
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3489 // 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
3490 // to 6 characters: reserve space for 2 extra
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3491 if (*p == '<')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3492 extra += 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3493 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3494 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3495
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3496 if (*p != '"')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3497 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
3498 semsg(_("E114: Missing quote: %s"), *arg);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3499 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3500 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3501
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3502 // If only parsing, set *arg and return here
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3503 if (!evaluate)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3504 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3505 *arg = p + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3506 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3507 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3508
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3509 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3510 * Copy the string into allocated memory, handling backslashed
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3511 * characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3512 */
16764
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16706
diff changeset
3513 name = alloc(p - *arg + extra);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3514 if (name == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3515 return FAIL;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3516 rettv->v_type = VAR_STRING;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3517 rettv->vval.v_string = name;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3518
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3519 for (p = *arg + 1; *p != NUL && *p != '"'; )
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3520 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3521 if (*p == '\\')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3522 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3523 switch (*++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3524 {
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3525 case 'b': *name++ = BS; ++p; break;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3526 case 'e': *name++ = ESC; ++p; break;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3527 case 'f': *name++ = FF; ++p; break;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3528 case 'n': *name++ = NL; ++p; break;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3529 case 'r': *name++ = CAR; ++p; break;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3530 case 't': *name++ = TAB; ++p; break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3531
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3532 case 'X': // hex: "\x1", "\x12"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3533 case 'x':
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3534 case 'u': // Unicode: "\u0023"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3535 case 'U':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3536 if (vim_isxdigit(p[1]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3537 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3538 int n, nr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3539 int c = toupper(*p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3540
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3541 if (c == 'X')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3542 n = 2;
6836
541abe8d5f55 patch 7.4.739
Bram Moolenaar <bram@vim.org>
parents: 6828
diff changeset
3543 else if (*p == 'u')
541abe8d5f55 patch 7.4.739
Bram Moolenaar <bram@vim.org>
parents: 6828
diff changeset
3544 n = 4;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3545 else
6836
541abe8d5f55 patch 7.4.739
Bram Moolenaar <bram@vim.org>
parents: 6828
diff changeset
3546 n = 8;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3547 nr = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3548 while (--n >= 0 && vim_isxdigit(p[1]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3549 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3550 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3551 nr = (nr << 4) + hex2nr(*p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3552 }
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3553 ++p;
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3554 // 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
3555 // 'encoding'.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3556 if (c != 'X')
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3557 name += (*mb_char2bytes)(nr, name);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3558 else
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3559 *name++ = nr;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3560 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3561 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3562
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3563 // octal: "\1", "\12", "\123"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3564 case '0':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3565 case '1':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3566 case '2':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3567 case '3':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3568 case '4':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3569 case '5':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3570 case '6':
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3571 case '7': *name = *p++ - '0';
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3572 if (*p >= '0' && *p <= '7')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3573 {
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3574 *name = (*name << 3) + *p++ - '0';
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3575 if (*p >= '0' && *p <= '7')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3576 *name = (*name << 3) + *p++ - '0';
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3577 }
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3578 ++name;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3579 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3580
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3581 // 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
3582 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
3583 TRUE, NULL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3584 if (extra != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3585 {
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3586 name += extra;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3587 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3588 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3589 // FALLTHROUGH
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3590
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3591 default: MB_COPY_CHAR(p, name);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3592 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3593 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3594 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3595 else
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3596 MB_COPY_CHAR(p, name);
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3597
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3598 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3599 *name = NUL;
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3600 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
3601 ++p;
b329e3ca0dcb commit https://github.com/vim/vim/commit/db249f26edf7a5f88d1f4468d08ec5b84f5ab7ad
Christian Brabandt <cb@256bit.org>
parents: 9915
diff changeset
3602 *arg = p;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3603
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3604 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3605 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3606
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3607 /*
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3608 * Allocate a variable for a 'str''ing' constant.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3609 * Return OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3610 */
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3611 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
3612 get_lit_string_tv(char_u **arg, typval_T *rettv, int evaluate)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3613 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3614 char_u *p;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3615 char_u *str;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3616 int reduce = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3617
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3618 /*
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3619 * Find the end of the string, skipping ''.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3620 */
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 10964
diff changeset
3621 for (p = *arg + 1; *p != NUL; MB_PTR_ADV(p))
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3622 {
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3623 if (*p == '\'')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3624 {
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3625 if (p[1] != '\'')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3626 break;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3627 ++reduce;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3628 ++p;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3629 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3630 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3631
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3632 if (*p != '\'')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3633 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
3634 semsg(_("E115: Missing quote: %s"), *arg);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3635 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3636 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3637
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3638 // If only parsing return after setting "*arg"
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
3639 if (!evaluate)
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
3640 {
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
3641 *arg = p + 1;
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
3642 return OK;
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
3643 }
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
3644
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
3645 /*
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3646 * Copy the string into allocated memory, handling '' to ' reduction.
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
3647 */
16764
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16706
diff changeset
3648 str = alloc((p - *arg) - reduce);
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
3649 if (str == NULL)
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
3650 return FAIL;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3651 rettv->v_type = VAR_STRING;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3652 rettv->vval.v_string = str;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3653
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3654 for (p = *arg + 1; *p != NUL; )
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3655 {
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3656 if (*p == '\'')
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3657 {
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3658 if (p[1] != '\'')
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
3659 break;
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
3660 ++p;
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
3661 }
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3662 MB_COPY_CHAR(p, str);
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3663 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
3664 *str = NUL;
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
3665 *arg = p + 1;
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
3666
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
3667 return OK;
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
3668 }
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
3669
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3670 /*
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3671 * 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
3672 */
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3673 char_u *
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3674 partial_name(partial_T *pt)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3675 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3676 if (pt->pt_name != NULL)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3677 return pt->pt_name;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3678 return pt->pt_func->uf_name;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3679 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3680
8855
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3681 static void
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
3682 partial_free(partial_T *pt)
8855
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3683 {
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3684 int i;
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3685
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3686 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
3687 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
3688 vim_free(pt->pt_argv);
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
3689 dict_unref(pt->pt_dict);
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3690 if (pt->pt_name != NULL)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3691 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3692 func_unref(pt->pt_name);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3693 vim_free(pt->pt_name);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3694 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3695 else
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3696 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
3697 vim_free(pt);
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3698 }
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3699
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3700 /*
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3701 * 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
3702 * becomes zero.
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3703 */
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3704 void
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3705 partial_unref(partial_T *pt)
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3706 {
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3707 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
3708 partial_free(pt);
8855
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3709 }
b76195a1e38e commit https://github.com/vim/vim/commit/ddecc25947dbdd689d5bcaed32f298a08abdd497
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
3710
2634
fcb916bed51a updated for version 7.3.055
Bram Moolenaar <bram@vim.org>
parents: 2610
diff changeset
3711 static int tv_equal_recurse_limit;
fcb916bed51a updated for version 7.3.055
Bram Moolenaar <bram@vim.org>
parents: 2610
diff changeset
3712
9183
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3713 static int
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3714 func_equal(
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3715 typval_T *tv1,
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3716 typval_T *tv2,
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3717 int ic) // ignore case
9183
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3718 {
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3719 char_u *s1, *s2;
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3720 dict_T *d1, *d2;
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3721 int a1, a2;
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3722 int i;
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3723
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3724 // 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
3725 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
3726 : 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
3727 if (s1 != NULL && *s1 == NUL)
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3728 s1 = NULL;
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3729 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
3730 : 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
3731 if (s2 != NULL && *s2 == NUL)
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3732 s2 = NULL;
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3733 if (s1 == NULL || s2 == NULL)
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3734 {
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3735 if (s1 != s2)
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3736 return FALSE;
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3737 }
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3738 else if (STRCMP(s1, s2) != 0)
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3739 return FALSE;
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3740
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3741 // 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
3742 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
3743 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
3744 if (d1 == NULL || d2 == NULL)
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3745 {
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3746 if (d1 != d2)
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3747 return FALSE;
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3748 }
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3749 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
3750 return FALSE;
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3751
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3752 // 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
3753 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
3754 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
3755 if (a1 != a2)
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3756 return FALSE;
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3757 for (i = 0; i < a1; ++i)
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3758 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
3759 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
3760 return FALSE;
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3761
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3762 return TRUE;
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3763 }
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3764
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
3765 /*
80
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
3766 * Return TRUE if "tv1" and "tv2" have the same value.
388
f92bb1845823 updated for version 7.0101
vimboss
parents: 387
diff changeset
3767 * Compares the items just like "==" would compare them, but strings and
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
3768 * numbers are different. Floats and numbers are also different.
80
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
3769 */
9556
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents: 9527
diff changeset
3770 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
3771 tv_equal(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
3772 typval_T *tv1,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
3773 typval_T *tv2,
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3774 int ic, // ignore case
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3775 int recursive) // TRUE when used recursively
80
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
3776 {
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
3777 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN];
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
3778 char_u *s1, *s2;
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3779 static int recursive_cnt = 0; // catch recursive loops
1008
58059676e24a updated for version 7.0-134
vimboss
parents: 998
diff changeset
3780 int r;
58059676e24a updated for version 7.0-134
vimboss
parents: 998
diff changeset
3781
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3782 // 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
3783 // 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
3784 // 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
3785 // 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
3786 // 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
3787 // recursiveness quickly.
2634
fcb916bed51a updated for version 7.3.055
Bram Moolenaar <bram@vim.org>
parents: 2610
diff changeset
3788 if (!recursive)
fcb916bed51a updated for version 7.3.055
Bram Moolenaar <bram@vim.org>
parents: 2610
diff changeset
3789 tv_equal_recurse_limit = 1000;
fcb916bed51a updated for version 7.3.055
Bram Moolenaar <bram@vim.org>
parents: 2610
diff changeset
3790 if (recursive_cnt >= tv_equal_recurse_limit)
fcb916bed51a updated for version 7.3.055
Bram Moolenaar <bram@vim.org>
parents: 2610
diff changeset
3791 {
fcb916bed51a updated for version 7.3.055
Bram Moolenaar <bram@vim.org>
parents: 2610
diff changeset
3792 --tv_equal_recurse_limit;
1014
2651e7d07cd6 updated for version 7.0-140
vimboss
parents: 1009
diff changeset
3793 return TRUE;
2634
fcb916bed51a updated for version 7.3.055
Bram Moolenaar <bram@vim.org>
parents: 2610
diff changeset
3794 }
388
f92bb1845823 updated for version 7.0101
vimboss
parents: 387
diff changeset
3795
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3796 // 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
3797 // arguments.
9183
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3798 if ((tv1->v_type == VAR_FUNC
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3799 || (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
3800 && (tv2->v_type == VAR_FUNC
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3801 || (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
3802 {
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3803 ++recursive_cnt;
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3804 r = func_equal(tv1, tv2, ic);
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3805 --recursive_cnt;
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3806 return r;
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3807 }
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3808
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3809 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
3810 return FALSE;
988c8ab557bf commit https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766
Christian Brabandt <cb@256bit.org>
parents: 9169
diff changeset
3811
388
f92bb1845823 updated for version 7.0101
vimboss
parents: 387
diff changeset
3812 switch (tv1->v_type)
f92bb1845823 updated for version 7.0101
vimboss
parents: 387
diff changeset
3813 {
f92bb1845823 updated for version 7.0101
vimboss
parents: 387
diff changeset
3814 case VAR_LIST:
2634
fcb916bed51a updated for version 7.3.055
Bram Moolenaar <bram@vim.org>
parents: 2610
diff changeset
3815 ++recursive_cnt;
fcb916bed51a updated for version 7.3.055
Bram Moolenaar <bram@vim.org>
parents: 2610
diff changeset
3816 r = list_equal(tv1->vval.v_list, tv2->vval.v_list, ic, TRUE);
fcb916bed51a updated for version 7.3.055
Bram Moolenaar <bram@vim.org>
parents: 2610
diff changeset
3817 --recursive_cnt;
1008
58059676e24a updated for version 7.0-134
vimboss
parents: 998
diff changeset
3818 return r;
388
f92bb1845823 updated for version 7.0101
vimboss
parents: 387
diff changeset
3819
f92bb1845823 updated for version 7.0101
vimboss
parents: 387
diff changeset
3820 case VAR_DICT:
2634
fcb916bed51a updated for version 7.3.055
Bram Moolenaar <bram@vim.org>
parents: 2610
diff changeset
3821 ++recursive_cnt;
fcb916bed51a updated for version 7.3.055
Bram Moolenaar <bram@vim.org>
parents: 2610
diff changeset
3822 r = dict_equal(tv1->vval.v_dict, tv2->vval.v_dict, ic, TRUE);
fcb916bed51a updated for version 7.3.055
Bram Moolenaar <bram@vim.org>
parents: 2610
diff changeset
3823 --recursive_cnt;
1008
58059676e24a updated for version 7.0-134
vimboss
parents: 998
diff changeset
3824 return r;
388
f92bb1845823 updated for version 7.0101
vimboss
parents: 387
diff changeset
3825
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3826 case VAR_BLOB:
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
3827 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
3828
388
f92bb1845823 updated for version 7.0101
vimboss
parents: 387
diff changeset
3829 case VAR_NUMBER:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3830 case VAR_BOOL:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3831 case VAR_SPECIAL:
388
f92bb1845823 updated for version 7.0101
vimboss
parents: 387
diff changeset
3832 return tv1->vval.v_number == tv2->vval.v_number;
f92bb1845823 updated for version 7.0101
vimboss
parents: 387
diff changeset
3833
f92bb1845823 updated for version 7.0101
vimboss
parents: 387
diff changeset
3834 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
3835 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
3836 s2 = tv_get_string_buf(tv2, buf2);
388
f92bb1845823 updated for version 7.0101
vimboss
parents: 387
diff changeset
3837 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
3838
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
3839 case VAR_FLOAT:
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
3840 #ifdef FEAT_FLOAT
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
3841 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
3842 #endif
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
3843 case VAR_JOB:
8493
caed4b2d305f commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents: 8491
diff changeset
3844 #ifdef FEAT_JOB_CHANNEL
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
3845 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
3846 #endif
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
3847 case VAR_CHANNEL:
8493
caed4b2d305f commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents: 8491
diff changeset
3848 #ifdef FEAT_JOB_CHANNEL
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
3849 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
3850 #endif
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3851
8635
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents: 8633
diff changeset
3852 case VAR_FUNC:
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents: 8633
diff changeset
3853 case VAR_PARTIAL:
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
3854 case VAR_UNKNOWN:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
3855 case VAR_VOID:
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
3856 break;
388
f92bb1845823 updated for version 7.0101
vimboss
parents: 387
diff changeset
3857 }
f92bb1845823 updated for version 7.0101
vimboss
parents: 387
diff changeset
3858
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3859 // 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
3860 // 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
3861 return FALSE;
80
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
3862 }
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
3863
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
3864 /*
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
3865 * Return the next (unique) copy ID.
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
3866 * Used for serializing nested structures.
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
3867 */
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
3868 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
3869 get_copyID(void)
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
3870 {
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
3871 current_copyID += COPYID_INC;
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
3872 return current_copyID;
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
3873 }
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
3874
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
3875 /*
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3876 * Garbage collection for lists and dictionaries.
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3877 *
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3878 * We use reference counts to be able to free most items right away when they
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3879 * are no longer used. But for composite items it's possible that it becomes
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3880 * unused while the reference count is > 0: When there is a recursive
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3881 * reference. Example:
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3882 * :let l = [1, 2, 3]
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3883 * :let d = {9: l}
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3884 * :let l[1] = d
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3885 *
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3886 * Since this is quite unusual we handle this with garbage collection: every
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3887 * once in a while find out which lists and dicts are not referenced from any
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3888 * variable.
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3889 *
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3890 * Here is a good reference text about garbage collection (refers to Python
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3891 * but it applies to all reference-counting mechanisms):
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3892 * http://python.ca/nas/python/gc/
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3893 */
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3894
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3895 /*
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3896 * 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
3897 * When "testing" is TRUE this is called from test_garbagecollect_now().
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3898 * Return TRUE if some memory was freed.
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3899 */
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3900 int
8881
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8877
diff changeset
3901 garbage_collect(int testing)
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3902 {
1891
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
3903 int copyID;
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3904 int abort = FALSE;
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3905 buf_T *buf;
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3906 win_T *wp;
6588
1ffe91b5e514 updated for version 7.4.620
Bram Moolenaar <bram@vim.org>
parents: 6577
diff changeset
3907 int did_free = FALSE;
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
3908 tabpage_T *tp;
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3909
8881
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8877
diff changeset
3910 if (!testing)
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8877
diff changeset
3911 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3912 // Only do this once.
8881
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8877
diff changeset
3913 want_garbage_collect = FALSE;
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8877
diff changeset
3914 may_garbage_collect = FALSE;
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8877
diff changeset
3915 garbage_collect_at_exit = FALSE;
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8877
diff changeset
3916 }
958
e88950f0d4f6 updated for version 7.0-084
vimboss
parents: 956
diff changeset
3917
19001
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3918 // The execution stack can grow big, limit the size.
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3919 if (exestack.ga_maxlen - exestack.ga_len > 500)
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3920 {
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3921 size_t new_len;
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3922 char_u *pp;
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3923 int n;
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3924
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3925 // Keep 150% of the current size, with a minimum of the growth size.
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3926 n = exestack.ga_len / 2;
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3927 if (n < exestack.ga_growsize)
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3928 n = exestack.ga_growsize;
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3929
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3930 // Don't make it bigger though.
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3931 if (exestack.ga_len + n < exestack.ga_maxlen)
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3932 {
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3933 new_len = exestack.ga_itemsize * (exestack.ga_len + n);
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3934 pp = vim_realloc(exestack.ga_data, new_len);
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3935 if (pp == NULL)
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3936 return FAIL;
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3937 exestack.ga_maxlen = exestack.ga_len + n;
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3938 exestack.ga_data = pp;
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3939 }
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3940 }
1ebfb46710cd patch 8.2.0061: the execute stack can grow big and never shrinks
Bram Moolenaar <Bram@vim.org>
parents: 18968
diff changeset
3941
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3942 // 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
3943 // previous_funccal.
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
3944 copyID = get_copyID();
1891
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
3945
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3946 /*
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3947 * 1. Go through all accessible variables and mark all lists and dicts
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3948 * with copyID.
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3949 */
1891
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
3950
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3951 // 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
3952 // 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
3953 // 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
3954 abort = abort || set_ref_in_previous_funccal(copyID);
1891
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
3955
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3956 // 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
3957 abort = abort || garbage_collect_scriptvars(copyID);
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3958
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3959 // buffer-local variables
9649
fd9727ae3c49 commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents: 9636
diff changeset
3960 FOR_ALL_BUFFERS(buf)
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3961 abort = abort || set_ref_in_item(&buf->b_bufvar.di_tv, copyID,
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3962 NULL, NULL);
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3963
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3964 // window-local variables
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
3965 FOR_ALL_TAB_WINDOWS(tp, wp)
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3966 abort = abort || set_ref_in_item(&wp->w_winvar.di_tv, copyID,
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3967 NULL, NULL);
4309
bdab73bf24a8 updated for version 7.3.904
Bram Moolenaar <bram@vim.org>
parents: 4297
diff changeset
3968 if (aucmd_win != NULL)
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3969 abort = abort || set_ref_in_item(&aucmd_win->w_winvar.di_tv, copyID,
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3970 NULL, NULL);
18763
49b78d6465e5 patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
3971 #ifdef FEAT_PROP_POPUP
16778
eda4d65f232c patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
3972 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
3973 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
3974 NULL, NULL);
eda4d65f232c patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
3975 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
3976 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
3977 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
3978 NULL, NULL);
eda4d65f232c patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
3979 #endif
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3980
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3981 // tabpage-local variables
9649
fd9727ae3c49 commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents: 9636
diff changeset
3982 FOR_ALL_TABPAGES(tp)
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3983 abort = abort || set_ref_in_item(&tp->tp_winvar.di_tv, copyID,
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
3984 NULL, NULL);
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3985 // 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
3986 abort = abort || garbage_collect_globvars(copyID);
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3987
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3988 // function-local variables
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
3989 abort = abort || set_ref_in_call_stack(copyID);
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
3990
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3991 // named functions (matters for closures)
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
3992 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
3993
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3994 // 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
3995 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
3996
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3997 // 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
3998 abort = abort || garbage_collect_vimvars(copyID);
1733
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1730
diff changeset
3999
17151
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 17085
diff changeset
4000 // callbacks in buffers
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 17085
diff changeset
4001 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
4002
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3435
diff changeset
4003 #ifdef FEAT_LUA
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4004 abort = abort || set_ref_in_lua(copyID);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3435
diff changeset
4005 #endif
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3435
diff changeset
4006
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3600
diff changeset
4007 #ifdef FEAT_PYTHON
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4008 abort = abort || set_ref_in_python(copyID);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3600
diff changeset
4009 #endif
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3600
diff changeset
4010
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3600
diff changeset
4011 #ifdef FEAT_PYTHON3
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4012 abort = abort || set_ref_in_python3(copyID);
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4013 #endif
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4014
8493
caed4b2d305f commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents: 8491
diff changeset
4015 #ifdef FEAT_JOB_CHANNEL
8877
50e40f322e78 commit https://github.com/vim/vim/commit/3780bb923a688e0051a9a23474eeb38a8acb695a
Christian Brabandt <cb@256bit.org>
parents: 8870
diff changeset
4016 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
4017 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
4018 #endif
9052
3a6b66c02d6d commit https://github.com/vim/vim/commit/3266c85a44a637862b0ed6e531680c6ab2897ab5
Christian Brabandt <cb@256bit.org>
parents: 9027
diff changeset
4019 #ifdef FEAT_NETBEANS_INTG
3a6b66c02d6d commit https://github.com/vim/vim/commit/3266c85a44a637862b0ed6e531680c6ab2897ab5
Christian Brabandt <cb@256bit.org>
parents: 9027
diff changeset
4020 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
4021 #endif
7931
2679e636e862 commit https://github.com/vim/vim/commit/4b6a6dcbe7bd13170c4884cc17acb1eac2c633d1
Christian Brabandt <cb@256bit.org>
parents: 7895
diff changeset
4022
9153
c2fe86f2bda1 commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents: 9127
diff changeset
4023 #ifdef FEAT_TIMERS
c2fe86f2bda1 commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents: 9127
diff changeset
4024 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
4025 #endif
c2fe86f2bda1 commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents: 9127
diff changeset
4026
11412
84baca75b7f2 patch 8.0.0590: cannot add a context to locations
Christian Brabandt <cb@256bit.org>
parents: 11323
diff changeset
4027 #ifdef FEAT_QUICKFIX
84baca75b7f2 patch 8.0.0590: cannot add a context to locations
Christian Brabandt <cb@256bit.org>
parents: 11323
diff changeset
4028 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
4029 #endif
84baca75b7f2 patch 8.0.0590: cannot add a context to locations
Christian Brabandt <cb@256bit.org>
parents: 11323
diff changeset
4030
11804
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11418
diff changeset
4031 #ifdef FEAT_TERMINAL
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11418
diff changeset
4032 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
4033 #endif
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11418
diff changeset
4034
18763
49b78d6465e5 patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
4035 #ifdef FEAT_PROP_POPUP
17151
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 17085
diff changeset
4036 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
4037 #endif
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 17085
diff changeset
4038
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4039 if (!abort)
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4040 {
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4041 /*
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4042 * 2. Free lists and dictionaries that are not referenced.
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4043 */
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4044 did_free = free_unref_items(copyID);
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4045
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4046 /*
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4047 * 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
4048 * This may call us back recursively.
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4049 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
4050 free_unref_funccal(copyID, testing);
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4051 }
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4052 else if (p_verbose > 0)
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4053 {
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15517
diff changeset
4054 verb_msg(_("Not enough memory to set references, garbage collection aborted!"));
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4055 }
1891
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
4056
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
4057 return did_free;
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
4058 }
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
4059
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
4060 /*
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4061 * Free lists, dictionaries, channels and jobs that are no longer referenced.
1891
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
4062 */
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
4063 static int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4064 free_unref_items(int copyID)
1891
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
4065 {
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
4066 int did_free = FALSE;
7a4ad3fb109d updated for version 7.2-188
vimboss
parents: 1880
diff changeset
4067
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4068 // 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
4069 // 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
4070 // do that here.
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4071 in_free_unref_items = TRUE;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4072
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4073 /*
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4074 * 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
4075 * 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
4076 */
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4077
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4078 // 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
4079 did_free |= dict_free_nonref(copyID);
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4080
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4081 // 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
4082 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
4083
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4084 #ifdef FEAT_JOB_CHANNEL
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4085 // 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
4086 // 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
4087 // 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
4088 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
4089
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4090 // 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
4091 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
4092 #endif
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4093
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4094 /*
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4095 * PASS 2: free the items themselves.
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4096 */
9556
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents: 9527
diff changeset
4097 dict_free_items(copyID);
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents: 9556
diff changeset
4098 list_free_items(copyID);
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4099
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4100 #ifdef FEAT_JOB_CHANNEL
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4101 // 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
4102 // 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
4103 // 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
4104 free_unused_jobs(copyID, COPYID_MASK);
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4105
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4106 // 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
4107 free_unused_channels(copyID, COPYID_MASK);
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4108 #endif
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4109
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4110 in_free_unref_items = FALSE;
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
4111
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4112 return did_free;
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4113 }
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4114
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4115 /*
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4116 * Mark all lists and dicts referenced through hashtab "ht" with "copyID".
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4117 * "list_stack" is used to add lists to be marked. Can be NULL.
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4118 *
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4119 * Returns TRUE if setting references failed somehow.
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4120 */
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4121 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4122 set_ref_in_ht(hashtab_T *ht, int copyID, list_stack_T **list_stack)
364
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
4123 {
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
4124 int todo;
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4125 int abort = FALSE;
364
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
4126 hashitem_T *hi;
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4127 hashtab_T *cur_ht;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4128 ht_stack_T *ht_stack = NULL;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4129 ht_stack_T *tempitem;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4130
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4131 cur_ht = ht;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4132 for (;;)
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4133 {
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4134 if (!abort)
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4135 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4136 // 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
4137 // 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
4138 // list_stack.
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4139 todo = (int)cur_ht->ht_used;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4140 for (hi = cur_ht->ht_array; todo > 0; ++hi)
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4141 if (!HASHITEM_EMPTY(hi))
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4142 {
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4143 --todo;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4144 abort = abort || set_ref_in_item(&HI2DI(hi)->di_tv, copyID,
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4145 &ht_stack, list_stack);
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4146 }
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4147 }
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4148
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4149 if (ht_stack == NULL)
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4150 break;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4151
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4152 // take an item from the stack
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4153 cur_ht = ht_stack->ht;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4154 tempitem = ht_stack;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4155 ht_stack = ht_stack->prev;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4156 free(tempitem);
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4157 }
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4158
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4159 return abort;
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4160 }
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4161
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4162 /*
17168
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4163 * 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
4164 * 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
4165 */
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4166 int
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4167 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
4168 {
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4169 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
4170 {
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4171 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
4172 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
4173 }
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4174 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
4175 }
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4176
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4177 /*
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4178 * 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
4179 * 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
4180 */
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4181 int
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4182 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
4183 {
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4184 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
4185 {
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4186 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
4187 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
4188 }
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4189 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
4190 }
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4191
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4192 /*
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4193 * Mark all lists and dicts referenced through list "l" with "copyID".
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4194 * "ht_stack" is used to add hashtabs to be marked. Can be NULL.
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4195 *
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4196 * Returns TRUE if setting references failed somehow.
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4197 */
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4198 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
4199 set_ref_in_list_items(list_T *l, int copyID, ht_stack_T **ht_stack)
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4200 {
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4201 listitem_T *li;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4202 int abort = FALSE;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4203 list_T *cur_l;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4204 list_stack_T *list_stack = NULL;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4205 list_stack_T *tempitem;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4206
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4207 cur_l = l;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4208 for (;;)
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4209 {
19201
e7b4fff348dd patch 8.2.0159: non-materialized range() list causes problems
Bram Moolenaar <Bram@vim.org>
parents: 19191
diff changeset
4210 if (!abort && cur_l->lv_first != &range_list_item)
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4211 // 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
4212 // 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
4213 // list_stack.
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4214 for (li = cur_l->lv_first; !abort && li != NULL; li = li->li_next)
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4215 abort = abort || set_ref_in_item(&li->li_tv, copyID,
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4216 ht_stack, &list_stack);
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4217 if (list_stack == NULL)
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4218 break;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4219
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4220 // take an item from the stack
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4221 cur_l = list_stack->list;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4222 tempitem = list_stack;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4223 list_stack = list_stack->prev;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4224 free(tempitem);
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4225 }
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4226
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4227 return abort;
371
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4228 }
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4229
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4230 /*
4b9fef49d7ff updated for version 7.0095
vimboss
parents: 364
diff changeset
4231 * Mark all lists and dicts referenced through typval "tv" with "copyID".
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4232 * "list_stack" is used to add lists to be marked. Can be NULL.
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4233 * "ht_stack" is used to add hashtabs to be marked. Can be NULL.
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4234 *
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4235 * Returns TRUE if setting references failed somehow.
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4236 */
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4237 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4238 set_ref_in_item(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4239 typval_T *tv,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4240 int copyID,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4241 ht_stack_T **ht_stack,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4242 list_stack_T **list_stack)
364
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
4243 {
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4244 int abort = FALSE;
364
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
4245
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4246 if (tv->v_type == VAR_DICT)
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 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
4249
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4250 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
4251 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4252 // 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
4253 dd->dv_copyID = copyID;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4254 if (ht_stack == NULL)
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4255 {
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4256 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
4257 }
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4258 else
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4259 {
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4260 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
4261 if (newitem == NULL)
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4262 abort = TRUE;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4263 else
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4264 {
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4265 newitem->ht = &dd->dv_hashtab;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4266 newitem->prev = *ht_stack;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4267 *ht_stack = newitem;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4268 }
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4269 }
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4270 }
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4271 }
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4272 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
4273 {
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4274 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
4275
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4276 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
4277 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4278 // 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
4279 ll->lv_copyID = copyID;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4280 if (list_stack == NULL)
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4281 {
17168
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4282 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
4283 }
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4284 else
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4285 {
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4286 list_stack_T *newitem = (list_stack_T*)malloc(
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4287 sizeof(list_stack_T));
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4288 if (newitem == NULL)
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4289 abort = TRUE;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4290 else
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4291 {
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4292 newitem->list = ll;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4293 newitem->prev = *list_stack;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4294 *list_stack = newitem;
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4295 }
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4296 }
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4297 }
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4298 }
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
4299 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
4300 {
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
4301 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
4302 }
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4303 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
4304 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4305 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
4306 int i;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4307
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4308 // 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
4309 if (pt != NULL)
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4310 {
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
4311 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
4312
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4313 if (pt->pt_dict != NULL)
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4314 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4315 typval_T dtv;
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 dtv.v_type = VAR_DICT;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4318 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
4319 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
4320 }
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4321
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4322 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
4323 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
4324 ht_stack, list_stack);
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4325 }
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4326 }
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4327 #ifdef FEAT_JOB_CHANNEL
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4328 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
4329 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4330 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
4331 typval_T dtv;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4332
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4333 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
4334 {
8870
30988ffb7498 commit https://github.com/vim/vim/commit/0239acb11fe4bfe9b525ea90b782759da5eb7704
Christian Brabandt <cb@256bit.org>
parents: 8863
diff changeset
4335 job->jv_copyID = copyID;
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4336 if (job->jv_channel != NULL)
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4337 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4338 dtv.v_type = VAR_CHANNEL;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4339 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
4340 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
4341 }
16872
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
4342 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
4343 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4344 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
4345 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
4346 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
4347 }
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4348 }
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4349 }
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4350 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
4351 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4352 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
4353 ch_part_T part;
8863
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4354 typval_T dtv;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4355 jsonq_T *jq;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4356 cbq_T *cq;
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4357
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4358 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
4359 {
8870
30988ffb7498 commit https://github.com/vim/vim/commit/0239acb11fe4bfe9b525ea90b782759da5eb7704
Christian Brabandt <cb@256bit.org>
parents: 8863
diff changeset
4360 ch->ch_copyID = copyID;
10259
a09db7a4afe0 commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents: 10235
diff changeset
4361 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
4362 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4363 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
4364 jq = jq->jq_next)
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4365 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
4366 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
4367 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
4368 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
4369 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4370 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
4371 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
4372 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
4373 }
16872
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
4374 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
4375 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4376 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
4377 dtv.vval.v_partial =
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
4378 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
4379 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
4380 }
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4381 }
16872
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
4382 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
4383 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4384 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
4385 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
4386 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
4387 }
16872
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
4388 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
4389 {
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4390 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
4391 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
4392 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
4393 }
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4394 }
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4395 }
e1b84109506a commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents: 8861
diff changeset
4396 #endif
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6549
diff changeset
4397 return abort;
364
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
4398 }
5332dd13733c updated for version 7.0094
vimboss
parents: 359
diff changeset
4399
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4400 /*
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4401 * Return a string with the string representation of a variable.
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4402 * If the memory is allocated "tofree" is set to it, otherwise NULL.
80
d2796c60ca6f updated for version 7.0032
vimboss
parents: 76
diff changeset
4403 * "numbuf" is used for a number.
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4404 * 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
4405 * 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
4406 * 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
4407 * ":echo" displays values.
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4408 * 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
4409 * are replaced with "...".
1360
8d09c1eed8a5 updated for version 7.1-074
vimboss
parents: 1341
diff changeset
4410 * May return NULL.
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4411 */
9556
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents: 9527
diff changeset
4412 char_u *
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4413 echo_string_core(
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4414 typval_T *tv,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4415 char_u **tofree,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4416 char_u *numbuf,
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4417 int copyID,
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4418 int echo_style,
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4419 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
4420 int composite_val)
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4421 {
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
4422 static int recurse = 0;
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
4423 char_u *r = NULL;
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
4424
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4425 if (recurse >= DICT_MAXNEST)
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
4426 {
5973
99d8f2d72dcd updated for version 7.4.327
Bram Moolenaar <bram@vim.org>
parents: 5964
diff changeset
4427 if (!did_echo_string_emsg)
99d8f2d72dcd updated for version 7.4.327
Bram Moolenaar <bram@vim.org>
parents: 5964
diff changeset
4428 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4429 // 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
4430 // 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
4431 // and dicts.
5973
99d8f2d72dcd updated for version 7.4.327
Bram Moolenaar <bram@vim.org>
parents: 5964
diff changeset
4432 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
4433 emsg(_("E724: variable nested too deep for displaying"));
5973
99d8f2d72dcd updated for version 7.4.327
Bram Moolenaar <bram@vim.org>
parents: 5964
diff changeset
4434 }
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
4435 *tofree = NULL;
5973
99d8f2d72dcd updated for version 7.4.327
Bram Moolenaar <bram@vim.org>
parents: 5964
diff changeset
4436 return (char_u *)"{E724}";
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
4437 }
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
4438 ++recurse;
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
4439
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4440 switch (tv->v_type)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4441 {
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4442 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
4443 if (echo_style && !composite_val)
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4444 {
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4445 *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
4446 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
4447 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
4448 r = (char_u *)"";
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4449 }
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4450 else
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4451 {
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4452 *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
4453 r = *tofree;
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4454 }
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4455 break;
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4456
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4457 case VAR_FUNC:
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4458 if (echo_style)
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4459 {
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4460 *tofree = NULL;
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4461 r = tv->vval.v_string;
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4462 }
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4463 else
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4464 {
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4465 *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
4466 r = *tofree;
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4467 }
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
4468 break;
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4469
8538
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
4470 case VAR_PARTIAL:
8710
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4471 {
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4472 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
4473 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
4474 : partial_name(pt), FALSE);
8710
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4475 garray_T ga;
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4476 int i;
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4477 char_u *tf;
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4478
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4479 ga_init2(&ga, 1, 100);
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4480 ga_concat(&ga, (char_u *)"function(");
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4481 if (fname != NULL)
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4482 {
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4483 ga_concat(&ga, fname);
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4484 vim_free(fname);
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4485 }
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4486 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
4487 {
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4488 ga_concat(&ga, (char_u *)", [");
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4489 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
4490 {
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4491 if (i > 0)
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4492 ga_concat(&ga, (char_u *)", ");
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4493 ga_concat(&ga,
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4494 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
4495 vim_free(tf);
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4496 }
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4497 ga_concat(&ga, (char_u *)"]");
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4498 }
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4499 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
4500 {
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4501 typval_T dtv;
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4502
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4503 ga_concat(&ga, (char_u *)", ");
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4504 dtv.v_type = VAR_DICT;
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4505 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
4506 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
4507 vim_free(tf);
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4508 }
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4509 ga_concat(&ga, (char_u *)")");
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4510
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4511 *tofree = ga.ga_data;
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4512 r = *tofree;
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4513 break;
af3cb5c068fd commit https://github.com/vim/vim/commit/24c77a1e3a2ad510582116229462b482d69b4b8e
Christian Brabandt <cb@256bit.org>
parents: 8708
diff changeset
4514 }
8538
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
4515
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
4516 case VAR_BLOB:
15466
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15464
diff changeset
4517 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
4518 break;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
4519
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4520 case VAR_LIST:
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4521 if (tv->vval.v_list == NULL)
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4522 {
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4523 *tofree = NULL;
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4524 r = NULL;
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4525 }
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4526 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
4527 && tv->vval.v_list->lv_len > 0)
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4528 {
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4529 *tofree = NULL;
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4530 r = (char_u *)"[...]";
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4531 }
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4532 else
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4533 {
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4534 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
4535
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4536 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
4537 *tofree = list2string(tv, copyID, restore_copyID);
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4538 if (restore_copyID)
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4539 tv->vval.v_list->lv_copyID = old_copyID;
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4540 r = *tofree;
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4541 }
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4542 break;
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4543
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4544 case VAR_DICT:
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4545 if (tv->vval.v_dict == NULL)
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4546 {
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4547 *tofree = NULL;
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4548 r = NULL;
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4549 }
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4550 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
4551 && tv->vval.v_dict->dv_hashtab.ht_used != 0)
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4552 {
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4553 *tofree = NULL;
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4554 r = (char_u *)"{...}";
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4555 }
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4556 else
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4557 {
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4558 int old_copyID = tv->vval.v_dict->dv_copyID;
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4559 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
4560 *tofree = dict2string(tv, copyID, restore_copyID);
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4561 if (restore_copyID)
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4562 tv->vval.v_dict->dv_copyID = old_copyID;
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4563 r = *tofree;
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4564 }
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4565 break;
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4566
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4567 case VAR_NUMBER:
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
4568 case VAR_UNKNOWN:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
4569 case VAR_VOID:
11973
aec3df2af27c patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents: 11848
diff changeset
4570 *tofree = NULL;
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
4571 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
4572 break;
aec3df2af27c patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents: 11848
diff changeset
4573
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
4574 case VAR_JOB:
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
4575 case VAR_CHANNEL:
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
4576 *tofree = NULL;
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
4577 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
4578 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
4579 {
aec3df2af27c patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents: 11848
diff changeset
4580 *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
4581 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
4582 }
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4583 break;
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 630
diff changeset
4584
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4585 case VAR_FLOAT:
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
4586 #ifdef FEAT_FLOAT
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4587 *tofree = NULL;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4588 vim_snprintf((char *)numbuf, NUMBUFLEN, "%g", tv->vval.v_float);
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4589 r = numbuf;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4590 break;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4591 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4592
19102
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 19087
diff changeset
4593 case VAR_BOOL:
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
4594 case VAR_SPECIAL:
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
4595 *tofree = NULL;
7730
80ce794827c4 commit https://github.com/vim/vim/commit/17a13437c9414a8693369a97f3be2fc8ad48c12e
Christian Brabandt <cb@256bit.org>
parents: 7720
diff changeset
4596 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
4597 break;
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
4598 }
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
4599
5973
99d8f2d72dcd updated for version 7.4.327
Bram Moolenaar <bram@vim.org>
parents: 5964
diff changeset
4600 if (--recurse == 0)
99d8f2d72dcd updated for version 7.4.327
Bram Moolenaar <bram@vim.org>
parents: 5964
diff changeset
4601 did_echo_string_emsg = FALSE;
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
4602 return r;
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4603 }
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4604
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4605 /*
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4606 * Return a string with the string representation of a variable.
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4607 * If the memory is allocated "tofree" is set to it, otherwise NULL.
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4608 * "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
4609 * 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
4610 * 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
4611 * May return NULL.
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4612 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
4613 char_u *
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4614 echo_string(
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4615 typval_T *tv,
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4616 char_u **tofree,
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4617 char_u *numbuf,
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4618 int copyID)
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4619 {
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4620 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
4621 }
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4622
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4623 /*
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4624 * 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
4625 * 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
4626 * "numbuf" is used for a number.
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4627 * Puts quotes around strings, so that they can be parsed back by eval().
1360
8d09c1eed8a5 updated for version 7.1-074
vimboss
parents: 1341
diff changeset
4628 * May return NULL.
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4629 */
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8887
diff changeset
4630 char_u *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4631 tv2string(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4632 typval_T *tv,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4633 char_u **tofree,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4634 char_u *numbuf,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4635 int copyID)
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4636 {
9157
e316b83892c1 commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
4637 return echo_string_core(tv, tofree, numbuf, copyID, FALSE, TRUE, FALSE);
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4638 }
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4639
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
4640 /*
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4641 * Return string "str" in ' quotes, doubling ' characters.
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4642 * If "str" is NULL an empty string is assumed.
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4643 * If "function" is TRUE make it function('string').
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4644 */
9556
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents: 9527
diff changeset
4645 char_u *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4646 string_quote(char_u *str, int function)
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4647 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4648 unsigned len;
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4649 char_u *p, *r, *s;
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4650
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4651 len = (function ? 13 : 3);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4652 if (str != NULL)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4653 {
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 833
diff changeset
4654 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
4655 for (p = str; *p != NUL; MB_PTR_ADV(p))
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4656 if (*p == '\'')
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4657 ++len;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4658 }
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4659 s = r = alloc(len);
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4660 if (r != NULL)
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4661 {
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4662 if (function)
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4663 {
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4664 STRCPY(r, "function('");
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4665 r += 10;
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4666 }
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4667 else
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4668 *r++ = '\'';
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4669 if (str != NULL)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4670 for (p = str; *p != NUL; )
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4671 {
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4672 if (*p == '\'')
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4673 *r++ = '\'';
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4674 MB_COPY_CHAR(p, r);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
4675 }
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
4676 *r++ = '\'';
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4677 if (function)
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4678 *r++ = ')';
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4679 *r++ = NUL;
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4680 }
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4681 return s;
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4682 }
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4683
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
4684 #if defined(FEAT_FLOAT) || defined(PROTO)
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4685 /*
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4686 * Convert the string "text" to a floating point number.
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4687 * This uses strtod(). setlocale(LC_NUMERIC, "C") has been used to make sure
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4688 * this always uses a decimal point.
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4689 * Returns the length of the text that was consumed.
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4690 */
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
4691 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4692 string2float(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4693 char_u *text,
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4694 float_T *value) // result stored here
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4695 {
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4696 char *s = (char *)text;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4697 float_T f;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4698
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4699 // 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
4700 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
4701 {
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
4702 *value = INFINITY;
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
4703 return 3;
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
4704 }
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
4705 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
4706 {
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
4707 *value = -INFINITY;
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
4708 return 4;
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
4709 }
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
4710 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
4711 {
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
4712 *value = NAN;
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
4713 return 3;
6ddf322ff7cf patch 8.0.0158: float funcion test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
4714 }
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4715 f = strtod(s, &s);
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4716 *value = f;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4717 return (int)((char_u *)s - text);
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4718 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4719 #endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
4720
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
4721 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4722 * Get the value of an environment variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4723 * "arg" is pointing to the '$'. It is advanced to after the name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4724 * If the environment variable was not set, silently assume it is empty.
5858
00228400629e updated for version 7.4.272
Bram Moolenaar <bram@vim.org>
parents: 5850
diff changeset
4725 * Return FAIL if the name is invalid.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4726 */
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
4727 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4728 get_env_tv(char_u **arg, typval_T *rettv, int evaluate)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4729 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4730 char_u *string = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4731 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4732 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4733 char_u *name;
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4734 int mustfree = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4735
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4736 ++*arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4737 name = *arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4738 len = get_env_len(arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4739 if (evaluate)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4740 {
5858
00228400629e updated for version 7.4.272
Bram Moolenaar <bram@vim.org>
parents: 5850
diff changeset
4741 if (len == 0)
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4742 return FAIL; // invalid empty name
5858
00228400629e updated for version 7.4.272
Bram Moolenaar <bram@vim.org>
parents: 5850
diff changeset
4743
00228400629e updated for version 7.4.272
Bram Moolenaar <bram@vim.org>
parents: 5850
diff changeset
4744 cc = name[len];
00228400629e updated for version 7.4.272
Bram Moolenaar <bram@vim.org>
parents: 5850
diff changeset
4745 name[len] = NUL;
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4746 // first try vim_getenv(), fast for normal environment vars
5858
00228400629e updated for version 7.4.272
Bram Moolenaar <bram@vim.org>
parents: 5850
diff changeset
4747 string = vim_getenv(name, &mustfree);
00228400629e updated for version 7.4.272
Bram Moolenaar <bram@vim.org>
parents: 5850
diff changeset
4748 if (string != NULL && *string != NUL)
00228400629e updated for version 7.4.272
Bram Moolenaar <bram@vim.org>
parents: 5850
diff changeset
4749 {
00228400629e updated for version 7.4.272
Bram Moolenaar <bram@vim.org>
parents: 5850
diff changeset
4750 if (!mustfree)
00228400629e updated for version 7.4.272
Bram Moolenaar <bram@vim.org>
parents: 5850
diff changeset
4751 string = vim_strsave(string);
00228400629e updated for version 7.4.272
Bram Moolenaar <bram@vim.org>
parents: 5850
diff changeset
4752 }
00228400629e updated for version 7.4.272
Bram Moolenaar <bram@vim.org>
parents: 5850
diff changeset
4753 else
00228400629e updated for version 7.4.272
Bram Moolenaar <bram@vim.org>
parents: 5850
diff changeset
4754 {
00228400629e updated for version 7.4.272
Bram Moolenaar <bram@vim.org>
parents: 5850
diff changeset
4755 if (mustfree)
00228400629e updated for version 7.4.272
Bram Moolenaar <bram@vim.org>
parents: 5850
diff changeset
4756 vim_free(string);
00228400629e updated for version 7.4.272
Bram Moolenaar <bram@vim.org>
parents: 5850
diff changeset
4757
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4758 // next try expanding things like $VIM and ${HOME}
5858
00228400629e updated for version 7.4.272
Bram Moolenaar <bram@vim.org>
parents: 5850
diff changeset
4759 string = expand_env_save(name - 1);
00228400629e updated for version 7.4.272
Bram Moolenaar <bram@vim.org>
parents: 5850
diff changeset
4760 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
4761 VIM_CLEAR(string);
5858
00228400629e updated for version 7.4.272
Bram Moolenaar <bram@vim.org>
parents: 5850
diff changeset
4762 }
00228400629e updated for version 7.4.272
Bram Moolenaar <bram@vim.org>
parents: 5850
diff changeset
4763 name[len] = cc;
00228400629e updated for version 7.4.272
Bram Moolenaar <bram@vim.org>
parents: 5850
diff changeset
4764
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4765 rettv->v_type = VAR_STRING;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
4766 rettv->vval.v_string = string;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4767 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4768
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4769 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4770 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4771
3214
cd145cc2f2c9 updated for version 7.3.377
Bram Moolenaar <bram@vim.org>
parents: 3180
diff changeset
4772 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4773 * Translate a String variable into a position.
685
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4774 * Returns NULL when there is an error.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4775 */
9571
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9562
diff changeset
4776 pos_T *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4777 var2fpos(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4778 typval_T *varp,
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4779 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
4780 int *fnum) // set to fnum for '0, 'A, etc.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4781 {
700
c78d973dce9e updated for version 7.0211
vimboss
parents: 697
diff changeset
4782 char_u *name;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4783 static pos_T pos;
700
c78d973dce9e updated for version 7.0211
vimboss
parents: 697
diff changeset
4784 pos_T *pp;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4785
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4786 // Argument can be [lnum, col, coladd].
685
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4787 if (varp->v_type == VAR_LIST)
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4788 {
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4789 list_T *l;
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4790 int len;
705
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
4791 int error = FALSE;
1317
45bae37de037 updated for version 7.1-031
vimboss
parents: 1311
diff changeset
4792 listitem_T *li;
685
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4793
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4794 l = varp->vval.v_list;
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4795 if (l == NULL)
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4796 return NULL;
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4797
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4798 // Get the line number
705
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
4799 pos.lnum = list_find_nr(l, 0L, &error);
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
4800 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
4801 return NULL; // invalid line number
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4802
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4803 // Get the column number
705
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
4804 pos.col = list_find_nr(l, 1L, &error);
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
4805 if (error)
685
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4806 return NULL;
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4807 len = (long)STRLEN(ml_get(pos.lnum));
1317
45bae37de037 updated for version 7.1-031
vimboss
parents: 1311
diff changeset
4808
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4809 // We accept "$" for the column number: last column.
1317
45bae37de037 updated for version 7.1-031
vimboss
parents: 1311
diff changeset
4810 li = list_find(l, 1L);
45bae37de037 updated for version 7.1-031
vimboss
parents: 1311
diff changeset
4811 if (li != NULL && li->li_tv.v_type == VAR_STRING
45bae37de037 updated for version 7.1-031
vimboss
parents: 1311
diff changeset
4812 && li->li_tv.vval.v_string != NULL
45bae37de037 updated for version 7.1-031
vimboss
parents: 1311
diff changeset
4813 && STRCMP(li->li_tv.vval.v_string, "$") == 0)
45bae37de037 updated for version 7.1-031
vimboss
parents: 1311
diff changeset
4814 pos.col = len + 1;
45bae37de037 updated for version 7.1-031
vimboss
parents: 1311
diff changeset
4815
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4816 // Accept a position up to the NUL after the line.
826
1cdd2661f34c updated for version 7.0d01
vimboss
parents: 819
diff changeset
4817 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
4818 return NULL; // invalid column number
705
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
4819 --pos.col;
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
4820
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4821 // Get the virtual offset. Defaults to zero.
705
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
4822 pos.coladd = list_find_nr(l, 2L, &error);
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
4823 if (error)
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
4824 pos.coladd = 0;
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
4825
685
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4826 return &pos;
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4827 }
d7e33248b9c8 updated for version 7.0206
vimboss
parents: 681
diff changeset
4828
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
4829 name = tv_get_string_chk(varp);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
4830 if (name == NULL)
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
4831 return NULL;
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4832 if (name[0] == '.') // cursor
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4833 return &curwin->w_cursor;
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4834 if (name[0] == 'v' && name[1] == NUL) // Visual start
1609
1324b7b755f3 updated for version 7.1-322
vimboss
parents: 1591
diff changeset
4835 {
1324b7b755f3 updated for version 7.1-322
vimboss
parents: 1591
diff changeset
4836 if (VIsual_active)
1324b7b755f3 updated for version 7.1-322
vimboss
parents: 1591
diff changeset
4837 return &VIsual;
1324b7b755f3 updated for version 7.1-322
vimboss
parents: 1591
diff changeset
4838 return &curwin->w_cursor;
1324b7b755f3 updated for version 7.1-322
vimboss
parents: 1591
diff changeset
4839 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4840 if (name[0] == '\'') // mark
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4841 {
4043
80b041b994d1 updated for version 7.3.776
Bram Moolenaar <bram@vim.org>
parents: 3986
diff changeset
4842 pp = getmark_buf_fnum(curbuf, name[1], FALSE, fnum);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4843 if (pp == NULL || pp == (pos_T *)-1 || pp->lnum <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4844 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4845 return pp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4846 }
705
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
4847
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
4848 pos.coladd = 0;
69e8006af734 updated for version 7.0212
vimboss
parents: 700
diff changeset
4849
1317
45bae37de037 updated for version 7.1-031
vimboss
parents: 1311
diff changeset
4850 if (name[0] == 'w' && dollar_lnum)
666
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
4851 {
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
4852 pos.col = 0;
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4853 if (name[1] == '0') // "w0": first visible line
666
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
4854 {
671
83a006f81bac updated for version 7.0199
vimboss
parents: 667
diff changeset
4855 update_topline();
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4856 // 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
4857 // 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
4858 pos.lnum = curwin->w_topline > 0 ? curwin->w_topline : 1;
666
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
4859 return &pos;
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
4860 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4861 else if (name[1] == '$') // "w$": last visible line
666
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
4862 {
671
83a006f81bac updated for version 7.0199
vimboss
parents: 667
diff changeset
4863 validate_botline();
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4864 // 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
4865 pos.lnum = curwin->w_botline > 0 ? curwin->w_botline - 1 : 0;
666
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
4866 return &pos;
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
4867 }
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
4868 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4869 else if (name[0] == '$') // last column or line
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4870 {
1317
45bae37de037 updated for version 7.1-031
vimboss
parents: 1311
diff changeset
4871 if (dollar_lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4872 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4873 pos.lnum = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4874 pos.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4875 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4876 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4877 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4878 pos.lnum = curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4879 pos.col = (colnr_T)STRLEN(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4880 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4881 return &pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4882 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4883 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4884 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4885
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4886 /*
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4887 * Convert list in "arg" into a position and optional file number.
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4888 * When "fnump" is NULL there is no file number, only 3 items.
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4889 * Note that the column is passed on as-is, the caller may want to decrement
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4890 * it to use 1 for the first column.
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4891 * Return FAIL when conversion is not possible, doesn't check the position for
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4892 * validity.
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4893 */
9571
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9562
diff changeset
4894 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4895 list2fpos(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4896 typval_T *arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4897 pos_T *posp,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4898 int *fnump,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4899 colnr_T *curswantp)
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4900 {
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4901 list_T *l = arg->vval.v_list;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4902 long i = 0;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4903 long n;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4904
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4905 // 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
4906 // there when "fnump" isn't NULL; "coladd" and "curswant" are optional.
915
d87865573d80 updated for version 7.0-041
vimboss
parents: 914
diff changeset
4907 if (arg->v_type != VAR_LIST
d87865573d80 updated for version 7.0-041
vimboss
parents: 914
diff changeset
4908 || l == NULL
d87865573d80 updated for version 7.0-041
vimboss
parents: 914
diff changeset
4909 || l->lv_len < (fnump == NULL ? 2 : 3)
5938
ccac0aa34eea updated for version 7.4.310
Bram Moolenaar <bram@vim.org>
parents: 5930
diff changeset
4910 || l->lv_len > (fnump == NULL ? 4 : 5))
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4911 return FAIL;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4912
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4913 if (fnump != NULL)
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4914 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4915 n = list_find_nr(l, i++, NULL); // fnum
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4916 if (n < 0)
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4917 return FAIL;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4918 if (n == 0)
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4919 n = curbuf->b_fnum; // current buffer
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4920 *fnump = n;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4921 }
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4922
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4923 n = list_find_nr(l, i++, NULL); // lnum
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4924 if (n < 0)
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4925 return FAIL;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4926 posp->lnum = n;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4927
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4928 n = list_find_nr(l, i++, NULL); // col
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4929 if (n < 0)
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4930 return FAIL;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4931 posp->col = n;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4932
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4933 n = list_find_nr(l, i, NULL); // off
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4934 if (n < 0)
915
d87865573d80 updated for version 7.0-041
vimboss
parents: 914
diff changeset
4935 posp->coladd = 0;
d87865573d80 updated for version 7.0-041
vimboss
parents: 914
diff changeset
4936 else
d87865573d80 updated for version 7.0-041
vimboss
parents: 914
diff changeset
4937 posp->coladd = n;
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4938
5938
ccac0aa34eea updated for version 7.4.310
Bram Moolenaar <bram@vim.org>
parents: 5930
diff changeset
4939 if (curswantp != NULL)
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4940 *curswantp = list_find_nr(l, i + 1, NULL); // curswant
5938
ccac0aa34eea updated for version 7.4.310
Bram Moolenaar <bram@vim.org>
parents: 5930
diff changeset
4941
709
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4942 return OK;
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4943 }
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4944
ecee28dd16d2 updated for version 7.0213
vimboss
parents: 705
diff changeset
4945 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4946 * Get the length of an environment variable name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4947 * Advance "arg" to the first character after the name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4948 * Return 0 for error.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4949 */
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17833
diff changeset
4950 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4951 get_env_len(char_u **arg)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4952 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4953 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4954 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4955
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4956 for (p = *arg; vim_isIDc(*p); ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4957 ;
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4958 if (p == *arg) // no name found
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4959 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4960
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4961 len = (int)(p - *arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4962 *arg = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4963 return len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4964 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4965
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4966 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4967 * Get the length of the name of a function or internal variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4968 * "arg" is advanced to the first non-white character after the name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4969 * Return 0 if something is wrong.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4970 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
4971 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
4972 get_id_len(char_u **arg)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4973 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4974 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4975 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4976
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4977 // Find the end of the name.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4978 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
4979 {
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
4980 if (*p == ':')
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
4981 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4982 // "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
4983 // 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
4984 len = (int)(p - *arg);
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
4985 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
4986 || len > 1)
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
4987 break;
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
4988 }
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
4989 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
4990 if (p == *arg) // no name found
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4991 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4992
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4993 len = (int)(p - *arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4994 *arg = skipwhite(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4995
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4996 return len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4997 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4998
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4999 /*
124
f455396f3c3f updated for version 7.0043
vimboss
parents: 121
diff changeset
5000 * Get the length of the name of a variable or function.
f455396f3c3f updated for version 7.0043
vimboss
parents: 121
diff changeset
5001 * Only the name is recognized, does not handle ".key" or "[idx]".
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5002 * "arg" is advanced to the first non-white character after the name.
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5003 * Return -1 if curly braces expansion failed.
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5004 * Return 0 if something else is wrong.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5005 * If the name contains 'magic' {}'s, expand them and return the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5006 * expanded name in an allocated string via 'alias' - caller must free.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5007 */
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17833
diff changeset
5008 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5009 get_name_len(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5010 char_u **arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5011 char_u **alias,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5012 int evaluate,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5013 int verbose)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5014 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5015 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5016 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5017 char_u *expr_start;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5018 char_u *expr_end;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5019
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5020 *alias = NULL; // default to no alias
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5021
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5022 if ((*arg)[0] == K_SPECIAL && (*arg)[1] == KS_EXTRA
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5023 && (*arg)[2] == (int)KE_SNR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5024 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5025 // hard coded <SNR>, already translated
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5026 *arg += 3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5027 return get_id_len(arg) + 3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5028 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5029 len = eval_fname_script(*arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5030 if (len > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5031 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5032 // literal "<SID>", "s:" or "<SNR>"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5033 *arg += len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5034 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5035
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5036 /*
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5037 * Find the end of the name; check for {} construction.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5038 */
271
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
5039 p = find_name_end(*arg, &expr_start, &expr_end,
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
5040 len > 0 ? 0 : FNE_CHECK_START);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5041 if (expr_start != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5042 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5043 char_u *temp_string;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5044
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5045 if (!evaluate)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5046 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5047 len += (int)(p - *arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5048 *arg = skipwhite(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5049 return len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5050 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5051
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5052 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5053 * Include any <SID> etc in the expanded string:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5054 * Thus the -len here.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5055 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5056 temp_string = make_expanded_name(*arg - len, expr_start, expr_end, p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5057 if (temp_string == NULL)
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5058 return -1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5059 *alias = temp_string;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5060 *arg = skipwhite(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5061 return (int)STRLEN(temp_string);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5062 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5063
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5064 len += get_id_len(arg);
15464
3faa7cc8207c patch 8.1.0740: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents: 15460
diff changeset
5065 // 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
5066 // reported at a higher level.
3faa7cc8207c patch 8.1.0740: Tcl test fails
Bram Moolenaar <Bram@vim.org>
parents: 15460
diff changeset
5067 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
5068 semsg(_(e_invexpr2), *arg);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5069
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5070 return len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5071 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5072
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5073 /*
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5074 * Find the end of a variable or function name, taking care of magic braces.
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5075 * If "expr_start" is not NULL then "expr_start" and "expr_end" are set to the
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5076 * start and end of the first magic braces item.
271
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
5077 * "flags" can have FNE_INCL_BR and FNE_CHECK_START.
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5078 * Return a pointer to just after the name. Equal to "arg" if there is no
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5079 * valid name.
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5080 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
5081 char_u *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5082 find_name_end(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5083 char_u *arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5084 char_u **expr_start,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5085 char_u **expr_end,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5086 int flags)
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5087 {
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5088 int mb_nest = 0;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5089 int br_nest = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5090 char_u *p;
7611
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
5091 int len;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5092
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5093 if (expr_start != NULL)
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5094 {
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5095 *expr_start = NULL;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5096 *expr_end = NULL;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5097 }
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5098
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5099 // Quick check for valid starting character.
271
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
5100 if ((flags & FNE_CHECK_START) && !eval_isnamec1(*arg) && *arg != '{')
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
5101 return arg;
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
5102
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5103 for (p = arg; *p != NUL
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5104 && (eval_isnamec(*p)
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5105 || *p == '{'
271
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
5106 || ((flags & FNE_INCL_BR) && (*p == '[' || *p == '.'))
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5107 || mb_nest != 0
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 10964
diff changeset
5108 || br_nest != 0); MB_PTR_ADV(p))
468
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5109 {
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5110 if (*p == '\'')
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5111 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5112 // 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
5113 for (p = p + 1; *p != NUL && *p != '\''; MB_PTR_ADV(p))
468
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5114 ;
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5115 if (*p == NUL)
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5116 break;
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5117 }
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5118 else if (*p == '"')
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5119 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5120 // 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
5121 for (p = p + 1; *p != NUL && *p != '"'; MB_PTR_ADV(p))
468
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5122 if (*p == '\\' && p[1] != NUL)
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5123 ++p;
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5124 if (*p == NUL)
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5125 break;
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5126 }
7611
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
5127 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
5128 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5129 // "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
5130 // 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
5131 len = (int)(p - arg);
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
5132 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
5133 || (len > 1 && p[-1] != '}'))
7611
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
5134 break;
9c420b8db435 commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents: 7605
diff changeset
5135 }
468
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5136
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5137 if (mb_nest == 0)
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5138 {
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5139 if (*p == '[')
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5140 ++br_nest;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5141 else if (*p == ']')
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5142 --br_nest;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5143 }
468
0a60be12e47e updated for version 7.0125
vimboss
parents: 464
diff changeset
5144
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5145 if (br_nest == 0)
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5146 {
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5147 if (*p == '{')
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5148 {
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5149 mb_nest++;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5150 if (expr_start != NULL && *expr_start == NULL)
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5151 *expr_start = p;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5152 }
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5153 else if (*p == '}')
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5154 {
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5155 mb_nest--;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5156 if (expr_start != NULL && mb_nest == 0 && *expr_end == NULL)
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5157 *expr_end = p;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5158 }
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5159 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5160 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5161
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5162 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5163 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5164
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5165 /*
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5166 * Expands out the 'magic' {}'s in a variable/function name.
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5167 * Note that this can call itself recursively, to deal with
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5168 * constructs like foo{bar}{baz}{bam}
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5169 * The four pointer arguments point to "foo{expre}ss{ion}bar"
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5170 * "in_start" ^
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5171 * "expr_start" ^
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5172 * "expr_end" ^
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5173 * "in_end" ^
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5174 *
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5175 * Returns a new allocated string, which the caller must free.
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5176 * Returns NULL for failure.
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5177 */
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5178 static char_u *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5179 make_expanded_name(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5180 char_u *in_start,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5181 char_u *expr_start,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5182 char_u *expr_end,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5183 char_u *in_end)
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5184 {
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5185 char_u c1;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5186 char_u *retval = NULL;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5187 char_u *temp_result;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5188 char_u *nextcmd = NULL;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5189
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5190 if (expr_end == NULL || in_end == NULL)
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5191 return NULL;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5192 *expr_start = NUL;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5193 *expr_end = NUL;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5194 c1 = *in_end;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5195 *in_end = NUL;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5196
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 713
diff changeset
5197 temp_result = eval_to_string(expr_start + 1, &nextcmd, FALSE);
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5198 if (temp_result != NULL && nextcmd == NULL)
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5199 {
16764
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16706
diff changeset
5200 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
5201 + (in_end - expr_end) + 1);
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5202 if (retval != NULL)
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5203 {
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5204 STRCPY(retval, in_start);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5205 STRCAT(retval, temp_result);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5206 STRCAT(retval, expr_end + 1);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5207 }
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5208 }
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5209 vim_free(temp_result);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5210
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5211 *in_end = c1; // put char back for error messages
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5212 *expr_start = '{';
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5213 *expr_end = '}';
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5214
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5215 if (retval != NULL)
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5216 {
271
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
5217 temp_result = find_name_end(retval, &expr_start, &expr_end, 0);
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5218 if (expr_start != NULL)
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5219 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5220 // Further expansion!
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5221 temp_result = make_expanded_name(retval, expr_start,
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5222 expr_end, temp_result);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5223 vim_free(retval);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5224 retval = temp_result;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5225 }
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5226 }
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5227
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5228 return retval;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5229 }
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5230
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5231 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5232 * Return TRUE if character "c" can be used in a variable or function name.
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5233 * Does not include '{' or '}' for magic braces.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5234 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
5235 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5236 eval_isnamec(int c)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5237 {
271
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
5238 return (ASCII_ISALNUM(c) || c == '_' || c == ':' || c == AUTOLOAD_CHAR);
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
5239 }
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
5240
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
5241 /*
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
5242 * Return TRUE if character "c" can be used as the first character in a
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
5243 * variable or function name (excluding '{' and '}').
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
5244 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
5245 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5246 eval_isnamec1(int c)
271
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
5247 {
8d34af900bae updated for version 7.0072
vimboss
parents: 266
diff changeset
5248 return (ASCII_ISALPHA(c) || c == '_');
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5249 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5250
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5251 /*
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
5252 * Handle:
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
5253 * - 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
5254 * - ".name" lookup
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
5255 * - 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
5256 * - method call: var->method()
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
5257 *
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
5258 * Can all be combined in any order: dict.func(expr)[idx]['func'](expr)->len()
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5259 */
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
5260 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5261 handle_subscript(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5262 char_u **arg,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5263 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
5264 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
5265 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
5266 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
5267 char_u **end_leaderp) // end of '!' and '-' prefixes
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5268 {
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5269 int ret = OK;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5270 dict_T *selfdict = NULL;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5271
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
5272 // "." 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
5273 // scriptversion is at least 2, where string concatenation is "..".
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5274 while (ret == OK
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
5275 && (((**arg == '['
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
5276 || (**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
5277 || (!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
5278 && (*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
5279 && 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
5280 || (**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
5281 || 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
5282 && !VIM_ISWHITE(*(*arg - 1)))
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
5283 || (**arg == '-' && (*arg)[1] == '>')))
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5284 {
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5285 if (**arg == '(')
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5286 {
17674
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
5287 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
5288
06c3e15ad84d patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents: 17661
diff changeset
5289 // 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
5290 // 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
5291 // but not caught.
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5292 if (aborting())
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5293 {
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5294 if (ret == OK)
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5295 clear_tv(rettv);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5296 ret = FAIL;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5297 }
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5298 dict_unref(selfdict);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5299 selfdict = NULL;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5300 }
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
5301 else if (**arg == '-')
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
5302 {
17763
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
5303 // 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
5304 // applying ->.
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
5305 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
5306 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
5307 if (ret == OK)
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
5308 {
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
5309 if ((*arg)[2] == '{')
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
5310 // expr->{lambda}()
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
5311 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
5312 else
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
5313 // expr->name()
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17674
diff changeset
5314 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
5315 }
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
5316 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5317 else // **arg == '[' || **arg == '.'
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5318 {
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5319 dict_unref(selfdict);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5320 if (rettv->v_type == VAR_DICT)
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5321 {
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5322 selfdict = rettv->vval.v_dict;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5323 if (selfdict != NULL)
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5324 ++selfdict->dv_refcount;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5325 }
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5326 else
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5327 selfdict = NULL;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5328 if (eval_index(arg, rettv, evaluate, verbose) == FAIL)
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5329 {
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5330 clear_tv(rettv);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5331 ret = FAIL;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5332 }
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5333 }
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5334 }
8575
b5209a4e5baf commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents: 8554
diff changeset
5335
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5336 // 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
5337 // 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
5338 // explicitly (pt_auto is FALSE).
9104
2242a5766417 commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents: 9093
diff changeset
5339 if (selfdict != NULL
2242a5766417 commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents: 9093
diff changeset
5340 && (rettv->v_type == VAR_FUNC
2242a5766417 commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents: 9093
diff changeset
5341 || (rettv->v_type == VAR_PARTIAL
2242a5766417 commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents: 9093
diff changeset
5342 && (rettv->vval.v_partial->pt_auto
2242a5766417 commit https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Christian Brabandt <cb@256bit.org>
parents: 9093
diff changeset
5343 || 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
5344 selfdict = make_partial(selfdict, rettv);
8575
b5209a4e5baf commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents: 8554
diff changeset
5345
159
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5346 dict_unref(selfdict);
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5347 return ret;
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5348 }
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5349
389c8abd5925 updated for version 7.0048
vimboss
parents: 156
diff changeset
5350 /*
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5351 * Allocate memory for a variable type-value, and make it empty (0 or NULL
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5352 * value).
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5353 */
7877
7fbd2de703a9 commit https://github.com/vim/vim/commit/11e0afa00a8e6c0aa1d50f760b5d5cb62dade038
Christian Brabandt <cb@256bit.org>
parents: 7864
diff changeset
5354 typval_T *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5355 alloc_tv(void)
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5356 {
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
5357 return ALLOC_CLEAR_ONE(typval_T);
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5358 }
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5359
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5360 /*
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5361 * Allocate memory for a variable type-value, and assign a string to it.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5362 * The string "s" must have been allocated, it is consumed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5363 * Return NULL for out of memory, the variable otherwise.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5364 */
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
5365 typval_T *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5366 alloc_string_tv(char_u *s)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5367 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
5368 typval_T *rettv;
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5369
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5370 rettv = alloc_tv();
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5371 if (rettv != NULL)
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5372 {
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5373 rettv->v_type = VAR_STRING;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5374 rettv->vval.v_string = s;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5375 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5376 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5377 vim_free(s);
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5378 return rettv;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5379 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5380
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5381 /*
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5382 * Free the memory for a variable type-value.
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5383 */
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 615
diff changeset
5384 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5385 free_tv(typval_T *varp)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5386 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5387 if (varp != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5388 {
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5389 switch (varp->v_type)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5390 {
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
5391 case VAR_FUNC:
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
5392 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
5393 // FALLTHROUGH
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5394 case VAR_STRING:
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5395 vim_free(varp->vval.v_string);
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5396 break;
8538
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
5397 case VAR_PARTIAL:
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
5398 partial_unref(varp->vval.v_partial);
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
5399 break;
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
5400 case VAR_BLOB:
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
5401 blob_unref(varp->vval.v_blob);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
5402 break;
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5403 case VAR_LIST:
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5404 list_unref(varp->vval.v_list);
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5405 break;
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
5406 case VAR_DICT:
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
5407 dict_unref(varp->vval.v_dict);
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
5408 break;
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5409 case VAR_JOB:
8493
caed4b2d305f commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents: 8491
diff changeset
5410 #ifdef FEAT_JOB_CHANNEL
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5411 job_unref(varp->vval.v_job);
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5412 break;
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5413 #endif
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
5414 case VAR_CHANNEL:
8493
caed4b2d305f commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents: 8491
diff changeset
5415 #ifdef FEAT_JOB_CHANNEL
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
5416 channel_unref(varp->vval.v_channel);
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
5417 break;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
5418 #endif
156
c5b05f6de1ad updated for version 7.0047
vimboss
parents: 151
diff changeset
5419 case VAR_NUMBER:
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5420 case VAR_FLOAT:
156
c5b05f6de1ad updated for version 7.0047
vimboss
parents: 151
diff changeset
5421 case VAR_UNKNOWN:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5422 case VAR_VOID:
19102
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 19087
diff changeset
5423 case VAR_BOOL:
7768
3d8e4e0d7127 commit https://github.com/vim/vim/commit/6650a694547eb744afa060ec62dd8270e99db9f2
Christian Brabandt <cb@256bit.org>
parents: 7765
diff changeset
5424 case VAR_SPECIAL:
156
c5b05f6de1ad updated for version 7.0047
vimboss
parents: 151
diff changeset
5425 break;
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5426 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5427 vim_free(varp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5428 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5429 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5430
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5431 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5432 * Free the memory for a variable value and set the value to NULL or 0.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5433 */
446
7472c565592a updated for version 7.0117
vimboss
parents: 445
diff changeset
5434 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5435 clear_tv(typval_T *varp)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5436 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5437 if (varp != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5438 {
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5439 switch (varp->v_type)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5440 {
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
5441 case VAR_FUNC:
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
5442 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
5443 // FALLTHROUGH
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5444 case VAR_STRING:
13244
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 13037
diff changeset
5445 VIM_CLEAR(varp->vval.v_string);
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5446 break;
8538
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
5447 case VAR_PARTIAL:
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
5448 partial_unref(varp->vval.v_partial);
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
5449 varp->vval.v_partial = NULL;
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
5450 break;
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
5451 case VAR_BLOB:
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
5452 blob_unref(varp->vval.v_blob);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
5453 varp->vval.v_blob = NULL;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
5454 break;
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5455 case VAR_LIST:
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5456 list_unref(varp->vval.v_list);
121
86d71ae0c85a updated for version 7.0042
vimboss
parents: 117
diff changeset
5457 varp->vval.v_list = NULL;
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5458 break;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
5459 case VAR_DICT:
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
5460 dict_unref(varp->vval.v_dict);
121
86d71ae0c85a updated for version 7.0042
vimboss
parents: 117
diff changeset
5461 varp->vval.v_dict = NULL;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
5462 break;
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5463 case VAR_NUMBER:
19102
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 19087
diff changeset
5464 case VAR_BOOL:
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
5465 case VAR_SPECIAL:
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5466 varp->vval.v_number = 0;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5467 break;
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5468 case VAR_FLOAT:
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5469 #ifdef FEAT_FLOAT
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5470 varp->vval.v_float = 0.0;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5471 break;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5472 #endif
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5473 case VAR_JOB:
8493
caed4b2d305f commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents: 8491
diff changeset
5474 #ifdef FEAT_JOB_CHANNEL
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5475 job_unref(varp->vval.v_job);
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5476 varp->vval.v_job = NULL;
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5477 #endif
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5478 break;
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
5479 case VAR_CHANNEL:
8493
caed4b2d305f commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents: 8491
diff changeset
5480 #ifdef FEAT_JOB_CHANNEL
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
5481 channel_unref(varp->vval.v_channel);
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
5482 varp->vval.v_channel = NULL;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
5483 #endif
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5484 case VAR_UNKNOWN:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5485 case VAR_VOID:
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5486 break;
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5487 }
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 142
diff changeset
5488 varp->v_lock = 0;
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5489 }
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5490 }
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5491
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5492 /*
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5493 * Set the value of a variable to NULL without freeing items.
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5494 */
9571
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9562
diff changeset
5495 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5496 init_tv(typval_T *varp)
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5497 {
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
5498 if (varp != NULL)
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
5499 vim_memset(varp, 0, sizeof(typval_T));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5500 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5501
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5502 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5503 * Get the number value of a variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5504 * If it is a String variable, uses vim_str2nr().
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
5505 * 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
5506 * tv_get_number_chk() is similar to tv_get_number(), but informs the
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
5507 * caller of incompatible types: it sets *denote to TRUE if "denote"
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
5508 * is not NULL or returns -1 otherwise.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5509 */
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
5510 varnumber_T
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
5511 tv_get_number(typval_T *varp)
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5512 {
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
5513 int error = FALSE;
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
5514
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5515 return tv_get_number_chk(varp, &error); // return 0L on error
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
5516 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
5517
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
5518 varnumber_T
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
5519 tv_get_number_chk(typval_T *varp, int *denote)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
5520 {
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
5521 varnumber_T n = 0L;
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5522
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5523 switch (varp->v_type)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5524 {
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5525 case VAR_NUMBER:
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
5526 return varp->vval.v_number;
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5527 case VAR_FLOAT:
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5528 #ifdef FEAT_FLOAT
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
5529 emsg(_("E805: Using a Float as a Number"));
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5530 break;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5531 #endif
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5532 case VAR_FUNC:
8538
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
5533 case VAR_PARTIAL:
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
5534 emsg(_("E703: Using a Funcref as a Number"));
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5535 break;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5536 case VAR_STRING:
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5537 if (varp->vval.v_string != NULL)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5538 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
5539 STR2NR_ALL, &n, NULL, 0, FALSE);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
5540 return n;
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
5541 case VAR_LIST:
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
5542 emsg(_("E745: Using a List as a Number"));
97
d4f3db33d782 updated for version 7.0037
vimboss
parents: 92
diff changeset
5543 break;
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
5544 case VAR_DICT:
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
5545 emsg(_("E728: Using a Dictionary as a Number"));
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
5546 break;
19102
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 19087
diff changeset
5547 case VAR_BOOL:
7730
80ce794827c4 commit https://github.com/vim/vim/commit/17a13437c9414a8693369a97f3be2fc8ad48c12e
Christian Brabandt <cb@256bit.org>
parents: 7720
diff changeset
5548 case VAR_SPECIAL:
80ce794827c4 commit https://github.com/vim/vim/commit/17a13437c9414a8693369a97f3be2fc8ad48c12e
Christian Brabandt <cb@256bit.org>
parents: 7720
diff changeset
5549 return varp->vval.v_number == VVAL_TRUE ? 1 : 0;
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5550 case VAR_JOB:
8493
caed4b2d305f commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents: 8491
diff changeset
5551 #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
5552 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
5553 break;
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5554 #endif
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
5555 case VAR_CHANNEL:
8493
caed4b2d305f commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents: 8491
diff changeset
5556 #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
5557 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
5558 break;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
5559 #endif
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
5560 case VAR_BLOB:
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
5561 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
5562 break;
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5563 case VAR_UNKNOWN:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5564 case VAR_VOID:
19554
b38d73f36467 patch 8.2.0334: abort called when using test_void()
Bram Moolenaar <Bram@vim.org>
parents: 19477
diff changeset
5565 internal_error_no_abort("tv_get_number(UNKNOWN)");
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5566 break;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5567 }
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5568 if (denote == NULL) // useful for values that must be unsigned
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
5569 n = -1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
5570 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
5571 *denote = TRUE;
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5572 return n;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5573 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5574
7689
20dc2763a3b9 commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents: 7683
diff changeset
5575 #ifdef FEAT_FLOAT
9571
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9562
diff changeset
5576 float_T
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
5577 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
5578 {
20dc2763a3b9 commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents: 7683
diff changeset
5579 switch (varp->v_type)
20dc2763a3b9 commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents: 7683
diff changeset
5580 {
20dc2763a3b9 commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents: 7683
diff changeset
5581 case VAR_NUMBER:
20dc2763a3b9 commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents: 7683
diff changeset
5582 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
5583 case VAR_FLOAT:
20dc2763a3b9 commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents: 7683
diff changeset
5584 return varp->vval.v_float;
20dc2763a3b9 commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents: 7683
diff changeset
5585 case VAR_FUNC:
8538
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
5586 case VAR_PARTIAL:
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
5587 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
5588 break;
20dc2763a3b9 commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents: 7683
diff changeset
5589 case VAR_STRING:
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
5590 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
5591 break;
20dc2763a3b9 commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents: 7683
diff changeset
5592 case VAR_LIST:
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
5593 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
5594 break;
20dc2763a3b9 commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents: 7683
diff changeset
5595 case VAR_DICT:
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
5596 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
5597 break;
19102
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 19087
diff changeset
5598 case VAR_BOOL:
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 19087
diff changeset
5599 emsg(_("E362: Using a boolean value as a Float"));
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 19087
diff changeset
5600 break;
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5601 case VAR_SPECIAL:
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
5602 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
5603 break;
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5604 case VAR_JOB:
8493
caed4b2d305f commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents: 8491
diff changeset
5605 # 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
5606 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
5607 break;
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5608 # endif
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
5609 case VAR_CHANNEL:
8493
caed4b2d305f commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents: 8491
diff changeset
5610 # 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
5611 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
5612 break;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
5613 # endif
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
5614 case VAR_BLOB:
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
5615 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
5616 break;
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5617 case VAR_UNKNOWN:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5618 case VAR_VOID:
19554
b38d73f36467 patch 8.2.0334: abort called when using test_void()
Bram Moolenaar <Bram@vim.org>
parents: 19477
diff changeset
5619 internal_error_no_abort("tv_get_float(UNKNOWN)");
7689
20dc2763a3b9 commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents: 7683
diff changeset
5620 break;
20dc2763a3b9 commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents: 7683
diff changeset
5621 }
20dc2763a3b9 commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents: 7683
diff changeset
5622 return 0;
20dc2763a3b9 commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents: 7683
diff changeset
5623 }
20dc2763a3b9 commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents: 7683
diff changeset
5624 #endif
20dc2763a3b9 commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents: 7683
diff changeset
5625
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5626 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5627 * Get the string value of a variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5628 * 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
5629 * 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
5630 * tv_get_string_buf() uses a given buffer.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5631 * If the String variable has never been set, return an empty string.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5632 * 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
5633 * tv_get_string_chk() and tv_get_string_buf_chk() are similar, but return
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
5634 * NULL on error.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5635 */
8498
42277980a76d commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents: 8493
diff changeset
5636 char_u *
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
5637 tv_get_string(typval_T *varp)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5638 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5639 static char_u mybuf[NUMBUFLEN];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5640
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
5641 return tv_get_string_buf(varp, mybuf);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5642 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5643
8498
42277980a76d commit https://github.com/vim/vim/commit/8e2c942ce49f2555d7dc2088cf3aa856820c5e32
Christian Brabandt <cb@256bit.org>
parents: 8493
diff changeset
5644 char_u *
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
5645 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
5646 {
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
5647 char_u *res = tv_get_string_buf_chk(varp, buf);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
5648
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
5649 return res != NULL ? res : (char_u *)"";
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
5650 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
5651
5810
0b9a66ea49f4 updated for version 7.4.249
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
5652 /*
0b9a66ea49f4 updated for version 7.4.249
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
5653 * Careful: This uses a single, static buffer. YOU CAN ONLY USE IT ONCE!
0b9a66ea49f4 updated for version 7.4.249
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
5654 */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 448
diff changeset
5655 char_u *
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
5656 tv_get_string_chk(typval_T *varp)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
5657 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
5658 static char_u mybuf[NUMBUFLEN];
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
5659
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
5660 return tv_get_string_buf_chk(varp, mybuf);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
5661 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
5662
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
5663 char_u *
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
5664 tv_get_string_buf_chk(typval_T *varp, char_u *buf)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
5665 {
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5666 switch (varp->v_type)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5667 {
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5668 case VAR_NUMBER:
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
5669 vim_snprintf((char *)buf, NUMBUFLEN, "%lld",
19477
2bb0e80fcd32 patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents: 19201
diff changeset
5670 (varnumber_T)varp->vval.v_number);
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5671 return buf;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5672 case VAR_FUNC:
8538
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
5673 case VAR_PARTIAL:
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
5674 emsg(_("E729: using Funcref as a String"));
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5675 break;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5676 case VAR_LIST:
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
5677 emsg(_("E730: using List as a String"));
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
5678 break;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
5679 case VAR_DICT:
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
5680 emsg(_("E731: using Dictionary as a String"));
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5681 break;
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5682 case VAR_FLOAT:
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5683 #ifdef FEAT_FLOAT
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
5684 emsg(_(e_float_as_string));
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5685 break;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5686 #endif
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5687 case VAR_STRING:
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5688 if (varp->vval.v_string != NULL)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5689 return varp->vval.v_string;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
5690 return (char_u *)"";
19102
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 19087
diff changeset
5691 case VAR_BOOL:
7730
80ce794827c4 commit https://github.com/vim/vim/commit/17a13437c9414a8693369a97f3be2fc8ad48c12e
Christian Brabandt <cb@256bit.org>
parents: 7720
diff changeset
5692 case VAR_SPECIAL:
80ce794827c4 commit https://github.com/vim/vim/commit/17a13437c9414a8693369a97f3be2fc8ad48c12e
Christian Brabandt <cb@256bit.org>
parents: 7720
diff changeset
5693 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
5694 return buf;
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
5695 case VAR_BLOB:
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
5696 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
5697 break;
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5698 case VAR_JOB:
8493
caed4b2d305f commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents: 8491
diff changeset
5699 #ifdef FEAT_JOB_CHANNEL
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5700 {
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5701 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
5702 char *status;
be45d4921f1f commit https://github.com/vim/vim/commit/839fd11d7ed1a96bace3159c4d1861658864aae3
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
5703
be45d4921f1f commit https://github.com/vim/vim/commit/839fd11d7ed1a96bace3159c4d1861658864aae3
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
5704 if (job == NULL)
be45d4921f1f commit https://github.com/vim/vim/commit/839fd11d7ed1a96bace3159c4d1861658864aae3
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
5705 return (char_u *)"no process";
be45d4921f1f commit https://github.com/vim/vim/commit/839fd11d7ed1a96bace3159c4d1861658864aae3
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
5706 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
5707 : 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
5708 : "run";
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5709 # ifdef UNIX
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5710 vim_snprintf((char *)buf, NUMBUFLEN,
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5711 "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
5712 # elif defined(MSWIN)
8001
e5dbeb923ce6 commit https://github.com/vim/vim/commit/4d8747cdfc13843a5680dc8340fbeb6d32e7b626
Christian Brabandt <cb@256bit.org>
parents: 7995
diff changeset
5713 vim_snprintf((char *)buf, NUMBUFLEN,
8023
75e0831549f1 commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents: 8019
diff changeset
5714 "process %ld %s",
75e0831549f1 commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents: 8019
diff changeset
5715 (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
5716 status);
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5717 # else
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5718 // fall-back
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5719 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
5720 # endif
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5721 return buf;
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5722 }
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5723 #endif
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5724 break;
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
5725 case VAR_CHANNEL:
8493
caed4b2d305f commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents: 8491
diff changeset
5726 #ifdef FEAT_JOB_CHANNEL
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
5727 {
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
5728 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
5729 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
5730
8070
e4c3f6720b03 commit https://github.com/vim/vim/commit/5cefd4098204b4677387511b586673649f2fab48
Christian Brabandt <cb@256bit.org>
parents: 8062
diff changeset
5731 if (channel == NULL)
e4c3f6720b03 commit https://github.com/vim/vim/commit/5cefd4098204b4677387511b586673649f2fab48
Christian Brabandt <cb@256bit.org>
parents: 8062
diff changeset
5732 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
5733 else
e4c3f6720b03 commit https://github.com/vim/vim/commit/5cefd4098204b4677387511b586673649f2fab48
Christian Brabandt <cb@256bit.org>
parents: 8062
diff changeset
5734 vim_snprintf((char *)buf, NUMBUFLEN,
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
5735 "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
5736 return buf;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
5737 }
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
5738 #endif
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
5739 break;
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5740 case VAR_UNKNOWN:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5741 case VAR_VOID:
19085
fd1070ff696b patch 8.2.0103: using null object with execute() has strange effects
Bram Moolenaar <Bram@vim.org>
parents: 19081
diff changeset
5742 emsg(_(e_inval_string));
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5743 break;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5744 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 315
diff changeset
5745 return NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5746 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5747
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5748 /*
15219
dada0b389d4f patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
5749 * 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
5750 * 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
5751 */
17789
0f7ae8010787 patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents: 17781
diff changeset
5752 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
5753 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
5754 {
dada0b389d4f patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
5755 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
5756 || varp->v_type == VAR_DICT
19081
3b1f83fdaabc patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
5757 || varp->v_type == VAR_BLOB
15219
dada0b389d4f patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
5758 || 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
5759 || 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
5760 || 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
5761 {
dada0b389d4f patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
5762 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
5763
dada0b389d4f patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
5764 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
5765 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
5766 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
5767 *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
5768 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
5769 }
dada0b389d4f patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
5770 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
5771 }
dada0b389d4f patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
5772
dada0b389d4f patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
5773 /*
15780
5b6c3c7feba8 patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents: 15770
diff changeset
5774 * 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
5775 * 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
5776 * TRUE.
5b6c3c7feba8 patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents: 15770
diff changeset
5777 */
5b6c3c7feba8 patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents: 15770
diff changeset
5778 static int
5b6c3c7feba8 patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents: 15770
diff changeset
5779 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
5780 {
5b6c3c7feba8 patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents: 15770
diff changeset
5781 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
5782
5b6c3c7feba8 patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents: 15770
diff changeset
5783 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
5784 {
5b6c3c7feba8 patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents: 15770
diff changeset
5785 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
5786 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
5787 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
5788 break;
5b6c3c7feba8 patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents: 15770
diff changeset
5789 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
5790 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
5791 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
5792 break;
5b6c3c7feba8 patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents: 15770
diff changeset
5793 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
5794 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
5795 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
5796 break;
5b6c3c7feba8 patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents: 15770
diff changeset
5797 default:
5b6c3c7feba8 patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents: 15770
diff changeset
5798 break;
5b6c3c7feba8 patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents: 15770
diff changeset
5799 }
5b6c3c7feba8 patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents: 15770
diff changeset
5800 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
5801 || (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
5802 }
5b6c3c7feba8 patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents: 15770
diff changeset
5803
5b6c3c7feba8 patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents: 15770
diff changeset
5804 /*
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
5805 * Copy the values from typval_T "from" to typval_T "to".
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5806 * 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
5807 * Does not make a copy of a list, blob or dict but copies the reference!
1772
42ac369bd824 updated for version 7.2-070
vimboss
parents: 1768
diff changeset
5808 * It is OK for "from" and "to" to point to the same item. This is used to
42ac369bd824 updated for version 7.2-070
vimboss
parents: 1768
diff changeset
5809 * make a copy later.
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5810 */
2050
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2045
diff changeset
5811 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5812 copy_tv(typval_T *from, typval_T *to)
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5813 {
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5814 to->v_type = from->v_type;
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 142
diff changeset
5815 to->v_lock = 0;
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5816 switch (from->v_type)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5817 {
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5818 case VAR_NUMBER:
19102
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 19087
diff changeset
5819 case VAR_BOOL:
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7705
diff changeset
5820 case VAR_SPECIAL:
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5821 to->vval.v_number = from->vval.v_number;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5822 break;
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5823 case VAR_FLOAT:
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5824 #ifdef FEAT_FLOAT
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5825 to->vval.v_float = from->vval.v_float;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5826 break;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5827 #endif
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5828 case VAR_JOB:
8493
caed4b2d305f commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents: 8491
diff changeset
5829 #ifdef FEAT_JOB_CHANNEL
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5830 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
5831 if (to->vval.v_job != NULL)
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
5832 ++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
5833 break;
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5834 #endif
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
5835 case VAR_CHANNEL:
8493
caed4b2d305f commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents: 8491
diff changeset
5836 #ifdef FEAT_JOB_CHANNEL
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
5837 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
5838 if (to->vval.v_channel != NULL)
e4c3f6720b03 commit https://github.com/vim/vim/commit/5cefd4098204b4677387511b586673649f2fab48
Christian Brabandt <cb@256bit.org>
parents: 8062
diff changeset
5839 ++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
5840 break;
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
5841 #endif
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5842 case VAR_STRING:
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5843 case VAR_FUNC:
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5844 if (from->vval.v_string == NULL)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5845 to->vval.v_string = NULL;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5846 else
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
5847 {
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5848 to->vval.v_string = vim_strsave(from->vval.v_string);
117
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
5849 if (from->v_type == VAR_FUNC)
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
5850 func_ref(to->vval.v_string);
d4ea645c7748 updated for version 7.0041
vimboss
parents: 110
diff changeset
5851 }
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5852 break;
8538
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
5853 case VAR_PARTIAL:
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
5854 if (from->vval.v_partial == NULL)
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
5855 to->vval.v_partial = NULL;
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
5856 else
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
5857 {
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
5858 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
5859 ++to->vval.v_partial->pt_refcount;
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
5860 }
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
5861 break;
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
5862 case VAR_BLOB:
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
5863 if (from->vval.v_blob == NULL)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
5864 to->vval.v_blob = NULL;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
5865 else
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
5866 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
5867 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
5868 ++to->vval.v_blob->bv_refcount;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
5869 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
5870 break;
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5871 case VAR_LIST:
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5872 if (from->vval.v_list == NULL)
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5873 to->vval.v_list = NULL;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5874 else
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5875 {
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5876 to->vval.v_list = from->vval.v_list;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5877 ++to->vval.v_list->lv_refcount;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5878 }
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5879 break;
100
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
5880 case VAR_DICT:
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
5881 if (from->vval.v_dict == NULL)
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
5882 to->vval.v_dict = NULL;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
5883 else
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
5884 {
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
5885 to->vval.v_dict = from->vval.v_dict;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
5886 ++to->vval.v_dict->dv_refcount;
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
5887 }
1f3902f3eb5c updated for version 7.0038
vimboss
parents: 97
diff changeset
5888 break;
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5889 case VAR_UNKNOWN:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5890 case VAR_VOID:
19554
b38d73f36467 patch 8.2.0334: abort called when using test_void()
Bram Moolenaar <Bram@vim.org>
parents: 19477
diff changeset
5891 internal_error_no_abort("copy_tv(UNKNOWN)");
56
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5892 break;
dbf53ece2e23 updated for version 7.0029
vimboss
parents: 51
diff changeset
5893 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5894 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5895
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5896 /*
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5897 * Make a copy of an item.
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5898 * Lists and Dictionaries are also copied. A deep copy if "deep" is set.
165
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5899 * For deepcopy() "copyID" is zero for a full copy or the ID for when a
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5900 * reference to an already copied list/dict can be used.
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5901 * Returns FAIL or OK.
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5902 */
9556
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents: 9527
diff changeset
5903 int
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5904 item_copy(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5905 typval_T *from,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5906 typval_T *to,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5907 int deep,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
5908 int copyID)
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5909 {
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5910 static int recurse = 0;
165
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5911 int ret = OK;
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5912
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
5913 if (recurse >= DICT_MAXNEST)
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5914 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
5915 emsg(_("E698: variable nested too deep for making a copy"));
165
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5916 return FAIL;
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5917 }
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5918 ++recurse;
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5919
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5920 switch (from->v_type)
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5921 {
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5922 case VAR_NUMBER:
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
5923 case VAR_FLOAT:
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5924 case VAR_STRING:
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5925 case VAR_FUNC:
8538
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents: 8536
diff changeset
5926 case VAR_PARTIAL:
19102
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 19087
diff changeset
5927 case VAR_BOOL:
7862
d4fec9208e7e commit https://github.com/vim/vim/commit/155500077c80cdb5d9c63996000c011b66a676bf
Christian Brabandt <cb@256bit.org>
parents: 7856
diff changeset
5928 case VAR_SPECIAL:
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7955
diff changeset
5929 case VAR_JOB:
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
5930 case VAR_CHANNEL:
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5931 copy_tv(from, to);
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5932 break;
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5933 case VAR_LIST:
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5934 to->v_type = VAR_LIST;
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 142
diff changeset
5935 to->v_lock = 0;
165
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5936 if (from->vval.v_list == NULL)
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5937 to->vval.v_list = NULL;
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5938 else if (copyID != 0 && from->vval.v_list->lv_copyID == copyID)
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5939 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5940 // use the copy made earlier
165
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5941 to->vval.v_list = from->vval.v_list->lv_copylist;
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5942 ++to->vval.v_list->lv_refcount;
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5943 }
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5944 else
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5945 to->vval.v_list = list_copy(from->vval.v_list, deep, copyID);
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5946 if (to->vval.v_list == NULL)
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5947 ret = FAIL;
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5948 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
5949 case VAR_BLOB:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5950 ret = blob_copy(from->vval.v_blob, 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
5951 break;
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5952 case VAR_DICT:
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5953 to->v_type = VAR_DICT;
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 142
diff changeset
5954 to->v_lock = 0;
165
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5955 if (from->vval.v_dict == NULL)
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5956 to->vval.v_dict = NULL;
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5957 else if (copyID != 0 && from->vval.v_dict->dv_copyID == copyID)
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5958 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
5959 // use the copy made earlier
165
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5960 to->vval.v_dict = from->vval.v_dict->dv_copydict;
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5961 ++to->vval.v_dict->dv_refcount;
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5962 }
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5963 else
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5964 to->vval.v_dict = dict_copy(from->vval.v_dict, deep, copyID);
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5965 if (to->vval.v_dict == NULL)
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5966 ret = FAIL;
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5967 break;
7943
e875f0fbd9c0 commit https://github.com/vim/vim/commit/a03f23351588f04276469cd7742b7ec655bb604b
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
5968 case VAR_UNKNOWN:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5969 case VAR_VOID:
19554
b38d73f36467 patch 8.2.0334: abort called when using test_void()
Bram Moolenaar <Bram@vim.org>
parents: 19477
diff changeset
5970 internal_error_no_abort("item_copy(UNKNOWN)");
165
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5971 ret = FAIL;
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5972 }
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5973 --recurse;
165
e943e5502fc9 updated for version 7.0050
vimboss
parents: 163
diff changeset
5974 return ret;
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5975 }
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
5976
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5977 void
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5978 echo_one(typval_T *rettv, int with_space, int *atstart, int *needclr)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5979 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5980 char_u *tofree;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5981 char_u numbuf[NUMBUFLEN];
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5982 char_u *p = echo_string(rettv, &tofree, numbuf, get_copyID());
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5983
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5984 if (*atstart)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5985 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5986 *atstart = FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5987 // Call msg_start() after eval1(), evaluating the expression
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5988 // may cause a message to appear.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5989 if (with_space)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5990 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5991 // Mark the saved text as finishing the line, so that what
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5992 // follows is displayed on a new line when scrolling back
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5993 // at the more prompt.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5994 msg_sb_eol();
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5995 msg_start();
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5996 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5997 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5998 else if (with_space)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
5999 msg_puts_attr(" ", echo_attr);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6000
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6001 if (p != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6002 for ( ; *p != NUL && !got_int; ++p)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6003 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6004 if (*p == '\n' || *p == '\r' || *p == TAB)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6005 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6006 if (*p != TAB && *needclr)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6007 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6008 // remove any text still there from the command
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6009 msg_clr_eos();
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6010 *needclr = FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6011 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6012 msg_putchar_attr(*p, echo_attr);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6013 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6014 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6015 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6016 if (has_mbyte)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6017 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6018 int i = (*mb_ptr2len)(p);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6019
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6020 (void)msg_outtrans_len_attr(p, i, echo_attr);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6021 p += i - 1;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6022 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6023 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6024 (void)msg_outtrans_len_attr(p, 1, echo_attr);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6025 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6026 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6027 vim_free(tofree);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6028 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6029
104
2b913f7eb9d2 updated for version 7.0039
vimboss
parents: 100
diff changeset
6030 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6031 * ":echo expr1 ..." print each argument separated with a space, add a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6032 * newline at the end.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6033 * ":echon expr1 ..." print each argument plain.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6034 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6035 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6036 ex_echo(exarg_T *eap)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6037 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6038 char_u *arg = eap->arg;
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
6039 typval_T rettv;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6040 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6041 int needclr = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6042 int atstart = TRUE;
15079
a527110d5f56 patch 8.1.0550: expression evaluation may repeat an error message
Bram Moolenaar <Bram@vim.org>
parents: 14968
diff changeset
6043 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
6044 int called_emsg_before = called_emsg;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6045
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6046 if (eap->skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6047 ++emsg_skip;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6048 while (*arg != NUL && *arg != '|' && *arg != '\n' && !got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6049 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6050 // 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
6051 // still need to be cleared. E.g., "echo 22,44".
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
6052 need_clr_eos = needclr;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
6053
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6054 p = arg;
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
6055 if (eval1(&arg, &rettv, !eap->skip) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6056 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6057 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6058 * Report the invalid expression unless the expression evaluation
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6059 * has been cancelled due to an aborting error, an interrupt, or an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6060 * exception.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6061 */
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
6062 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
6063 && 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
6064 semsg(_(e_invexpr2), p);
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
6065 need_clr_eos = FALSE;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
6066 break;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
6067 }
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
6068 need_clr_eos = FALSE;
18ee39301b82 updated for version 7.2a
vimboss
parents: 1609
diff changeset
6069
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6070 if (!eap->skip)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6071 echo_one(&rettv, eap->cmdidx == CMD_echo, &atstart, &needclr);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6072
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
6073 clear_tv(&rettv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6074 arg = skipwhite(arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6075 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6076 eap->nextcmd = check_nextcmd(arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6077
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6078 if (eap->skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6079 --emsg_skip;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6080 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6081 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6082 // remove text that may still be there from the command
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6083 if (needclr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6084 msg_clr_eos();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6085 if (eap->cmdidx == CMD_echo)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6086 msg_end();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6087 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6088 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6089
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6090 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6091 * ":echohl {name}".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6092 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6093 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6094 ex_echohl(exarg_T *eap)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6095 {
12487
3f16cf18386c patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents: 12477
diff changeset
6096 echo_attr = syn_name2attr(eap->arg);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6097 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6098
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6099 /*
17922
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
6100 * 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
6101 */
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
6102 int
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
6103 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
6104 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
6105 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
6106 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
6107
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
6108 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6109 * ":execute expr1 ..." execute the result of an expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6110 * ":echomsg expr1 ..." Print a message
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6111 * ":echoerr expr1 ..." Print an error
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6112 * Each gets spaces around each argument and a newline at the end for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6113 * echo commands
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6114 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6115 void
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6116 ex_execute(exarg_T *eap)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6117 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6118 char_u *arg = eap->arg;
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 124
diff changeset
6119 typval_T rettv;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6120 int ret = OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6121 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6122 garray_T ga;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6123 int len;
16054
78faa25f9698 patch 8.1.1032: warnings from clang static analyzer
Bram Moolenaar <Bram@vim.org>
parents: 16036
diff changeset
6124 int save_did_emsg;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6125
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6126 ga_init2(&ga, 1, 80);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6127
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6128 if (eap->skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6129 ++emsg_skip;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6130 while (*arg != NUL && *arg != '|' && *arg != '\n')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6131 {
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
6132 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
6133 if (ret == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6134 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6135
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6136 if (!eap->skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6137 {
15219
dada0b389d4f patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
6138 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
6139
dada0b389d4f patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
6140 if (eap->cmdidx == CMD_execute)
19087
e3848b251a01 patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents: 19085
diff changeset
6141 {
e3848b251a01 patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents: 19085
diff changeset
6142 if (rettv.v_type == VAR_CHANNEL || rettv.v_type == VAR_JOB)
e3848b251a01 patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents: 19085
diff changeset
6143 {
e3848b251a01 patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents: 19085
diff changeset
6144 emsg(_(e_inval_string));
e3848b251a01 patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents: 19085
diff changeset
6145 p = NULL;
e3848b251a01 patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents: 19085
diff changeset
6146 }
e3848b251a01 patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents: 19085
diff changeset
6147 else
e3848b251a01 patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents: 19085
diff changeset
6148 p = tv_get_string_buf(&rettv, buf);
e3848b251a01 patch 8.2.0104: using channel or job with ":execute" has strange effects
Bram Moolenaar <Bram@vim.org>
parents: 19085
diff changeset
6149 }
15219
dada0b389d4f patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
6150 else
dada0b389d4f patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
6151 p = tv_stringify(&rettv, buf);
19081
3b1f83fdaabc patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
6152 if (p == NULL)
3b1f83fdaabc patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
6153 {
3b1f83fdaabc patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
6154 clear_tv(&rettv);
3b1f83fdaabc patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
6155 ret = FAIL;
3b1f83fdaabc patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
6156 break;
3b1f83fdaabc patch 8.2.0101: crash when passing null object to ":echomsg"
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
6157 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6158 len = (int)STRLEN(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6159 if (ga_grow(&ga, len + 2) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6160 {
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
6161 clear_tv(&rettv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6162 ret = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6163 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6164 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6165 if (ga.ga_len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6166 ((char_u *)(ga.ga_data))[ga.ga_len++] = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6167 STRCPY((char_u *)(ga.ga_data) + ga.ga_len, p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6168 ga.ga_len += len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6169 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6170
71
7557b6ea0fb1 updated for version 7.0030
vimboss
parents: 56
diff changeset
6171 clear_tv(&rettv);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6172 arg = skipwhite(arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6173 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6174
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6175 if (ret != FAIL && ga.ga_data != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6176 {
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
6177 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
6178 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6179 // 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
6180 // 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
6181 // 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
6182 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
6183 }
404e98047f0b patch 8.0.0467: using g< after :for does not show the right output
Christian Brabandt <cb@256bit.org>
parents: 11129
diff changeset
6184
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6185 if (eap->cmdidx == CMD_echomsg)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 615
diff changeset
6186 {
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15517
diff changeset
6187 msg_attr(ga.ga_data, echo_attr);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 615
diff changeset
6188 out_flush();
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 615
diff changeset
6189 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6190 else if (eap->cmdidx == CMD_echoerr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6191 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6192 // We don't want to abort following commands, restore did_emsg.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6193 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
6194 emsg(ga.ga_data);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6195 if (!force_abort)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6196 did_emsg = save_did_emsg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6197 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6198 else if (eap->cmdidx == CMD_execute)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6199 do_cmdline((char_u *)ga.ga_data,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6200 eap->getline, eap->cookie, DOCMD_NOWAIT|DOCMD_VERBOSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6201 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6202
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6203 ga_clear(&ga);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6204
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6205 if (eap->skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6206 --emsg_skip;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6207
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6208 eap->nextcmd = check_nextcmd(arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6209 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6210
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6211 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6212 * Skip over the name of an option: "&option", "&g:option" or "&l:option".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6213 * "arg" points to the "&" or '+' when called, to "option" when returning.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6214 * Returns NULL when no option name found. Otherwise pointer to the char
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6215 * after the option name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6216 */
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17833
diff changeset
6217 char_u *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6218 find_option_end(char_u **arg, int *opt_flags)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6219 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6220 char_u *p = *arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6221
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6222 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6223 if (*p == 'g' && p[1] == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6224 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6225 *opt_flags = OPT_GLOBAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6226 p += 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6227 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6228 else if (*p == 'l' && p[1] == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6229 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6230 *opt_flags = OPT_LOCAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6231 p += 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6232 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6233 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6234 *opt_flags = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6235
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6236 if (!ASCII_ISALPHA(*p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6237 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6238 *arg = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6239
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6240 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
6241 p += 4; // termcap option
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6242 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6243 while (ASCII_ISALPHA(*p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6244 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6245 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6246 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6247
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6248 /*
448
dd9db57ee7ce updated for version 7.0118
vimboss
parents: 446
diff changeset
6249 * Display script name where an item was last set.
dd9db57ee7ce updated for version 7.0118
vimboss
parents: 446
diff changeset
6250 * Should only be invoked when 'verbose' is non-zero.
dd9db57ee7ce updated for version 7.0118
vimboss
parents: 446
diff changeset
6251 */
dd9db57ee7ce updated for version 7.0118
vimboss
parents: 446
diff changeset
6252 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
6253 last_set_msg(sctx_T script_ctx)
448
dd9db57ee7ce updated for version 7.0118
vimboss
parents: 446
diff changeset
6254 {
507
a1059cda45f2 updated for version 7.0142
vimboss
parents: 505
diff changeset
6255 char_u *p;
a1059cda45f2 updated for version 7.0142
vimboss
parents: 505
diff changeset
6256
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
6257 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
6258 {
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14439
diff changeset
6259 p = home_replace_save(NULL, get_scriptname(script_ctx.sc_sid));
507
a1059cda45f2 updated for version 7.0142
vimboss
parents: 505
diff changeset
6260 if (p != NULL)
a1059cda45f2 updated for version 7.0142
vimboss
parents: 505
diff changeset
6261 {
a1059cda45f2 updated for version 7.0142
vimboss
parents: 505
diff changeset
6262 verbose_enter();
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15517
diff changeset
6263 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
6264 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
6265 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
6266 {
18939
25ebc35e104f patch 8.2.0030: "gF" does not work on output of "verbose command"
Bram Moolenaar <Bram@vim.org>
parents: 18851
diff changeset
6267 msg_puts(_(line_msg));
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
6268 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
6269 }
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14439
diff changeset
6270 verbose_leave();
507
a1059cda45f2 updated for version 7.0142
vimboss
parents: 505
diff changeset
6271 vim_free(p);
a1059cda45f2 updated for version 7.0142
vimboss
parents: 505
diff changeset
6272 }
448
dd9db57ee7ce updated for version 7.0118
vimboss
parents: 446
diff changeset
6273 }
dd9db57ee7ce updated for version 7.0118
vimboss
parents: 446
diff changeset
6274 }
dd9db57ee7ce updated for version 7.0118
vimboss
parents: 446
diff changeset
6275
16036
89fb86821b4a patch 8.1.1023: may use NULL pointer when indexing a blob
Bram Moolenaar <Bram@vim.org>
parents: 16013
diff changeset
6276 /*
13274
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6277 * 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
6278 */
13262
69278c25429d patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
6279 int
69278c25429d patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
6280 typval_compare(
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6281 typval_T *typ1, // first operand
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6282 typval_T *typ2, // second operand
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6283 exptype_T type, // operator
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6284 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
6285 {
69278c25429d patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
6286 int i;
69278c25429d patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
6287 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
6288 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
6289 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN];
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6290 int type_is = type == EXPR_IS || type == EXPR_ISNOT;
13262
69278c25429d patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
6291
13274
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6292 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
6293 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6294 // 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
6295 // it means TRUE.
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6296 n1 = (type == EXPR_ISNOT);
13274
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6297 }
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
6298 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
6299 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
6300 if (type_is)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
6301 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
6302 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
6303 && typ1->vval.v_blob == typ2->vval.v_blob);
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6304 if (type == EXPR_ISNOT)
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
6305 n1 = !n1;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
6306 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
6307 else if (typ1->v_type != typ2->v_type
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6308 || (type != EXPR_EQUAL && type != EXPR_NEQUAL))
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
6309 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
6310 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
6311 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
6312 else
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
6313 emsg(_(e_invalblob));
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
6314 clear_tv(typ1);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
6315 return FAIL;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
6316 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
6317 else
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
6318 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
6319 // 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
6320 n1 = blob_equal(typ1->vval.v_blob, typ2->vval.v_blob);
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6321 if (type == EXPR_NEQUAL)
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
6322 n1 = !n1;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
6323 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15219
diff changeset
6324 }
13274
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6325 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
6326 {
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6327 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
6328 {
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6329 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
6330 && typ1->vval.v_list == typ2->vval.v_list);
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6331 if (type == EXPR_ISNOT)
13274
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6332 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
6333 }
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6334 else if (typ1->v_type != typ2->v_type
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6335 || (type != EXPR_EQUAL && type != EXPR_NEQUAL))
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 {
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6337 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
6338 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
6339 else
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
6340 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
6341 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
6342 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
6343 }
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6344 else
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6345 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6346 // 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
6347 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
6348 ic, FALSE);
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6349 if (type == EXPR_NEQUAL)
13274
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6350 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
6351 }
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6352 }
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6353
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6354 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
6355 {
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6356 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
6357 {
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6358 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
6359 && typ1->vval.v_dict == typ2->vval.v_dict);
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6360 if (type == EXPR_ISNOT)
13262
69278c25429d patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
6361 n1 = !n1;
69278c25429d patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
6362 }
13274
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6363 else if (typ1->v_type != typ2->v_type
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6364 || (type != EXPR_EQUAL && type != EXPR_NEQUAL))
13274
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6365 {
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6366 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
6367 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
6368 else
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
6369 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
6370 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
6371 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
6372 }
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6373 else
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6374 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6375 // 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
6376 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
6377 ic, FALSE);
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6378 if (type == EXPR_NEQUAL)
13274
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6379 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
6380 }
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6381 }
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6382
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6383 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
6384 || 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
6385 {
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6386 if (type != EXPR_EQUAL && type != EXPR_NEQUAL
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6387 && type != EXPR_IS && type != EXPR_ISNOT)
13274
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6388 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15466
diff changeset
6389 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
6390 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
6391 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
6392 }
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6393 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
6394 && 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
6395 || (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
6396 && 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
6397 // 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
6398 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
6399 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
6400 {
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6401 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
6402 // 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
6403 // 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
6404 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
6405 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
6406 && 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
6407 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
6408 else
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6409 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
6410 }
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6411 else
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6412 n1 = tv_equal(typ1, typ2, ic, FALSE);
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6413 if (type == EXPR_NEQUAL || type == EXPR_ISNOT)
13274
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6414 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
6415 }
13262
69278c25429d patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
6416
69278c25429d patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
6417 #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
6418 /*
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6419 * 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
6420 * 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
6421 */
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6422 else if ((typ1->v_type == VAR_FLOAT || typ2->v_type == VAR_FLOAT)
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6423 && type != EXPR_MATCH && type != EXPR_NOMATCH)
13274
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6424 {
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6425 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
6426
15904
fec4416adb80 patch 8.1.0958: compiling weird regexp pattern is very slow
Bram Moolenaar <Bram@vim.org>
parents: 15868
diff changeset
6427 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
6428 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
6429 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
6430 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
6431 {
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6432 case EXPR_IS:
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6433 case EXPR_EQUAL: n1 = (f1 == f2); break;
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6434 case EXPR_ISNOT:
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6435 case EXPR_NEQUAL: n1 = (f1 != f2); break;
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6436 case EXPR_GREATER: n1 = (f1 > f2); break;
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6437 case EXPR_GEQUAL: n1 = (f1 >= f2); break;
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6438 case EXPR_SMALLER: n1 = (f1 < f2); break;
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6439 case EXPR_SEQUAL: n1 = (f1 <= f2); break;
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6440 case EXPR_UNKNOWN:
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6441 case EXPR_MATCH:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6442 default: 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
6443 }
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6444 }
13262
69278c25429d patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
6445 #endif
69278c25429d patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
6446
13274
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6447 /*
18968
24941a950cc7 patch 8.2.0045: script test fails
Bram Moolenaar <Bram@vim.org>
parents: 18966
diff changeset
6448 * If one of the two variables is a number, compare as a number.
24941a950cc7 patch 8.2.0045: script test fails
Bram Moolenaar <Bram@vim.org>
parents: 18966
diff changeset
6449 * When using "=~" or "!~", always compare as string.
24941a950cc7 patch 8.2.0045: script test fails
Bram Moolenaar <Bram@vim.org>
parents: 18966
diff changeset
6450 */
13274
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6451 else if ((typ1->v_type == VAR_NUMBER || typ2->v_type == VAR_NUMBER)
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6452 && type != EXPR_MATCH && type != EXPR_NOMATCH)
13274
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6453 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
6454 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
6455 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
6456 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
6457 {
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6458 case EXPR_IS:
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6459 case EXPR_EQUAL: n1 = (n1 == n2); break;
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6460 case EXPR_ISNOT:
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6461 case EXPR_NEQUAL: n1 = (n1 != n2); break;
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6462 case EXPR_GREATER: n1 = (n1 > n2); break;
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6463 case EXPR_GEQUAL: n1 = (n1 >= n2); break;
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6464 case EXPR_SMALLER: n1 = (n1 < n2); break;
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6465 case EXPR_SEQUAL: n1 = (n1 <= n2); break;
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6466 case EXPR_UNKNOWN:
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6467 case EXPR_MATCH:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6468 default: 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
6469 }
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6470 }
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6471 else
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6472 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
6473 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
6474 s2 = tv_get_string_buf(typ2, buf2);
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6475 if (type != EXPR_MATCH && type != EXPR_NOMATCH)
13274
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6476 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
6477 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
6478 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
6479 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
6480 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
6481 {
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6482 case EXPR_IS:
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6483 case EXPR_EQUAL: n1 = (i == 0); break;
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6484 case EXPR_ISNOT:
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6485 case EXPR_NEQUAL: n1 = (i != 0); break;
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6486 case EXPR_GREATER: n1 = (i > 0); break;
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6487 case EXPR_GEQUAL: n1 = (i >= 0); break;
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6488 case EXPR_SMALLER: n1 = (i < 0); break;
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6489 case EXPR_SEQUAL: n1 = (i <= 0); break;
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6490
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6491 case EXPR_MATCH:
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6492 case EXPR_NOMATCH:
13274
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6493 n1 = pattern_match(s2, s1, ic);
19017
d9ea4f0bfd34 patch 8.2.0069: ETYPE_ is used for two different enums
Bram Moolenaar <Bram@vim.org>
parents: 19001
diff changeset
6494 if (type == EXPR_NOMATCH)
13274
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6495 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
6496 break;
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6497
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19108
diff changeset
6498 default: 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
6499 }
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6500 }
f4b4162264b1 patch 8.0.1511: some code for the debugger watch expression is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
6501 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
6502 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
6503 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
6504
13262
69278c25429d patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
6505 return OK;
69278c25429d patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
6506 }
69278c25429d patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
6507
69278c25429d patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
6508 char_u *
14391
46f14852a919 patch 8.1.0210: still a few K&R function declarations
Christian Brabandt <cb@256bit.org>
parents: 14331
diff changeset
6509 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
6510 {
69278c25429d patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
6511 char_u *tofree;
69278c25429d patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
6512 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
6513 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
6514
69278c25429d patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
6515 if (arg == NULL)
69278c25429d patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
6516 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
6517 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
6518 // 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
6519 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
6520 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
6521 return ret;
69278c25429d patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
6522 }
69278c25429d patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
6523
17966
46f95606b9ec patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
6524 #endif // FEAT_EVAL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6525
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6526 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6527 * 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
6528 * When "sub" is NULL "expr" is used, must be a VAR_FUNC or VAR_PARTIAL.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6529 * "flags" can be "g" to do a global substitute.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6530 * Returns an allocated string, NULL for error.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6531 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6532 char_u *
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6533 do_string_sub(
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6534 char_u *str,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6535 char_u *pat,
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6536 char_u *sub,
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9587
diff changeset
6537 typval_T *expr,
7817
83861277e6a3 commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents: 7788
diff changeset
6538 char_u *flags)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6539 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6540 int sublen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6541 regmatch_T regmatch;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6542 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6543 int do_all;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6544 char_u *tail;
6332
65e72747feca updated for version 7.4.499
Bram Moolenaar <bram@vim.org>
parents: 6316
diff changeset
6545 char_u *end;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6546 garray_T ga;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6547 char_u *ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6548 char_u *save_cpo;
5623
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
6549 char_u *zero_width = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6550
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6551 // Make 'cpoptions' empty, so that the 'l' flag doesn't work here
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6552 save_cpo = p_cpo;
1672
fddea6c03dee updated for version 7.2b-004
vimboss
parents: 1668
diff changeset
6553 p_cpo = empty_option;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6554
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6555 ga_init2(&ga, 1, 200);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6556
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6557 do_all = (flags[0] == 'g');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6558
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6559 regmatch.rm_ic = p_ic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6560 regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6561 if (regmatch.regprog != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6562 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6563 tail = str;
6332
65e72747feca updated for version 7.4.499
Bram Moolenaar <bram@vim.org>
parents: 6316
diff changeset
6564 end = str + STRLEN(str);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6565 while (vim_regexec_nl(&regmatch, str, (colnr_T)(tail - str)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6566 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6567 // Skip empty match except for first match.
5623
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
6568 if (regmatch.startp[0] == regmatch.endp[0])
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
6569 {
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
6570 if (zero_width == regmatch.startp[0])
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
6571 {
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6572 // 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
6573 i = mb_ptr2len(tail);
5964
238f5027830c updated for version 7.4.323
Bram Moolenaar <bram@vim.org>
parents: 5944
diff changeset
6574 mch_memmove((char_u *)ga.ga_data + ga.ga_len, tail,
238f5027830c updated for version 7.4.323
Bram Moolenaar <bram@vim.org>
parents: 5944
diff changeset
6575 (size_t)i);
238f5027830c updated for version 7.4.323
Bram Moolenaar <bram@vim.org>
parents: 5944
diff changeset
6576 ga.ga_len += i;
238f5027830c updated for version 7.4.323
Bram Moolenaar <bram@vim.org>
parents: 5944
diff changeset
6577 tail += i;
5623
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
6578 continue;
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
6579 }
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
6580 zero_width = regmatch.startp[0];
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
6581 }
d59544f3022b updated for version 7.4.158
Bram Moolenaar <bram@vim.org>
parents: 5614
diff changeset
6582
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6583 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6584 * Get some space for a temporary buffer to do the substitution
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6585 * into. It will contain:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6586 * - The text up to where the match is.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6587 * - The substituted text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6588 * - The text after the match.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6589 */
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9587
diff changeset
6590 sublen = vim_regsub(&regmatch, sub, expr, tail, FALSE, TRUE, FALSE);
6332
65e72747feca updated for version 7.4.499
Bram Moolenaar <bram@vim.org>
parents: 6316
diff changeset
6591 if (ga_grow(&ga, (int)((end - tail) + sublen -
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6592 (regmatch.endp[0] - regmatch.startp[0]))) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6593 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6594 ga_clear(&ga);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6595 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6596 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6597
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6598 // copy the text up to where the match is
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6599 i = (int)(regmatch.startp[0] - tail);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6600 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
6601 // add the substituted text
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9587
diff changeset
6602 (void)vim_regsub(&regmatch, sub, expr, (char_u *)ga.ga_data
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6603 + ga.ga_len + i, TRUE, TRUE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6604 ga.ga_len += i + sublen - 1;
5388
8ced827b2e8b updated for version 7.4.045
Bram Moolenaar <bram@vim.org>
parents: 5378
diff changeset
6605 tail = regmatch.endp[0];
8ced827b2e8b updated for version 7.4.045
Bram Moolenaar <bram@vim.org>
parents: 5378
diff changeset
6606 if (*tail == NUL)
8ced827b2e8b updated for version 7.4.045
Bram Moolenaar <bram@vim.org>
parents: 5378
diff changeset
6607 break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6608 if (!do_all)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6609 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6610 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6611
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6612 if (ga.ga_data != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6613 STRCPY((char *)ga.ga_data + ga.ga_len, tail);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6614
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4778
diff changeset
6615 vim_regfree(regmatch.regprog);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6616 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6617
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6618 ret = vim_strsave(ga.ga_data == NULL ? str : (char_u *)ga.ga_data);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6619 ga_clear(&ga);
1672
fddea6c03dee updated for version 7.2b-004
vimboss
parents: 1668
diff changeset
6620 if (p_cpo == empty_option)
fddea6c03dee updated for version 7.2b-004
vimboss
parents: 1668
diff changeset
6621 p_cpo = save_cpo;
fddea6c03dee updated for version 7.2b-004
vimboss
parents: 1668
diff changeset
6622 else
18777
3a68dc2a1bc1 patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
6623 // Darn, evaluating {sub} expression or {expr} changed the value.
1672
fddea6c03dee updated for version 7.2b-004
vimboss
parents: 1668
diff changeset
6624 free_string_option(save_cpo);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6625
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6626 return ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6627 }