Mercurial > vim
annotate src/list.c @ 28055:5bf3ed75e26c v8.2.4552
patch 8.2.4552: in a :def function "put = expr" does not work
Commit: https://github.com/vim/vim/commit/d0b7bfa95798f5ec743d8afffbffb83aeac823da
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Mar 12 14:51:16 2022 +0000
patch 8.2.4552: in a :def function "put = expr" does not work
Problem: In a :def function "put = expr" does not work.
Solution: Skip over white space. (closes https://github.com/vim/vim/issues/9936)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 12 Mar 2022 16:00:03 +0100 |
parents | 3cb1a109e987 |
children | 18319c0c36f9 |
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 /* |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
11 * list.c: List support and container (List, Dict, Blob) functions. |
9560
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 |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
18 // List heads for garbage collection. |
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
19 static list_T *first_list = NULL; // list of all lists |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
20 |
19934
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
21 #define FOR_ALL_WATCHERS(l, lw) \ |
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
22 for ((lw) = (l)->lv_watch; (lw) != NULL; (lw) = (lw)->lw_next) |
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
23 |
19916
dcec86d796bc
patch 8.2.0514: several global functions are used in only one file
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
24 static void list_free_item(list_T *l, listitem_T *item); |
dcec86d796bc
patch 8.2.0514: several global functions are used in only one file
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
25 |
9560
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 * Add a watcher to a list. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
28 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
29 void |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
30 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
|
31 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
32 lw->lw_next = l->lv_watch; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
33 l->lv_watch = lw; |
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 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
36 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
37 * Remove a watcher from a list. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
38 * No warning when it isn't found... |
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 void |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
41 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
|
42 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
43 listwatch_T *lw, **lwp; |
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 = &l->lv_watch; |
19934
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
46 FOR_ALL_WATCHERS(l, lw) |
9560
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 if (lw == lwrem) |
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 *lwp = lw->lw_next; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
51 break; |
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 lwp = &lw->lw_next; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
54 } |
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 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
57 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
58 * 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
|
59 * item. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
60 */ |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
61 static void |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
62 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
|
63 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
64 listwatch_T *lw; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
65 |
19934
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
66 FOR_ALL_WATCHERS(l, lw) |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
67 if (lw->lw_item == item) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
68 lw->lw_item = item->li_next; |
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 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
71 static void |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
72 list_init(list_T *l) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
73 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
74 // Prepend the list to the list of lists for garbage collection. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
75 if (first_list != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
76 first_list->lv_used_prev = l; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
77 l->lv_used_prev = NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
78 l->lv_used_next = first_list; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
79 first_list = l; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
80 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
81 |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
82 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
83 * Allocate an empty header for a list. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
84 * 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
|
85 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
86 list_T * |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
87 list_alloc(void) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
88 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
89 list_T *l; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
90 |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
91 l = ALLOC_CLEAR_ONE(list_T); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
92 if (l != NULL) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
93 list_init(l); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
94 return l; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
95 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
96 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
97 /* |
15016
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14391
diff
changeset
|
98 * 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
|
99 */ |
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14391
diff
changeset
|
100 list_T * |
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14391
diff
changeset
|
101 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
|
102 { |
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14391
diff
changeset
|
103 #ifdef FEAT_EVAL |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
104 if (alloc_fail_id == id && alloc_does_fail(sizeof(list_T))) |
15016
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14391
diff
changeset
|
105 return NULL; |
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14391
diff
changeset
|
106 #endif |
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14391
diff
changeset
|
107 return (list_alloc()); |
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14391
diff
changeset
|
108 } |
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14391
diff
changeset
|
109 |
c338c91086b9
patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents:
14391
diff
changeset
|
110 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
111 * Allocate space for a list, plus "count" items. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
112 * Next list_set_item() must be called for each item. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
113 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
114 list_T * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
115 list_alloc_with_items(int count) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
116 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
117 list_T *l; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
118 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
119 l = (list_T *)alloc_clear(sizeof(list_T) + count * sizeof(listitem_T)); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
120 if (l != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
121 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
122 list_init(l); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
123 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
124 if (count > 0) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
125 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
126 listitem_T *li = (listitem_T *)(l + 1); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
127 int i; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
128 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
129 l->lv_len = count; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
130 l->lv_with_items = count; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
131 l->lv_first = li; |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19203
diff
changeset
|
132 l->lv_u.mat.lv_last = li + count - 1; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
133 for (i = 0; i < count; ++i) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
134 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
135 if (i == 0) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
136 li->li_prev = NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
137 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
138 li->li_prev = li - 1; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
139 if (i == count - 1) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
140 li->li_next = NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
141 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
142 li->li_next = li + 1; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
143 ++li; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
144 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
145 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
146 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
147 return l; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
148 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
149 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
150 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
151 * Set item "idx" for a list previously allocated with list_alloc_with_items(). |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
152 * The contents of "tv" is moved into the list item. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
153 * Each item must be set exactly once. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
154 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
155 void |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
156 list_set_item(list_T *l, int idx, typval_T *tv) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
157 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
158 listitem_T *li = (listitem_T *)(l + 1) + idx; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
159 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
160 li->li_tv = *tv; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
161 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
162 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
163 /* |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
164 * 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
|
165 * Returns OK or FAIL. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
166 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
167 int |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
168 rettv_list_alloc(typval_T *rettv) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
169 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
170 list_T *l = list_alloc(); |
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 if (l == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
173 return FAIL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
174 |
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
|
175 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
|
176 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
|
177 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
|
178 } |
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
|
179 |
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
|
180 /* |
15209
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15016
diff
changeset
|
181 * 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
|
182 */ |
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15016
diff
changeset
|
183 int |
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15016
diff
changeset
|
184 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
|
185 { |
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15016
diff
changeset
|
186 #ifdef FEAT_EVAL |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
187 if (alloc_fail_id == id && alloc_does_fail(sizeof(list_T))) |
15209
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15016
diff
changeset
|
188 return FAIL; |
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15016
diff
changeset
|
189 #endif |
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15016
diff
changeset
|
190 return rettv_list_alloc(rettv); |
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15016
diff
changeset
|
191 } |
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15016
diff
changeset
|
192 |
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15016
diff
changeset
|
193 |
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15016
diff
changeset
|
194 /* |
17262
041156ce1d22
patch 8.1.1630: various small problems
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
195 * Set a list as the return value. Increments the reference count. |
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
|
196 */ |
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
|
197 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
|
198 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
|
199 { |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
200 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
|
201 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
|
202 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
|
203 ++l->lv_refcount; |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
204 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
205 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
206 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
207 * 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
|
208 * becomes zero. |
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 void |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
211 list_unref(list_T *l) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
212 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
213 if (l != NULL && --l->lv_refcount <= 0) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
214 list_free(l); |
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 |
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 * 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
|
219 * Ignores the reference count. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
220 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
221 static void |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
222 list_free_contents(list_T *l) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
223 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
224 listitem_T *item; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
225 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
226 if (l->lv_first != &range_list_item) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
227 for (item = l->lv_first; item != NULL; item = l->lv_first) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
228 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
229 // Remove the item before deleting it. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
230 l->lv_first = item->li_next; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
231 clear_tv(&item->li_tv); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
232 list_free_item(l, item); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
233 } |
9560
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 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
236 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
237 * 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
|
238 * 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
|
239 * are not referenced anywhere. |
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 int |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
242 list_free_nonref(int copyID) |
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 list_T *ll; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
245 int did_free = FALSE; |
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 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
|
248 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
|
249 && ll->lv_watch == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
250 { |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
251 // Free the List and ordinary items it contains, but don't recurse |
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
252 // into Lists and Dictionaries, they will be in the list of dicts |
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
253 // or list of lists. |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
254 list_free_contents(ll); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
255 did_free = TRUE; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
256 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
257 return did_free; |
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 static void |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
261 list_free_list(list_T *l) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
262 { |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
263 // Remove the list from the list of lists for garbage collection. |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
264 if (l->lv_used_prev == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
265 first_list = l->lv_used_next; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
266 else |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
267 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
|
268 if (l->lv_used_next != NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
269 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
|
270 |
23458
d2b1269c2c68
patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
271 free_type(l->lv_type); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
272 vim_free(l); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
273 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
274 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
275 void |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
276 list_free_items(int copyID) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
277 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
278 list_T *ll, *ll_next; |
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 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
|
281 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
282 ll_next = ll->lv_used_next; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
283 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
|
284 && ll->lv_watch == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
285 { |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
286 // Free the List and ordinary items it contains, but don't recurse |
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
287 // into Lists and Dictionaries, they will be in the list of dicts |
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
288 // or list of lists. |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
289 list_free_list(ll); |
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 } |
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 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
294 void |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
295 list_free(list_T *l) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
296 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
297 if (!in_free_unref_items) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
298 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
299 list_free_contents(l); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
300 list_free_list(l); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
301 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
302 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
303 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
304 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
305 * Allocate a list item. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
306 * 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
|
307 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
308 listitem_T * |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
309 listitem_alloc(void) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
310 { |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
311 return ALLOC_ONE(listitem_T); |
9560
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 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
314 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
315 * Free a list item, unless it was allocated together with the list itself. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
316 * Does not clear the value. Does not notify watchers. |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
317 */ |
19916
dcec86d796bc
patch 8.2.0514: several global functions are used in only one file
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
318 static void |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
319 list_free_item(list_T *l, listitem_T *item) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
320 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
321 if (l->lv_with_items == 0 || item < (listitem_T *)l |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
322 || item >= (listitem_T *)(l + 1) + l->lv_with_items) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
323 vim_free(item); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
324 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
325 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
326 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
327 * Free a list item, unless it was allocated together with the list itself. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
328 * Also clears the value. Does not notify watchers. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
329 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
330 void |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
331 listitem_free(list_T *l, listitem_T *item) |
9560
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 clear_tv(&item->li_tv); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
334 list_free_item(l, item); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
335 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
336 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
337 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
338 * 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
|
339 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
340 void |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
341 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
|
342 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
343 vimlist_remove(l, item, item); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
344 listitem_free(l, item); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
345 } |
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 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
348 * 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
|
349 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
350 long |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
351 list_len(list_T *l) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
352 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
353 if (l == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
354 return 0L; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
355 return l->lv_len; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
356 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
357 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
358 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
359 * 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
|
360 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
361 int |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
362 list_equal( |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
363 list_T *l1, |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
364 list_T *l2, |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
365 int ic, // ignore case for strings |
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
366 int recursive) // TRUE when used recursively |
9560
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 listitem_T *item1, *item2; |
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 if (l1 == l2) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
371 return TRUE; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
372 if (list_len(l1) != list_len(l2)) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
373 return FALSE; |
19966
c0eb073378e7
patch 8.2.0539: comparing two NULL list fails
Bram Moolenaar <Bram@vim.org>
parents:
19934
diff
changeset
|
374 if (list_len(l1) == 0) |
c0eb073378e7
patch 8.2.0539: comparing two NULL list fails
Bram Moolenaar <Bram@vim.org>
parents:
19934
diff
changeset
|
375 // empty and NULL list are considered equal |
c0eb073378e7
patch 8.2.0539: comparing two NULL list fails
Bram Moolenaar <Bram@vim.org>
parents:
19934
diff
changeset
|
376 return TRUE; |
c0eb073378e7
patch 8.2.0539: comparing two NULL list fails
Bram Moolenaar <Bram@vim.org>
parents:
19934
diff
changeset
|
377 if (l1 == NULL || l2 == NULL) |
c0eb073378e7
patch 8.2.0539: comparing two NULL list fails
Bram Moolenaar <Bram@vim.org>
parents:
19934
diff
changeset
|
378 return FALSE; |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
379 |
20392
4c317d8c1051
patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents:
20158
diff
changeset
|
380 CHECK_LIST_MATERIALIZE(l1); |
4c317d8c1051
patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents:
20158
diff
changeset
|
381 CHECK_LIST_MATERIALIZE(l2); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
382 |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
383 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
|
384 item1 != NULL && item2 != NULL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
385 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
|
386 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
|
387 return FALSE; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
388 return item1 == NULL && item2 == NULL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
389 } |
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 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
392 * 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
|
393 * 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
|
394 * 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
|
395 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
396 listitem_T * |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
397 list_find(list_T *l, long n) |
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 listitem_T *item; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
400 long idx; |
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 (l == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
403 return NULL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
404 |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
405 // Negative index is relative to the end. |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
406 if (n < 0) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
407 n = l->lv_len + n; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
408 |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
409 // Check for index out of range. |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
410 if (n < 0 || n >= l->lv_len) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
411 return NULL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
412 |
20392
4c317d8c1051
patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents:
20158
diff
changeset
|
413 CHECK_LIST_MATERIALIZE(l); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
414 |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
415 // When there is a cached index may start search from there. |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19203
diff
changeset
|
416 if (l->lv_u.mat.lv_idx_item != NULL) |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
417 { |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19203
diff
changeset
|
418 if (n < l->lv_u.mat.lv_idx / 2) |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
419 { |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
420 // closest to the start of the list |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
421 item = l->lv_first; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
422 idx = 0; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
423 } |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19203
diff
changeset
|
424 else if (n > (l->lv_u.mat.lv_idx + l->lv_len) / 2) |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
425 { |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
426 // closest to the end of the list |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19203
diff
changeset
|
427 item = l->lv_u.mat.lv_last; |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
428 idx = l->lv_len - 1; |
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 else |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
431 { |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
432 // closest to the cached index |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19203
diff
changeset
|
433 item = l->lv_u.mat.lv_idx_item; |
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19203
diff
changeset
|
434 idx = l->lv_u.mat.lv_idx; |
9560
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 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
437 else |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
438 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
439 if (n < l->lv_len / 2) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
440 { |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
441 // closest to the start of the list |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
442 item = l->lv_first; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
443 idx = 0; |
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 else |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
446 { |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
447 // closest to the end of the list |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19203
diff
changeset
|
448 item = l->lv_u.mat.lv_last; |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
449 idx = l->lv_len - 1; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
450 } |
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 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
453 while (n > idx) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
454 { |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
455 // search forward |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
456 item = item->li_next; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
457 ++idx; |
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 while (n < idx) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
460 { |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
461 // search backward |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
462 item = item->li_prev; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
463 --idx; |
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 |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
466 // cache the used index |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19203
diff
changeset
|
467 l->lv_u.mat.lv_idx = idx; |
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19203
diff
changeset
|
468 l->lv_u.mat.lv_idx_item = item; |
9560
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 return item; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
471 } |
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 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
474 * 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
|
475 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
476 long |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
477 list_find_nr( |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
478 list_T *l, |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
479 long idx, |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
480 int *errorp) // set to TRUE when something wrong |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
481 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
482 listitem_T *li; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
483 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
484 if (l != NULL && l->lv_first == &range_list_item) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
485 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
486 long n = idx; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
487 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
488 // not materialized range() list: compute the value. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
489 // Negative index is relative to the end. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
490 if (n < 0) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
491 n = l->lv_len + n; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
492 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
493 // Check for index out of range. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
494 if (n < 0 || n >= l->lv_len) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
495 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
496 if (errorp != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
497 *errorp = TRUE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
498 return -1L; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
499 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
500 |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19203
diff
changeset
|
501 return l->lv_u.nonmat.lv_start + n * l->lv_u.nonmat.lv_stride; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
502 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
503 |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
504 li = list_find(l, idx); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
505 if (li == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
506 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
507 if (errorp != NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
508 *errorp = TRUE; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
509 return -1L; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
510 } |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15209
diff
changeset
|
511 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
|
512 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
513 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
514 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
515 * 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
|
516 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
517 char_u * |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
518 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
|
519 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
520 listitem_T *li; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
521 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
522 li = list_find(l, idx - 1); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
523 if (li == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
524 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
525 semsg(_(e_list_index_out_of_range_nr), idx); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
526 return NULL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
527 } |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15209
diff
changeset
|
528 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
|
529 } |
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 /* |
23982
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23917
diff
changeset
|
532 * Like list_find() but when a negative index is used that is not found use |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23917
diff
changeset
|
533 * zero and set "idx" to zero. Used for first index of a range. |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23917
diff
changeset
|
534 */ |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23917
diff
changeset
|
535 listitem_T * |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23917
diff
changeset
|
536 list_find_index(list_T *l, long *idx) |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23917
diff
changeset
|
537 { |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23917
diff
changeset
|
538 listitem_T *li = list_find(l, *idx); |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23917
diff
changeset
|
539 |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23917
diff
changeset
|
540 if (li == NULL) |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23917
diff
changeset
|
541 { |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23917
diff
changeset
|
542 if (*idx < 0) |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23917
diff
changeset
|
543 { |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23917
diff
changeset
|
544 *idx = 0; |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23917
diff
changeset
|
545 li = list_find(l, *idx); |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23917
diff
changeset
|
546 } |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23917
diff
changeset
|
547 } |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23917
diff
changeset
|
548 return li; |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23917
diff
changeset
|
549 } |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23917
diff
changeset
|
550 |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23917
diff
changeset
|
551 /* |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
552 * 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
|
553 * 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
|
554 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
555 long |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
556 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
|
557 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
558 long idx = 0; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
559 listitem_T *li; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
560 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
561 if (l == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
562 return -1; |
20392
4c317d8c1051
patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents:
20158
diff
changeset
|
563 CHECK_LIST_MATERIALIZE(l); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
564 idx = 0; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
565 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
|
566 ++idx; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
567 if (li == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
568 return -1; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
569 return idx; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
570 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
571 |
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 * 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
|
574 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
575 void |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
576 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
|
577 { |
20392
4c317d8c1051
patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents:
20158
diff
changeset
|
578 CHECK_LIST_MATERIALIZE(l); |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19203
diff
changeset
|
579 if (l->lv_u.mat.lv_last == NULL) |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
580 { |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
581 // empty list |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
582 l->lv_first = item; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
583 item->li_prev = NULL; |
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 else |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
586 { |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19203
diff
changeset
|
587 l->lv_u.mat.lv_last->li_next = item; |
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19203
diff
changeset
|
588 item->li_prev = l->lv_u.mat.lv_last; |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
589 } |
27406
4c1bdee75bed
patch 8.2.4231: Vim9: map() gives type error when type was not declared
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
590 l->lv_u.mat.lv_last = item; |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
591 ++l->lv_len; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
592 item->li_next = NULL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
593 } |
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 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
596 * Append typval_T "tv" to the end of list "l". "tv" is copied. |
25182
14448e7acdb2
patch 8.2.3127: Vim9: no error when adding number to list of string
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
597 * Return FAIL when out of memory or the type is wrong. |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
598 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
599 int |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
600 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
|
601 { |
25194
6c75baaa54ee
patch 8.2.3133: Vim9: memory leak when add() fails
Bram Moolenaar <Bram@vim.org>
parents:
25182
diff
changeset
|
602 listitem_T *li; |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
603 |
25182
14448e7acdb2
patch 8.2.3127: Vim9: no error when adding number to list of string
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
604 if (l->lv_type != NULL && l->lv_type->tt_member != NULL |
25326
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
605 && check_typval_arg_type(l->lv_type->tt_member, tv, |
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
606 NULL, 0) == FAIL) |
25182
14448e7acdb2
patch 8.2.3127: Vim9: no error when adding number to list of string
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
607 return FAIL; |
25194
6c75baaa54ee
patch 8.2.3133: Vim9: memory leak when add() fails
Bram Moolenaar <Bram@vim.org>
parents:
25182
diff
changeset
|
608 li = listitem_alloc(); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
609 if (li == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
610 return FAIL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
611 copy_tv(tv, &li->li_tv); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
612 list_append(l, li); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
613 return OK; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
614 } |
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 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
617 * As list_append_tv() but move the value instead of copying it. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
618 * Return FAIL when out of memory. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
619 */ |
25567
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25495
diff
changeset
|
620 static int |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
621 list_append_tv_move(list_T *l, typval_T *tv) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
622 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
623 listitem_T *li = listitem_alloc(); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
624 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
625 if (li == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
626 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
627 li->li_tv = *tv; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
628 list_append(l, li); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
629 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
630 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
631 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
632 /* |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
633 * 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
|
634 * Return FAIL when out of memory. |
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 int |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
637 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
|
638 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
639 listitem_T *li = listitem_alloc(); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
640 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
641 if (li == 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 li->li_tv.v_type = VAR_DICT; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
644 li->li_tv.v_lock = 0; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
645 li->li_tv.vval.v_dict = dict; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
646 list_append(list, li); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
647 ++dict->dv_refcount; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
648 return OK; |
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 /* |
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
|
652 * 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
|
653 * 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
|
654 */ |
dd3b2ecf91f6
patch 8.0.1497: getting the jump list requires parsing the output of :jumps
Christian Brabandt <cb@256bit.org>
parents:
11973
diff
changeset
|
655 int |
14391
46f14852a919
patch 8.1.0210: still a few K&R function declarations
Christian Brabandt <cb@256bit.org>
parents:
13246
diff
changeset
|
656 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
|
657 { |
dd3b2ecf91f6
patch 8.0.1497: getting the jump list requires parsing the output of :jumps
Christian Brabandt <cb@256bit.org>
parents:
11973
diff
changeset
|
658 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
|
659 |
dd3b2ecf91f6
patch 8.0.1497: getting the jump list requires parsing the output of :jumps
Christian Brabandt <cb@256bit.org>
parents:
11973
diff
changeset
|
660 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
|
661 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
|
662 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
|
663 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
|
664 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
|
665 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
|
666 ++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
|
667 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
|
668 } |
dd3b2ecf91f6
patch 8.0.1497: getting the jump list requires parsing the output of :jumps
Christian Brabandt <cb@256bit.org>
parents:
11973
diff
changeset
|
669 |
dd3b2ecf91f6
patch 8.0.1497: getting the jump list requires parsing the output of :jumps
Christian Brabandt <cb@256bit.org>
parents:
11973
diff
changeset
|
670 /* |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
671 * 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
|
672 * When "len" >= 0 use "str[len]". |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
673 * Returns FAIL when out of memory. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
674 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
675 int |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
676 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
|
677 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
678 listitem_T *li = listitem_alloc(); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
679 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
680 if (li == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
681 return FAIL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
682 list_append(l, li); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
683 li->li_tv.v_type = VAR_STRING; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
684 li->li_tv.v_lock = 0; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
685 if (str == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
686 li->li_tv.vval.v_string = NULL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
687 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
|
688 : vim_strsave(str))) == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
689 return FAIL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
690 return OK; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
691 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
692 |
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 * Append "n" to list "l". |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
695 * Returns FAIL when out of memory. |
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 int |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
698 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
|
699 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
700 listitem_T *li; |
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 li = listitem_alloc(); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
703 if (li == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
704 return FAIL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
705 li->li_tv.v_type = VAR_NUMBER; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
706 li->li_tv.v_lock = 0; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
707 li->li_tv.vval.v_number = n; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
708 list_append(l, li); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
709 return OK; |
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 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
712 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
713 * 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
|
714 * If "item" is NULL append at the end. |
23458
d2b1269c2c68
patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
715 * Return FAIL when out of memory or the type is wrong. |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
716 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
717 int |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
718 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
|
719 { |
23458
d2b1269c2c68
patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
720 listitem_T *ni; |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
721 |
23458
d2b1269c2c68
patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
722 if (l->lv_type != NULL && l->lv_type->tt_member != NULL |
25326
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
723 && check_typval_arg_type(l->lv_type->tt_member, tv, |
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
724 NULL, 0) == FAIL) |
23458
d2b1269c2c68
patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
725 return FAIL; |
d2b1269c2c68
patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
726 ni = listitem_alloc(); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
727 if (ni == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
728 return FAIL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
729 copy_tv(tv, &ni->li_tv); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
730 list_insert(l, ni, item); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
731 return OK; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
732 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
733 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
734 void |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
735 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
|
736 { |
20392
4c317d8c1051
patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents:
20158
diff
changeset
|
737 CHECK_LIST_MATERIALIZE(l); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
738 if (item == NULL) |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
739 // Append new item at end of list. |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
740 list_append(l, ni); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
741 else |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
742 { |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
743 // Insert new item before existing item. |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
744 ni->li_prev = item->li_prev; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
745 ni->li_next = item; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
746 if (item->li_prev == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
747 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
748 l->lv_first = ni; |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19203
diff
changeset
|
749 ++l->lv_u.mat.lv_idx; |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
750 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
751 else |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
752 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
753 item->li_prev->li_next = ni; |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19203
diff
changeset
|
754 l->lv_u.mat.lv_idx_item = NULL; |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
755 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
756 item->li_prev = ni; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
757 ++l->lv_len; |
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 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
761 /* |
25591
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
762 * Get the list item in "l" with index "n1". "n1" is adjusted if needed. |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
763 * In Vim9, it is at the end of the list, add an item. |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
764 * Return NULL if there is no such item. |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
765 */ |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
766 listitem_T * |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
767 check_range_index_one(list_T *l, long *n1, int quiet) |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
768 { |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
769 listitem_T *li = list_find_index(l, n1); |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
770 |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
771 if (li == NULL) |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
772 { |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
773 // Vim9: Allow for adding an item at the end. |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
774 if (in_vim9script() && *n1 == l->lv_len && l->lv_lock == 0) |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
775 { |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
776 list_append_number(l, 0); |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
777 li = list_find_index(l, n1); |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
778 } |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
779 if (li == NULL) |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
780 { |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
781 if (!quiet) |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
782 semsg(_(e_list_index_out_of_range_nr), *n1); |
25591
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
783 return NULL; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
784 } |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
785 } |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
786 return li; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
787 } |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
788 |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
789 /* |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
790 * Check that "n2" can be used as the second index in a range of list "l". |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
791 * If "n1" or "n2" is negative it is changed to the positive index. |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
792 * "li1" is the item for item "n1". |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
793 * Return OK or FAIL. |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
794 */ |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
795 int |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
796 check_range_index_two( |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
797 list_T *l, |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
798 long *n1, |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
799 listitem_T *li1, |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
800 long *n2, |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
801 int quiet) |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
802 { |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
803 if (*n2 < 0) |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
804 { |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
805 listitem_T *ni = list_find(l, *n2); |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
806 |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
807 if (ni == NULL) |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
808 { |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
809 if (!quiet) |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
810 semsg(_(e_list_index_out_of_range_nr), *n2); |
25591
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
811 return FAIL; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
812 } |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
813 *n2 = list_idx_of_item(l, ni); |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
814 } |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
815 |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
816 // Check that n2 isn't before n1. |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
817 if (*n1 < 0) |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
818 *n1 = list_idx_of_item(l, li1); |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
819 if (*n2 < *n1) |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
820 { |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
821 if (!quiet) |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
822 semsg(_(e_list_index_out_of_range_nr), *n2); |
25591
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
823 return FAIL; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
824 } |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
825 return OK; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
826 } |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
827 |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
828 /* |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
829 * Assign values from list "src" into a range of "dest". |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
830 * "idx1_arg" is the index of the first item in "dest" to be replaced. |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
831 * "idx2" is the index of last item to be replaced, but when "empty_idx2" is |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
832 * TRUE then replace all items after "idx1". |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
833 * "op" is the operator, normally "=" but can be "+=" and the like. |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
834 * "varname" is used for error messages. |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
835 * Returns OK or FAIL. |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
836 */ |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
837 int |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
838 list_assign_range( |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
839 list_T *dest, |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
840 list_T *src, |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
841 long idx1_arg, |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
842 long idx2, |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
843 int empty_idx2, |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
844 char_u *op, |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
845 char_u *varname) |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
846 { |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
847 listitem_T *src_li; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
848 listitem_T *dest_li; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
849 long idx1 = idx1_arg; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
850 listitem_T *first_li = list_find_index(dest, &idx1); |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
851 long idx; |
25603
525ef4d1d412
patch 8.2.3338: Vim9: no type check when assigning a list range
Bram Moolenaar <Bram@vim.org>
parents:
25599
diff
changeset
|
852 type_T *member_type = NULL; |
25591
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
853 |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
854 // Check whether any of the list items is locked before making any changes. |
25591
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
855 idx = idx1; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
856 dest_li = first_li; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
857 for (src_li = src->lv_first; src_li != NULL && dest_li != NULL; ) |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
858 { |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
859 if (value_check_lock(dest_li->li_tv.v_lock, varname, FALSE)) |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
860 return FAIL; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
861 src_li = src_li->li_next; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
862 if (src_li == NULL || (!empty_idx2 && idx2 == idx)) |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
863 break; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
864 dest_li = dest_li->li_next; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
865 ++idx; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
866 } |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
867 |
25603
525ef4d1d412
patch 8.2.3338: Vim9: no type check when assigning a list range
Bram Moolenaar <Bram@vim.org>
parents:
25599
diff
changeset
|
868 if (in_vim9script() && dest->lv_type != NULL |
525ef4d1d412
patch 8.2.3338: Vim9: no type check when assigning a list range
Bram Moolenaar <Bram@vim.org>
parents:
25599
diff
changeset
|
869 && dest->lv_type->tt_member != NULL) |
525ef4d1d412
patch 8.2.3338: Vim9: no type check when assigning a list range
Bram Moolenaar <Bram@vim.org>
parents:
25599
diff
changeset
|
870 member_type = dest->lv_type->tt_member; |
525ef4d1d412
patch 8.2.3338: Vim9: no type check when assigning a list range
Bram Moolenaar <Bram@vim.org>
parents:
25599
diff
changeset
|
871 |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
872 // Assign the List values to the list items. |
25591
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
873 idx = idx1; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
874 dest_li = first_li; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
875 for (src_li = src->lv_first; src_li != NULL; ) |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
876 { |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
877 if (op != NULL && *op != '=') |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
878 tv_op(&dest_li->li_tv, &src_li->li_tv, op); |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
879 else |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
880 { |
25603
525ef4d1d412
patch 8.2.3338: Vim9: no type check when assigning a list range
Bram Moolenaar <Bram@vim.org>
parents:
25599
diff
changeset
|
881 if (member_type != NULL |
525ef4d1d412
patch 8.2.3338: Vim9: no type check when assigning a list range
Bram Moolenaar <Bram@vim.org>
parents:
25599
diff
changeset
|
882 && check_typval_arg_type(member_type, &src_li->li_tv, |
525ef4d1d412
patch 8.2.3338: Vim9: no type check when assigning a list range
Bram Moolenaar <Bram@vim.org>
parents:
25599
diff
changeset
|
883 NULL, 0) == FAIL) |
525ef4d1d412
patch 8.2.3338: Vim9: no type check when assigning a list range
Bram Moolenaar <Bram@vim.org>
parents:
25599
diff
changeset
|
884 return FAIL; |
25591
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
885 clear_tv(&dest_li->li_tv); |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
886 copy_tv(&src_li->li_tv, &dest_li->li_tv); |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
887 } |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
888 src_li = src_li->li_next; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
889 if (src_li == NULL || (!empty_idx2 && idx2 == idx)) |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
890 break; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
891 if (dest_li->li_next == NULL) |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
892 { |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
893 // Need to add an empty item. |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
894 if (list_append_number(dest, 0) == FAIL) |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
895 { |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
896 src_li = NULL; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
897 break; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
898 } |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
899 } |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
900 dest_li = dest_li->li_next; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
901 ++idx; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
902 } |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
903 if (src_li != NULL) |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
904 { |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
905 emsg(_(e_list_value_has_more_items_than_targets)); |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
906 return FAIL; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
907 } |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
908 if (empty_idx2 |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
909 ? (dest_li != NULL && dest_li->li_next != NULL) |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
910 : idx != idx2) |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
911 { |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
912 emsg(_(e_list_value_does_not_have_enough_items)); |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
913 return FAIL; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
914 } |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
915 return OK; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
916 } |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
917 |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
918 /* |
20766
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
919 * Flatten "list" to depth "maxdepth". |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
920 * It does nothing if "maxdepth" is 0. |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
921 * Returns FAIL when out of memory. |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
922 */ |
23816
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
923 static void |
20766
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
924 list_flatten(list_T *list, long maxdepth) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
925 { |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
926 listitem_T *item; |
20770
b366a0fe8296
patch 8.2.0937: asan failure in the flatten() test
Bram Moolenaar <Bram@vim.org>
parents:
20766
diff
changeset
|
927 listitem_T *tofree; |
20766
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
928 int n; |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
929 |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
930 if (maxdepth == 0) |
23816
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
931 return; |
20766
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
932 CHECK_LIST_MATERIALIZE(list); |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
933 |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
934 n = 0; |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
935 item = list->lv_first; |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
936 while (item != NULL) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
937 { |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
938 fast_breakcheck(); |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
939 if (got_int) |
23816
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
940 return; |
20766
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
941 |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
942 if (item->li_tv.v_type == VAR_LIST) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
943 { |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
944 listitem_T *next = item->li_next; |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
945 |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
946 vimlist_remove(list, item, item); |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
947 if (list_extend(list, item->li_tv.vval.v_list, next) == FAIL) |
25784
8dfcee931c6c
patch 8.2.3427: double free when list is copied
Bram Moolenaar <Bram@vim.org>
parents:
25774
diff
changeset
|
948 { |
8dfcee931c6c
patch 8.2.3427: double free when list is copied
Bram Moolenaar <Bram@vim.org>
parents:
25774
diff
changeset
|
949 list_free_item(list, item); |
23816
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
950 return; |
25784
8dfcee931c6c
patch 8.2.3427: double free when list is copied
Bram Moolenaar <Bram@vim.org>
parents:
25774
diff
changeset
|
951 } |
20770
b366a0fe8296
patch 8.2.0937: asan failure in the flatten() test
Bram Moolenaar <Bram@vim.org>
parents:
20766
diff
changeset
|
952 clear_tv(&item->li_tv); |
b366a0fe8296
patch 8.2.0937: asan failure in the flatten() test
Bram Moolenaar <Bram@vim.org>
parents:
20766
diff
changeset
|
953 tofree = item; |
20766
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
954 |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
955 if (item->li_prev == NULL) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
956 item = list->lv_first; |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
957 else |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
958 item = item->li_prev->li_next; |
20770
b366a0fe8296
patch 8.2.0937: asan failure in the flatten() test
Bram Moolenaar <Bram@vim.org>
parents:
20766
diff
changeset
|
959 list_free_item(list, tofree); |
20766
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
960 |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
961 if (++n >= maxdepth) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
962 { |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
963 n = 0; |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
964 item = next; |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
965 } |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
966 } |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
967 else |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
968 { |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
969 n = 0; |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
970 item = item->li_next; |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
971 } |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
972 } |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
973 } |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
974 |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
975 /* |
23816
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
976 * "flatten()" and "flattennew()" functions |
20766
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
977 */ |
23816
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
978 static void |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
979 flatten_common(typval_T *argvars, typval_T *rettv, int make_copy) |
20766
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
980 { |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
981 list_T *l; |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
982 long maxdepth; |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
983 int error = FALSE; |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
984 |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25290
diff
changeset
|
985 if (in_vim9script() |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25290
diff
changeset
|
986 && (check_for_list_arg(argvars, 0) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25290
diff
changeset
|
987 || check_for_opt_number_arg(argvars, 1) == FAIL)) |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25290
diff
changeset
|
988 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25290
diff
changeset
|
989 |
20766
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
990 if (argvars[0].v_type != VAR_LIST) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
991 { |
26887
612339679616
patch 8.2.3972: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
992 semsg(_(e_argument_of_str_must_be_list), "flatten()"); |
20766
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
993 return; |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
994 } |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
995 |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
996 if (argvars[1].v_type == VAR_UNKNOWN) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
997 maxdepth = 999999; |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
998 else |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
999 { |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
1000 maxdepth = (long)tv_get_number_chk(&argvars[1], &error); |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
1001 if (error) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
1002 return; |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
1003 if (maxdepth < 0) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
1004 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26952
diff
changeset
|
1005 emsg(_(e_maxdepth_must_be_non_negative_number)); |
20766
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
1006 return; |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
1007 } |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
1008 } |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
1009 |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
1010 l = argvars[0].vval.v_list; |
23816
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1011 rettv->v_type = VAR_LIST; |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1012 rettv->vval.v_list = l; |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1013 if (l == NULL) |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1014 return; |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1015 |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1016 if (make_copy) |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1017 { |
27517
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27453
diff
changeset
|
1018 l = list_copy(l, TRUE, TRUE, get_copyID()); |
23816
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1019 rettv->vval.v_list = l; |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1020 if (l == NULL) |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1021 return; |
25784
8dfcee931c6c
patch 8.2.3427: double free when list is copied
Bram Moolenaar <Bram@vim.org>
parents:
25774
diff
changeset
|
1022 // The type will change. |
8dfcee931c6c
patch 8.2.3427: double free when list is copied
Bram Moolenaar <Bram@vim.org>
parents:
25774
diff
changeset
|
1023 free_type(l->lv_type); |
8dfcee931c6c
patch 8.2.3427: double free when list is copied
Bram Moolenaar <Bram@vim.org>
parents:
25774
diff
changeset
|
1024 l->lv_type = NULL; |
23816
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1025 } |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1026 else |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1027 { |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1028 if (value_check_lock(l->lv_lock, |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1029 (char_u *)N_("flatten() argument"), TRUE)) |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1030 return; |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1031 ++l->lv_refcount; |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1032 } |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1033 |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1034 list_flatten(l, maxdepth); |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1035 } |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1036 |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1037 /* |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1038 * "flatten(list[, {maxdepth}])" function |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1039 */ |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1040 void |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1041 f_flatten(typval_T *argvars, typval_T *rettv) |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1042 { |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1043 if (in_vim9script()) |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1044 emsg(_(e_cannot_use_flatten_in_vim9_script)); |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1045 else |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1046 flatten_common(argvars, rettv, FALSE); |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1047 } |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1048 |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1049 /* |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1050 * "flattennew(list[, {maxdepth}])" function |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1051 */ |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1052 void |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1053 f_flattennew(typval_T *argvars, typval_T *rettv) |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1054 { |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23800
diff
changeset
|
1055 flatten_common(argvars, rettv, TRUE); |
20766
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
1056 } |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
1057 |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20657
diff
changeset
|
1058 /* |
22545
47596deedfb5
patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
22303
diff
changeset
|
1059 * Extend "l1" with "l2". "l1" must not be NULL. |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1060 * 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
|
1061 * Returns FAIL when out of memory. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1062 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1063 int |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1064 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
|
1065 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1066 listitem_T *item; |
22545
47596deedfb5
patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
22303
diff
changeset
|
1067 int todo; |
24396
d406858354a6
patch 8.2.2738: extending a list with itself can give wrong result
Bram Moolenaar <Bram@vim.org>
parents:
24160
diff
changeset
|
1068 listitem_T *bef_prev; |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1069 |
22545
47596deedfb5
patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
22303
diff
changeset
|
1070 // NULL list is equivalent to an empty list: nothing to do. |
47596deedfb5
patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
22303
diff
changeset
|
1071 if (l2 == NULL || l2->lv_len == 0) |
47596deedfb5
patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
22303
diff
changeset
|
1072 return OK; |
47596deedfb5
patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
22303
diff
changeset
|
1073 |
47596deedfb5
patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
22303
diff
changeset
|
1074 todo = l2->lv_len; |
20392
4c317d8c1051
patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents:
20158
diff
changeset
|
1075 CHECK_LIST_MATERIALIZE(l1); |
4c317d8c1051
patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents:
20158
diff
changeset
|
1076 CHECK_LIST_MATERIALIZE(l2); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
1077 |
24396
d406858354a6
patch 8.2.2738: extending a list with itself can give wrong result
Bram Moolenaar <Bram@vim.org>
parents:
24160
diff
changeset
|
1078 // When exending a list with itself, at some point we run into the item |
d406858354a6
patch 8.2.2738: extending a list with itself can give wrong result
Bram Moolenaar <Bram@vim.org>
parents:
24160
diff
changeset
|
1079 // that was before "bef" and need to skip over the already inserted items |
d406858354a6
patch 8.2.2738: extending a list with itself can give wrong result
Bram Moolenaar <Bram@vim.org>
parents:
24160
diff
changeset
|
1080 // to "bef". |
d406858354a6
patch 8.2.2738: extending a list with itself can give wrong result
Bram Moolenaar <Bram@vim.org>
parents:
24160
diff
changeset
|
1081 bef_prev = bef == NULL ? NULL : bef->li_prev; |
d406858354a6
patch 8.2.2738: extending a list with itself can give wrong result
Bram Moolenaar <Bram@vim.org>
parents:
24160
diff
changeset
|
1082 |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
1083 // We also quit the loop when we have inserted the original item count of |
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
1084 // the list, avoid a hang when we extend a list with itself. |
24396
d406858354a6
patch 8.2.2738: extending a list with itself can give wrong result
Bram Moolenaar <Bram@vim.org>
parents:
24160
diff
changeset
|
1085 for (item = l2->lv_first; item != NULL && --todo >= 0; |
d406858354a6
patch 8.2.2738: extending a list with itself can give wrong result
Bram Moolenaar <Bram@vim.org>
parents:
24160
diff
changeset
|
1086 item = item == bef_prev ? bef : item->li_next) |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1087 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
|
1088 return FAIL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1089 return OK; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1090 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1091 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1092 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1093 * 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
|
1094 * Return FAIL when out of memory. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1095 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1096 int |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1097 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
|
1098 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1099 list_T *l; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1100 |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
1101 // make a copy of the first list. |
22545
47596deedfb5
patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
22303
diff
changeset
|
1102 if (l1 == NULL) |
47596deedfb5
patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
22303
diff
changeset
|
1103 l = list_alloc(); |
47596deedfb5
patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
22303
diff
changeset
|
1104 else |
27517
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27453
diff
changeset
|
1105 l = list_copy(l1, FALSE, TRUE, 0); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1106 if (l == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1107 return FAIL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1108 tv->v_type = VAR_LIST; |
22961
6426acc72539
patch 8.2.2027: Coverity warnts for uninitialized field
Bram Moolenaar <Bram@vim.org>
parents:
22866
diff
changeset
|
1109 tv->v_lock = 0; |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1110 tv->vval.v_list = l; |
22545
47596deedfb5
patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
22303
diff
changeset
|
1111 if (l1 == NULL) |
47596deedfb5
patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
22303
diff
changeset
|
1112 ++l->lv_refcount; |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1113 |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
1114 // append all items from the second list |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1115 return list_extend(l, l2, NULL); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1116 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1117 |
20871
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20770
diff
changeset
|
1118 list_T * |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20770
diff
changeset
|
1119 list_slice(list_T *ol, long n1, long n2) |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20770
diff
changeset
|
1120 { |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20770
diff
changeset
|
1121 listitem_T *item; |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20770
diff
changeset
|
1122 list_T *l = list_alloc(); |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20770
diff
changeset
|
1123 |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20770
diff
changeset
|
1124 if (l == NULL) |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20770
diff
changeset
|
1125 return NULL; |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20770
diff
changeset
|
1126 for (item = list_find(ol, n1); n1 <= n2; ++n1) |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20770
diff
changeset
|
1127 { |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20770
diff
changeset
|
1128 if (list_append_tv(l, &item->li_tv) == FAIL) |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20770
diff
changeset
|
1129 { |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20770
diff
changeset
|
1130 list_free(l); |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20770
diff
changeset
|
1131 return NULL; |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20770
diff
changeset
|
1132 } |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20770
diff
changeset
|
1133 item = item->li_next; |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20770
diff
changeset
|
1134 } |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20770
diff
changeset
|
1135 return l; |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20770
diff
changeset
|
1136 } |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20770
diff
changeset
|
1137 |
21828
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1138 int |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1139 list_slice_or_index( |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1140 list_T *list, |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1141 int range, |
23604
1816ea68c022
patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents:
23588
diff
changeset
|
1142 varnumber_T n1_arg, |
1816ea68c022
patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents:
23588
diff
changeset
|
1143 varnumber_T n2_arg, |
1816ea68c022
patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents:
23588
diff
changeset
|
1144 int exclusive, |
21828
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1145 typval_T *rettv, |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1146 int verbose) |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1147 { |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1148 long len = list_len(list); |
23604
1816ea68c022
patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents:
23588
diff
changeset
|
1149 varnumber_T n1 = n1_arg; |
1816ea68c022
patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents:
23588
diff
changeset
|
1150 varnumber_T n2 = n2_arg; |
21828
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1151 typval_T var1; |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1152 |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1153 if (n1 < 0) |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1154 n1 = len + n1; |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1155 if (n1 < 0 || n1 >= len) |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1156 { |
25599
b85e44974a08
patch 8.2.3336: behavior of negative index in list change changed
Bram Moolenaar <Bram@vim.org>
parents:
25597
diff
changeset
|
1157 // For a range we allow invalid values and for legacy script return an |
b85e44974a08
patch 8.2.3336: behavior of negative index in list change changed
Bram Moolenaar <Bram@vim.org>
parents:
25597
diff
changeset
|
1158 // empty list, for Vim9 script start at the first item. |
b85e44974a08
patch 8.2.3336: behavior of negative index in list change changed
Bram Moolenaar <Bram@vim.org>
parents:
25597
diff
changeset
|
1159 // A list index out of range is an error. |
21828
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1160 if (!range) |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1161 { |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1162 if (verbose) |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
1163 semsg(_(e_list_index_out_of_range_nr), (long)n1_arg); |
21828
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1164 return FAIL; |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1165 } |
25599
b85e44974a08
patch 8.2.3336: behavior of negative index in list change changed
Bram Moolenaar <Bram@vim.org>
parents:
25597
diff
changeset
|
1166 if (in_vim9script()) |
b85e44974a08
patch 8.2.3336: behavior of negative index in list change changed
Bram Moolenaar <Bram@vim.org>
parents:
25597
diff
changeset
|
1167 n1 = n1 < 0 ? 0 : len; |
b85e44974a08
patch 8.2.3336: behavior of negative index in list change changed
Bram Moolenaar <Bram@vim.org>
parents:
25597
diff
changeset
|
1168 else |
b85e44974a08
patch 8.2.3336: behavior of negative index in list change changed
Bram Moolenaar <Bram@vim.org>
parents:
25597
diff
changeset
|
1169 n1 = len; |
21828
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1170 } |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1171 if (range) |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1172 { |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1173 list_T *l; |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1174 |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1175 if (n2 < 0) |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1176 n2 = len + n2; |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1177 else if (n2 >= len) |
23604
1816ea68c022
patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents:
23588
diff
changeset
|
1178 n2 = len - (exclusive ? 0 : 1); |
1816ea68c022
patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents:
23588
diff
changeset
|
1179 if (exclusive) |
1816ea68c022
patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents:
23588
diff
changeset
|
1180 --n2; |
21828
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1181 if (n2 < 0 || n2 + 1 < n1) |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1182 n2 = -1; |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1183 l = list_slice(list, n1, n2); |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1184 if (l == NULL) |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1185 return FAIL; |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1186 clear_tv(rettv); |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1187 rettv_list_set(rettv, l); |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1188 } |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1189 else |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1190 { |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1191 // copy the item to "var1" to avoid that freeing the list makes it |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1192 // invalid. |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1193 copy_tv(&list_find(list, n1)->li_tv, &var1); |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1194 clear_tv(rettv); |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1195 *rettv = var1; |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1196 } |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1197 return OK; |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1198 } |
af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
1199 |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1200 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1201 * 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
|
1202 * The refcount of the new list is set to 1. |
27517
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27453
diff
changeset
|
1203 * See item_copy() for "top" and "copyID". |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1204 * Returns NULL when out of memory. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1205 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1206 list_T * |
27517
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27453
diff
changeset
|
1207 list_copy(list_T *orig, int deep, int top, int copyID) |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1208 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1209 list_T *copy; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1210 listitem_T *item; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1211 listitem_T *ni; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1212 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1213 if (orig == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1214 return NULL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1215 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1216 copy = list_alloc(); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1217 if (copy != NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1218 { |
27535
e2bb28237695
patch 8.2.4295: Vim9: concatenating two lists may result in wrong type
Bram Moolenaar <Bram@vim.org>
parents:
27531
diff
changeset
|
1219 if (orig->lv_type == NULL || top || deep) |
27531
4ca0ee7b4f86
patch 8.2.4293: Vim9: when copying a list it gets type list<any>
Bram Moolenaar <Bram@vim.org>
parents:
27517
diff
changeset
|
1220 copy->lv_type = NULL; |
4ca0ee7b4f86
patch 8.2.4293: Vim9: when copying a list it gets type list<any>
Bram Moolenaar <Bram@vim.org>
parents:
27517
diff
changeset
|
1221 else |
27535
e2bb28237695
patch 8.2.4295: Vim9: concatenating two lists may result in wrong type
Bram Moolenaar <Bram@vim.org>
parents:
27531
diff
changeset
|
1222 copy->lv_type = alloc_type(orig->lv_type); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1223 if (copyID != 0) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1224 { |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
1225 // Do this before adding the items, because one of the items may |
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
1226 // refer back to this list. |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1227 orig->lv_copyID = copyID; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1228 orig->lv_copylist = copy; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1229 } |
20392
4c317d8c1051
patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents:
20158
diff
changeset
|
1230 CHECK_LIST_MATERIALIZE(orig); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1231 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
|
1232 item = item->li_next) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1233 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1234 ni = listitem_alloc(); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1235 if (ni == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1236 break; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1237 if (deep) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1238 { |
27517
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27453
diff
changeset
|
1239 if (item_copy(&item->li_tv, &ni->li_tv, |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27453
diff
changeset
|
1240 deep, FALSE, copyID) == FAIL) |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1241 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1242 vim_free(ni); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1243 break; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1244 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1245 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1246 else |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1247 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
|
1248 list_append(copy, ni); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1249 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1250 ++copy->lv_refcount; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1251 if (item != NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1252 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1253 list_unref(copy); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1254 copy = NULL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1255 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1256 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1257 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1258 return copy; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1259 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1260 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1261 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1262 * 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
|
1263 * 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
|
1264 * 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
|
1265 * file. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1266 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1267 void |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1268 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
|
1269 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1270 listitem_T *ip; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1271 |
20392
4c317d8c1051
patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents:
20158
diff
changeset
|
1272 CHECK_LIST_MATERIALIZE(l); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
1273 |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
1274 // notify watchers |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1275 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
|
1276 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1277 --l->lv_len; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1278 list_fix_watch(l, ip); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1279 if (ip == item2) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1280 break; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1281 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1282 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1283 if (item2->li_next == NULL) |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19203
diff
changeset
|
1284 l->lv_u.mat.lv_last = item->li_prev; |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1285 else |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1286 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
|
1287 if (item->li_prev == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1288 l->lv_first = item2->li_next; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1289 else |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1290 item->li_prev->li_next = item2->li_next; |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19203
diff
changeset
|
1291 l->lv_u.mat.lv_idx_item = NULL; |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1292 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1293 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1294 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1295 * 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
|
1296 * May return NULL. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1297 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1298 char_u * |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1299 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
|
1300 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1301 garray_T ga; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1302 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1303 if (tv->vval.v_list == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1304 return NULL; |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
1305 ga_init2(&ga, sizeof(char), 80); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1306 ga_append(&ga, '['); |
20392
4c317d8c1051
patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents:
20158
diff
changeset
|
1307 CHECK_LIST_MATERIALIZE(tv->vval.v_list); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1308 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
|
1309 FALSE, restore_copyID, copyID) == FAIL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1310 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1311 vim_free(ga.ga_data); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1312 return NULL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1313 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1314 ga_append(&ga, ']'); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1315 ga_append(&ga, NUL); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1316 return (char_u *)ga.ga_data; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1317 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1318 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1319 typedef struct join_S { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1320 char_u *s; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1321 char_u *tofree; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1322 } join_T; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1323 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1324 static int |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1325 list_join_inner( |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
1326 garray_T *gap, // to store the result in |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1327 list_T *l, |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1328 char_u *sep, |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1329 int echo_style, |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1330 int restore_copyID, |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1331 int copyID, |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
1332 garray_T *join_gap) // to keep each list item string |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1333 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1334 int i; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1335 join_T *p; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1336 int len; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1337 int sumlen = 0; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1338 int first = TRUE; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1339 char_u *tofree; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1340 char_u numbuf[NUMBUFLEN]; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1341 listitem_T *item; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1342 char_u *s; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1343 |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
1344 // Stringify each item in the list. |
20392
4c317d8c1051
patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents:
20158
diff
changeset
|
1345 CHECK_LIST_MATERIALIZE(l); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1346 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
|
1347 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1348 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
|
1349 echo_style, restore_copyID, !echo_style); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1350 if (s == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1351 return FAIL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1352 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1353 len = (int)STRLEN(s); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1354 sumlen += len; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1355 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1356 (void)ga_grow(join_gap, 1); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1357 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
|
1358 if (tofree != NULL || s != numbuf) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1359 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1360 p->s = s; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1361 p->tofree = tofree; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1362 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1363 else |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1364 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1365 p->s = vim_strnsave(s, len); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1366 p->tofree = p->s; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1367 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1368 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1369 line_breakcheck(); |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
1370 if (did_echo_string_emsg) // recursion error, bail out |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1371 break; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1372 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1373 |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
1374 // Allocate result buffer with its total size, avoid re-allocation and |
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
1375 // multiple copy operations. Add 2 for a tailing ']' and NUL. |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1376 if (join_gap->ga_len >= 2) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1377 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
|
1378 if (ga_grow(gap, sumlen + 2) == FAIL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1379 return FAIL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1380 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1381 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
|
1382 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1383 if (first) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1384 first = FALSE; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1385 else |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1386 ga_concat(gap, sep); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1387 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
|
1388 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1389 if (p->s != NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1390 ga_concat(gap, p->s); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1391 line_breakcheck(); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1392 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1393 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1394 return OK; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1395 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1396 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1397 /* |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1398 * 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
|
1399 * 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
|
1400 * Return FAIL or OK. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1401 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1402 int |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1403 list_join( |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1404 garray_T *gap, |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1405 list_T *l, |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1406 char_u *sep, |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1407 int echo_style, |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1408 int restore_copyID, |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1409 int copyID) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1410 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1411 garray_T join_ga; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1412 int retval; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1413 join_T *p; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1414 int i; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1415 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1416 if (l->lv_len < 1) |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
1417 return OK; // nothing to do |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
1418 ga_init2(&join_ga, sizeof(join_T), l->lv_len); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1419 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
|
1420 copyID, &join_ga); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1421 |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
1422 // Dispose each item in join_ga. |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1423 if (join_ga.ga_data != NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1424 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1425 p = (join_T *)join_ga.ga_data; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1426 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
|
1427 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1428 vim_free(p->tofree); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1429 ++p; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1430 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1431 ga_clear(&join_ga); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1432 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1433 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1434 return retval; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1435 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1436 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1437 /* |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1438 * "join()" function |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1439 */ |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1440 void |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1441 f_join(typval_T *argvars, typval_T *rettv) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1442 { |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1443 garray_T ga; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1444 char_u *sep; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1445 |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25290
diff
changeset
|
1446 if (in_vim9script() |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25290
diff
changeset
|
1447 && (check_for_list_arg(argvars, 0) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25290
diff
changeset
|
1448 || check_for_opt_string_arg(argvars, 1) == FAIL)) |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25290
diff
changeset
|
1449 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25290
diff
changeset
|
1450 |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1451 if (argvars[0].v_type != VAR_LIST) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1452 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
1453 emsg(_(e_list_required)); |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1454 return; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1455 } |
25597
0fdacd8f0cf3
patch 8.2.3335: Vim9: not enough tests run with Vim9
Bram Moolenaar <Bram@vim.org>
parents:
25591
diff
changeset
|
1456 rettv->v_type = VAR_STRING; |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1457 if (argvars[0].vval.v_list == NULL) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1458 return; |
25597
0fdacd8f0cf3
patch 8.2.3335: Vim9: not enough tests run with Vim9
Bram Moolenaar <Bram@vim.org>
parents:
25591
diff
changeset
|
1459 |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1460 if (argvars[1].v_type == VAR_UNKNOWN) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1461 sep = (char_u *)" "; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1462 else |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1463 sep = tv_get_string_chk(&argvars[1]); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1464 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1465 if (sep != NULL) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1466 { |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
1467 ga_init2(&ga, sizeof(char), 80); |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1468 list_join(&ga, argvars[0].vval.v_list, sep, TRUE, FALSE, 0); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1469 ga_append(&ga, NUL); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1470 rettv->vval.v_string = (char_u *)ga.ga_data; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1471 } |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1472 else |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1473 rettv->vval.v_string = NULL; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1474 } |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1475 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1476 /* |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1477 * Allocate a variable for a List and fill it from "*arg". |
21028
7acceb76669f
patch 8.2.1065: Vim9: no line break allowed inside a list
Bram Moolenaar <Bram@vim.org>
parents:
21000
diff
changeset
|
1478 * "*arg" points to the "[". |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1479 * Return OK or FAIL. |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1480 */ |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1481 int |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
21118
diff
changeset
|
1482 eval_list(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int do_error) |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1483 { |
21028
7acceb76669f
patch 8.2.1065: Vim9: no line break allowed inside a list
Bram Moolenaar <Bram@vim.org>
parents:
21000
diff
changeset
|
1484 int evaluate = evalarg == NULL ? FALSE |
7acceb76669f
patch 8.2.1065: Vim9: no line break allowed inside a list
Bram Moolenaar <Bram@vim.org>
parents:
21000
diff
changeset
|
1485 : evalarg->eval_flags & EVAL_EVALUATE; |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1486 list_T *l = NULL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1487 typval_T tv; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1488 listitem_T *item; |
21279
8d1d11afd8c8
patch 8.2.1190: Vim9: checking for Vim9 syntax is spread out
Bram Moolenaar <Bram@vim.org>
parents:
21148
diff
changeset
|
1489 int vim9script = in_vim9script(); |
21028
7acceb76669f
patch 8.2.1065: Vim9: no line break allowed inside a list
Bram Moolenaar <Bram@vim.org>
parents:
21000
diff
changeset
|
1490 int had_comma; |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1491 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1492 if (evaluate) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1493 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1494 l = list_alloc(); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1495 if (l == NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1496 return FAIL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1497 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1498 |
21148
667192c5938b
patch 8.2.1125: Vim9: double quote can be a string or a comment
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
1499 *arg = skipwhite_and_linebreak(*arg + 1, evalarg); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1500 while (**arg != ']' && **arg != NUL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1501 { |
21028
7acceb76669f
patch 8.2.1065: Vim9: no line break allowed inside a list
Bram Moolenaar <Bram@vim.org>
parents:
21000
diff
changeset
|
1502 if (eval1(arg, &tv, evalarg) == FAIL) // recursive! |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1503 goto failret; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1504 if (evaluate) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1505 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1506 item = listitem_alloc(); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1507 if (item != NULL) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1508 { |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1509 item->li_tv = tv; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1510 item->li_tv.v_lock = 0; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1511 list_append(l, item); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1512 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1513 else |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1514 clear_tv(&tv); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1515 } |
21556
963913d80284
patch 8.2.1328: no space allowed before comma in list
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
1516 // Legacy Vim script allowed a space before the comma. |
963913d80284
patch 8.2.1328: no space allowed before comma in list
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
1517 if (!vim9script) |
963913d80284
patch 8.2.1328: no space allowed before comma in list
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
1518 *arg = skipwhite(*arg); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1519 |
21036
f58ee30d863f
patch 8.2.1069: Vim9: fail to check for white space in list
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
1520 // the comma must come after the value |
21028
7acceb76669f
patch 8.2.1065: Vim9: no line break allowed inside a list
Bram Moolenaar <Bram@vim.org>
parents:
21000
diff
changeset
|
1521 had_comma = **arg == ','; |
7acceb76669f
patch 8.2.1065: Vim9: no line break allowed inside a list
Bram Moolenaar <Bram@vim.org>
parents:
21000
diff
changeset
|
1522 if (had_comma) |
21036
f58ee30d863f
patch 8.2.1069: Vim9: fail to check for white space in list
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
1523 { |
22866
52e64d340a98
patch 8.2.1980: Vim9: some tests are not done at the script level
Bram Moolenaar <Bram@vim.org>
parents:
22848
diff
changeset
|
1524 if (vim9script && !IS_WHITE_OR_NUL((*arg)[1]) && (*arg)[1] != ']') |
21036
f58ee30d863f
patch 8.2.1069: Vim9: fail to check for white space in list
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
1525 { |
23877
85cf06ddb2a8
patch 8.2.2480: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents:
23816
diff
changeset
|
1526 semsg(_(e_white_space_required_after_str_str), ",", *arg); |
21036
f58ee30d863f
patch 8.2.1069: Vim9: fail to check for white space in list
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
1527 goto failret; |
f58ee30d863f
patch 8.2.1069: Vim9: fail to check for white space in list
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
1528 } |
21028
7acceb76669f
patch 8.2.1065: Vim9: no line break allowed inside a list
Bram Moolenaar <Bram@vim.org>
parents:
21000
diff
changeset
|
1529 *arg = skipwhite(*arg + 1); |
21036
f58ee30d863f
patch 8.2.1069: Vim9: fail to check for white space in list
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
1530 } |
21028
7acceb76669f
patch 8.2.1065: Vim9: no line break allowed inside a list
Bram Moolenaar <Bram@vim.org>
parents:
21000
diff
changeset
|
1531 |
21118
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21064
diff
changeset
|
1532 // The "]" can be on the next line. But a double quoted string may |
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21064
diff
changeset
|
1533 // follow, not a comment. |
21148
667192c5938b
patch 8.2.1125: Vim9: double quote can be a string or a comment
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
1534 *arg = skipwhite_and_linebreak(*arg, evalarg); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1535 if (**arg == ']') |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1536 break; |
21028
7acceb76669f
patch 8.2.1065: Vim9: no line break allowed inside a list
Bram Moolenaar <Bram@vim.org>
parents:
21000
diff
changeset
|
1537 |
7acceb76669f
patch 8.2.1065: Vim9: no line break allowed inside a list
Bram Moolenaar <Bram@vim.org>
parents:
21000
diff
changeset
|
1538 if (!had_comma) |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1539 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
1540 if (do_error) |
21761
5a2373c25a86
patch 8.2.1430: Vim9: error for missing comma instead of extra white space
Bram Moolenaar <Bram@vim.org>
parents:
21556
diff
changeset
|
1541 { |
5a2373c25a86
patch 8.2.1430: Vim9: error for missing comma instead of extra white space
Bram Moolenaar <Bram@vim.org>
parents:
21556
diff
changeset
|
1542 if (**arg == ',') |
23888
d95403445b6b
patch 8.2.2486: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents:
23877
diff
changeset
|
1543 semsg(_(e_no_white_space_allowed_before_str_str), |
d95403445b6b
patch 8.2.2486: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents:
23877
diff
changeset
|
1544 ",", *arg); |
21761
5a2373c25a86
patch 8.2.1430: Vim9: error for missing comma instead of extra white space
Bram Moolenaar <Bram@vim.org>
parents:
21556
diff
changeset
|
1545 else |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26937
diff
changeset
|
1546 semsg(_(e_missing_comma_in_list_str), *arg); |
21761
5a2373c25a86
patch 8.2.1430: Vim9: error for missing comma instead of extra white space
Bram Moolenaar <Bram@vim.org>
parents:
21556
diff
changeset
|
1547 } |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1548 goto failret; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1549 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1550 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1551 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1552 if (**arg != ']') |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1553 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19123
diff
changeset
|
1554 if (do_error) |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
1555 semsg(_(e_missing_end_of_list_rsb_str), *arg); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1556 failret: |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1557 if (evaluate) |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1558 list_free(l); |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1559 return FAIL; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1560 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1561 |
21552
cbc570e66d11
patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
1562 *arg += 1; |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1563 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
|
1564 rettv_list_set(rettv, l); |
9560
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1565 |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1566 return OK; |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1567 } |
1e68dfd7931b
commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1568 |
9571
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1569 /* |
10549
055b1633aed7
patch 8.0.0164: outdated and misplaced comments
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1570 * 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
|
1571 */ |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1572 int |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1573 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
|
1574 { |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1575 listitem_T *li; |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1576 int c; |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1577 int ret = OK; |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1578 char_u *s; |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1579 |
20392
4c317d8c1051
patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents:
20158
diff
changeset
|
1580 CHECK_LIST_MATERIALIZE(list); |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
1581 FOR_ALL_LIST_ITEMS(list, li) |
9571
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1582 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15209
diff
changeset
|
1583 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
|
1584 { |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1585 if (*s == '\n') |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1586 c = putc(NUL, fd); |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1587 else |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1588 c = putc(*s, fd); |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1589 if (c == EOF) |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1590 { |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1591 ret = FAIL; |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1592 break; |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1593 } |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1594 } |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1595 if (!binary || li->li_next != NULL) |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1596 if (putc('\n', fd) == EOF) |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1597 { |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1598 ret = FAIL; |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1599 break; |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1600 } |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1601 if (ret == FAIL) |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1602 { |
26439
b18f3b0f317c
patch 8.2.3750: error messages are everywhere
Bram Moolenaar <Bram@vim.org>
parents:
25828
diff
changeset
|
1603 emsg(_(e_error_while_writing)); |
9571
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1604 break; |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1605 } |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1606 } |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1607 return ret; |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1608 } |
5eaa708ab50d
commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents:
9560
diff
changeset
|
1609 |
9626
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1610 /* |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1611 * 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
|
1612 */ |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1613 void |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1614 init_static_list(staticList10_T *sl) |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1615 { |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1616 list_T *l = &sl->sl_list; |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1617 int i; |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1618 |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1619 memset(sl, 0, sizeof(staticList10_T)); |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1620 l->lv_first = &sl->sl_items[0]; |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19203
diff
changeset
|
1621 l->lv_u.mat.lv_last = &sl->sl_items[9]; |
9626
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1622 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
|
1623 l->lv_lock = VAR_FIXED; |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1624 sl->sl_list.lv_len = 10; |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1625 |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1626 for (i = 0; i < 10; ++i) |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1627 { |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1628 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
|
1629 |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1630 if (i == 0) |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1631 li->li_prev = NULL; |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1632 else |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1633 li->li_prev = li - 1; |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1634 if (i == 9) |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1635 li->li_next = NULL; |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1636 else |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1637 li->li_next = li + 1; |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1638 } |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1639 } |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9571
diff
changeset
|
1640 |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1641 /* |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1642 * "list2str()" function |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1643 */ |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1644 void |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1645 f_list2str(typval_T *argvars, typval_T *rettv) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1646 { |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1647 list_T *l; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1648 listitem_T *li; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1649 garray_T ga; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1650 int utf8 = FALSE; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1651 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1652 rettv->v_type = VAR_STRING; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1653 rettv->vval.v_string = NULL; |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25290
diff
changeset
|
1654 |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25290
diff
changeset
|
1655 if (in_vim9script() |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25290
diff
changeset
|
1656 && (check_for_list_arg(argvars, 0) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25290
diff
changeset
|
1657 || check_for_opt_bool_arg(argvars, 1) == FAIL)) |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25290
diff
changeset
|
1658 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25290
diff
changeset
|
1659 |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1660 if (argvars[0].v_type != VAR_LIST) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1661 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26763
diff
changeset
|
1662 emsg(_(e_invalid_argument)); |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1663 return; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1664 } |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1665 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1666 l = argvars[0].vval.v_list; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1667 if (l == NULL) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1668 return; // empty list results in empty string |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1669 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1670 if (argvars[1].v_type != VAR_UNKNOWN) |
22121
b50610a6aee0
patch 8.2.1610: Vim9: cannot pass "true" to list2str() and str2list()
Bram Moolenaar <Bram@vim.org>
parents:
22043
diff
changeset
|
1671 utf8 = (int)tv_get_bool_chk(&argvars[1], NULL); |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1672 |
20392
4c317d8c1051
patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents:
20158
diff
changeset
|
1673 CHECK_LIST_MATERIALIZE(l); |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1674 ga_init2(&ga, 1, 80); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1675 if (has_mbyte || utf8) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1676 { |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1677 char_u buf[MB_MAXBYTES + 1]; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1678 int (*char2bytes)(int, char_u *); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1679 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1680 if (utf8 || enc_utf8) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1681 char2bytes = utf_char2bytes; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1682 else |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1683 char2bytes = mb_char2bytes; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1684 |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
1685 FOR_ALL_LIST_ITEMS(l, li) |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1686 { |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1687 buf[(*char2bytes)(tv_get_number(&li->li_tv), buf)] = NUL; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1688 ga_concat(&ga, buf); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1689 } |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1690 ga_append(&ga, NUL); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1691 } |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1692 else if (ga_grow(&ga, list_len(l) + 1) == OK) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1693 { |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
1694 FOR_ALL_LIST_ITEMS(l, li) |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1695 ga_append(&ga, tv_get_number(&li->li_tv)); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1696 ga_append(&ga, NUL); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1697 } |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1698 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1699 rettv->v_type = VAR_STRING; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1700 rettv->vval.v_string = ga.ga_data; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1701 } |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1702 |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1703 /* |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1704 * Remove item argvars[1] from List argvars[0]. If argvars[2] is supplied, then |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1705 * remove the range of items from argvars[1] to argvars[2] (inclusive). |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1706 */ |
19916
dcec86d796bc
patch 8.2.0514: several global functions are used in only one file
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1707 static void |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1708 list_remove(typval_T *argvars, typval_T *rettv, char_u *arg_errmsg) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1709 { |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1710 list_T *l; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1711 listitem_T *item, *item2; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1712 listitem_T *li; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1713 int error = FALSE; |
23650
83a69ada0274
patch 8.2.2367: test failures on some less often used systems
Bram Moolenaar <Bram@vim.org>
parents:
23646
diff
changeset
|
1714 long idx; |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1715 long end; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1716 int cnt = 0; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1717 list_T *rl; |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1718 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1719 if ((l = argvars[0].vval.v_list) == NULL |
22298
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22121
diff
changeset
|
1720 || value_check_lock(l->lv_lock, arg_errmsg, TRUE)) |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1721 return; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1722 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1723 idx = (long)tv_get_number_chk(&argvars[1], &error); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1724 if (error) |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1725 return; // type error: do nothing, errmsg already given |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1726 |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1727 if ((item = list_find(l, idx)) == NULL) |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1728 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
1729 semsg(_(e_list_index_out_of_range_nr), idx); |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1730 return; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1731 } |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1732 |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1733 if (argvars[2].v_type == VAR_UNKNOWN) |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1734 { |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1735 // Remove one item, return its value. |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1736 vimlist_remove(l, item, item); |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1737 *rettv = item->li_tv; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1738 list_free_item(l, item); |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1739 return; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1740 } |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1741 |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1742 // Remove range of items, return list with values. |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1743 end = (long)tv_get_number_chk(&argvars[2], &error); |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1744 if (error) |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1745 return; // type error: do nothing |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1746 |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1747 if ((item2 = list_find(l, end)) == NULL) |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1748 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
1749 semsg(_(e_list_index_out_of_range_nr), end); |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1750 return; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1751 } |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1752 |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1753 for (li = item; li != NULL; li = li->li_next) |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1754 { |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1755 ++cnt; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1756 if (li == item2) |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1757 break; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1758 } |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1759 if (li == NULL) // didn't find "item2" after "item" |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1760 { |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1761 emsg(_(e_invalid_range)); |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1762 return; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1763 } |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1764 |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1765 vimlist_remove(l, item, item2); |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1766 if (rettv_list_alloc(rettv) != OK) |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1767 return; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1768 |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1769 rl = rettv->vval.v_list; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1770 |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1771 if (l->lv_with_items > 0) |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1772 { |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1773 // need to copy the list items and move the value |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1774 while (item != NULL) |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1775 { |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1776 li = listitem_alloc(); |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1777 if (li == NULL) |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1778 return; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1779 li->li_tv = item->li_tv; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1780 init_tv(&item->li_tv); |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1781 list_append(rl, li); |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1782 if (item == item2) |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1783 break; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1784 item = item->li_next; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1785 } |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1786 } |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1787 else |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1788 { |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1789 rl->lv_first = item; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1790 rl->lv_u.mat.lv_last = item2; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1791 item->li_prev = NULL; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1792 item2->li_next = NULL; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
1793 rl->lv_len = cnt; |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1794 } |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1795 } |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1796 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1797 static int item_compare(const void *s1, const void *s2); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1798 static int item_compare2(const void *s1, const void *s2); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1799 |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
1800 // struct used in the array that's given to qsort() |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1801 typedef struct |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1802 { |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1803 listitem_T *item; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1804 int idx; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1805 } sortItem_T; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1806 |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
1807 // struct storing information about current sort |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1808 typedef struct |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1809 { |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1810 int item_compare_ic; |
22770
3e4981de5636
patch 8.2.1933: cannot sort using locale ordering
Bram Moolenaar <Bram@vim.org>
parents:
22608
diff
changeset
|
1811 int item_compare_lc; |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1812 int item_compare_numeric; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1813 int item_compare_numbers; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1814 #ifdef FEAT_FLOAT |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1815 int item_compare_float; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1816 #endif |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1817 char_u *item_compare_func; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1818 partial_T *item_compare_partial; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1819 dict_T *item_compare_selfdict; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1820 int item_compare_func_err; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1821 int item_compare_keep_zero; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1822 } sortinfo_T; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1823 static sortinfo_T *sortinfo = NULL; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1824 #define ITEM_COMPARE_FAIL 999 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1825 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1826 /* |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1827 * Compare functions for f_sort() and f_uniq() below. |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1828 */ |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1829 static int |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1830 item_compare(const void *s1, const void *s2) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1831 { |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1832 sortItem_T *si1, *si2; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1833 typval_T *tv1, *tv2; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1834 char_u *p1, *p2; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1835 char_u *tofree1 = NULL, *tofree2 = NULL; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1836 int res; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1837 char_u numbuf1[NUMBUFLEN]; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1838 char_u numbuf2[NUMBUFLEN]; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1839 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1840 si1 = (sortItem_T *)s1; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1841 si2 = (sortItem_T *)s2; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1842 tv1 = &si1->item->li_tv; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1843 tv2 = &si2->item->li_tv; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1844 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1845 if (sortinfo->item_compare_numbers) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1846 { |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1847 varnumber_T v1 = tv_get_number(tv1); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1848 varnumber_T v2 = tv_get_number(tv2); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1849 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1850 return v1 == v2 ? 0 : v1 > v2 ? 1 : -1; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1851 } |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1852 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1853 #ifdef FEAT_FLOAT |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1854 if (sortinfo->item_compare_float) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1855 { |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1856 float_T v1 = tv_get_float(tv1); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1857 float_T v2 = tv_get_float(tv2); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1858 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1859 return v1 == v2 ? 0 : v1 > v2 ? 1 : -1; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1860 } |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1861 #endif |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1862 |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
1863 // tv2string() puts quotes around a string and allocates memory. Don't do |
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
1864 // that for string variables. Use a single quote when comparing with a |
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
1865 // non-string to do what the docs promise. |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1866 if (tv1->v_type == VAR_STRING) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1867 { |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1868 if (tv2->v_type != VAR_STRING || sortinfo->item_compare_numeric) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1869 p1 = (char_u *)"'"; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1870 else |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1871 p1 = tv1->vval.v_string; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1872 } |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1873 else |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1874 p1 = tv2string(tv1, &tofree1, numbuf1, 0); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1875 if (tv2->v_type == VAR_STRING) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1876 { |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1877 if (tv1->v_type != VAR_STRING || sortinfo->item_compare_numeric) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1878 p2 = (char_u *)"'"; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1879 else |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1880 p2 = tv2->vval.v_string; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1881 } |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1882 else |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1883 p2 = tv2string(tv2, &tofree2, numbuf2, 0); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1884 if (p1 == NULL) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1885 p1 = (char_u *)""; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1886 if (p2 == NULL) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1887 p2 = (char_u *)""; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1888 if (!sortinfo->item_compare_numeric) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1889 { |
22770
3e4981de5636
patch 8.2.1933: cannot sort using locale ordering
Bram Moolenaar <Bram@vim.org>
parents:
22608
diff
changeset
|
1890 if (sortinfo->item_compare_lc) |
3e4981de5636
patch 8.2.1933: cannot sort using locale ordering
Bram Moolenaar <Bram@vim.org>
parents:
22608
diff
changeset
|
1891 res = strcoll((char *)p1, (char *)p2); |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1892 else |
22770
3e4981de5636
patch 8.2.1933: cannot sort using locale ordering
Bram Moolenaar <Bram@vim.org>
parents:
22608
diff
changeset
|
1893 res = sortinfo->item_compare_ic ? STRICMP(p1, p2): STRCMP(p1, p2); |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1894 } |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1895 else |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1896 { |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1897 double n1, n2; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1898 n1 = strtod((char *)p1, (char **)&p1); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1899 n2 = strtod((char *)p2, (char **)&p2); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1900 res = n1 == n2 ? 0 : n1 > n2 ? 1 : -1; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1901 } |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1902 |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
1903 // When the result would be zero, compare the item indexes. Makes the |
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
1904 // sort stable. |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1905 if (res == 0 && !sortinfo->item_compare_keep_zero) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1906 res = si1->idx > si2->idx ? 1 : -1; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1907 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1908 vim_free(tofree1); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1909 vim_free(tofree2); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1910 return res; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1911 } |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1912 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1913 static int |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1914 item_compare2(const void *s1, const void *s2) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1915 { |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1916 sortItem_T *si1, *si2; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1917 int res; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1918 typval_T rettv; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1919 typval_T argv[3]; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1920 char_u *func_name; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1921 partial_T *partial = sortinfo->item_compare_partial; |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17530
diff
changeset
|
1922 funcexe_T funcexe; |
26763
9cb27a68a01b
patch 8.2.3910: when compare function of sort() fails it does not abort
Bram Moolenaar <Bram@vim.org>
parents:
26737
diff
changeset
|
1923 int did_emsg_before = did_emsg; |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1924 |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
1925 // shortcut after failure in previous call; compare all items equal |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1926 if (sortinfo->item_compare_func_err) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1927 return 0; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1928 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1929 si1 = (sortItem_T *)s1; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1930 si2 = (sortItem_T *)s2; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1931 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1932 if (partial == NULL) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1933 func_name = sortinfo->item_compare_func; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1934 else |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1935 func_name = partial_name(partial); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1936 |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
1937 // Copy the values. This is needed to be able to set v_lock to VAR_FIXED |
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
1938 // in the copy without changing the original list items. |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1939 copy_tv(&si1->item->li_tv, &argv[0]); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1940 copy_tv(&si2->item->li_tv, &argv[1]); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1941 |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
1942 rettv.v_type = VAR_UNKNOWN; // clear_tv() uses this |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19966
diff
changeset
|
1943 CLEAR_FIELD(funcexe); |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26439
diff
changeset
|
1944 funcexe.fe_evaluate = TRUE; |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26439
diff
changeset
|
1945 funcexe.fe_partial = partial; |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26439
diff
changeset
|
1946 funcexe.fe_selfdict = sortinfo->item_compare_selfdict; |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17530
diff
changeset
|
1947 res = call_func(func_name, -1, &rettv, 2, argv, &funcexe); |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1948 clear_tv(&argv[0]); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1949 clear_tv(&argv[1]); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1950 |
26763
9cb27a68a01b
patch 8.2.3910: when compare function of sort() fails it does not abort
Bram Moolenaar <Bram@vim.org>
parents:
26737
diff
changeset
|
1951 if (res == FAIL || did_emsg > did_emsg_before) |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1952 res = ITEM_COMPARE_FAIL; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1953 else |
25828
14954a7e7c6d
patch 8.2.3449: sort fails if the sort compare function returns 999
Bram Moolenaar <Bram@vim.org>
parents:
25784
diff
changeset
|
1954 { |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1955 res = (int)tv_get_number_chk(&rettv, &sortinfo->item_compare_func_err); |
25828
14954a7e7c6d
patch 8.2.3449: sort fails if the sort compare function returns 999
Bram Moolenaar <Bram@vim.org>
parents:
25784
diff
changeset
|
1956 if (res > 0) |
14954a7e7c6d
patch 8.2.3449: sort fails if the sort compare function returns 999
Bram Moolenaar <Bram@vim.org>
parents:
25784
diff
changeset
|
1957 res = 1; |
14954a7e7c6d
patch 8.2.3449: sort fails if the sort compare function returns 999
Bram Moolenaar <Bram@vim.org>
parents:
25784
diff
changeset
|
1958 else if (res < 0) |
14954a7e7c6d
patch 8.2.3449: sort fails if the sort compare function returns 999
Bram Moolenaar <Bram@vim.org>
parents:
25784
diff
changeset
|
1959 res = -1; |
14954a7e7c6d
patch 8.2.3449: sort fails if the sort compare function returns 999
Bram Moolenaar <Bram@vim.org>
parents:
25784
diff
changeset
|
1960 } |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1961 if (sortinfo->item_compare_func_err) |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
1962 res = ITEM_COMPARE_FAIL; // return value has wrong type |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1963 clear_tv(&rettv); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1964 |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
1965 // When the result would be zero, compare the pointers themselves. Makes |
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
1966 // the sort stable. |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1967 if (res == 0 && !sortinfo->item_compare_keep_zero) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1968 res = si1->idx > si2->idx ? 1 : -1; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1969 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1970 return res; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1971 } |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1972 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
1973 /* |
26676
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
1974 * sort() List "l" |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
1975 */ |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
1976 static void |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
1977 do_sort(list_T *l, sortinfo_T *info) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
1978 { |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
1979 long len; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
1980 sortItem_T *ptrs; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
1981 long i = 0; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
1982 listitem_T *li; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
1983 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
1984 len = list_len(l); |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
1985 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
1986 // Make an array with each entry pointing to an item in the List. |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
1987 ptrs = ALLOC_MULT(sortItem_T, len); |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
1988 if (ptrs == NULL) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
1989 return; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
1990 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
1991 // sort(): ptrs will be the list to sort |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
1992 FOR_ALL_LIST_ITEMS(l, li) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
1993 { |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
1994 ptrs[i].item = li; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
1995 ptrs[i].idx = i; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
1996 ++i; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
1997 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
1998 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
1999 info->item_compare_func_err = FALSE; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2000 info->item_compare_keep_zero = FALSE; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2001 // test the compare function |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2002 if ((info->item_compare_func != NULL |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2003 || info->item_compare_partial != NULL) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2004 && item_compare2((void *)&ptrs[0], (void *)&ptrs[1]) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2005 == ITEM_COMPARE_FAIL) |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26937
diff
changeset
|
2006 emsg(_(e_sort_compare_function_failed)); |
26676
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2007 else |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2008 { |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2009 // Sort the array with item pointers. |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2010 qsort((void *)ptrs, (size_t)len, sizeof(sortItem_T), |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2011 info->item_compare_func == NULL |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2012 && info->item_compare_partial == NULL |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2013 ? item_compare : item_compare2); |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2014 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2015 if (!info->item_compare_func_err) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2016 { |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2017 // Clear the List and append the items in sorted order. |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2018 l->lv_first = l->lv_u.mat.lv_last |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2019 = l->lv_u.mat.lv_idx_item = NULL; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2020 l->lv_len = 0; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2021 for (i = 0; i < len; ++i) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2022 list_append(l, ptrs[i].item); |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2023 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2024 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2025 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2026 vim_free(ptrs); |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2027 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2028 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2029 /* |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2030 * uniq() List "l" |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2031 */ |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2032 static void |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2033 do_uniq(list_T *l, sortinfo_T *info) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2034 { |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2035 long len; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2036 sortItem_T *ptrs; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2037 long i = 0; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2038 listitem_T *li; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2039 int (*item_compare_func_ptr)(const void *, const void *); |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2040 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2041 len = list_len(l); |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2042 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2043 // Make an array with each entry pointing to an item in the List. |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2044 ptrs = ALLOC_MULT(sortItem_T, len); |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2045 if (ptrs == NULL) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2046 return; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2047 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2048 // f_uniq(): ptrs will be a stack of items to remove |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2049 info->item_compare_func_err = FALSE; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2050 info->item_compare_keep_zero = TRUE; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2051 item_compare_func_ptr = info->item_compare_func != NULL |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2052 || info->item_compare_partial != NULL |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2053 ? item_compare2 : item_compare; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2054 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2055 for (li = l->lv_first; li != NULL && li->li_next != NULL; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2056 li = li->li_next) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2057 { |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2058 if (item_compare_func_ptr((void *)&li, (void *)&li->li_next) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2059 == 0) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2060 ptrs[i++].item = li; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2061 if (info->item_compare_func_err) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2062 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26952
diff
changeset
|
2063 emsg(_(e_uniq_compare_function_failed)); |
26676
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2064 break; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2065 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2066 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2067 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2068 if (!info->item_compare_func_err) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2069 { |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2070 while (--i >= 0) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2071 { |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2072 li = ptrs[i].item->li_next; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2073 ptrs[i].item->li_next = li->li_next; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2074 if (li->li_next != NULL) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2075 li->li_next->li_prev = ptrs[i].item; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2076 else |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2077 l->lv_u.mat.lv_last = ptrs[i].item; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2078 list_fix_watch(l, li); |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2079 listitem_free(l, li); |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2080 l->lv_len--; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2081 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2082 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2083 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2084 vim_free(ptrs); |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2085 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2086 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2087 /* |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2088 * Parse the optional arguments supplied to the sort() or uniq() function and |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2089 * return the values in "info". |
26676
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2090 */ |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2091 static int |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2092 parse_sort_uniq_args(typval_T *argvars, sortinfo_T *info) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2093 { |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2094 info->item_compare_ic = FALSE; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2095 info->item_compare_lc = FALSE; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2096 info->item_compare_numeric = FALSE; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2097 info->item_compare_numbers = FALSE; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2098 #ifdef FEAT_FLOAT |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2099 info->item_compare_float = FALSE; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2100 #endif |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2101 info->item_compare_func = NULL; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2102 info->item_compare_partial = NULL; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2103 info->item_compare_selfdict = NULL; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2104 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2105 if (argvars[1].v_type == VAR_UNKNOWN) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2106 return OK; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2107 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2108 // optional second argument: {func} |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2109 if (argvars[1].v_type == VAR_FUNC) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2110 info->item_compare_func = argvars[1].vval.v_string; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2111 else if (argvars[1].v_type == VAR_PARTIAL) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2112 info->item_compare_partial = argvars[1].vval.v_partial; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2113 else |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2114 { |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2115 int error = FALSE; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2116 int nr = 0; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2117 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2118 if (argvars[1].v_type == VAR_NUMBER) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2119 { |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2120 nr = tv_get_number_chk(&argvars[1], &error); |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2121 if (error) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2122 return FAIL; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2123 if (nr == 1) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2124 info->item_compare_ic = TRUE; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2125 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2126 if (nr != 1) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2127 { |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2128 if (argvars[1].v_type != VAR_NUMBER) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2129 info->item_compare_func = tv_get_string(&argvars[1]); |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2130 else if (nr != 0) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2131 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26763
diff
changeset
|
2132 emsg(_(e_invalid_argument)); |
26676
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2133 return FAIL; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2134 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2135 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2136 if (info->item_compare_func != NULL) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2137 { |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2138 if (*info->item_compare_func == NUL) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2139 { |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2140 // empty string means default sort |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2141 info->item_compare_func = NULL; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2142 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2143 else if (STRCMP(info->item_compare_func, "n") == 0) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2144 { |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2145 info->item_compare_func = NULL; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2146 info->item_compare_numeric = TRUE; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2147 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2148 else if (STRCMP(info->item_compare_func, "N") == 0) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2149 { |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2150 info->item_compare_func = NULL; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2151 info->item_compare_numbers = TRUE; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2152 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2153 #ifdef FEAT_FLOAT |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2154 else if (STRCMP(info->item_compare_func, "f") == 0) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2155 { |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2156 info->item_compare_func = NULL; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2157 info->item_compare_float = TRUE; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2158 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2159 #endif |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2160 else if (STRCMP(info->item_compare_func, "i") == 0) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2161 { |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2162 info->item_compare_func = NULL; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2163 info->item_compare_ic = TRUE; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2164 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2165 else if (STRCMP(info->item_compare_func, "l") == 0) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2166 { |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2167 info->item_compare_func = NULL; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2168 info->item_compare_lc = TRUE; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2169 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2170 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2171 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2172 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2173 if (argvars[2].v_type != VAR_UNKNOWN) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2174 { |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2175 // optional third argument: {dict} |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2176 if (argvars[2].v_type != VAR_DICT) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2177 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
2178 emsg(_(e_dictionary_required)); |
26676
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2179 return FAIL; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2180 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2181 info->item_compare_selfdict = argvars[2].vval.v_dict; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2182 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2183 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2184 return OK; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2185 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2186 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2187 /* |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2188 * "sort()" or "uniq()" function |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2189 */ |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2190 static void |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2191 do_sort_uniq(typval_T *argvars, typval_T *rettv, int sort) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2192 { |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2193 list_T *l; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2194 sortinfo_T *old_sortinfo; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2195 sortinfo_T info; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2196 long len; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2197 |
25338
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2198 if (in_vim9script() |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2199 && (check_for_list_arg(argvars, 0) == FAIL |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2200 || (argvars[1].v_type != VAR_UNKNOWN |
27859
3cb1a109e987
patch 8.2.4455: accepting one and zero for second sort() argument is strange
Bram Moolenaar <Bram@vim.org>
parents:
27535
diff
changeset
|
2201 && (check_for_string_or_func_arg(argvars, 1) == FAIL |
3cb1a109e987
patch 8.2.4455: accepting one and zero for second sort() argument is strange
Bram Moolenaar <Bram@vim.org>
parents:
27535
diff
changeset
|
2202 || check_for_opt_dict_arg(argvars, 2) == FAIL)))) |
25338
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2203 return; |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2204 |
26676
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2205 if (argvars[0].v_type != VAR_LIST) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2206 { |
26887
612339679616
patch 8.2.3972: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
2207 semsg(_(e_argument_of_str_must_be_list), sort ? "sort()" : "uniq()"); |
26676
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2208 return; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2209 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2210 |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
2211 // Pointer to current info struct used in compare function. Save and |
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
2212 // restore the current one for nested calls. |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2213 old_sortinfo = sortinfo; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2214 sortinfo = &info; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2215 |
26676
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2216 l = argvars[0].vval.v_list; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2217 if (l != NULL && value_check_lock(l->lv_lock, |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2218 (char_u *)(sort ? N_("sort() argument") : N_("uniq() argument")), |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2219 TRUE)) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2220 goto theend; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2221 rettv_list_set(rettv, l); |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2222 if (l == NULL) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2223 goto theend; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2224 CHECK_LIST_MATERIALIZE(l); |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2225 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2226 len = list_len(l); |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2227 if (len <= 1) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2228 goto theend; // short list sorts pretty quickly |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2229 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2230 if (parse_sort_uniq_args(argvars, &info) == FAIL) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2231 goto theend; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2232 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2233 if (sort) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2234 do_sort(l, &info); |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2235 else |
26676
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2236 do_uniq(l, &info); |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2237 |
17530
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2238 theend: |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2239 sortinfo = old_sortinfo; |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2240 } |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2241 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2242 /* |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2243 * "sort({list})" function |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2244 */ |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2245 void |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2246 f_sort(typval_T *argvars, typval_T *rettv) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2247 { |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2248 do_sort_uniq(argvars, rettv, TRUE); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2249 } |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2250 |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2251 /* |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2252 * "uniq({list})" function |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2253 */ |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2254 void |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2255 f_uniq(typval_T *argvars, typval_T *rettv) |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2256 { |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2257 do_sort_uniq(argvars, rettv, FALSE); |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2258 } |
ef23ec1eee54
patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2259 |
17964
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2260 /* |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2261 * Handle one item for map() and filter(). |
22844
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2262 * Sets v:val to "tv". Caller must set v:key. |
17964
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2263 */ |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2264 int |
22844
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2265 filter_map_one( |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2266 typval_T *tv, // original value |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2267 typval_T *expr, // callback |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2268 filtermap_T filtermap, |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2269 typval_T *newtv, // for map() and mapnew(): new value |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2270 int *remp) // for filter(): remove flag |
17964
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2271 { |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2272 typval_T argv[3]; |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2273 int retval = FAIL; |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2274 |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2275 copy_tv(tv, get_vim_var_tv(VV_VAL)); |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2276 argv[0] = *get_vim_var_tv(VV_KEY); |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2277 argv[1] = *get_vim_var_tv(VV_VAL); |
22844
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2278 if (eval_expr_typval(expr, argv, 2, newtv) == FAIL) |
17964
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2279 goto theend; |
22844
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2280 if (filtermap == FILTERMAP_FILTER) |
17964
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2281 { |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2282 int error = FALSE; |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2283 |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2284 // filter(): when expr is zero remove the item |
21831
d8422de73113
patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21828
diff
changeset
|
2285 if (in_vim9script()) |
26737
10d3105030ab
patch 8.2.3897: Vim9: second argument of map() and filter() not checked
Bram Moolenaar <Bram@vim.org>
parents:
26684
diff
changeset
|
2286 *remp = !tv_get_bool_chk(newtv, &error); |
21831
d8422de73113
patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21828
diff
changeset
|
2287 else |
22844
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2288 *remp = (tv_get_number_chk(newtv, &error) == 0); |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2289 clear_tv(newtv); |
17964
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2290 // On type error, nothing has been removed; return FAIL to stop the |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2291 // loop. The error message was given by tv_get_number_chk(). |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2292 if (error) |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2293 goto theend; |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2294 } |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2295 retval = OK; |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2296 theend: |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2297 clear_tv(get_vim_var_tv(VV_VAL)); |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2298 return retval; |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2299 } |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2300 |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2301 /* |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2302 * Implementation of map() and filter() for a List. Apply "expr" to every item |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2303 * in List "l" and return the result in "rettv". |
26640
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2304 */ |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2305 static void |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2306 list_filter_map( |
26640
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2307 list_T *l, |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2308 filtermap_T filtermap, |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2309 type_T *argtype, |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2310 char *func_name, |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2311 char_u *arg_errmsg, |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2312 typval_T *expr, |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2313 typval_T *rettv) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2314 { |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2315 int prev_lock; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2316 list_T *l_ret = NULL; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2317 int idx = 0; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2318 int rem; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2319 listitem_T *li, *nli; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2320 |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2321 if (filtermap == FILTERMAP_MAPNEW) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2322 { |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2323 rettv->v_type = VAR_LIST; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2324 rettv->vval.v_list = NULL; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2325 } |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2326 if (l == NULL |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2327 || (filtermap == FILTERMAP_FILTER |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2328 && value_check_lock(l->lv_lock, arg_errmsg, TRUE))) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2329 return; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2330 |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2331 prev_lock = l->lv_lock; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2332 |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2333 if (filtermap == FILTERMAP_MAPNEW) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2334 { |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2335 if (rettv_list_alloc(rettv) == FAIL) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2336 return; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2337 l_ret = rettv->vval.v_list; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2338 } |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2339 // set_vim_var_nr() doesn't set the type |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2340 set_vim_var_type(VV_KEY, VAR_NUMBER); |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2341 |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2342 if (filtermap != FILTERMAP_FILTER && l->lv_lock == 0) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2343 l->lv_lock = VAR_LOCKED; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2344 |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2345 if (l->lv_first == &range_list_item) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2346 { |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2347 varnumber_T val = l->lv_u.nonmat.lv_start; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2348 int len = l->lv_len; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2349 int stride = l->lv_u.nonmat.lv_stride; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2350 |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2351 // List from range(): loop over the numbers |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2352 if (filtermap != FILTERMAP_MAPNEW) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2353 { |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2354 l->lv_first = NULL; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2355 l->lv_u.mat.lv_last = NULL; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2356 l->lv_len = 0; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2357 l->lv_u.mat.lv_idx_item = NULL; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2358 } |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2359 |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2360 for (idx = 0; idx < len; ++idx) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2361 { |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2362 typval_T tv; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2363 typval_T newtv; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2364 |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2365 tv.v_type = VAR_NUMBER; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2366 tv.v_lock = 0; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2367 tv.vval.v_number = val; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2368 set_vim_var_nr(VV_KEY, idx); |
27406
4c1bdee75bed
patch 8.2.4231: Vim9: map() gives type error when type was not declared
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2369 if (filter_map_one(&tv, expr, filtermap, &newtv, &rem) == FAIL) |
26640
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2370 break; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2371 if (did_emsg) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2372 { |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2373 clear_tv(&newtv); |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2374 break; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2375 } |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2376 if (filtermap != FILTERMAP_FILTER) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2377 { |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2378 if (filtermap == FILTERMAP_MAP && argtype != NULL |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2379 && check_typval_arg_type( |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2380 argtype->tt_member, &newtv, |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2381 func_name, 0) == FAIL) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2382 { |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2383 clear_tv(&newtv); |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2384 break; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2385 } |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2386 // map(), mapnew(): always append the new value to the |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2387 // list |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2388 if (list_append_tv_move(filtermap == FILTERMAP_MAP |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2389 ? l : l_ret, &newtv) == FAIL) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2390 break; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2391 } |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2392 else if (!rem) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2393 { |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2394 // filter(): append the list item value when not rem |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2395 if (list_append_tv_move(l, &tv) == FAIL) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2396 break; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2397 } |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2398 |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2399 val += stride; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2400 } |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2401 } |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2402 else |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2403 { |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2404 // Materialized list: loop over the items |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2405 for (li = l->lv_first; li != NULL; li = nli) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2406 { |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2407 typval_T newtv; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2408 |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2409 if (filtermap == FILTERMAP_MAP && value_check_lock( |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2410 li->li_tv.v_lock, arg_errmsg, TRUE)) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2411 break; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2412 nli = li->li_next; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2413 set_vim_var_nr(VV_KEY, idx); |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2414 if (filter_map_one(&li->li_tv, expr, filtermap, |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2415 &newtv, &rem) == FAIL) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2416 break; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2417 if (did_emsg) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2418 { |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2419 clear_tv(&newtv); |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2420 break; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2421 } |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2422 if (filtermap == FILTERMAP_MAP) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2423 { |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2424 if (argtype != NULL && check_typval_arg_type( |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2425 argtype->tt_member, &newtv, func_name, 0) == FAIL) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2426 { |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2427 clear_tv(&newtv); |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2428 break; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2429 } |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2430 // map(): replace the list item value |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2431 clear_tv(&li->li_tv); |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2432 newtv.v_lock = 0; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2433 li->li_tv = newtv; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2434 } |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2435 else if (filtermap == FILTERMAP_MAPNEW) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2436 { |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2437 // mapnew(): append the list item value |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2438 if (list_append_tv_move(l_ret, &newtv) == FAIL) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2439 break; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2440 } |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2441 else if (filtermap == FILTERMAP_FILTER && rem) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2442 listitem_remove(l, li); |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2443 ++idx; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2444 } |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2445 } |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2446 |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2447 l->lv_lock = prev_lock; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2448 } |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2449 |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2450 /* |
17964
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2451 * Implementation of map() and filter(). |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2452 */ |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2453 static void |
22844
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2454 filter_map(typval_T *argvars, typval_T *rettv, filtermap_T filtermap) |
17964
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2455 { |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2456 typval_T *expr; |
25326
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2457 char *func_name = filtermap == FILTERMAP_MAP ? "map()" |
22844
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2458 : filtermap == FILTERMAP_MAPNEW ? "mapnew()" |
25326
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2459 : "filter()"; |
22844
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2460 char_u *arg_errmsg = (char_u *)(filtermap == FILTERMAP_MAP |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2461 ? N_("map() argument") |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2462 : filtermap == FILTERMAP_MAPNEW |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2463 ? N_("mapnew() argument") |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2464 : N_("filter() argument")); |
17964
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2465 int save_did_emsg; |
23646
5d77a7587927
patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents:
23604
diff
changeset
|
2466 type_T *type = NULL; |
17964
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2467 |
22844
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2468 // map() and filter() return the first argument, also on failure. |
26585
0d2a709e2ff0
patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
26578
diff
changeset
|
2469 if (filtermap != FILTERMAP_MAPNEW && argvars[0].v_type != VAR_STRING) |
22844
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2470 copy_tv(&argvars[0], rettv); |
25338
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2471 |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2472 if (in_vim9script() |
26585
0d2a709e2ff0
patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
26578
diff
changeset
|
2473 && (check_for_list_or_dict_or_blob_or_string_arg(argvars, 0) |
0d2a709e2ff0
patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
26578
diff
changeset
|
2474 == FAIL)) |
25338
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2475 return; |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2476 |
23646
5d77a7587927
patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents:
23604
diff
changeset
|
2477 if (filtermap == FILTERMAP_MAP && in_vim9script()) |
5d77a7587927
patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents:
23604
diff
changeset
|
2478 { |
27406
4c1bdee75bed
patch 8.2.4231: Vim9: map() gives type error when type was not declared
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2479 // Check that map() does not change the declared type of the list or |
4c1bdee75bed
patch 8.2.4231: Vim9: map() gives type error when type was not declared
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2480 // dict. |
4c1bdee75bed
patch 8.2.4231: Vim9: map() gives type error when type was not declared
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2481 if (argvars[0].v_type == VAR_DICT && argvars[0].vval.v_dict != NULL) |
4c1bdee75bed
patch 8.2.4231: Vim9: map() gives type error when type was not declared
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2482 type = argvars[0].vval.v_dict->dv_type; |
4c1bdee75bed
patch 8.2.4231: Vim9: map() gives type error when type was not declared
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2483 else if (argvars[0].v_type == VAR_LIST |
4c1bdee75bed
patch 8.2.4231: Vim9: map() gives type error when type was not declared
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2484 && argvars[0].vval.v_list != NULL) |
4c1bdee75bed
patch 8.2.4231: Vim9: map() gives type error when type was not declared
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2485 type = argvars[0].vval.v_list->lv_type; |
23646
5d77a7587927
patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents:
23604
diff
changeset
|
2486 } |
22608
f140b9036aa5
patch 8.2.1852: map() returing zero for NULL list is unexpected
Bram Moolenaar <Bram@vim.org>
parents:
22545
diff
changeset
|
2487 |
26640
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2488 if (argvars[0].v_type != VAR_BLOB |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2489 && argvars[0].v_type != VAR_LIST |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2490 && argvars[0].v_type != VAR_DICT |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2491 && argvars[0].v_type != VAR_STRING) |
17964
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2492 { |
26578
06693d1afc48
patch 8.2.3818: cannot filter or map characters in a string
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
2493 semsg(_(e_argument_of_str_must_be_list_string_dictionary_or_blob), |
06693d1afc48
patch 8.2.3818: cannot filter or map characters in a string
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
2494 func_name); |
27408
ec54436eda32
patch 8.2.4232: some compilers don't like a goto label without statement
Bram Moolenaar <Bram@vim.org>
parents:
27406
diff
changeset
|
2495 return; |
17964
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2496 } |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2497 |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2498 // On type errors, the preceding call has already displayed an error |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2499 // message. Avoid a misleading error message for an empty string that |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2500 // was not passed as argument. |
27406
4c1bdee75bed
patch 8.2.4231: Vim9: map() gives type error when type was not declared
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2501 expr = &argvars[1]; |
17964
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2502 if (expr->v_type != VAR_UNKNOWN) |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2503 { |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2504 typval_T save_val; |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2505 typval_T save_key; |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2506 |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2507 prepare_vimvar(VV_VAL, &save_val); |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2508 prepare_vimvar(VV_KEY, &save_key); |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2509 |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2510 // We reset "did_emsg" to be able to detect whether an error |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2511 // occurred during evaluation of the expression. |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2512 save_did_emsg = did_emsg; |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2513 did_emsg = FALSE; |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2514 |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2515 if (argvars[0].v_type == VAR_DICT) |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2516 dict_filter_map(argvars[0].vval.v_dict, filtermap, type, func_name, |
26640
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2517 arg_errmsg, expr, rettv); |
17964
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2518 else if (argvars[0].v_type == VAR_BLOB) |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2519 blob_filter_map(argvars[0].vval.v_blob, filtermap, expr, rettv); |
26578
06693d1afc48
patch 8.2.3818: cannot filter or map characters in a string
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
2520 else if (argvars[0].v_type == VAR_STRING) |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2521 string_filter_map(tv_get_string(&argvars[0]), filtermap, expr, |
26640
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2522 rettv); |
17964
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2523 else // argvars[0].v_type == VAR_LIST |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2524 list_filter_map(argvars[0].vval.v_list, filtermap, type, func_name, |
26640
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2525 arg_errmsg, expr, rettv); |
17964
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2526 |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2527 restore_vimvar(VV_KEY, &save_key); |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2528 restore_vimvar(VV_VAL, &save_val); |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2529 |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2530 did_emsg |= save_did_emsg; |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2531 } |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2532 } |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2533 |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2534 /* |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2535 * "filter()" function |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2536 */ |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2537 void |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2538 f_filter(typval_T *argvars, typval_T *rettv) |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2539 { |
22844
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2540 filter_map(argvars, rettv, FILTERMAP_FILTER); |
17964
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2541 } |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2542 |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2543 /* |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2544 * "map()" function |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2545 */ |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2546 void |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2547 f_map(typval_T *argvars, typval_T *rettv) |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2548 { |
22844
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2549 filter_map(argvars, rettv, FILTERMAP_MAP); |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2550 } |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2551 |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2552 /* |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2553 * "mapnew()" function |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2554 */ |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2555 void |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2556 f_mapnew(typval_T *argvars, typval_T *rettv) |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2557 { |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
2558 filter_map(argvars, rettv, FILTERMAP_MAPNEW); |
17964
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2559 } |
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2560 |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2561 /* |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2562 * "add(list, item)" function |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2563 */ |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2564 static void |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2565 list_add(typval_T *argvars, typval_T *rettv) |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2566 { |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2567 list_T *l = argvars[0].vval.v_list; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2568 |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2569 if (l == NULL) |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2570 { |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2571 if (in_vim9script()) |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2572 emsg(_(e_cannot_add_to_null_list)); |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2573 } |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2574 else if (!value_check_lock(l->lv_lock, |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2575 (char_u *)N_("add() argument"), TRUE) |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2576 && list_append_tv(l, &argvars[1]) == OK) |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2577 { |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2578 copy_tv(&argvars[0], rettv); |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2579 } |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2580 } |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2581 |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2582 /* |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2583 * "add(object, item)" function |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2584 */ |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2585 void |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2586 f_add(typval_T *argvars, typval_T *rettv) |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2587 { |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17970
diff
changeset
|
2588 rettv->vval.v_number = 1; // Default: Failed |
25338
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2589 |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2590 if (in_vim9script() |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2591 && (check_for_list_or_blob_arg(argvars, 0) == FAIL |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2592 || (argvars[0].v_type == VAR_BLOB |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2593 && check_for_number_arg(argvars, 1) == FAIL))) |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2594 return; |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2595 |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2596 if (argvars[0].v_type == VAR_LIST) |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2597 list_add(argvars, rettv); |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2598 else if (argvars[0].v_type == VAR_BLOB) |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2599 blob_add(argvars, rettv); |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2600 else |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
2601 emsg(_(e_list_or_blob_required)); |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2602 } |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2603 |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2604 /* |
26676
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2605 * Count the number of times item "needle" occurs in List "l" starting at index |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2606 * "idx". Case is ignored if "ic" is TRUE. |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2607 */ |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2608 static long |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2609 list_count(list_T *l, typval_T *needle, long idx, int ic) |
26676
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2610 { |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2611 long n = 0; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2612 listitem_T *li; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2613 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2614 if (l == NULL) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2615 return 0; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2616 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2617 CHECK_LIST_MATERIALIZE(l); |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2618 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2619 if (list_len(l) == 0) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2620 return 0; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2621 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2622 li = list_find(l, idx); |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2623 if (li == NULL) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2624 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
2625 semsg(_(e_list_index_out_of_range_nr), idx); |
26676
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2626 return 0; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2627 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2628 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2629 for ( ; li != NULL; li = li->li_next) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2630 if (tv_equal(&li->li_tv, needle, ic, FALSE)) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2631 ++n; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2632 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2633 return n; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2634 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2635 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2636 /* |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2637 * "count()" function |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2638 */ |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2639 void |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2640 f_count(typval_T *argvars, typval_T *rettv) |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2641 { |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2642 long n = 0; |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2643 int ic = FALSE; |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2644 int error = FALSE; |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2645 |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25290
diff
changeset
|
2646 if (in_vim9script() |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
2647 && (check_for_string_or_list_or_dict_arg(argvars, 0) == FAIL |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25290
diff
changeset
|
2648 || check_for_opt_bool_arg(argvars, 2) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25290
diff
changeset
|
2649 || (argvars[2].v_type != VAR_UNKNOWN |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25290
diff
changeset
|
2650 && check_for_opt_number_arg(argvars, 3) == FAIL))) |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25290
diff
changeset
|
2651 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25290
diff
changeset
|
2652 |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2653 if (argvars[2].v_type != VAR_UNKNOWN) |
22043
4bc644f4dd2d
patch 8.2.1571: Vim9: count() third argument cannot be "true"
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
2654 ic = (int)tv_get_bool_chk(&argvars[2], &error); |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2655 |
26676
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2656 if (!error && argvars[0].v_type == VAR_STRING) |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2657 n = string_count(argvars[0].vval.v_string, |
26676
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2658 tv_get_string_chk(&argvars[1]), ic); |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2659 else if (!error && argvars[0].v_type == VAR_LIST) |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2660 { |
26676
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2661 long idx = 0; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2662 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2663 if (argvars[2].v_type != VAR_UNKNOWN |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2664 && argvars[3].v_type != VAR_UNKNOWN) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2665 idx = (long)tv_get_number_chk(&argvars[3], &error); |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2666 if (!error) |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2667 n = list_count(argvars[0].vval.v_list, &argvars[1], idx, ic); |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2668 } |
26676
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2669 else if (!error && argvars[0].v_type == VAR_DICT) |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2670 { |
26676
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2671 if (argvars[2].v_type != VAR_UNKNOWN |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2672 && argvars[3].v_type != VAR_UNKNOWN) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26763
diff
changeset
|
2673 emsg(_(e_invalid_argument)); |
26676
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2674 else |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2675 n = dict_count(argvars[0].vval.v_dict, &argvars[1], ic); |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2676 } |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2677 else |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
2678 semsg(_(e_argument_of_str_must_be_list_or_dictionary), "count()"); |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2679 rettv->vval.v_number = n; |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2680 } |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2681 |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2682 /* |
26676
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2683 * extend() a List. Append List argvars[1] to List argvars[0] before index |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2684 * argvars[3] and return the resulting list in "rettv". "is_new" is TRUE for |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2685 * extendnew(). |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2686 */ |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2687 static void |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2688 list_extend_func( |
26676
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2689 typval_T *argvars, |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2690 type_T *type, |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2691 char *func_name, |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2692 char_u *arg_errmsg, |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2693 int is_new, |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2694 typval_T *rettv) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2695 { |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2696 list_T *l1, *l2; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2697 listitem_T *item; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2698 long before; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2699 int error = FALSE; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2700 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2701 l1 = argvars[0].vval.v_list; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2702 if (l1 == NULL) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2703 { |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2704 emsg(_(e_cannot_extend_null_list)); |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2705 return; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2706 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2707 l2 = argvars[1].vval.v_list; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2708 if ((is_new || !value_check_lock(l1->lv_lock, arg_errmsg, TRUE)) |
27517
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27453
diff
changeset
|
2709 && l2 != NULL) |
26676
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2710 { |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2711 if (is_new) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2712 { |
27517
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27453
diff
changeset
|
2713 l1 = list_copy(l1, FALSE, TRUE, get_copyID()); |
26676
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2714 if (l1 == NULL) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2715 return; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2716 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2717 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2718 if (argvars[2].v_type != VAR_UNKNOWN) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2719 { |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2720 before = (long)tv_get_number_chk(&argvars[2], &error); |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2721 if (error) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2722 return; // type error; errmsg already given |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2723 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2724 if (before == l1->lv_len) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2725 item = NULL; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2726 else |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2727 { |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2728 item = list_find(l1, before); |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2729 if (item == NULL) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2730 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
2731 semsg(_(e_list_index_out_of_range_nr), before); |
26676
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2732 return; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2733 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2734 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2735 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2736 else |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2737 item = NULL; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2738 if (type != NULL && check_typval_arg_type( |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2739 type, &argvars[1], func_name, 2) == FAIL) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2740 return; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2741 list_extend(l1, l2, item); |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2742 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2743 if (is_new) |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2744 { |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2745 rettv->v_type = VAR_LIST; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2746 rettv->vval.v_list = l1; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2747 rettv->v_lock = FALSE; |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2748 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2749 else |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2750 copy_tv(&argvars[0], rettv); |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2751 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2752 } |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2753 |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2754 /* |
23588
510088f8c66f
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents:
23565
diff
changeset
|
2755 * "extend()" or "extendnew()" function. "is_new" is TRUE for extendnew(). |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2756 */ |
23588
510088f8c66f
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents:
23565
diff
changeset
|
2757 static void |
510088f8c66f
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents:
23565
diff
changeset
|
2758 extend(typval_T *argvars, typval_T *rettv, char_u *arg_errmsg, int is_new) |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2759 { |
23800
57f0e3fd7c05
patch 8.2.2441: Vim9: extend() does not give an error for a type mismatch
Bram Moolenaar <Bram@vim.org>
parents:
23650
diff
changeset
|
2760 type_T *type = NULL; |
25326
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2761 char *func_name = is_new ? "extendnew()" : "extend()"; |
23800
57f0e3fd7c05
patch 8.2.2441: Vim9: extend() does not give an error for a type mismatch
Bram Moolenaar <Bram@vim.org>
parents:
23650
diff
changeset
|
2762 |
26931
6cdf92e77a91
patch 8.2.3994: Vim9: extend() complains about type when it was not declared
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
2763 if (argvars[0].v_type == VAR_LIST && argvars[1].v_type == VAR_LIST) |
23800
57f0e3fd7c05
patch 8.2.2441: Vim9: extend() does not give an error for a type mismatch
Bram Moolenaar <Bram@vim.org>
parents:
23650
diff
changeset
|
2764 { |
26931
6cdf92e77a91
patch 8.2.3994: Vim9: extend() complains about type when it was not declared
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
2765 // Check that extend() does not change the type of the list if it was |
6cdf92e77a91
patch 8.2.3994: Vim9: extend() complains about type when it was not declared
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
2766 // declared. |
6cdf92e77a91
patch 8.2.3994: Vim9: extend() complains about type when it was not declared
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
2767 if (!is_new && in_vim9script() && argvars[0].vval.v_list != NULL) |
6cdf92e77a91
patch 8.2.3994: Vim9: extend() complains about type when it was not declared
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
2768 type = argvars[0].vval.v_list->lv_type; |
6cdf92e77a91
patch 8.2.3994: Vim9: extend() complains about type when it was not declared
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
2769 list_extend_func(argvars, type, func_name, arg_errmsg, is_new, rettv); |
23800
57f0e3fd7c05
patch 8.2.2441: Vim9: extend() does not give an error for a type mismatch
Bram Moolenaar <Bram@vim.org>
parents:
23650
diff
changeset
|
2770 } |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2771 else if (argvars[0].v_type == VAR_DICT && argvars[1].v_type == VAR_DICT) |
26931
6cdf92e77a91
patch 8.2.3994: Vim9: extend() complains about type when it was not declared
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
2772 { |
6cdf92e77a91
patch 8.2.3994: Vim9: extend() complains about type when it was not declared
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
2773 // Check that extend() does not change the type of the list if it was |
6cdf92e77a91
patch 8.2.3994: Vim9: extend() complains about type when it was not declared
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
2774 // declared. |
6cdf92e77a91
patch 8.2.3994: Vim9: extend() complains about type when it was not declared
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
2775 if (!is_new && in_vim9script() && argvars[0].vval.v_dict != NULL) |
6cdf92e77a91
patch 8.2.3994: Vim9: extend() complains about type when it was not declared
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
2776 type = argvars[0].vval.v_dict->dv_type; |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2777 dict_extend_func(argvars, type, func_name, arg_errmsg, is_new, rettv); |
26931
6cdf92e77a91
patch 8.2.3994: Vim9: extend() complains about type when it was not declared
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
2778 } |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2779 else |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
2780 semsg(_(e_argument_of_str_must_be_list_or_dictionary), func_name); |
23588
510088f8c66f
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents:
23565
diff
changeset
|
2781 } |
510088f8c66f
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents:
23565
diff
changeset
|
2782 |
510088f8c66f
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents:
23565
diff
changeset
|
2783 /* |
510088f8c66f
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents:
23565
diff
changeset
|
2784 * "extend(list, list [, idx])" function |
510088f8c66f
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents:
23565
diff
changeset
|
2785 * "extend(dict, dict [, action])" function |
510088f8c66f
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents:
23565
diff
changeset
|
2786 */ |
510088f8c66f
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents:
23565
diff
changeset
|
2787 void |
510088f8c66f
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents:
23565
diff
changeset
|
2788 f_extend(typval_T *argvars, typval_T *rettv) |
510088f8c66f
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents:
23565
diff
changeset
|
2789 { |
510088f8c66f
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents:
23565
diff
changeset
|
2790 char_u *errmsg = (char_u *)N_("extend() argument"); |
510088f8c66f
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents:
23565
diff
changeset
|
2791 |
510088f8c66f
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents:
23565
diff
changeset
|
2792 extend(argvars, rettv, errmsg, FALSE); |
510088f8c66f
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents:
23565
diff
changeset
|
2793 } |
510088f8c66f
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents:
23565
diff
changeset
|
2794 |
510088f8c66f
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents:
23565
diff
changeset
|
2795 /* |
510088f8c66f
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents:
23565
diff
changeset
|
2796 * "extendnew(list, list [, idx])" function |
510088f8c66f
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents:
23565
diff
changeset
|
2797 * "extendnew(dict, dict [, action])" function |
510088f8c66f
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents:
23565
diff
changeset
|
2798 */ |
510088f8c66f
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents:
23565
diff
changeset
|
2799 void |
510088f8c66f
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents:
23565
diff
changeset
|
2800 f_extendnew(typval_T *argvars, typval_T *rettv) |
510088f8c66f
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents:
23565
diff
changeset
|
2801 { |
510088f8c66f
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents:
23565
diff
changeset
|
2802 char_u *errmsg = (char_u *)N_("extendnew() argument"); |
510088f8c66f
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents:
23565
diff
changeset
|
2803 |
510088f8c66f
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents:
23565
diff
changeset
|
2804 extend(argvars, rettv, errmsg, TRUE); |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2805 } |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2806 |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2807 static void |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2808 list_insert_func(typval_T *argvars, typval_T *rettv) |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2809 { |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2810 list_T *l = argvars[0].vval.v_list; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2811 long before = 0; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2812 listitem_T *item; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2813 int error = FALSE; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2814 |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2815 if (l == NULL) |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2816 { |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2817 if (in_vim9script()) |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2818 emsg(_(e_cannot_add_to_null_list)); |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2819 return; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2820 } |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2821 |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2822 if (value_check_lock(l->lv_lock, (char_u *)N_("insert() argument"), TRUE)) |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2823 return; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2824 |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2825 if (argvars[2].v_type != VAR_UNKNOWN) |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2826 before = (long)tv_get_number_chk(&argvars[2], &error); |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2827 if (error) |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2828 return; // type error; errmsg already given |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2829 |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2830 if (before == l->lv_len) |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2831 item = NULL; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2832 else |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2833 { |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2834 item = list_find(l, before); |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2835 if (item == NULL) |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2836 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
2837 semsg(_(e_list_index_out_of_range_nr), before); |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2838 l = NULL; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2839 } |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2840 } |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2841 if (l != NULL) |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2842 { |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2843 (void)list_insert_tv(l, &argvars[1], item); |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2844 copy_tv(&argvars[0], rettv); |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2845 } |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2846 } |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2847 |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2848 /* |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2849 * "insert()" function |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2850 */ |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2851 void |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2852 f_insert(typval_T *argvars, typval_T *rettv) |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2853 { |
25338
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2854 if (in_vim9script() |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2855 && (check_for_list_or_blob_arg(argvars, 0) == FAIL |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2856 || (argvars[0].v_type == VAR_BLOB |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2857 && check_for_number_arg(argvars, 1) == FAIL) |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2858 || check_for_opt_number_arg(argvars, 2) == FAIL)) |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2859 return; |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2860 |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2861 if (argvars[0].v_type == VAR_BLOB) |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2862 blob_insert_func(argvars, rettv); |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2863 else if (argvars[0].v_type != VAR_LIST) |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26952
diff
changeset
|
2864 semsg(_(e_argument_of_str_must_be_list_or_blob), "insert()"); |
24484
bc1a533148d7
patch 8.2.2782: Vim9: blob operations not fully tested
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
2865 else |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2866 list_insert_func(argvars, rettv); |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2867 } |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2868 |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2869 /* |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2870 * "remove()" function |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2871 */ |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2872 void |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2873 f_remove(typval_T *argvars, typval_T *rettv) |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2874 { |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2875 char_u *arg_errmsg = (char_u *)N_("remove() argument"); |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2876 |
25338
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2877 if (in_vim9script() |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2878 && (check_for_list_or_dict_or_blob_arg(argvars, 0) == FAIL |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2879 || ((argvars[0].v_type == VAR_LIST |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2880 || argvars[0].v_type == VAR_BLOB) |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2881 && (check_for_number_arg(argvars, 1) == FAIL |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2882 || check_for_opt_number_arg(argvars, 2) == FAIL)) |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2883 || (argvars[0].v_type == VAR_DICT |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2884 && check_for_string_or_number_arg(argvars, 1) == FAIL))) |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2885 return; |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2886 |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2887 if (argvars[0].v_type == VAR_DICT) |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2888 dict_remove(argvars, rettv, arg_errmsg); |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2889 else if (argvars[0].v_type == VAR_BLOB) |
25495
7144d2ffc86b
patch 8.2.3284: no error for insert() or remove() changing a locked blob
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
2890 blob_remove(argvars, rettv, arg_errmsg); |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2891 else if (argvars[0].v_type == VAR_LIST) |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2892 list_remove(argvars, rettv, arg_errmsg); |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2893 else |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
2894 semsg(_(e_argument_of_str_must_be_list_dictionary_or_blob), "remove()"); |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2895 } |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2896 |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2897 static void |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2898 list_reverse(list_T *l, typval_T *rettv) |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2899 { |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2900 listitem_T *li, *ni; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2901 |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2902 rettv_list_set(rettv, l); |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2903 if (l != NULL |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2904 && !value_check_lock(l->lv_lock, |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2905 (char_u *)N_("reverse() argument"), TRUE)) |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2906 { |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2907 if (l->lv_first == &range_list_item) |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2908 { |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2909 varnumber_T new_start = l->lv_u.nonmat.lv_start |
27453
c7f614c9ceb3
patch 8.2.4255: theoretical computation overflow
Bram Moolenaar <Bram@vim.org>
parents:
27408
diff
changeset
|
2910 + ((varnumber_T)l->lv_len - 1) * l->lv_u.nonmat.lv_stride; |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2911 l->lv_u.nonmat.lv_end = new_start |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2912 - (l->lv_u.nonmat.lv_end - l->lv_u.nonmat.lv_start); |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2913 l->lv_u.nonmat.lv_start = new_start; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2914 l->lv_u.nonmat.lv_stride = -l->lv_u.nonmat.lv_stride; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2915 return; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2916 } |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2917 li = l->lv_u.mat.lv_last; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2918 l->lv_first = l->lv_u.mat.lv_last = NULL; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2919 l->lv_len = 0; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2920 while (li != NULL) |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2921 { |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2922 ni = li->li_prev; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2923 list_append(l, li); |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2924 li = ni; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2925 } |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2926 l->lv_u.mat.lv_idx = l->lv_len - l->lv_u.mat.lv_idx - 1; |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2927 } |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2928 } |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2929 |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2930 /* |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2931 * "reverse({list})" function |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2932 */ |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2933 void |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2934 f_reverse(typval_T *argvars, typval_T *rettv) |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2935 { |
25338
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2936 if (in_vim9script() && check_for_list_or_blob_arg(argvars, 0) == FAIL) |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2937 return; |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
2938 |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2939 if (argvars[0].v_type == VAR_BLOB) |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2940 blob_reverse(argvars[0].vval.v_blob, rettv); |
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2941 else if (argvars[0].v_type != VAR_LIST) |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26952
diff
changeset
|
2942 semsg(_(e_argument_of_str_must_be_list_or_blob), "reverse()"); |
25597
0fdacd8f0cf3
patch 8.2.3335: Vim9: not enough tests run with Vim9
Bram Moolenaar <Bram@vim.org>
parents:
25591
diff
changeset
|
2943 else |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2944 list_reverse(argvars[0].vval.v_list, rettv); |
17970
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2945 } |
684a15da9929
patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17964
diff
changeset
|
2946 |
20649
1fa0ace0ba65
patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents:
20550
diff
changeset
|
2947 /* |
26676
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2948 * reduce() List argvars[0] using the function 'funcname' with arguments in |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2949 * 'funcexe' starting with the initial value argvars[2] and return the result |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
2950 * in 'rettv'. |
26640
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2951 */ |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2952 static void |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
2953 list_reduce( |
26640
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2954 typval_T *argvars, |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2955 char_u *func_name, |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2956 funcexe_T *funcexe, |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2957 typval_T *rettv) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2958 { |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2959 list_T *l = argvars[0].vval.v_list; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2960 listitem_T *li = NULL; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2961 typval_T initial; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2962 typval_T argv[3]; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2963 int r; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2964 int called_emsg_start = called_emsg; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2965 int prev_locked; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2966 |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2967 if (l != NULL) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2968 CHECK_LIST_MATERIALIZE(l); |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2969 if (argvars[2].v_type == VAR_UNKNOWN) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2970 { |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2971 if (l == NULL || l->lv_first == NULL) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2972 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
2973 semsg(_(e_reduce_of_an_empty_str_with_no_initial_value), "List"); |
26640
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2974 return; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2975 } |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2976 initial = l->lv_first->li_tv; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2977 li = l->lv_first->li_next; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2978 } |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2979 else |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2980 { |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2981 initial = argvars[2]; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2982 if (l != NULL) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2983 li = l->lv_first; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2984 } |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2985 copy_tv(&initial, rettv); |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2986 |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2987 if (l == NULL) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2988 return; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2989 |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2990 prev_locked = l->lv_lock; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2991 |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2992 l->lv_lock = VAR_FIXED; // disallow the list changing here |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2993 for ( ; li != NULL; li = li->li_next) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2994 { |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2995 argv[0] = *rettv; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2996 argv[1] = li->li_tv; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2997 rettv->v_type = VAR_UNKNOWN; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2998 r = call_func(func_name, -1, rettv, 2, argv, funcexe); |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
2999 clear_tv(&argv[0]); |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
3000 if (r == FAIL || called_emsg != called_emsg_start) |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
3001 break; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
3002 } |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
3003 l->lv_lock = prev_locked; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
3004 } |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
3005 |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
3006 /* |
23229
b545334ae654
patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents:
23058
diff
changeset
|
3007 * "reduce(list, { accumulator, element -> value } [, initial])" function |
26676
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
3008 * "reduce(blob, { accumulator, element -> value } [, initial])" |
b856b797c5d1
patch 8.2.3867: implementation of some list functions too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26640
diff
changeset
|
3009 * "reduce(string, { accumulator, element -> value } [, initial])" |
20649
1fa0ace0ba65
patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents:
20550
diff
changeset
|
3010 */ |
1fa0ace0ba65
patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents:
20550
diff
changeset
|
3011 void |
1fa0ace0ba65
patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents:
20550
diff
changeset
|
3012 f_reduce(typval_T *argvars, typval_T *rettv) |
1fa0ace0ba65
patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents:
20550
diff
changeset
|
3013 { |
1fa0ace0ba65
patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents:
20550
diff
changeset
|
3014 char_u *func_name; |
1fa0ace0ba65
patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents:
20550
diff
changeset
|
3015 partial_T *partial = NULL; |
1fa0ace0ba65
patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents:
20550
diff
changeset
|
3016 funcexe_T funcexe; |
26638
6fd15d82e898
patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents:
26585
diff
changeset
|
3017 |
6fd15d82e898
patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents:
26585
diff
changeset
|
3018 if (in_vim9script() |
6fd15d82e898
patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents:
26585
diff
changeset
|
3019 && check_for_string_or_list_or_blob_arg(argvars, 0) == FAIL) |
20649
1fa0ace0ba65
patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents:
20550
diff
changeset
|
3020 return; |
26638
6fd15d82e898
patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents:
26585
diff
changeset
|
3021 |
6fd15d82e898
patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents:
26585
diff
changeset
|
3022 if (argvars[0].v_type != VAR_STRING |
6fd15d82e898
patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents:
26585
diff
changeset
|
3023 && argvars[0].v_type != VAR_LIST |
6fd15d82e898
patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents:
26585
diff
changeset
|
3024 && argvars[0].v_type != VAR_BLOB) |
26640
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
3025 { |
26638
6fd15d82e898
patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents:
26585
diff
changeset
|
3026 semsg(_(e_string_list_or_blob_required), "reduce()"); |
26640
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
3027 return; |
7c055fdd6200
patch 8.2.3849: functions implementing reduce and map are too long
Bram Moolenaar <Bram@vim.org>
parents:
26638
diff
changeset
|
3028 } |
20649
1fa0ace0ba65
patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents:
20550
diff
changeset
|
3029 |
1fa0ace0ba65
patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents:
20550
diff
changeset
|
3030 if (argvars[1].v_type == VAR_FUNC) |
1fa0ace0ba65
patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents:
20550
diff
changeset
|
3031 func_name = argvars[1].vval.v_string; |
1fa0ace0ba65
patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents:
20550
diff
changeset
|
3032 else if (argvars[1].v_type == VAR_PARTIAL) |
1fa0ace0ba65
patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents:
20550
diff
changeset
|
3033 { |
1fa0ace0ba65
patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents:
20550
diff
changeset
|
3034 partial = argvars[1].vval.v_partial; |
1fa0ace0ba65
patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents:
20550
diff
changeset
|
3035 func_name = partial_name(partial); |
1fa0ace0ba65
patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents:
20550
diff
changeset
|
3036 } |
1fa0ace0ba65
patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents:
20550
diff
changeset
|
3037 else |
1fa0ace0ba65
patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents:
20550
diff
changeset
|
3038 func_name = tv_get_string(&argvars[1]); |
22794
42bb78d46354
patch 8.2.1945: crash when passing NULL function to reduce()
Bram Moolenaar <Bram@vim.org>
parents:
22770
diff
changeset
|
3039 if (func_name == NULL || *func_name == NUL) |
42bb78d46354
patch 8.2.1945: crash when passing NULL function to reduce()
Bram Moolenaar <Bram@vim.org>
parents:
22770
diff
changeset
|
3040 { |
42bb78d46354
patch 8.2.1945: crash when passing NULL function to reduce()
Bram Moolenaar <Bram@vim.org>
parents:
22770
diff
changeset
|
3041 emsg(_(e_missing_function_argument)); |
42bb78d46354
patch 8.2.1945: crash when passing NULL function to reduce()
Bram Moolenaar <Bram@vim.org>
parents:
22770
diff
changeset
|
3042 return; |
42bb78d46354
patch 8.2.1945: crash when passing NULL function to reduce()
Bram Moolenaar <Bram@vim.org>
parents:
22770
diff
changeset
|
3043 } |
20649
1fa0ace0ba65
patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents:
20550
diff
changeset
|
3044 |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26439
diff
changeset
|
3045 CLEAR_FIELD(funcexe); |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26439
diff
changeset
|
3046 funcexe.fe_evaluate = TRUE; |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26439
diff
changeset
|
3047 funcexe.fe_partial = partial; |
20649
1fa0ace0ba65
patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents:
20550
diff
changeset
|
3048 |
1fa0ace0ba65
patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents:
20550
diff
changeset
|
3049 if (argvars[0].v_type == VAR_LIST) |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
3050 list_reduce(argvars, func_name, &funcexe, rettv); |
26638
6fd15d82e898
patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents:
26585
diff
changeset
|
3051 else if (argvars[0].v_type == VAR_STRING) |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
3052 string_reduce(argvars, func_name, &funcexe, rettv); |
20649
1fa0ace0ba65
patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents:
20550
diff
changeset
|
3053 else |
26684
2126feddeda6
patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents:
26676
diff
changeset
|
3054 blob_reduce(argvars, func_name, &funcexe, rettv); |
20649
1fa0ace0ba65
patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents:
20550
diff
changeset
|
3055 } |
1fa0ace0ba65
patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents:
20550
diff
changeset
|
3056 |
17964
6d4d3bce365d
patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
3057 #endif // defined(FEAT_EVAL) |