annotate src/dict.c @ 16268:0f65f2808470 v8.1.1138

patch 8.1.1138: plugins don't get notified when the popup menu changes commit https://github.com/vim/vim/commit/d7f246c68cfb97406bcd4b098a2df2d870b3ef92 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Apr 8 18:15:41 2019 +0200 patch 8.1.1138: plugins don't get notified when the popup menu changes Problem: Plugins don't get notified when the popup menu changes. Solution: Add the CompleteChanged event. (Andy Massimino. closes https://github.com/vim/vim/issues/4176)
author Bram Moolenaar <Bram@vim.org>
date Mon, 08 Apr 2019 18:30:06 +0200
parents 5b6c3c7feba8
children 54ffc82f38a8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10042
4aead6a9b7a9 commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents: 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
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 d = (dict_T *)alloc(sizeof(dict_T));
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
c338c91086b9 patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents: 14303
diff changeset
57 if (alloc_fail_id == id && alloc_does_fail((long_u)sizeof(list_T)))
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
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
213 di = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T) + STRLEN(key)));
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
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
231 di = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
232 + STRLEN(org->di_key)));
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
233 if (di != NULL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
234 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
235 STRCPY(di->di_key, org->di_key);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
236 di->di_flags = DI_FLAGS_ALLOC;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
237 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
238 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
239 return di;
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 /*
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
243 * 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
244 */
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
245 void
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
246 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
247 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
248 hashitem_T *hi;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
249
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
250 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
251 if (HASHITEM_EMPTY(hi))
10359
66f1b5bf3fa6 commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
252 internal_error("dictitem_remove()");
9556
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
253 else
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
254 hash_remove(&dict->dv_hashtab, hi);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
255 dictitem_free(item);
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 /*
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
259 * 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
260 */
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
261 void
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
262 dictitem_free(dictitem_T *item)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
263 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
264 clear_tv(&item->di_tv);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
265 if (item->di_flags & DI_FLAGS_ALLOC)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
266 vim_free(item);
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 /*
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
270 * 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
271 * 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
272 * See item_copy() for "copyID".
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
273 * Returns NULL when out of memory.
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
274 */
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
275 dict_T *
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
276 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
277 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
278 dict_T *copy;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
279 dictitem_T *di;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
280 int todo;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
281 hashitem_T *hi;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
282
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
283 if (orig == NULL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
284 return NULL;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
285
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
286 copy = dict_alloc();
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
287 if (copy != NULL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
288 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
289 if (copyID != 0)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
290 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
291 orig->dv_copyID = copyID;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
292 orig->dv_copydict = copy;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
293 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
294 todo = (int)orig->dv_hashtab.ht_used;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
295 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
296 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
297 if (!HASHITEM_EMPTY(hi))
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
298 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
299 --todo;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
300
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
301 di = dictitem_alloc(hi->hi_key);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
302 if (di == NULL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
303 break;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
304 if (deep)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
305 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
306 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
307 copyID) == FAIL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
308 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
309 vim_free(di);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
310 break;
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 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
313 else
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
314 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
315 if (dict_add(copy, di) == FAIL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
316 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
317 dictitem_free(di);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
318 break;
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
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
323 ++copy->dv_refcount;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
324 if (todo > 0)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
325 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
326 dict_unref(copy);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
327 copy = NULL;
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
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
331 return copy;
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 /*
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
335 * Add item "item" to Dictionary "d".
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
336 * 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
337 */
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
338 int
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
339 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
340 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
341 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
342 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
343
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
344 /*
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
345 * 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
346 * 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
347 */
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
348 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
349 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
350 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
351 dictitem_T *item;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
352
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
353 item = dictitem_alloc((char_u *)key);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
354 if (item == NULL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
355 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
356 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
357 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
358 if (dict_add(d, item) == FAIL)
9556
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
359 {
14301
3c80092eb211 patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13037
diff changeset
360 dictitem_free(item);
3c80092eb211 patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13037
diff changeset
361 return FAIL;
9556
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
362 }
14301
3c80092eb211 patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13037
diff changeset
363 return OK;
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
3c80092eb211 patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13037
diff changeset
366 /*
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
367 * 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
368 * 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
369 */
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 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
371 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
372 {
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 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
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 /*
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 * 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
378 * 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
379 */
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 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
381 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
382 {
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 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
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
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 15780
diff changeset
386 /*
14301
3c80092eb211 patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13037
diff changeset
387 * 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
388 * 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
389 */
3c80092eb211 patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13037
diff changeset
390 int
3c80092eb211 patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13037
diff changeset
391 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
392 {
15267
762fccd84b7c patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
393 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
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 /*
762fccd84b7c patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
397 * Add a string entry to dictionary "d".
762fccd84b7c patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
398 * "str" will be copied to allocated memory.
762fccd84b7c patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
399 * 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
400 * 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
401 */
762fccd84b7c patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
402 int
762fccd84b7c patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
403 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
404 {
14301
3c80092eb211 patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13037
diff changeset
405 dictitem_T *item;
15267
762fccd84b7c patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
406 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
407
3c80092eb211 patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13037
diff changeset
408 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
409 if (item == NULL)
3c80092eb211 patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13037
diff changeset
410 return FAIL;
3c80092eb211 patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents: 13037
diff changeset
411 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
412 if (str != NULL)
762fccd84b7c patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
413 {
762fccd84b7c patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
414 if (len == -1)
762fccd84b7c patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
415 val = vim_strsave(str);
762fccd84b7c patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
416 else
762fccd84b7c patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
417 val = vim_strnsave(str, len);
762fccd84b7c patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
418 }
762fccd84b7c patch 8.1.0642: swapinfo() leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
419 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
420 if (dict_add(d, item) == FAIL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
421 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
422 dictitem_free(item);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
423 return FAIL;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
424 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
425 return OK;
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 /*
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
429 * Add a list entry to dictionary "d".
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
430 * 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
431 */
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
432 int
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
433 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
434 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
435 dictitem_T *item;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
436
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
437 item = dictitem_alloc((char_u *)key);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
438 if (item == NULL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
439 return FAIL;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
440 item->di_tv.v_type = VAR_LIST;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
441 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
442 ++list->lv_refcount;
9556
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
443 if (dict_add(d, item) == FAIL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
444 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
445 dictitem_free(item);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
446 return FAIL;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
447 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
448 return OK;
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
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
451 /*
9858
3e96d9ed2ca1 commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents: 9770
diff changeset
452 * 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
453 * 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
454 */
3e96d9ed2ca1 commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents: 9770
diff changeset
455 int
3e96d9ed2ca1 commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents: 9770
diff changeset
456 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
457 {
3e96d9ed2ca1 commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents: 9770
diff changeset
458 dictitem_T *item;
3e96d9ed2ca1 commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents: 9770
diff changeset
459
3e96d9ed2ca1 commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents: 9770
diff changeset
460 item = dictitem_alloc((char_u *)key);
3e96d9ed2ca1 commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents: 9770
diff changeset
461 if (item == NULL)
3e96d9ed2ca1 commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents: 9770
diff changeset
462 return FAIL;
3e96d9ed2ca1 commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents: 9770
diff changeset
463 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
464 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
465 ++dict->dv_refcount;
9858
3e96d9ed2ca1 commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents: 9770
diff changeset
466 if (dict_add(d, item) == FAIL)
3e96d9ed2ca1 commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents: 9770
diff changeset
467 {
3e96d9ed2ca1 commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents: 9770
diff changeset
468 dictitem_free(item);
3e96d9ed2ca1 commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents: 9770
diff changeset
469 return FAIL;
3e96d9ed2ca1 commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents: 9770
diff changeset
470 }
3e96d9ed2ca1 commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents: 9770
diff changeset
471 return OK;
3e96d9ed2ca1 commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents: 9770
diff changeset
472 }
3e96d9ed2ca1 commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents: 9770
diff changeset
473
3e96d9ed2ca1 commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents: 9770
diff changeset
474 /*
9556
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
475 * 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
476 */
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
477 long
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
478 dict_len(dict_T *d)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
479 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
480 if (d == NULL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
481 return 0L;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
482 return (long)d->dv_hashtab.ht_used;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
483 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
484
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
485 /*
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
486 * Find item "key[len]" in Dictionary "d".
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
487 * If "len" is negative use strlen(key).
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
488 * Returns NULL when not found.
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
489 */
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
490 dictitem_T *
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
491 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
492 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
493 #define AKEYLEN 200
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
494 char_u buf[AKEYLEN];
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
495 char_u *akey;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
496 char_u *tofree = NULL;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
497 hashitem_T *hi;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
498
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
499 if (d == NULL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
500 return NULL;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
501 if (len < 0)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
502 akey = key;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
503 else if (len >= AKEYLEN)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
504 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
505 tofree = akey = vim_strnsave(key, len);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
506 if (akey == NULL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
507 return NULL;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
508 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
509 else
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
510 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
511 /* Avoid a malloc/free by using buf[]. */
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
512 vim_strncpy(buf, key, len);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
513 akey = buf;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
514 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
515
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
516 hi = hash_find(&d->dv_hashtab, akey);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
517 vim_free(tofree);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
518 if (HASHITEM_EMPTY(hi))
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
519 return NULL;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
520 return HI2DI(hi);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
521 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
522
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
523 /*
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
524 * Get a string item from a dictionary.
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
525 * 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
526 * 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
527 * 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
528 */
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
529 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
530 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
531 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
532 dictitem_T *di;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
533 char_u *s;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
534
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
535 di = dict_find(d, key, -1);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
536 if (di == NULL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
537 return NULL;
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
538 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
539 if (save && s != NULL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
540 s = vim_strsave(s);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
541 return s;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
542 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
543
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
544 /*
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
545 * Get a number item from a dictionary.
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
546 * 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
547 */
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
548 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
549 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
550 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
551 dictitem_T *di;
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 di = dict_find(d, key, -1);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
554 if (di == NULL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
555 return 0;
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
556 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
557 }
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 /*
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
560 * 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
561 * May return NULL.
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
562 */
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
563 char_u *
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
564 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
565 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
566 garray_T ga;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
567 int first = TRUE;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
568 char_u *tofree;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
569 char_u numbuf[NUMBUFLEN];
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
570 hashitem_T *hi;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
571 char_u *s;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
572 dict_T *d;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
573 int todo;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
574
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
575 if ((d = tv->vval.v_dict) == 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 ga_init2(&ga, (int)sizeof(char), 80);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
578 ga_append(&ga, '{');
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 todo = (int)d->dv_hashtab.ht_used;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
581 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
582 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
583 if (!HASHITEM_EMPTY(hi))
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 --todo;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
586
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
587 if (first)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
588 first = FALSE;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
589 else
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
590 ga_concat(&ga, (char_u *)", ");
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 tofree = string_quote(hi->hi_key, FALSE);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
593 if (tofree != NULL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
594 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
595 ga_concat(&ga, tofree);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
596 vim_free(tofree);
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 ga_concat(&ga, (char_u *)": ");
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
599 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
600 FALSE, restore_copyID, TRUE);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
601 if (s != NULL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
602 ga_concat(&ga, s);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
603 vim_free(tofree);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
604 if (s == NULL || did_echo_string_emsg)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
605 break;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
606 line_breakcheck();
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
607
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
608 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
609 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
610 if (todo > 0)
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 vim_free(ga.ga_data);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
613 return NULL;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
614 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
615
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
616 ga_append(&ga, '}');
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
617 ga_append(&ga, NUL);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
618 return (char_u *)ga.ga_data;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
619 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
620
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
621 /*
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
622 * Allocate a variable for a Dictionary and fill it from "*arg".
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
623 * 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
624 */
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
625 int
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
626 dict_get_tv(char_u **arg, typval_T *rettv, int evaluate)
9556
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
627 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
628 dict_T *d = NULL;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
629 typval_T tvkey;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
630 typval_T tv;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
631 char_u *key = NULL;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
632 dictitem_T *item;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
633 char_u *start = skipwhite(*arg + 1);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
634 char_u buf[NUMBUFLEN];
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
635
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 * 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
638 * 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
639 * 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
640 * first item.
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
641 * But {} is an empty Dictionary.
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
642 */
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
643 if (*start != '}')
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
644 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
645 if (eval1(&start, &tv, FALSE) == FAIL) /* recursive! */
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
646 return FAIL;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
647 if (*start == '}')
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
648 return NOTDONE;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
649 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
650
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
651 if (evaluate)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
652 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
653 d = dict_alloc();
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
654 if (d == NULL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
655 return FAIL;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
656 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
657 tvkey.v_type = VAR_UNKNOWN;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
658 tv.v_type = VAR_UNKNOWN;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
659
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
660 *arg = skipwhite(*arg + 1);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
661 while (**arg != '}' && **arg != NUL)
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 if (eval1(arg, &tvkey, evaluate) == FAIL) /* recursive! */
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
664 goto failret;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
665 if (**arg != ':')
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
666 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15267
diff changeset
667 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
668 clear_tv(&tvkey);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
669 goto failret;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
670 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
671 if (evaluate)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
672 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
673 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
674 if (key == NULL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
675 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
676 /* "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
677 clear_tv(&tvkey);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
678 goto failret;
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 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
681
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
682 *arg = skipwhite(*arg + 1);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
683 if (eval1(arg, &tv, evaluate) == FAIL) /* recursive! */
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 if (evaluate)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
686 clear_tv(&tvkey);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
687 goto failret;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
688 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
689 if (evaluate)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
690 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
691 item = dict_find(d, key, -1);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
692 if (item != NULL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
693 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15267
diff changeset
694 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
695 clear_tv(&tvkey);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
696 clear_tv(&tv);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
697 goto failret;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
698 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
699 item = dictitem_alloc(key);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
700 clear_tv(&tvkey);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
701 if (item != NULL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
702 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
703 item->di_tv = tv;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
704 item->di_tv.v_lock = 0;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
705 if (dict_add(d, item) == FAIL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
706 dictitem_free(item);
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 (**arg == '}')
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
711 break;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
712 if (**arg != ',')
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
713 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15267
diff changeset
714 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
715 goto failret;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
716 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
717 *arg = skipwhite(*arg + 1);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
718 }
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 if (**arg != '}')
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
721 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15267
diff changeset
722 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
723 failret:
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
724 if (evaluate)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
725 dict_free(d);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
726 return FAIL;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
727 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
728
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
729 *arg = skipwhite(*arg + 1);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
730 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
731 rettv_dict_set(rettv, d);
9556
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
732
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
733 return OK;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
734 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
735
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
736 /*
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
737 * 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
738 * 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
739 * 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
740 * 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
741 */
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
742 void
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
743 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
744 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
745 dictitem_T *di1;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
746 hashitem_T *hi2;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
747 int todo;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
748 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
749
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
750 todo = (int)d2->dv_hashtab.ht_used;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
751 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
752 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
753 if (!HASHITEM_EMPTY(hi2))
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
754 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
755 --todo;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
756 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
757 if (d1->dv_scope != 0)
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 /* 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
760 * 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
761 if (d1->dv_scope == VAR_DEF_SCOPE
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
762 && 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
763 && 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
764 break;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
765 if (!valid_varname(hi2->hi_key))
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
766 break;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
767 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
768 if (di1 == NULL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
769 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
770 di1 = dictitem_copy(HI2DI(hi2));
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
771 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
772 dictitem_free(di1);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
773 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
774 else if (*action == 'e')
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
775 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15267
diff changeset
776 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
777 break;
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 else if (*action == 'f' && HI2DI(hi2) != di1)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
780 {
15780
5b6c3c7feba8 patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
781 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
782 || 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
783 break;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
784 clear_tv(&di1->di_tv);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
785 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
786 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
787 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
788 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
789 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
790
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
791 /*
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
792 * 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
793 */
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
794 dictitem_T *
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
795 dict_lookup(hashitem_T *hi)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
796 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
797 return HI2DI(hi);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
798 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
799
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
800 /*
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
801 * 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
802 */
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
803 int
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
804 dict_equal(
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
805 dict_T *d1,
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
806 dict_T *d2,
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
807 int ic, /* ignore case for strings */
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
808 int recursive) /* TRUE when used recursively */
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 hashitem_T *hi;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
811 dictitem_T *item2;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
812 int todo;
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 (d1 == NULL && d2 == NULL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
815 return TRUE;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
816 if (d1 == NULL || d2 == NULL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
817 return FALSE;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
818 if (d1 == d2)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
819 return TRUE;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
820 if (dict_len(d1) != dict_len(d2))
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
821 return FALSE;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
822
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
823 todo = (int)d1->dv_hashtab.ht_used;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
824 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
825 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
826 if (!HASHITEM_EMPTY(hi))
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 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
829 if (item2 == NULL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
830 return FALSE;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
831 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
832 return FALSE;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
833 --todo;
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 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
836 return TRUE;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
837 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
838
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
839 /*
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
840 * Turn a dict into a list:
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
841 * "what" == 0: list of keys
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
842 * "what" == 1: list of values
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
843 * "what" == 2: list of items
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 void
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
846 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
847 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
848 list_T *l2;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
849 dictitem_T *di;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
850 hashitem_T *hi;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
851 listitem_T *li;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
852 listitem_T *li2;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
853 dict_T *d;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
854 int todo;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
855
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
856 if (argvars[0].v_type != VAR_DICT)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
857 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15267
diff changeset
858 emsg(_(e_dictreq));
9556
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
859 return;
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 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
862 return;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
863
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
864 if (rettv_list_alloc(rettv) == FAIL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
865 return;
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 todo = (int)d->dv_hashtab.ht_used;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
868 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
869 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
870 if (!HASHITEM_EMPTY(hi))
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
871 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
872 --todo;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
873 di = HI2DI(hi);
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 li = listitem_alloc();
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
876 if (li == NULL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
877 break;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
878 list_append(rettv->vval.v_list, li);
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 if (what == 0)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
881 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
882 /* keys() */
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
883 li->li_tv.v_type = VAR_STRING;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
884 li->li_tv.v_lock = 0;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
885 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
886 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
887 else if (what == 1)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
888 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
889 /* values() */
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
890 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
891 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
892 else
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
893 {
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
894 /* items() */
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
895 l2 = list_alloc();
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
896 li->li_tv.v_type = VAR_LIST;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
897 li->li_tv.v_lock = 0;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
898 li->li_tv.vval.v_list = l2;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
899 if (l2 == NULL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
900 break;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
901 ++l2->lv_refcount;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
902
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
903 li2 = listitem_alloc();
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
904 if (li2 == NULL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
905 break;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
906 list_append(l2, li2);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
907 li2->li_tv.v_type = VAR_STRING;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
908 li2->li_tv.v_lock = 0;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
909 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
910
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
911 li2 = listitem_alloc();
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
912 if (li2 == NULL)
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
913 break;
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
914 list_append(l2, li2);
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
915 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
916 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
917 }
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 }
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
920
13037
6e81a68d63a1 patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents: 11418
diff changeset
921 /*
6e81a68d63a1 patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents: 11418
diff changeset
922 * 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
923 */
6e81a68d63a1 patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents: 11418
diff changeset
924 void
6e81a68d63a1 patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents: 11418
diff changeset
925 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
926 {
6e81a68d63a1 patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents: 11418
diff changeset
927 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
928 hashitem_T *hi;
6e81a68d63a1 patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents: 11418
diff changeset
929
6e81a68d63a1 patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents: 11418
diff changeset
930 /* Set readonly */
6e81a68d63a1 patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents: 11418
diff changeset
931 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
932 {
6e81a68d63a1 patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents: 11418
diff changeset
933 if (HASHITEM_EMPTY(hi))
6e81a68d63a1 patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents: 11418
diff changeset
934 continue;
6e81a68d63a1 patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents: 11418
diff changeset
935 --todo;
6e81a68d63a1 patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents: 11418
diff changeset
936 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
937 }
6e81a68d63a1 patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents: 11418
diff changeset
938 }
6e81a68d63a1 patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents: 11418
diff changeset
939
9556
afaff1d283d3 commit https://github.com/vim/vim/commit/cd52459c387785796713826c63174cdeed295dd4
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
940 #endif /* defined(FEAT_EVAL) */