Mercurial > vim
annotate src/list.c @ 15636:6f1c7e9a6393 v8.1.0826
patch 8.1.0826: too many #ifdefs
commit https://github.com/vim/vim/commit/29ddebef4038d2d2b3bc9d8d3b0109f4046d6fbf
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 26 17:28:26 2019 +0100
patch 8.1.0826: too many #ifdefs
Problem: Too many #ifdefs.
Solution: Graduate FEAT_VIRTUALEDIT. Adds about 10Kbyte to the code.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 26 Jan 2019 17:30:15 +0100 |
parents | 55ccc2d353bd |
children | fc58fee685e2 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9626
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2 * |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4 * |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
8 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
9 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
10 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
11 * list.c: List support |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
12 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
13 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
14 #include "vim.h" |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
15 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
16 #if defined(FEAT_EVAL) || defined(PROTO) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
17 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
18 /* List heads for garbage collection. */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
19 static list_T *first_list = NULL; /* list of all lists */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
20 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
21 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
22 * Add a watcher to a list. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
23 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
24 void |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
25 list_add_watch(list_T *l, listwatch_T *lw) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
26 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
27 lw->lw_next = l->lv_watch; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
28 l->lv_watch = lw; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
29 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
30 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
31 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
32 * Remove a watcher from a list. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
33 * No warning when it isn't found... |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
34 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
35 void |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
36 list_rem_watch(list_T *l, listwatch_T *lwrem) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
37 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
38 listwatch_T *lw, **lwp; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
39 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
40 lwp = &l->lv_watch; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
41 for (lw = l->lv_watch; lw != NULL; lw = lw->lw_next) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
42 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
43 if (lw == lwrem) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
44 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
45 *lwp = lw->lw_next; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
46 break; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
47 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
48 lwp = &lw->lw_next; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
49 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
50 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
51 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
52 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
53 * Just before removing an item from a list: advance watchers to the next |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
54 * item. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
55 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
56 void |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
57 list_fix_watch(list_T *l, listitem_T *item) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
58 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
59 listwatch_T *lw; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
60 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
61 for (lw = l->lv_watch; lw != NULL; lw = lw->lw_next) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
62 if (lw->lw_item == item) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
63 lw->lw_item = item->li_next; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
64 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
65 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
66 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
67 * Allocate an empty header for a list. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
68 * Caller should take care of the reference count. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
69 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
70 list_T * |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
71 list_alloc(void) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
72 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
73 list_T *l; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
74 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
75 l = (list_T *)alloc_clear(sizeof(list_T)); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
76 if (l != NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
77 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
78 /* Prepend the list to the list of lists for garbage collection. */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
79 if (first_list != NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
80 first_list->lv_used_prev = l; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
81 l->lv_used_prev = NULL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
82 l->lv_used_next = first_list; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
83 first_list = l; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
84 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
85 return l; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
86 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
87 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
88 /* |
15016
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14391
diff
changeset
|
89 * list_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:
14391
diff
changeset
|
90 */ |
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14391
diff
changeset
|
91 list_T * |
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14391
diff
changeset
|
92 list_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:
14391
diff
changeset
|
93 { |
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14391
diff
changeset
|
94 #ifdef FEAT_EVAL |
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14391
diff
changeset
|
95 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:
14391
diff
changeset
|
96 return NULL; |
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14391
diff
changeset
|
97 #endif |
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14391
diff
changeset
|
98 return (list_alloc()); |
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14391
diff
changeset
|
99 } |
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14391
diff
changeset
|
100 |
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14391
diff
changeset
|
101 /* |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
102 * Allocate an empty list for a return value, with reference count set. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
103 * Returns OK or FAIL. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
104 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
105 int |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
106 rettv_list_alloc(typval_T *rettv) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
107 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
108 list_T *l = list_alloc(); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
109 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
110 if (l == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
111 return FAIL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
112 |
11418
162bcd0debd7
patch 8.0.0593: duplication of code for adding a list or dict return value
Christian Brabandt <cb@256bit.org>
parents:
10549
diff
changeset
|
113 rettv->v_lock = 0; |
162bcd0debd7
patch 8.0.0593: duplication of code for adding a list or dict return value
Christian Brabandt <cb@256bit.org>
parents:
10549
diff
changeset
|
114 rettv_list_set(rettv, l); |
162bcd0debd7
patch 8.0.0593: duplication of code for adding a list or dict return value
Christian Brabandt <cb@256bit.org>
parents:
10549
diff
changeset
|
115 return OK; |
162bcd0debd7
patch 8.0.0593: duplication of code for adding a list or dict return value
Christian Brabandt <cb@256bit.org>
parents:
10549
diff
changeset
|
116 } |
162bcd0debd7
patch 8.0.0593: duplication of code for adding a list or dict return value
Christian Brabandt <cb@256bit.org>
parents:
10549
diff
changeset
|
117 |
162bcd0debd7
patch 8.0.0593: duplication of code for adding a list or dict return value
Christian Brabandt <cb@256bit.org>
parents:
10549
diff
changeset
|
118 /* |
15209
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15016
diff
changeset
|
119 * Same as rettv_list_alloc() but uses an allocation id for testing. |
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15016
diff
changeset
|
120 */ |
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15016
diff
changeset
|
121 int |
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15016
diff
changeset
|
122 rettv_list_alloc_id(typval_T *rettv, alloc_id_T id UNUSED) |
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15016
diff
changeset
|
123 { |
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15016
diff
changeset
|
124 #ifdef FEAT_EVAL |
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15016
diff
changeset
|
125 if (alloc_fail_id == id && alloc_does_fail((long_u)sizeof(list_T))) |
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15016
diff
changeset
|
126 return FAIL; |
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15016
diff
changeset
|
127 #endif |
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15016
diff
changeset
|
128 return rettv_list_alloc(rettv); |
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15016
diff
changeset
|
129 } |
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15016
diff
changeset
|
130 |
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15016
diff
changeset
|
131 |
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15016
diff
changeset
|
132 /* |
11418
162bcd0debd7
patch 8.0.0593: duplication of code for adding a list or dict return value
Christian Brabandt <cb@256bit.org>
parents:
10549
diff
changeset
|
133 * Set a list 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:
10549
diff
changeset
|
134 */ |
162bcd0debd7
patch 8.0.0593: duplication of code for adding a list or dict return value
Christian Brabandt <cb@256bit.org>
parents:
10549
diff
changeset
|
135 void |
162bcd0debd7
patch 8.0.0593: duplication of code for adding a list or dict return value
Christian Brabandt <cb@256bit.org>
parents:
10549
diff
changeset
|
136 rettv_list_set(typval_T *rettv, list_T *l) |
162bcd0debd7
patch 8.0.0593: duplication of code for adding a list or dict return value
Christian Brabandt <cb@256bit.org>
parents:
10549
diff
changeset
|
137 { |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
138 rettv->v_type = VAR_LIST; |
11418
162bcd0debd7
patch 8.0.0593: duplication of code for adding a list or dict return value
Christian Brabandt <cb@256bit.org>
parents:
10549
diff
changeset
|
139 rettv->vval.v_list = l; |
162bcd0debd7
patch 8.0.0593: duplication of code for adding a list or dict return value
Christian Brabandt <cb@256bit.org>
parents:
10549
diff
changeset
|
140 if (l != NULL) |
162bcd0debd7
patch 8.0.0593: duplication of code for adding a list or dict return value
Christian Brabandt <cb@256bit.org>
parents:
10549
diff
changeset
|
141 ++l->lv_refcount; |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
142 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
143 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
144 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
145 * Unreference a list: decrement the reference count and free it when it |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
146 * becomes zero. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
147 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
148 void |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
149 list_unref(list_T *l) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
150 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
151 if (l != NULL && --l->lv_refcount <= 0) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
152 list_free(l); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
153 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
154 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
155 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
156 * Free a list, including all non-container items it points to. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
157 * Ignores the reference count. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
158 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
159 static void |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
160 list_free_contents(list_T *l) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
161 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
162 listitem_T *item; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
163 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
164 for (item = l->lv_first; item != NULL; item = l->lv_first) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
165 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
166 /* Remove the item before deleting it. */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
167 l->lv_first = item->li_next; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
168 clear_tv(&item->li_tv); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
169 vim_free(item); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
170 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
171 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
172 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
173 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
174 * Go through the list of lists and free items without the copyID. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
175 * But don't free a list that has a watcher (used in a for loop), these |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
176 * are not referenced anywhere. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
177 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
178 int |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
179 list_free_nonref(int copyID) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
180 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
181 list_T *ll; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
182 int did_free = FALSE; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
183 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
184 for (ll = first_list; ll != NULL; ll = ll->lv_used_next) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
185 if ((ll->lv_copyID & COPYID_MASK) != (copyID & COPYID_MASK) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
186 && ll->lv_watch == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
187 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
188 /* Free the List and ordinary items it contains, but don't recurse |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
189 * into Lists and Dictionaries, they will be in the list of dicts |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
190 * or list of lists. */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
191 list_free_contents(ll); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
192 did_free = TRUE; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
193 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
194 return did_free; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
195 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
196 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
197 static void |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
198 list_free_list(list_T *l) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
199 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
200 /* Remove the list from the list of lists for garbage collection. */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
201 if (l->lv_used_prev == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
202 first_list = l->lv_used_next; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
203 else |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
204 l->lv_used_prev->lv_used_next = l->lv_used_next; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
205 if (l->lv_used_next != NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
206 l->lv_used_next->lv_used_prev = l->lv_used_prev; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
207 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
208 vim_free(l); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
209 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
210 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
211 void |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
212 list_free_items(int copyID) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
213 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
214 list_T *ll, *ll_next; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
215 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
216 for (ll = first_list; ll != NULL; ll = ll_next) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
217 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
218 ll_next = ll->lv_used_next; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
219 if ((ll->lv_copyID & COPYID_MASK) != (copyID & COPYID_MASK) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
220 && ll->lv_watch == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
221 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
222 /* Free the List and ordinary items it contains, but don't recurse |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
223 * into Lists and Dictionaries, they will be in the list of dicts |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
224 * or list of lists. */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
225 list_free_list(ll); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
226 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
227 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
228 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
229 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
230 void |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
231 list_free(list_T *l) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
232 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
233 if (!in_free_unref_items) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
234 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
235 list_free_contents(l); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
236 list_free_list(l); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
237 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
238 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
239 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
240 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
241 * Allocate a list item. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
242 * It is not initialized, don't forget to set v_lock. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
243 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
244 listitem_T * |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
245 listitem_alloc(void) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
246 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
247 return (listitem_T *)alloc(sizeof(listitem_T)); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
248 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
249 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
250 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
251 * Free a list item. Also clears the value. Does not notify watchers. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
252 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
253 void |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
254 listitem_free(listitem_T *item) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
255 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
256 clear_tv(&item->li_tv); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
257 vim_free(item); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
258 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
259 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
260 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
261 * Remove a list item from a List and free it. Also clears the value. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
262 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
263 void |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
264 listitem_remove(list_T *l, listitem_T *item) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
265 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
266 vimlist_remove(l, item, item); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
267 listitem_free(item); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
268 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
269 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
270 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
271 * Get the number of items in a list. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
272 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
273 long |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
274 list_len(list_T *l) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
275 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
276 if (l == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
277 return 0L; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
278 return l->lv_len; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
279 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
280 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
281 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
282 * Return TRUE when two lists have exactly the same values. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
283 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
284 int |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
285 list_equal( |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
286 list_T *l1, |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
287 list_T *l2, |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
288 int ic, /* ignore case for strings */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
289 int recursive) /* TRUE when used recursively */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
290 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
291 listitem_T *item1, *item2; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
292 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
293 if (l1 == NULL || l2 == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
294 return FALSE; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
295 if (l1 == l2) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
296 return TRUE; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
297 if (list_len(l1) != list_len(l2)) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
298 return FALSE; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
299 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
300 for (item1 = l1->lv_first, item2 = l2->lv_first; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
301 item1 != NULL && item2 != NULL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
302 item1 = item1->li_next, item2 = item2->li_next) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
303 if (!tv_equal(&item1->li_tv, &item2->li_tv, ic, recursive)) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
304 return FALSE; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
305 return item1 == NULL && item2 == NULL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
306 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
307 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
308 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
309 * Locate item with index "n" in list "l" and return it. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
310 * A negative index is counted from the end; -1 is the last item. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
311 * Returns NULL when "n" is out of range. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
312 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
313 listitem_T * |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
314 list_find(list_T *l, long n) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
315 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
316 listitem_T *item; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
317 long idx; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
318 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
319 if (l == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
320 return NULL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
321 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
322 /* Negative index is relative to the end. */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
323 if (n < 0) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
324 n = l->lv_len + n; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
325 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
326 /* Check for index out of range. */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
327 if (n < 0 || n >= l->lv_len) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
328 return NULL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
329 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
330 /* When there is a cached index may start search from there. */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
331 if (l->lv_idx_item != NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
332 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
333 if (n < l->lv_idx / 2) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
334 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
335 /* closest to the start of the list */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
336 item = l->lv_first; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
337 idx = 0; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
338 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
339 else if (n > (l->lv_idx + l->lv_len) / 2) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
340 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
341 /* closest to the end of the list */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
342 item = l->lv_last; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
343 idx = l->lv_len - 1; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
344 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
345 else |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
346 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
347 /* closest to the cached index */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
348 item = l->lv_idx_item; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
349 idx = l->lv_idx; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
350 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
351 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
352 else |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
353 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
354 if (n < l->lv_len / 2) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
355 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
356 /* closest to the start of the list */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
357 item = l->lv_first; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
358 idx = 0; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
359 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
360 else |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
361 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
362 /* closest to the end of the list */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
363 item = l->lv_last; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
364 idx = l->lv_len - 1; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
365 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
366 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
367 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
368 while (n > idx) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
369 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
370 /* search forward */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
371 item = item->li_next; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
372 ++idx; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
373 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
374 while (n < idx) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
375 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
376 /* search backward */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
377 item = item->li_prev; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
378 --idx; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
379 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
380 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
381 /* cache the used index */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
382 l->lv_idx = idx; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
383 l->lv_idx_item = item; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
384 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
385 return item; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
386 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
387 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
388 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
389 * Get list item "l[idx]" as a number. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
390 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
391 long |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
392 list_find_nr( |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
393 list_T *l, |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
394 long idx, |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
395 int *errorp) /* set to TRUE when something wrong */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
396 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
397 listitem_T *li; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
398 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
399 li = list_find(l, idx); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
400 if (li == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
401 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
402 if (errorp != NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
403 *errorp = TRUE; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
404 return -1L; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
405 } |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15209
diff
changeset
|
406 return (long)tv_get_number_chk(&li->li_tv, errorp); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
407 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
408 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
409 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
410 * Get list item "l[idx - 1]" as a string. Returns NULL for failure. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
411 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
412 char_u * |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
413 list_find_str(list_T *l, long idx) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
414 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
415 listitem_T *li; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
416 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
417 li = list_find(l, idx - 1); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
418 if (li == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
419 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
420 semsg(_(e_listidx), idx); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
421 return NULL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
422 } |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15209
diff
changeset
|
423 return tv_get_string(&li->li_tv); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
424 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
425 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
426 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
427 * Locate "item" list "l" and return its index. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
428 * Returns -1 when "item" is not in the list. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
429 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
430 long |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
431 list_idx_of_item(list_T *l, listitem_T *item) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
432 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
433 long idx = 0; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
434 listitem_T *li; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
435 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
436 if (l == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
437 return -1; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
438 idx = 0; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
439 for (li = l->lv_first; li != NULL && li != item; li = li->li_next) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
440 ++idx; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
441 if (li == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
442 return -1; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
443 return idx; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
444 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
445 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
446 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
447 * Append item "item" to the end of list "l". |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
448 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
449 void |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
450 list_append(list_T *l, listitem_T *item) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
451 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
452 if (l->lv_last == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
453 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
454 /* empty list */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
455 l->lv_first = item; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
456 l->lv_last = item; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
457 item->li_prev = NULL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
458 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
459 else |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
460 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
461 l->lv_last->li_next = item; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
462 item->li_prev = l->lv_last; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
463 l->lv_last = item; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
464 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
465 ++l->lv_len; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
466 item->li_next = NULL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
467 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
468 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
469 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
470 * Append typval_T "tv" to the end of list "l". |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
471 * Return FAIL when out of memory. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
472 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
473 int |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
474 list_append_tv(list_T *l, typval_T *tv) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
475 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
476 listitem_T *li = listitem_alloc(); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
477 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
478 if (li == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
479 return FAIL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
480 copy_tv(tv, &li->li_tv); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
481 list_append(l, li); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
482 return OK; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
483 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
484 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
485 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
486 * Add a dictionary to a list. Used by getqflist(). |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
487 * Return FAIL when out of memory. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
488 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
489 int |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
490 list_append_dict(list_T *list, dict_T *dict) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
491 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
492 listitem_T *li = listitem_alloc(); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
493 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
494 if (li == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
495 return FAIL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
496 li->li_tv.v_type = VAR_DICT; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
497 li->li_tv.v_lock = 0; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
498 li->li_tv.vval.v_dict = dict; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
499 list_append(list, li); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
500 ++dict->dv_refcount; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
501 return OK; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
502 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
503 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
504 /* |
13246
dd3b2ecf91f6
patch 8.0.1497: getting the jump list requires parsing the output of :jumps
Christian Brabandt <cb@256bit.org>
parents:
11973
diff
changeset
|
505 * Append list2 to list1. |
dd3b2ecf91f6
patch 8.0.1497: getting the jump list requires parsing the output of :jumps
Christian Brabandt <cb@256bit.org>
parents:
11973
diff
changeset
|
506 * Return FAIL when out of memory. |
dd3b2ecf91f6
patch 8.0.1497: getting the jump list requires parsing the output of :jumps
Christian Brabandt <cb@256bit.org>
parents:
11973
diff
changeset
|
507 */ |
dd3b2ecf91f6
patch 8.0.1497: getting the jump list requires parsing the output of :jumps
Christian Brabandt <cb@256bit.org>
parents:
11973
diff
changeset
|
508 int |
14391
46f14852a919
patch 8.1.0210: still a few K&R function declarations
Christian Brabandt <cb@256bit.org>
parents:
13246
diff
changeset
|
509 list_append_list(list_T *list1, list_T *list2) |
13246
dd3b2ecf91f6
patch 8.0.1497: getting the jump list requires parsing the output of :jumps
Christian Brabandt <cb@256bit.org>
parents:
11973
diff
changeset
|
510 { |
dd3b2ecf91f6
patch 8.0.1497: getting the jump list requires parsing the output of :jumps
Christian Brabandt <cb@256bit.org>
parents:
11973
diff
changeset
|
511 listitem_T *li = listitem_alloc(); |
dd3b2ecf91f6
patch 8.0.1497: getting the jump list requires parsing the output of :jumps
Christian Brabandt <cb@256bit.org>
parents:
11973
diff
changeset
|
512 |
dd3b2ecf91f6
patch 8.0.1497: getting the jump list requires parsing the output of :jumps
Christian Brabandt <cb@256bit.org>
parents:
11973
diff
changeset
|
513 if (li == NULL) |
dd3b2ecf91f6
patch 8.0.1497: getting the jump list requires parsing the output of :jumps
Christian Brabandt <cb@256bit.org>
parents:
11973
diff
changeset
|
514 return FAIL; |
dd3b2ecf91f6
patch 8.0.1497: getting the jump list requires parsing the output of :jumps
Christian Brabandt <cb@256bit.org>
parents:
11973
diff
changeset
|
515 li->li_tv.v_type = VAR_LIST; |
dd3b2ecf91f6
patch 8.0.1497: getting the jump list requires parsing the output of :jumps
Christian Brabandt <cb@256bit.org>
parents:
11973
diff
changeset
|
516 li->li_tv.v_lock = 0; |
dd3b2ecf91f6
patch 8.0.1497: getting the jump list requires parsing the output of :jumps
Christian Brabandt <cb@256bit.org>
parents:
11973
diff
changeset
|
517 li->li_tv.vval.v_list = list2; |
dd3b2ecf91f6
patch 8.0.1497: getting the jump list requires parsing the output of :jumps
Christian Brabandt <cb@256bit.org>
parents:
11973
diff
changeset
|
518 list_append(list1, li); |
dd3b2ecf91f6
patch 8.0.1497: getting the jump list requires parsing the output of :jumps
Christian Brabandt <cb@256bit.org>
parents:
11973
diff
changeset
|
519 ++list2->lv_refcount; |
dd3b2ecf91f6
patch 8.0.1497: getting the jump list requires parsing the output of :jumps
Christian Brabandt <cb@256bit.org>
parents:
11973
diff
changeset
|
520 return OK; |
dd3b2ecf91f6
patch 8.0.1497: getting the jump list requires parsing the output of :jumps
Christian Brabandt <cb@256bit.org>
parents:
11973
diff
changeset
|
521 } |
dd3b2ecf91f6
patch 8.0.1497: getting the jump list requires parsing the output of :jumps
Christian Brabandt <cb@256bit.org>
parents:
11973
diff
changeset
|
522 |
dd3b2ecf91f6
patch 8.0.1497: getting the jump list requires parsing the output of :jumps
Christian Brabandt <cb@256bit.org>
parents:
11973
diff
changeset
|
523 /* |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
524 * Make a copy of "str" and append it as an item to list "l". |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
525 * When "len" >= 0 use "str[len]". |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
526 * Returns FAIL when out of memory. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
527 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
528 int |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
529 list_append_string(list_T *l, char_u *str, int len) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
530 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
531 listitem_T *li = listitem_alloc(); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
532 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
533 if (li == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
534 return FAIL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
535 list_append(l, li); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
536 li->li_tv.v_type = VAR_STRING; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
537 li->li_tv.v_lock = 0; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
538 if (str == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
539 li->li_tv.vval.v_string = NULL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
540 else if ((li->li_tv.vval.v_string = (len >= 0 ? vim_strnsave(str, len) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
541 : vim_strsave(str))) == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
542 return FAIL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
543 return OK; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
544 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
545 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
546 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
547 * Append "n" to list "l". |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
548 * Returns FAIL when out of memory. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
549 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
550 int |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
551 list_append_number(list_T *l, varnumber_T n) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
552 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
553 listitem_T *li; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
554 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
555 li = listitem_alloc(); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
556 if (li == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
557 return FAIL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
558 li->li_tv.v_type = VAR_NUMBER; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
559 li->li_tv.v_lock = 0; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
560 li->li_tv.vval.v_number = n; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
561 list_append(l, li); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
562 return OK; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
563 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
564 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
565 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
566 * Insert typval_T "tv" in list "l" before "item". |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
567 * If "item" is NULL append at the end. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
568 * Return FAIL when out of memory. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
569 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
570 int |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
571 list_insert_tv(list_T *l, typval_T *tv, listitem_T *item) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
572 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
573 listitem_T *ni = listitem_alloc(); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
574 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
575 if (ni == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
576 return FAIL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
577 copy_tv(tv, &ni->li_tv); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
578 list_insert(l, ni, item); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
579 return OK; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
580 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
581 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
582 void |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
583 list_insert(list_T *l, listitem_T *ni, listitem_T *item) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
584 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
585 if (item == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
586 /* Append new item at end of list. */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
587 list_append(l, ni); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
588 else |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
589 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
590 /* Insert new item before existing item. */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
591 ni->li_prev = item->li_prev; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
592 ni->li_next = item; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
593 if (item->li_prev == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
594 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
595 l->lv_first = ni; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
596 ++l->lv_idx; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
597 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
598 else |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
599 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
600 item->li_prev->li_next = ni; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
601 l->lv_idx_item = NULL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
602 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
603 item->li_prev = ni; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
604 ++l->lv_len; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
605 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
606 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
607 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
608 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
609 * Extend "l1" with "l2". |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
610 * If "bef" is NULL append at the end, otherwise insert before this item. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
611 * Returns FAIL when out of memory. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
612 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
613 int |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
614 list_extend(list_T *l1, list_T *l2, listitem_T *bef) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
615 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
616 listitem_T *item; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
617 int todo = l2->lv_len; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
618 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
619 /* We also quit the loop when we have inserted the original item count of |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
620 * the list, avoid a hang when we extend a list with itself. */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
621 for (item = l2->lv_first; item != NULL && --todo >= 0; item = item->li_next) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
622 if (list_insert_tv(l1, &item->li_tv, bef) == FAIL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
623 return FAIL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
624 return OK; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
625 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
626 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
627 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
628 * Concatenate lists "l1" and "l2" into a new list, stored in "tv". |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
629 * Return FAIL when out of memory. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
630 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
631 int |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
632 list_concat(list_T *l1, list_T *l2, typval_T *tv) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
633 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
634 list_T *l; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
635 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
636 if (l1 == NULL || l2 == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
637 return FAIL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
638 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
639 /* make a copy of the first list. */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
640 l = list_copy(l1, FALSE, 0); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
641 if (l == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
642 return FAIL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
643 tv->v_type = VAR_LIST; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
644 tv->vval.v_list = l; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
645 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
646 /* append all items from the second list */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
647 return list_extend(l, l2, NULL); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
648 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
649 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
650 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
651 * Make a copy of list "orig". Shallow if "deep" is FALSE. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
652 * The refcount of the new list is set to 1. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
653 * See item_copy() for "copyID". |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
654 * Returns NULL when out of memory. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
655 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
656 list_T * |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
657 list_copy(list_T *orig, int deep, int copyID) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
658 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
659 list_T *copy; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
660 listitem_T *item; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
661 listitem_T *ni; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
662 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
663 if (orig == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
664 return NULL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
665 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
666 copy = list_alloc(); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
667 if (copy != NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
668 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
669 if (copyID != 0) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
670 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
671 /* Do this before adding the items, because one of the items may |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
672 * refer back to this list. */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
673 orig->lv_copyID = copyID; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
674 orig->lv_copylist = copy; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
675 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
676 for (item = orig->lv_first; item != NULL && !got_int; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
677 item = item->li_next) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
678 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
679 ni = listitem_alloc(); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
680 if (ni == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
681 break; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
682 if (deep) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
683 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
684 if (item_copy(&item->li_tv, &ni->li_tv, deep, copyID) == FAIL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
685 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
686 vim_free(ni); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
687 break; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
688 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
689 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
690 else |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
691 copy_tv(&item->li_tv, &ni->li_tv); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
692 list_append(copy, ni); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
693 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
694 ++copy->lv_refcount; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
695 if (item != NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
696 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
697 list_unref(copy); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
698 copy = NULL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
699 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
700 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
701 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
702 return copy; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
703 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
704 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
705 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
706 * Remove items "item" to "item2" from list "l". |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
707 * Does not free the listitem or the value! |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
708 * This used to be called list_remove, but that conflicts with a Sun header |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
709 * file. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
710 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
711 void |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
712 vimlist_remove(list_T *l, listitem_T *item, listitem_T *item2) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
713 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
714 listitem_T *ip; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
715 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
716 /* notify watchers */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
717 for (ip = item; ip != NULL; ip = ip->li_next) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
718 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
719 --l->lv_len; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
720 list_fix_watch(l, ip); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
721 if (ip == item2) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
722 break; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
723 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
724 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
725 if (item2->li_next == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
726 l->lv_last = item->li_prev; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
727 else |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
728 item2->li_next->li_prev = item->li_prev; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
729 if (item->li_prev == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
730 l->lv_first = item2->li_next; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
731 else |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
732 item->li_prev->li_next = item2->li_next; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
733 l->lv_idx_item = NULL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
734 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
735 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
736 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
737 * Return an allocated string with the string representation of a list. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
738 * May return NULL. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
739 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
740 char_u * |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
741 list2string(typval_T *tv, int copyID, int restore_copyID) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
742 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
743 garray_T ga; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
744 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
745 if (tv->vval.v_list == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
746 return NULL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
747 ga_init2(&ga, (int)sizeof(char), 80); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
748 ga_append(&ga, '['); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
749 if (list_join(&ga, tv->vval.v_list, (char_u *)", ", |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
750 FALSE, restore_copyID, copyID) == FAIL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
751 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
752 vim_free(ga.ga_data); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
753 return NULL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
754 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
755 ga_append(&ga, ']'); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
756 ga_append(&ga, NUL); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
757 return (char_u *)ga.ga_data; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
758 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
759 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
760 typedef struct join_S { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
761 char_u *s; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
762 char_u *tofree; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
763 } join_T; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
764 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
765 static int |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
766 list_join_inner( |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
767 garray_T *gap, /* to store the result in */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
768 list_T *l, |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
769 char_u *sep, |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
770 int echo_style, |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
771 int restore_copyID, |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
772 int copyID, |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
773 garray_T *join_gap) /* to keep each list item string */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
774 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
775 int i; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
776 join_T *p; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
777 int len; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
778 int sumlen = 0; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
779 int first = TRUE; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
780 char_u *tofree; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
781 char_u numbuf[NUMBUFLEN]; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
782 listitem_T *item; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
783 char_u *s; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
784 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
785 /* Stringify each item in the list. */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
786 for (item = l->lv_first; item != NULL && !got_int; item = item->li_next) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
787 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
788 s = echo_string_core(&item->li_tv, &tofree, numbuf, copyID, |
11973
aec3df2af27c
patch 8.0.0867: job and channel in a dict value not quoted
Christian Brabandt <cb@256bit.org>
parents:
11418
diff
changeset
|
789 echo_style, restore_copyID, !echo_style); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
790 if (s == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
791 return FAIL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
792 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
793 len = (int)STRLEN(s); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
794 sumlen += len; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
795 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
796 (void)ga_grow(join_gap, 1); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
797 p = ((join_T *)join_gap->ga_data) + (join_gap->ga_len++); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
798 if (tofree != NULL || s != numbuf) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
799 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
800 p->s = s; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
801 p->tofree = tofree; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
802 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
803 else |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
804 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
805 p->s = vim_strnsave(s, len); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
806 p->tofree = p->s; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
807 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
808 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
809 line_breakcheck(); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
810 if (did_echo_string_emsg) /* recursion error, bail out */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
811 break; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
812 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
813 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
814 /* Allocate result buffer with its total size, avoid re-allocation and |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
815 * multiple copy operations. Add 2 for a tailing ']' and NUL. */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
816 if (join_gap->ga_len >= 2) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
817 sumlen += (int)STRLEN(sep) * (join_gap->ga_len - 1); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
818 if (ga_grow(gap, sumlen + 2) == FAIL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
819 return FAIL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
820 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
821 for (i = 0; i < join_gap->ga_len && !got_int; ++i) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
822 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
823 if (first) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
824 first = FALSE; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
825 else |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
826 ga_concat(gap, sep); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
827 p = ((join_T *)join_gap->ga_data) + i; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
828 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
829 if (p->s != NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
830 ga_concat(gap, p->s); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
831 line_breakcheck(); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
832 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
833 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
834 return OK; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
835 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
836 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
837 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
838 * Join list "l" into a string in "*gap", using separator "sep". |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
839 * When "echo_style" is TRUE use String as echoed, otherwise as inside a List. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
840 * Return FAIL or OK. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
841 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
842 int |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
843 list_join( |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
844 garray_T *gap, |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
845 list_T *l, |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
846 char_u *sep, |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
847 int echo_style, |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
848 int restore_copyID, |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
849 int copyID) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
850 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
851 garray_T join_ga; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
852 int retval; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
853 join_T *p; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
854 int i; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
855 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
856 if (l->lv_len < 1) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
857 return OK; /* nothing to do */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
858 ga_init2(&join_ga, (int)sizeof(join_T), l->lv_len); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
859 retval = list_join_inner(gap, l, sep, echo_style, restore_copyID, |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
860 copyID, &join_ga); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
861 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
862 /* Dispose each item in join_ga. */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
863 if (join_ga.ga_data != NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
864 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
865 p = (join_T *)join_ga.ga_data; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
866 for (i = 0; i < join_ga.ga_len; ++i) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
867 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
868 vim_free(p->tofree); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
869 ++p; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
870 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
871 ga_clear(&join_ga); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
872 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
873 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
874 return retval; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
875 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
876 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
877 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
878 * Allocate a variable for a List and fill it from "*arg". |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
879 * Return OK or FAIL. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
880 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
881 int |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
882 get_list_tv(char_u **arg, typval_T *rettv, int evaluate) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
883 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
884 list_T *l = NULL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
885 typval_T tv; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
886 listitem_T *item; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
887 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
888 if (evaluate) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
889 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
890 l = list_alloc(); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
891 if (l == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
892 return FAIL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
893 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
894 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
895 *arg = skipwhite(*arg + 1); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
896 while (**arg != ']' && **arg != NUL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
897 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
898 if (eval1(arg, &tv, evaluate) == FAIL) /* recursive! */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
899 goto failret; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
900 if (evaluate) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
901 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
902 item = listitem_alloc(); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
903 if (item != NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
904 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
905 item->li_tv = tv; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
906 item->li_tv.v_lock = 0; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
907 list_append(l, item); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
908 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
909 else |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
910 clear_tv(&tv); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
911 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
912 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
913 if (**arg == ']') |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
914 break; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
915 if (**arg != ',') |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
916 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
917 semsg(_("E696: Missing comma in List: %s"), *arg); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
918 goto failret; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
919 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
920 *arg = skipwhite(*arg + 1); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
921 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
922 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
923 if (**arg != ']') |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
924 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
925 semsg(_("E697: Missing end of List ']': %s"), *arg); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
926 failret: |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
927 if (evaluate) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
928 list_free(l); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
929 return FAIL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
930 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
931 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
932 *arg = skipwhite(*arg + 1); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
933 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:
10549
diff
changeset
|
934 rettv_list_set(rettv, l); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
935 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
936 return OK; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
937 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
938 |
9571
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
939 /* |
10549
055b1633aed7
patch 8.0.0164: outdated and misplaced comments
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
940 * Write "list" of strings to file "fd". |
9571
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
941 */ |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
942 int |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
943 write_list(FILE *fd, list_T *list, int binary) |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
944 { |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
945 listitem_T *li; |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
946 int c; |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
947 int ret = OK; |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
948 char_u *s; |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
949 |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
950 for (li = list->lv_first; li != NULL; li = li->li_next) |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
951 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15209
diff
changeset
|
952 for (s = tv_get_string(&li->li_tv); *s != NUL; ++s) |
9571
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
953 { |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
954 if (*s == '\n') |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
955 c = putc(NUL, fd); |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
956 else |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
957 c = putc(*s, fd); |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
958 if (c == EOF) |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
959 { |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
960 ret = FAIL; |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
961 break; |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
962 } |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
963 } |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
964 if (!binary || li->li_next != NULL) |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
965 if (putc('\n', fd) == EOF) |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
966 { |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
967 ret = FAIL; |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
968 break; |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
969 } |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
970 if (ret == FAIL) |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
971 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
972 emsg(_(e_write)); |
9571
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
973 break; |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
974 } |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
975 } |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
976 return ret; |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
977 } |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
978 |
9626
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
979 /* |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
980 * Initialize a static list with 10 items. |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
981 */ |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
982 void |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
983 init_static_list(staticList10_T *sl) |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
984 { |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
985 list_T *l = &sl->sl_list; |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
986 int i; |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
987 |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
988 memset(sl, 0, sizeof(staticList10_T)); |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
989 l->lv_first = &sl->sl_items[0]; |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
990 l->lv_last = &sl->sl_items[9]; |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
991 l->lv_refcount = DO_NOT_FREE_CNT; |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
992 l->lv_lock = VAR_FIXED; |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
993 sl->sl_list.lv_len = 10; |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
994 |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
995 for (i = 0; i < 10; ++i) |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
996 { |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
997 listitem_T *li = &sl->sl_items[i]; |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
998 |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
999 if (i == 0) |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1000 li->li_prev = NULL; |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1001 else |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1002 li->li_prev = li - 1; |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1003 if (i == 9) |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1004 li->li_next = NULL; |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1005 else |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1006 li->li_next = li + 1; |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1007 } |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1008 } |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1009 |
9571
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1010 #endif /* defined(FEAT_EVAL) */ |