Mercurial > vim
annotate src/dict.c @ 18069:1f52c157c2e9
Added tag v8.1.2029 for changeset 1101eacc1444fe34d9cb7c7a499843f16c07f360
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 14 Sep 2019 21:15:04 +0200 |
parents | fb773f73a4be |
children | 2ec4ed3f5e12 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9858
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2 * |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4 * |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
8 */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
9 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
10 /* |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
11 * dict.c: Dictionary support |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
12 */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
13 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
14 #include "vim.h" |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
15 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
16 #if defined(FEAT_EVAL) || defined(PROTO) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
17 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
18 /* List head for garbage collection. Although there can be a reference loop |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
19 * from partial to dict to partial, we don't need to keep track of the partial, |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
20 * since it will get freed when the dict is unused and gets freed. */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
21 static dict_T *first_dict = NULL; /* list of all dicts */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
22 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
23 /* |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
24 * Allocate an empty header for a dictionary. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
25 */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
26 dict_T * |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
27 dict_alloc(void) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
28 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
29 dict_T *d; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
30 |
17159
3fd0765f454f
patch 8.1.1579: dict and list could be GC'ed while displaying error
Bram Moolenaar <Bram@vim.org>
parents:
17123
diff
changeset
|
31 d = ALLOC_CLEAR_ONE(dict_T); |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
32 if (d != NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
33 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
34 /* Add the dict to the list of dicts for garbage collection. */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
35 if (first_dict != NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
36 first_dict->dv_used_prev = d; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
37 d->dv_used_next = first_dict; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
38 d->dv_used_prev = NULL; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
39 first_dict = d; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
40 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
41 hash_init(&d->dv_hashtab); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
42 d->dv_lock = 0; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
43 d->dv_scope = 0; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
44 d->dv_refcount = 0; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
45 d->dv_copyID = 0; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
46 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
47 return d; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
48 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
49 |
15016
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14303
diff
changeset
|
50 /* |
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14303
diff
changeset
|
51 * dict_alloc() with an ID for alloc_fail(). |
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14303
diff
changeset
|
52 */ |
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14303
diff
changeset
|
53 dict_T * |
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14303
diff
changeset
|
54 dict_alloc_id(alloc_id_T id UNUSED) |
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14303
diff
changeset
|
55 { |
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14303
diff
changeset
|
56 #ifdef FEAT_EVAL |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
57 if (alloc_fail_id == id && alloc_does_fail(sizeof(list_T))) |
15016
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14303
diff
changeset
|
58 return NULL; |
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14303
diff
changeset
|
59 #endif |
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14303
diff
changeset
|
60 return (dict_alloc()); |
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14303
diff
changeset
|
61 } |
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14303
diff
changeset
|
62 |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
63 dict_T * |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
64 dict_alloc_lock(int lock) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
65 { |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
66 dict_T *d = dict_alloc(); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
67 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
68 if (d != NULL) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
69 d->dv_lock = lock; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
70 return d; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
71 } |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
72 |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
73 /* |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
74 * Allocate an empty dict for a return value. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
75 * Returns OK or FAIL. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
76 */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
77 int |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
78 rettv_dict_alloc(typval_T *rettv) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
79 { |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
80 dict_T *d = dict_alloc_lock(0); |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
81 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
82 if (d == NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
83 return FAIL; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
84 |
11418
162bcd0debd7
patch 8.0.0593: duplication of code for adding a list or dict return value
Christian Brabandt <cb@256bit.org>
parents:
11142
diff
changeset
|
85 rettv_dict_set(rettv, d); |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
86 return OK; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
87 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
88 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
89 /* |
11418
162bcd0debd7
patch 8.0.0593: duplication of code for adding a list or dict return value
Christian Brabandt <cb@256bit.org>
parents:
11142
diff
changeset
|
90 * Set a dictionary as the return value |
162bcd0debd7
patch 8.0.0593: duplication of code for adding a list or dict return value
Christian Brabandt <cb@256bit.org>
parents:
11142
diff
changeset
|
91 */ |
162bcd0debd7
patch 8.0.0593: duplication of code for adding a list or dict return value
Christian Brabandt <cb@256bit.org>
parents:
11142
diff
changeset
|
92 void |
162bcd0debd7
patch 8.0.0593: duplication of code for adding a list or dict return value
Christian Brabandt <cb@256bit.org>
parents:
11142
diff
changeset
|
93 rettv_dict_set(typval_T *rettv, dict_T *d) |
162bcd0debd7
patch 8.0.0593: duplication of code for adding a list or dict return value
Christian Brabandt <cb@256bit.org>
parents:
11142
diff
changeset
|
94 { |
162bcd0debd7
patch 8.0.0593: duplication of code for adding a list or dict return value
Christian Brabandt <cb@256bit.org>
parents:
11142
diff
changeset
|
95 rettv->v_type = VAR_DICT; |
162bcd0debd7
patch 8.0.0593: duplication of code for adding a list or dict return value
Christian Brabandt <cb@256bit.org>
parents:
11142
diff
changeset
|
96 rettv->vval.v_dict = d; |
162bcd0debd7
patch 8.0.0593: duplication of code for adding a list or dict return value
Christian Brabandt <cb@256bit.org>
parents:
11142
diff
changeset
|
97 if (d != NULL) |
162bcd0debd7
patch 8.0.0593: duplication of code for adding a list or dict return value
Christian Brabandt <cb@256bit.org>
parents:
11142
diff
changeset
|
98 ++d->dv_refcount; |
162bcd0debd7
patch 8.0.0593: duplication of code for adding a list or dict return value
Christian Brabandt <cb@256bit.org>
parents:
11142
diff
changeset
|
99 } |
162bcd0debd7
patch 8.0.0593: duplication of code for adding a list or dict return value
Christian Brabandt <cb@256bit.org>
parents:
11142
diff
changeset
|
100 |
162bcd0debd7
patch 8.0.0593: duplication of code for adding a list or dict return value
Christian Brabandt <cb@256bit.org>
parents:
11142
diff
changeset
|
101 /* |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
102 * Free a Dictionary, including all non-container items it contains. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
103 * Ignores the reference count. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
104 */ |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
105 void |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
106 dict_free_contents(dict_T *d) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
107 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
108 int todo; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
109 hashitem_T *hi; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
110 dictitem_T *di; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
111 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
112 /* Lock the hashtab, we don't want it to resize while freeing items. */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
113 hash_lock(&d->dv_hashtab); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
114 todo = (int)d->dv_hashtab.ht_used; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
115 for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
116 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
117 if (!HASHITEM_EMPTY(hi)) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
118 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
119 /* Remove the item before deleting it, just in case there is |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
120 * something recursive causing trouble. */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
121 di = HI2DI(hi); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
122 hash_remove(&d->dv_hashtab, hi); |
10952
835604f3c37a
patch 8.0.0365: might free a dict item that wasn't allocated
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
123 dictitem_free(di); |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
124 --todo; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
125 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
126 } |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
127 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
128 /* The hashtab is still locked, it has to be re-initialized anyway */ |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
129 hash_clear(&d->dv_hashtab); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
130 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
131 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
132 static void |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
133 dict_free_dict(dict_T *d) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
134 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
135 /* Remove the dict from the list of dicts for garbage collection. */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
136 if (d->dv_used_prev == NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
137 first_dict = d->dv_used_next; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
138 else |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
139 d->dv_used_prev->dv_used_next = d->dv_used_next; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
140 if (d->dv_used_next != NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
141 d->dv_used_next->dv_used_prev = d->dv_used_prev; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
142 vim_free(d); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
143 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
144 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
145 static void |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
146 dict_free(dict_T *d) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
147 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
148 if (!in_free_unref_items) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
149 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
150 dict_free_contents(d); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
151 dict_free_dict(d); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
152 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
153 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
154 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
155 /* |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
156 * Unreference a Dictionary: decrement the reference count and free it when it |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
157 * becomes zero. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
158 */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
159 void |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
160 dict_unref(dict_T *d) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
161 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
162 if (d != NULL && --d->dv_refcount <= 0) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
163 dict_free(d); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
164 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
165 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
166 /* |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
167 * Go through the list of dicts and free items without the copyID. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
168 * Returns TRUE if something was freed. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
169 */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
170 int |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
171 dict_free_nonref(int copyID) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
172 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
173 dict_T *dd; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
174 int did_free = FALSE; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
175 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
176 for (dd = first_dict; dd != NULL; dd = dd->dv_used_next) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
177 if ((dd->dv_copyID & COPYID_MASK) != (copyID & COPYID_MASK)) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
178 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
179 /* Free the Dictionary and ordinary items it contains, but don't |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
180 * recurse into Lists and Dictionaries, they will be in the list |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
181 * of dicts or list of lists. */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
182 dict_free_contents(dd); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
183 did_free = TRUE; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
184 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
185 return did_free; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
186 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
187 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
188 void |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
189 dict_free_items(int copyID) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
190 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
191 dict_T *dd, *dd_next; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
192 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
193 for (dd = first_dict; dd != NULL; dd = dd_next) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
194 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
195 dd_next = dd->dv_used_next; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
196 if ((dd->dv_copyID & COPYID_MASK) != (copyID & COPYID_MASK)) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
197 dict_free_dict(dd); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
198 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
199 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
200 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
201 /* |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
202 * Allocate a Dictionary item. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
203 * The "key" is copied to the new item. |
14303
f761a55a8aed
patch 8.1.0167: lock flag in new dictitem is reset in many places
Christian Brabandt <cb@256bit.org>
parents:
14301
diff
changeset
|
204 * Note that the type and value of the item "di_tv" still needs to be |
f761a55a8aed
patch 8.1.0167: lock flag in new dictitem is reset in many places
Christian Brabandt <cb@256bit.org>
parents:
14301
diff
changeset
|
205 * initialized! |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
206 * Returns NULL when out of memory. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
207 */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
208 dictitem_T * |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
209 dictitem_alloc(char_u *key) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
210 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
211 dictitem_T *di; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
212 |
17655
8f82b1ec99b7
patch 8.1.1825: allocating more memory than needed for extended structs
Bram Moolenaar <Bram@vim.org>
parents:
17530
diff
changeset
|
213 di = alloc(offsetof(dictitem_T, di_key) + STRLEN(key) + 1); |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
214 if (di != NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
215 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
216 STRCPY(di->di_key, key); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
217 di->di_flags = DI_FLAGS_ALLOC; |
14303
f761a55a8aed
patch 8.1.0167: lock flag in new dictitem is reset in many places
Christian Brabandt <cb@256bit.org>
parents:
14301
diff
changeset
|
218 di->di_tv.v_lock = 0; |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
219 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
220 return di; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
221 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
222 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
223 /* |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
224 * Make a copy of a Dictionary item. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
225 */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
226 static dictitem_T * |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
227 dictitem_copy(dictitem_T *org) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
228 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
229 dictitem_T *di; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
230 |
17655
8f82b1ec99b7
patch 8.1.1825: allocating more memory than needed for extended structs
Bram Moolenaar <Bram@vim.org>
parents:
17530
diff
changeset
|
231 di = alloc(offsetof(dictitem_T, di_key) + STRLEN(org->di_key) + 1); |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
232 if (di != NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
233 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
234 STRCPY(di->di_key, org->di_key); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
235 di->di_flags = DI_FLAGS_ALLOC; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
236 copy_tv(&org->di_tv, &di->di_tv); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
237 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
238 return di; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
239 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
240 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
241 /* |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
242 * Remove item "item" from Dictionary "dict" and free it. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
243 */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
244 void |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
245 dictitem_remove(dict_T *dict, dictitem_T *item) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
246 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
247 hashitem_T *hi; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
248 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
249 hi = hash_find(&dict->dv_hashtab, item->di_key); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
250 if (HASHITEM_EMPTY(hi)) |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
251 internal_error("dictitem_remove()"); |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
252 else |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
253 hash_remove(&dict->dv_hashtab, hi); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
254 dictitem_free(item); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
255 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
256 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
257 /* |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
258 * Free a dict item. Also clears the value. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
259 */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
260 void |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
261 dictitem_free(dictitem_T *item) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
262 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
263 clear_tv(&item->di_tv); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
264 if (item->di_flags & DI_FLAGS_ALLOC) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
265 vim_free(item); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
266 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
267 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
268 /* |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
269 * Make a copy of dict "d". Shallow if "deep" is FALSE. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
270 * The refcount of the new dict is set to 1. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
271 * See item_copy() for "copyID". |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
272 * Returns NULL when out of memory. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
273 */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
274 dict_T * |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
275 dict_copy(dict_T *orig, int deep, int copyID) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
276 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
277 dict_T *copy; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
278 dictitem_T *di; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
279 int todo; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
280 hashitem_T *hi; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
281 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
282 if (orig == NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
283 return NULL; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
284 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
285 copy = dict_alloc(); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
286 if (copy != NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
287 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
288 if (copyID != 0) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
289 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
290 orig->dv_copyID = copyID; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
291 orig->dv_copydict = copy; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
292 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
293 todo = (int)orig->dv_hashtab.ht_used; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
294 for (hi = orig->dv_hashtab.ht_array; todo > 0 && !got_int; ++hi) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
295 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
296 if (!HASHITEM_EMPTY(hi)) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
297 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
298 --todo; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
299 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
300 di = dictitem_alloc(hi->hi_key); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
301 if (di == NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
302 break; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
303 if (deep) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
304 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
305 if (item_copy(&HI2DI(hi)->di_tv, &di->di_tv, deep, |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
306 copyID) == FAIL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
307 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
308 vim_free(di); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
309 break; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
310 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
311 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
312 else |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
313 copy_tv(&HI2DI(hi)->di_tv, &di->di_tv); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
314 if (dict_add(copy, di) == FAIL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
315 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
316 dictitem_free(di); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
317 break; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
318 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
319 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
320 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
321 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
322 ++copy->dv_refcount; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
323 if (todo > 0) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
324 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
325 dict_unref(copy); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
326 copy = NULL; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
327 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
328 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
329 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
330 return copy; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
331 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
332 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
333 /* |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
334 * Add item "item" to Dictionary "d". |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
335 * Returns FAIL when out of memory and when key already exists. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
336 */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
337 int |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
338 dict_add(dict_T *d, dictitem_T *item) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
339 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
340 return hash_add(&d->dv_hashtab, item->di_key); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
341 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
342 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
343 /* |
16268
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
15780
diff
changeset
|
344 * Add a number or special entry to dictionary "d". |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
345 * Returns FAIL when out of memory and when key already exists. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
346 */ |
16268
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
15780
diff
changeset
|
347 static int |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
15780
diff
changeset
|
348 dict_add_number_special(dict_T *d, char *key, varnumber_T nr, int special) |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
349 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
350 dictitem_T *item; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
351 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
352 item = dictitem_alloc((char_u *)key); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
353 if (item == NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
354 return FAIL; |
16268
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
15780
diff
changeset
|
355 item->di_tv.v_type = special ? VAR_SPECIAL : VAR_NUMBER; |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
356 item->di_tv.vval.v_number = nr; |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
357 if (dict_add(d, item) == FAIL) |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
358 { |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
359 dictitem_free(item); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
360 return FAIL; |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
361 } |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
362 return OK; |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
363 } |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
364 |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
365 /* |
16268
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
15780
diff
changeset
|
366 * Add a number entry to dictionary "d". |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
15780
diff
changeset
|
367 * Returns FAIL when out of memory and when key already exists. |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
15780
diff
changeset
|
368 */ |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
15780
diff
changeset
|
369 int |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
15780
diff
changeset
|
370 dict_add_number(dict_T *d, char *key, varnumber_T nr) |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
15780
diff
changeset
|
371 { |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
15780
diff
changeset
|
372 return dict_add_number_special(d, key, nr, FALSE); |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
15780
diff
changeset
|
373 } |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
15780
diff
changeset
|
374 |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
15780
diff
changeset
|
375 /* |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
15780
diff
changeset
|
376 * Add a special entry to dictionary "d". |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
15780
diff
changeset
|
377 * Returns FAIL when out of memory and when key already exists. |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
15780
diff
changeset
|
378 */ |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
15780
diff
changeset
|
379 int |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
15780
diff
changeset
|
380 dict_add_special(dict_T *d, char *key, varnumber_T nr) |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
15780
diff
changeset
|
381 { |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
15780
diff
changeset
|
382 return dict_add_number_special(d, key, nr, TRUE); |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
15780
diff
changeset
|
383 } |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
15780
diff
changeset
|
384 |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
15780
diff
changeset
|
385 /* |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
386 * Add a string entry to dictionary "d". |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
387 * Returns FAIL when out of memory and when key already exists. |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
388 */ |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
389 int |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
390 dict_add_string(dict_T *d, char *key, char_u *str) |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
391 { |
15267
762fccd84b7c
patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
392 return dict_add_string_len(d, key, str, -1); |
762fccd84b7c
patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
393 } |
762fccd84b7c
patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
394 |
762fccd84b7c
patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
395 /* |
762fccd84b7c
patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
396 * Add a string entry to dictionary "d". |
762fccd84b7c
patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
397 * "str" will be copied to allocated memory. |
762fccd84b7c
patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
398 * When "len" is -1 use the whole string, otherwise only this many bytes. |
762fccd84b7c
patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
399 * Returns FAIL when out of memory and when key already exists. |
762fccd84b7c
patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
400 */ |
762fccd84b7c
patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
401 int |
762fccd84b7c
patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
402 dict_add_string_len(dict_T *d, char *key, char_u *str, int len) |
762fccd84b7c
patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
403 { |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
404 dictitem_T *item; |
15267
762fccd84b7c
patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
405 char_u *val = NULL; |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
406 |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
407 item = dictitem_alloc((char_u *)key); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
408 if (item == NULL) |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
409 return FAIL; |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
410 item->di_tv.v_type = VAR_STRING; |
15267
762fccd84b7c
patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
411 if (str != NULL) |
762fccd84b7c
patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
412 { |
762fccd84b7c
patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
413 if (len == -1) |
762fccd84b7c
patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
414 val = vim_strsave(str); |
762fccd84b7c
patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
415 else |
762fccd84b7c
patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
416 val = vim_strnsave(str, len); |
762fccd84b7c
patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
417 } |
762fccd84b7c
patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
418 item->di_tv.vval.v_string = val; |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
419 if (dict_add(d, item) == FAIL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
420 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
421 dictitem_free(item); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
422 return FAIL; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
423 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
424 return OK; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
425 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
426 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
427 /* |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
428 * Add a list entry to dictionary "d". |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
429 * Returns FAIL when out of memory and when key already exists. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
430 */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
431 int |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
432 dict_add_list(dict_T *d, char *key, list_T *list) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
433 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
434 dictitem_T *item; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
435 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
436 item = dictitem_alloc((char_u *)key); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
437 if (item == NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
438 return FAIL; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
439 item->di_tv.v_type = VAR_LIST; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
440 item->di_tv.vval.v_list = list; |
11142
a54985a73ab2
patch 8.0.0458: potential crash if adding list or dict to dict fails
Christian Brabandt <cb@256bit.org>
parents:
10952
diff
changeset
|
441 ++list->lv_refcount; |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
442 if (dict_add(d, item) == FAIL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
443 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
444 dictitem_free(item); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
445 return FAIL; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
446 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
447 return OK; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
448 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
449 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
450 /* |
17123
efc6f5e3b543
patch 8.1.1561: popup_setoptions() is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16902
diff
changeset
|
451 * Add a callback to dictionary "d". |
efc6f5e3b543
patch 8.1.1561: popup_setoptions() is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16902
diff
changeset
|
452 * Returns FAIL when out of memory and when key already exists. |
efc6f5e3b543
patch 8.1.1561: popup_setoptions() is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16902
diff
changeset
|
453 */ |
efc6f5e3b543
patch 8.1.1561: popup_setoptions() is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16902
diff
changeset
|
454 int |
efc6f5e3b543
patch 8.1.1561: popup_setoptions() is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16902
diff
changeset
|
455 dict_add_callback(dict_T *d, char *key, callback_T *cb) |
efc6f5e3b543
patch 8.1.1561: popup_setoptions() is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16902
diff
changeset
|
456 { |
efc6f5e3b543
patch 8.1.1561: popup_setoptions() is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16902
diff
changeset
|
457 dictitem_T *item; |
efc6f5e3b543
patch 8.1.1561: popup_setoptions() is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16902
diff
changeset
|
458 |
efc6f5e3b543
patch 8.1.1561: popup_setoptions() is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16902
diff
changeset
|
459 item = dictitem_alloc((char_u *)key); |
efc6f5e3b543
patch 8.1.1561: popup_setoptions() is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16902
diff
changeset
|
460 if (item == NULL) |
efc6f5e3b543
patch 8.1.1561: popup_setoptions() is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16902
diff
changeset
|
461 return FAIL; |
efc6f5e3b543
patch 8.1.1561: popup_setoptions() is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16902
diff
changeset
|
462 put_callback(cb, &item->di_tv); |
efc6f5e3b543
patch 8.1.1561: popup_setoptions() is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16902
diff
changeset
|
463 if (dict_add(d, item) == FAIL) |
efc6f5e3b543
patch 8.1.1561: popup_setoptions() is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16902
diff
changeset
|
464 { |
efc6f5e3b543
patch 8.1.1561: popup_setoptions() is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16902
diff
changeset
|
465 dictitem_free(item); |
efc6f5e3b543
patch 8.1.1561: popup_setoptions() is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16902
diff
changeset
|
466 return FAIL; |
efc6f5e3b543
patch 8.1.1561: popup_setoptions() is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16902
diff
changeset
|
467 } |
efc6f5e3b543
patch 8.1.1561: popup_setoptions() is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16902
diff
changeset
|
468 return OK; |
efc6f5e3b543
patch 8.1.1561: popup_setoptions() is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16902
diff
changeset
|
469 } |
efc6f5e3b543
patch 8.1.1561: popup_setoptions() is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16902
diff
changeset
|
470 |
efc6f5e3b543
patch 8.1.1561: popup_setoptions() is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16902
diff
changeset
|
471 /* |
16447
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
472 * Initializes "iter" for iterating over dictionary items with |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
473 * dict_iterate_next(). |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
474 * If "var" is not a Dict or an empty Dict then there will be nothing to |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
475 * iterate over, no error is given. |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
476 * NOTE: The dictionary must not change until iterating is finished! |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
477 */ |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
478 void |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
479 dict_iterate_start(typval_T *var, dict_iterator_T *iter) |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
480 { |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
481 if (var->v_type != VAR_DICT || var->vval.v_dict == NULL) |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
482 iter->dit_todo = 0; |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
483 else |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
484 { |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
485 dict_T *d = var->vval.v_dict; |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
486 |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
487 iter->dit_todo = d->dv_hashtab.ht_used; |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
488 iter->dit_hi = d->dv_hashtab.ht_array; |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
489 } |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
490 } |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
491 |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
492 /* |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
493 * Iterate over the items referred to by "iter". It should be initialized with |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
494 * dict_iterate_start(). |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
495 * Returns a pointer to the key. |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
496 * "*tv_result" is set to point to the value for that key. |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
497 * If there are no more items, NULL is returned. |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
498 */ |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
499 char_u * |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
500 dict_iterate_next(dict_iterator_T *iter, typval_T **tv_result) |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
501 { |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
502 dictitem_T *di; |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
503 char_u *result; |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
504 |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
505 if (iter->dit_todo == 0) |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
506 return NULL; |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
507 |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
508 while (HASHITEM_EMPTY(iter->dit_hi)) |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
509 ++iter->dit_hi; |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
510 |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
511 di = HI2DI(iter->dit_hi); |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
512 result = di->di_key; |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
513 *tv_result = &di->di_tv; |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
514 |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
515 --iter->dit_todo; |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
516 ++iter->dit_hi; |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
517 return result; |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
518 } |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
519 |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16268
diff
changeset
|
520 /* |
9858
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9770
diff
changeset
|
521 * Add a dict entry to dictionary "d". |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9770
diff
changeset
|
522 * Returns FAIL when out of memory and when key already exists. |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9770
diff
changeset
|
523 */ |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9770
diff
changeset
|
524 int |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9770
diff
changeset
|
525 dict_add_dict(dict_T *d, char *key, dict_T *dict) |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9770
diff
changeset
|
526 { |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9770
diff
changeset
|
527 dictitem_T *item; |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9770
diff
changeset
|
528 |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9770
diff
changeset
|
529 item = dictitem_alloc((char_u *)key); |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9770
diff
changeset
|
530 if (item == NULL) |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9770
diff
changeset
|
531 return FAIL; |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9770
diff
changeset
|
532 item->di_tv.v_type = VAR_DICT; |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9770
diff
changeset
|
533 item->di_tv.vval.v_dict = dict; |
11142
a54985a73ab2
patch 8.0.0458: potential crash if adding list or dict to dict fails
Christian Brabandt <cb@256bit.org>
parents:
10952
diff
changeset
|
534 ++dict->dv_refcount; |
9858
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9770
diff
changeset
|
535 if (dict_add(d, item) == FAIL) |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9770
diff
changeset
|
536 { |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9770
diff
changeset
|
537 dictitem_free(item); |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9770
diff
changeset
|
538 return FAIL; |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9770
diff
changeset
|
539 } |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9770
diff
changeset
|
540 return OK; |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9770
diff
changeset
|
541 } |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9770
diff
changeset
|
542 |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9770
diff
changeset
|
543 /* |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
544 * Get the number of items in a Dictionary. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
545 */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
546 long |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
547 dict_len(dict_T *d) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
548 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
549 if (d == NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
550 return 0L; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
551 return (long)d->dv_hashtab.ht_used; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
552 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
553 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
554 /* |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
555 * Find item "key[len]" in Dictionary "d". |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
556 * If "len" is negative use strlen(key). |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
557 * Returns NULL when not found. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
558 */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
559 dictitem_T * |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
560 dict_find(dict_T *d, char_u *key, int len) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
561 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
562 #define AKEYLEN 200 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
563 char_u buf[AKEYLEN]; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
564 char_u *akey; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
565 char_u *tofree = NULL; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
566 hashitem_T *hi; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
567 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
568 if (d == NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
569 return NULL; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
570 if (len < 0) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
571 akey = key; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
572 else if (len >= AKEYLEN) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
573 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
574 tofree = akey = vim_strnsave(key, len); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
575 if (akey == NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
576 return NULL; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
577 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
578 else |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
579 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
580 /* Avoid a malloc/free by using buf[]. */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
581 vim_strncpy(buf, key, len); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
582 akey = buf; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
583 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
584 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
585 hi = hash_find(&d->dv_hashtab, akey); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
586 vim_free(tofree); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
587 if (HASHITEM_EMPTY(hi)) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
588 return NULL; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
589 return HI2DI(hi); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
590 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
591 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
592 /* |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
593 * Get a string item from a dictionary. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
594 * When "save" is TRUE allocate memory for it. |
9770
ba98d7ce0d74
commit https://github.com/vim/vim/commit/7dc5e2e486fe0287601968e535902a41a39f65bb
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
595 * When FALSE a shared buffer is used, can only be used once! |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
596 * Returns NULL if the entry doesn't exist or out of memory. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
597 */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
598 char_u * |
15146
7903dce131d4
patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string()
Bram Moolenaar <Bram@vim.org>
parents:
15016
diff
changeset
|
599 dict_get_string(dict_T *d, char_u *key, int save) |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
600 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
601 dictitem_T *di; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
602 char_u *s; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
603 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
604 di = dict_find(d, key, -1); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
605 if (di == NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
606 return NULL; |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
607 s = tv_get_string(&di->di_tv); |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
608 if (save && s != NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
609 s = vim_strsave(s); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
610 return s; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
611 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
612 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
613 /* |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
614 * Get a number item from a dictionary. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
615 * Returns 0 if the entry doesn't exist. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
616 */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
617 varnumber_T |
15146
7903dce131d4
patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string()
Bram Moolenaar <Bram@vim.org>
parents:
15016
diff
changeset
|
618 dict_get_number(dict_T *d, char_u *key) |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
619 { |
17905
fb773f73a4be
patch 8.1.1949: cannot scroll a popup window to the very bottom
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
620 return dict_get_number_def(d, key, 0); |
fb773f73a4be
patch 8.1.1949: cannot scroll a popup window to the very bottom
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
621 } |
fb773f73a4be
patch 8.1.1949: cannot scroll a popup window to the very bottom
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
622 |
fb773f73a4be
patch 8.1.1949: cannot scroll a popup window to the very bottom
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
623 /* |
fb773f73a4be
patch 8.1.1949: cannot scroll a popup window to the very bottom
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
624 * Get a number item from a dictionary. |
fb773f73a4be
patch 8.1.1949: cannot scroll a popup window to the very bottom
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
625 * Returns "def" if the entry doesn't exist. |
fb773f73a4be
patch 8.1.1949: cannot scroll a popup window to the very bottom
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
626 */ |
fb773f73a4be
patch 8.1.1949: cannot scroll a popup window to the very bottom
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
627 varnumber_T |
fb773f73a4be
patch 8.1.1949: cannot scroll a popup window to the very bottom
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
628 dict_get_number_def(dict_T *d, char_u *key, int def) |
fb773f73a4be
patch 8.1.1949: cannot scroll a popup window to the very bottom
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
629 { |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
630 dictitem_T *di; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
631 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
632 di = dict_find(d, key, -1); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
633 if (di == NULL) |
17905
fb773f73a4be
patch 8.1.1949: cannot scroll a popup window to the very bottom
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
634 return def; |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
635 return tv_get_number(&di->di_tv); |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
636 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
637 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
638 /* |
16902
23645f9a5ce2
patch 8.1.1452: line and col property of popup windows not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
639 * Get a number item from a dictionary. |
23645f9a5ce2
patch 8.1.1452: line and col property of popup windows not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
640 * Returns 0 if the entry doesn't exist. |
23645f9a5ce2
patch 8.1.1452: line and col property of popup windows not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
641 * Give an error if the entry is not a number. |
23645f9a5ce2
patch 8.1.1452: line and col property of popup windows not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
642 */ |
23645f9a5ce2
patch 8.1.1452: line and col property of popup windows not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
643 varnumber_T |
23645f9a5ce2
patch 8.1.1452: line and col property of popup windows not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
644 dict_get_number_check(dict_T *d, char_u *key) |
23645f9a5ce2
patch 8.1.1452: line and col property of popup windows not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
645 { |
23645f9a5ce2
patch 8.1.1452: line and col property of popup windows not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
646 dictitem_T *di; |
23645f9a5ce2
patch 8.1.1452: line and col property of popup windows not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
647 |
23645f9a5ce2
patch 8.1.1452: line and col property of popup windows not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
648 di = dict_find(d, key, -1); |
23645f9a5ce2
patch 8.1.1452: line and col property of popup windows not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
649 if (di == NULL) |
23645f9a5ce2
patch 8.1.1452: line and col property of popup windows not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
650 return 0; |
23645f9a5ce2
patch 8.1.1452: line and col property of popup windows not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
651 if (di->di_tv.v_type != VAR_NUMBER) |
23645f9a5ce2
patch 8.1.1452: line and col property of popup windows not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
652 { |
23645f9a5ce2
patch 8.1.1452: line and col property of popup windows not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
653 semsg(_(e_invarg2), tv_get_string(&di->di_tv)); |
23645f9a5ce2
patch 8.1.1452: line and col property of popup windows not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
654 return 0; |
23645f9a5ce2
patch 8.1.1452: line and col property of popup windows not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
655 } |
23645f9a5ce2
patch 8.1.1452: line and col property of popup windows not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
656 return tv_get_number(&di->di_tv); |
23645f9a5ce2
patch 8.1.1452: line and col property of popup windows not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
657 } |
23645f9a5ce2
patch 8.1.1452: line and col property of popup windows not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
658 |
23645f9a5ce2
patch 8.1.1452: line and col property of popup windows not properly checked
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
659 /* |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
660 * Return an allocated string with the string representation of a Dictionary. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
661 * May return NULL. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
662 */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
663 char_u * |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
664 dict2string(typval_T *tv, int copyID, int restore_copyID) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
665 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
666 garray_T ga; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
667 int first = TRUE; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
668 char_u *tofree; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
669 char_u numbuf[NUMBUFLEN]; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
670 hashitem_T *hi; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
671 char_u *s; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
672 dict_T *d; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
673 int todo; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
674 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
675 if ((d = tv->vval.v_dict) == NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
676 return NULL; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
677 ga_init2(&ga, (int)sizeof(char), 80); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
678 ga_append(&ga, '{'); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
679 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
680 todo = (int)d->dv_hashtab.ht_used; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
681 for (hi = d->dv_hashtab.ht_array; todo > 0 && !got_int; ++hi) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
682 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
683 if (!HASHITEM_EMPTY(hi)) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
684 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
685 --todo; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
686 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
687 if (first) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
688 first = FALSE; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
689 else |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
690 ga_concat(&ga, (char_u *)", "); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
691 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
692 tofree = string_quote(hi->hi_key, FALSE); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
693 if (tofree != NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
694 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
695 ga_concat(&ga, tofree); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
696 vim_free(tofree); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
697 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
698 ga_concat(&ga, (char_u *)": "); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
699 s = echo_string_core(&HI2DI(hi)->di_tv, &tofree, numbuf, copyID, |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
700 FALSE, restore_copyID, TRUE); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
701 if (s != NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
702 ga_concat(&ga, s); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
703 vim_free(tofree); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
704 if (s == NULL || did_echo_string_emsg) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
705 break; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
706 line_breakcheck(); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
707 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
708 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
709 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
710 if (todo > 0) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
711 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
712 vim_free(ga.ga_data); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
713 return NULL; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
714 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
715 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
716 ga_append(&ga, '}'); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
717 ga_append(&ga, NUL); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
718 return (char_u *)ga.ga_data; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
719 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
720 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
721 /* |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
722 * Get the key for #{key: val} into "tv" and advance "arg". |
17368
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17159
diff
changeset
|
723 * Return FAIL when there is no valid key. |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17159
diff
changeset
|
724 */ |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17159
diff
changeset
|
725 static int |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17159
diff
changeset
|
726 get_literal_key(char_u **arg, typval_T *tv) |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17159
diff
changeset
|
727 { |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17159
diff
changeset
|
728 char_u *p; |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17159
diff
changeset
|
729 |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17159
diff
changeset
|
730 if (!ASCII_ISALNUM(**arg) && **arg != '_' && **arg != '-') |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17159
diff
changeset
|
731 return FAIL; |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17159
diff
changeset
|
732 |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17159
diff
changeset
|
733 for (p = *arg; ASCII_ISALNUM(*p) || *p == '_' || *p == '-'; ++p) |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17159
diff
changeset
|
734 ; |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17159
diff
changeset
|
735 tv->v_type = VAR_STRING; |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17159
diff
changeset
|
736 tv->vval.v_string = vim_strnsave(*arg, (int)(p - *arg)); |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17159
diff
changeset
|
737 |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17159
diff
changeset
|
738 *arg = skipwhite(p); |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17159
diff
changeset
|
739 return OK; |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17159
diff
changeset
|
740 } |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17159
diff
changeset
|
741 |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17159
diff
changeset
|
742 /* |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
743 * Allocate a variable for a Dictionary and fill it from "*arg". |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
744 * "literal" is TRUE for #{key: val} |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
745 * Return OK or FAIL. Returns NOTDONE for {expr}. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
746 */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
747 int |
17368
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17159
diff
changeset
|
748 dict_get_tv(char_u **arg, typval_T *rettv, int evaluate, int literal) |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
749 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
750 dict_T *d = NULL; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
751 typval_T tvkey; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
752 typval_T tv; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
753 char_u *key = NULL; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
754 dictitem_T *item; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
755 char_u *start = skipwhite(*arg + 1); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
756 char_u buf[NUMBUFLEN]; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
757 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
758 /* |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
759 * First check if it's not a curly-braces thing: {expr}. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
760 * Must do this without evaluating, otherwise a function may be called |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
761 * twice. Unfortunately this means we need to call eval1() twice for the |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
762 * first item. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
763 * But {} is an empty Dictionary. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
764 */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
765 if (*start != '}') |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
766 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
767 if (eval1(&start, &tv, FALSE) == FAIL) /* recursive! */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
768 return FAIL; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
769 if (*start == '}') |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
770 return NOTDONE; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
771 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
772 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
773 if (evaluate) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
774 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
775 d = dict_alloc(); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
776 if (d == NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
777 return FAIL; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
778 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
779 tvkey.v_type = VAR_UNKNOWN; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
780 tv.v_type = VAR_UNKNOWN; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
781 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
782 *arg = skipwhite(*arg + 1); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
783 while (**arg != '}' && **arg != NUL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
784 { |
17368
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17159
diff
changeset
|
785 if ((literal |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17159
diff
changeset
|
786 ? get_literal_key(arg, &tvkey) |
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17159
diff
changeset
|
787 : eval1(arg, &tvkey, evaluate)) == FAIL) // recursive! |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
788 goto failret; |
17368
6604ecb7a615
patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents:
17159
diff
changeset
|
789 |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
790 if (**arg != ':') |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
791 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15267
diff
changeset
|
792 semsg(_("E720: Missing colon in Dictionary: %s"), *arg); |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
793 clear_tv(&tvkey); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
794 goto failret; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
795 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
796 if (evaluate) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
797 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
798 key = tv_get_string_buf_chk(&tvkey, buf); |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
799 if (key == NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
800 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
801 /* "key" is NULL when tv_get_string_buf_chk() gave an errmsg */ |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
802 clear_tv(&tvkey); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
803 goto failret; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
804 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
805 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
806 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
807 *arg = skipwhite(*arg + 1); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
808 if (eval1(arg, &tv, evaluate) == FAIL) /* recursive! */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
809 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
810 if (evaluate) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
811 clear_tv(&tvkey); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
812 goto failret; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
813 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
814 if (evaluate) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
815 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
816 item = dict_find(d, key, -1); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
817 if (item != NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
818 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15267
diff
changeset
|
819 semsg(_("E721: Duplicate key in Dictionary: \"%s\""), key); |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
820 clear_tv(&tvkey); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
821 clear_tv(&tv); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
822 goto failret; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
823 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
824 item = dictitem_alloc(key); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
825 clear_tv(&tvkey); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
826 if (item != NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
827 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
828 item->di_tv = tv; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
829 item->di_tv.v_lock = 0; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
830 if (dict_add(d, item) == FAIL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
831 dictitem_free(item); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
832 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
833 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
834 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
835 if (**arg == '}') |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
836 break; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
837 if (**arg != ',') |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
838 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15267
diff
changeset
|
839 semsg(_("E722: Missing comma in Dictionary: %s"), *arg); |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
840 goto failret; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
841 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
842 *arg = skipwhite(*arg + 1); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
843 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
844 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
845 if (**arg != '}') |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
846 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15267
diff
changeset
|
847 semsg(_("E723: Missing end of Dictionary '}': %s"), *arg); |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
848 failret: |
17159
3fd0765f454f
patch 8.1.1579: dict and list could be GC'ed while displaying error
Bram Moolenaar <Bram@vim.org>
parents:
17123
diff
changeset
|
849 if (d != NULL) |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
850 dict_free(d); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
851 return FAIL; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
852 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
853 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
854 *arg = skipwhite(*arg + 1); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
855 if (evaluate) |
11418
162bcd0debd7
patch 8.0.0593: duplication of code for adding a list or dict return value
Christian Brabandt <cb@256bit.org>
parents:
11142
diff
changeset
|
856 rettv_dict_set(rettv, d); |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
857 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
858 return OK; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
859 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
860 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
861 /* |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
862 * Go over all entries in "d2" and add them to "d1". |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
863 * When "action" is "error" then a duplicate key is an error. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
864 * When "action" is "force" then a duplicate key is overwritten. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
865 * Otherwise duplicate keys are ignored ("action" is "keep"). |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
866 */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
867 void |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
868 dict_extend(dict_T *d1, dict_T *d2, char_u *action) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
869 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
870 dictitem_T *di1; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
871 hashitem_T *hi2; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
872 int todo; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
873 char_u *arg_errmsg = (char_u *)N_("extend() argument"); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
874 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
875 todo = (int)d2->dv_hashtab.ht_used; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
876 for (hi2 = d2->dv_hashtab.ht_array; todo > 0; ++hi2) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
877 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
878 if (!HASHITEM_EMPTY(hi2)) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
879 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
880 --todo; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
881 di1 = dict_find(d1, hi2->hi_key, -1); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
882 if (d1->dv_scope != 0) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
883 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
884 /* Disallow replacing a builtin function in l: and g:. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
885 * Check the key to be valid when adding to any scope. */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
886 if (d1->dv_scope == VAR_DEF_SCOPE |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
887 && HI2DI(hi2)->di_tv.v_type == VAR_FUNC |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
888 && var_check_func_name(hi2->hi_key, di1 == NULL)) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
889 break; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
890 if (!valid_varname(hi2->hi_key)) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
891 break; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
892 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
893 if (di1 == NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
894 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
895 di1 = dictitem_copy(HI2DI(hi2)); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
896 if (di1 != NULL && dict_add(d1, di1) == FAIL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
897 dictitem_free(di1); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
898 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
899 else if (*action == 'e') |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
900 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15267
diff
changeset
|
901 semsg(_("E737: Key already exists: %s"), hi2->hi_key); |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
902 break; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
903 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
904 else if (*action == 'f' && HI2DI(hi2) != di1) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
905 { |
15780
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
906 if (var_check_lock(di1->di_tv.v_lock, arg_errmsg, TRUE) |
5b6c3c7feba8
patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
907 || var_check_ro(di1->di_flags, arg_errmsg, TRUE)) |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
908 break; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
909 clear_tv(&di1->di_tv); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
910 copy_tv(&HI2DI(hi2)->di_tv, &di1->di_tv); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
911 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
912 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
913 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
914 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
915 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
916 /* |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
917 * Return the dictitem that an entry in a hashtable points to. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
918 */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
919 dictitem_T * |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
920 dict_lookup(hashitem_T *hi) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
921 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
922 return HI2DI(hi); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
923 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
924 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
925 /* |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
926 * Return TRUE when two dictionaries have exactly the same key/values. |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
927 */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
928 int |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
929 dict_equal( |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
930 dict_T *d1, |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
931 dict_T *d2, |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
932 int ic, /* ignore case for strings */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
933 int recursive) /* TRUE when used recursively */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
934 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
935 hashitem_T *hi; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
936 dictitem_T *item2; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
937 int todo; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
938 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
939 if (d1 == NULL && d2 == NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
940 return TRUE; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
941 if (d1 == NULL || d2 == NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
942 return FALSE; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
943 if (d1 == d2) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
944 return TRUE; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
945 if (dict_len(d1) != dict_len(d2)) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
946 return FALSE; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
947 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
948 todo = (int)d1->dv_hashtab.ht_used; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
949 for (hi = d1->dv_hashtab.ht_array; todo > 0; ++hi) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
950 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
951 if (!HASHITEM_EMPTY(hi)) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
952 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
953 item2 = dict_find(d2, hi->hi_key, -1); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
954 if (item2 == NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
955 return FALSE; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
956 if (!tv_equal(&HI2DI(hi)->di_tv, &item2->di_tv, ic, recursive)) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
957 return FALSE; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
958 --todo; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
959 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
960 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
961 return TRUE; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
962 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
963 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
964 /* |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
965 * Turn a dict into a list: |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
966 * "what" == 0: list of keys |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
967 * "what" == 1: list of values |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
968 * "what" == 2: list of items |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
969 */ |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17655
diff
changeset
|
970 static void |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
971 dict_list(typval_T *argvars, typval_T *rettv, int what) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
972 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
973 list_T *l2; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
974 dictitem_T *di; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
975 hashitem_T *hi; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
976 listitem_T *li; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
977 listitem_T *li2; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
978 dict_T *d; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
979 int todo; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
980 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
981 if (argvars[0].v_type != VAR_DICT) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
982 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15267
diff
changeset
|
983 emsg(_(e_dictreq)); |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
984 return; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
985 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
986 if ((d = argvars[0].vval.v_dict) == NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
987 return; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
988 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
989 if (rettv_list_alloc(rettv) == FAIL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
990 return; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
991 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
992 todo = (int)d->dv_hashtab.ht_used; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
993 for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
994 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
995 if (!HASHITEM_EMPTY(hi)) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
996 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
997 --todo; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
998 di = HI2DI(hi); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
999 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1000 li = listitem_alloc(); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1001 if (li == NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1002 break; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1003 list_append(rettv->vval.v_list, li); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1004 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1005 if (what == 0) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1006 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1007 /* keys() */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1008 li->li_tv.v_type = VAR_STRING; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1009 li->li_tv.v_lock = 0; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1010 li->li_tv.vval.v_string = vim_strsave(di->di_key); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1011 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1012 else if (what == 1) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1013 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1014 /* values() */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1015 copy_tv(&di->di_tv, &li->li_tv); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1016 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1017 else |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1018 { |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1019 /* items() */ |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1020 l2 = list_alloc(); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1021 li->li_tv.v_type = VAR_LIST; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1022 li->li_tv.v_lock = 0; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1023 li->li_tv.vval.v_list = l2; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1024 if (l2 == NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1025 break; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1026 ++l2->lv_refcount; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1027 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1028 li2 = listitem_alloc(); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1029 if (li2 == NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1030 break; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1031 list_append(l2, li2); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1032 li2->li_tv.v_type = VAR_STRING; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1033 li2->li_tv.v_lock = 0; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1034 li2->li_tv.vval.v_string = vim_strsave(di->di_key); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1035 |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1036 li2 = listitem_alloc(); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1037 if (li2 == NULL) |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1038 break; |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1039 list_append(l2, li2); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1040 copy_tv(&di->di_tv, &li2->li_tv); |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1041 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1042 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1043 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1044 } |
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1045 |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
1046 /* |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1047 * "items(dict)" function |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1048 */ |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1049 void |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1050 f_items(typval_T *argvars, typval_T *rettv) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1051 { |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1052 dict_list(argvars, rettv, 2); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1053 } |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1054 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1055 /* |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1056 * "keys()" function |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1057 */ |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1058 void |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1059 f_keys(typval_T *argvars, typval_T *rettv) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1060 { |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1061 dict_list(argvars, rettv, 0); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1062 } |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1063 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1064 /* |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1065 * "values(dict)" function |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1066 */ |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1067 void |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1068 f_values(typval_T *argvars, typval_T *rettv) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1069 { |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1070 dict_list(argvars, rettv, 1); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1071 } |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1072 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1073 /* |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
1074 * Make each item in the dict readonly (not the value of the item). |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
1075 */ |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
1076 void |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
1077 dict_set_items_ro(dict_T *di) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
1078 { |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
1079 int todo = (int)di->dv_hashtab.ht_used; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
1080 hashitem_T *hi; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
1081 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
1082 /* Set readonly */ |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
1083 for (hi = di->dv_hashtab.ht_array; todo > 0 ; ++hi) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
1084 { |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
1085 if (HASHITEM_EMPTY(hi)) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
1086 continue; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
1087 --todo; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
1088 HI2DI(hi)->di_flags |= DI_FLAGS_RO | DI_FLAGS_FIX; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
1089 } |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
1090 } |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
1091 |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1092 /* |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1093 * "has_key()" function |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1094 */ |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1095 void |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1096 f_has_key(typval_T *argvars, typval_T *rettv) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1097 { |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1098 if (argvars[0].v_type != VAR_DICT) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1099 { |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1100 emsg(_(e_dictreq)); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1101 return; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1102 } |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1103 if (argvars[0].vval.v_dict == NULL) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1104 return; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1105 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1106 rettv->vval.v_number = dict_find(argvars[0].vval.v_dict, |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1107 tv_get_string(&argvars[1]), -1) != NULL; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1108 } |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1109 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1110 /* |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1111 * "remove({dict})" function |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1112 */ |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1113 void |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1114 dict_remove(typval_T *argvars, typval_T *rettv, char_u *arg_errmsg) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1115 { |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1116 dict_T *d; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1117 char_u *key; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1118 dictitem_T *di; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1119 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1120 if (argvars[2].v_type != VAR_UNKNOWN) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1121 semsg(_(e_toomanyarg), "remove()"); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1122 else if ((d = argvars[0].vval.v_dict) != NULL |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1123 && !var_check_lock(d->dv_lock, arg_errmsg, TRUE)) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1124 { |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1125 key = tv_get_string_chk(&argvars[1]); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1126 if (key != NULL) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1127 { |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1128 di = dict_find(d, key, -1); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1129 if (di == NULL) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1130 semsg(_(e_dictkey), key); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1131 else if (!var_check_fixed(di->di_flags, arg_errmsg, TRUE) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1132 && !var_check_ro(di->di_flags, arg_errmsg, TRUE)) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1133 { |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1134 *rettv = di->di_tv; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1135 init_tv(&di->di_tv); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1136 dictitem_remove(d, di); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1137 } |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1138 } |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1139 } |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1140 } |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17368
diff
changeset
|
1141 |
9556
afaff1d283d3
commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1142 #endif /* defined(FEAT_EVAL) */ |