annotate src/list.c @ 19627:6b1564fcab92 v8.2.0370

patch 8.2.0370: the typebuf_was_filled flag is sometimes not reset Commit: https://github.com/vim/vim/commit/e49b4bb89505fad28cf89f0891aef3e2d397919e Author: Bram Moolenaar <Bram@vim.org> Date: Wed Mar 11 13:01:40 2020 +0100 patch 8.2.0370: the typebuf_was_filled flag is sometimes not reset Problem: The typebuf_was_filled flag is sometimes not reset, which may cause a hang. Solution: Make sure typebuf_was_filled is reset when the typeahead buffer is empty.
author Bram Moolenaar <Bram@vim.org>
date Wed, 11 Mar 2020 13:15:04 +0100
parents 04c164c971a3
children 293a22b677a8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10042
4aead6a9b7a9 commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents: 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
17970
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
18 static char *e_listblobarg = N_("E899: Argument of %s must be a List or Blob");
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
19
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
20 // List heads for garbage collection.
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
21 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
22
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 /*
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 * Add a watcher to a list.
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 */
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 void
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 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
28 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 lw->lw_next = l->lv_watch;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 l->lv_watch = 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
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 /*
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 * Remove a watcher from a list.
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 * No warning when it isn't found...
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 void
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 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
39 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 listwatch_T *lw, **lwp;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 lwp = &l->lv_watch;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 for (lw = l->lv_watch; lw != NULL; lw = lw->lw_next)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 if (lw == lwrem)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 *lwp = lw->lw_next;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 break;
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 }
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
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 * 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
56 * item.
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 */
17789
0f7ae8010787 patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
58 static void
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59 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
60 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61 listwatch_T *lw;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 for (lw = l->lv_watch; lw != NULL; lw = lw->lw_next)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 if (lw->lw_item == item)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65 lw->lw_item = item->li_next;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
68 static void
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
69 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
70 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
71 // 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
72 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
73 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
74 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
75 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
76 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
77 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
78
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79 /*
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80 * Allocate an empty header for a list.
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81 * 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
82 */
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
83 list_T *
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84 list_alloc(void)
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 *l;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87
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
88 l = ALLOC_CLEAR_ONE(list_T);
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
89 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
90 list_init(l);
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 return l;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
94 /*
15016
c338c91086b9 patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents: 14391
diff changeset
95 * 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
96 */
c338c91086b9 patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents: 14391
diff changeset
97 list_T *
c338c91086b9 patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents: 14391
diff changeset
98 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
99 {
c338c91086b9 patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents: 14391
diff changeset
100 #ifdef FEAT_EVAL
16782
fc58fee685e2 patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
101 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
102 return NULL;
c338c91086b9 patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents: 14391
diff changeset
103 #endif
c338c91086b9 patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents: 14391
diff changeset
104 return (list_alloc());
c338c91086b9 patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents: 14391
diff changeset
105 }
c338c91086b9 patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents: 14391
diff changeset
106
c338c91086b9 patch 8.1.0519: cannot save and restore the tag stack
Bram Moolenaar <Bram@vim.org>
parents: 14391
diff changeset
107 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
108 * 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
109 * 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
110 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
111 list_T *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
112 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
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 *l;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
115
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
116 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
117 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
118 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
119 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
120
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
121 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
122 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
123 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
124 int i;
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 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
127 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
128 l->lv_first = li;
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19203
diff changeset
129 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
130 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
131 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
132 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
133 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
134 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
135 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
136 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
137 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
138 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
139 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
140 ++li;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
141 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
142 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
143 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
144 return l;
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 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
148 * 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
149 * 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
150 * 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
151 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
152 void
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
153 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
154 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
155 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
156
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
157 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
158 }
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 /*
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
161 * 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
162 * Returns OK or FAIL.
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
163 */
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
164 int
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
165 rettv_list_alloc(typval_T *rettv)
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 list_T *l = list_alloc();
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
168
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
169 if (l == NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
170 return FAIL;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
171
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
172 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
173 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
174 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
175 }
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
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 /*
15209
3a99b2e6d136 patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents: 15016
diff changeset
178 * 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
179 */
3a99b2e6d136 patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents: 15016
diff changeset
180 int
3a99b2e6d136 patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents: 15016
diff changeset
181 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
182 {
3a99b2e6d136 patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents: 15016
diff changeset
183 #ifdef FEAT_EVAL
16782
fc58fee685e2 patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
184 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
185 return FAIL;
3a99b2e6d136 patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents: 15016
diff changeset
186 #endif
3a99b2e6d136 patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents: 15016
diff changeset
187 return rettv_list_alloc(rettv);
3a99b2e6d136 patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents: 15016
diff changeset
188 }
3a99b2e6d136 patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents: 15016
diff changeset
189
3a99b2e6d136 patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents: 15016
diff changeset
190
3a99b2e6d136 patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents: 15016
diff changeset
191 /*
17262
041156ce1d22 patch 8.1.1630: various small problems
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
192 * 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
193 */
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
194 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
195 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
196 {
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
197 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
198 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
199 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
200 ++l->lv_refcount;
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
201 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
202
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
203 /*
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
204 * 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
205 * becomes zero.
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 void
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
208 list_unref(list_T *l)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
209 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
210 if (l != NULL && --l->lv_refcount <= 0)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
211 list_free(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
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
214 /*
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
215 * 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
216 * Ignores the reference count.
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 static void
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
219 list_free_contents(list_T *l)
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 listitem_T *item;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
222
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
223 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
224 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
225 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
226 // 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
227 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
228 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
229 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
230 }
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
231 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
232
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
233 /*
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
234 * 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
235 * 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
236 * are not referenced anywhere.
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
237 */
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
238 int
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
239 list_free_nonref(int copyID)
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 list_T *ll;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
242 int did_free = FALSE;
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 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
245 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
246 && ll->lv_watch == NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
247 {
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
248 // 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
249 // 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
250 // or list of lists.
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
251 list_free_contents(ll);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
252 did_free = TRUE;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
253 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
254 return did_free;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
255 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
256
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
257 static void
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
258 list_free_list(list_T *l)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
259 {
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
260 // 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
261 if (l->lv_used_prev == NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
262 first_list = l->lv_used_next;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
263 else
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
264 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
265 if (l->lv_used_next != NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
266 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
267
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
268 vim_free(l);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
269 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
270
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
271 void
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
272 list_free_items(int copyID)
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 list_T *ll, *ll_next;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
275
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
276 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
277 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
278 ll_next = ll->lv_used_next;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
279 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
280 && ll->lv_watch == NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
281 {
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
282 // 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
283 // 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
284 // or list of lists.
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
285 list_free_list(ll);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
286 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
287 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
288 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
289
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
290 void
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
291 list_free(list_T *l)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
292 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
293 if (!in_free_unref_items)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
294 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
295 list_free_contents(l);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
296 list_free_list(l);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
297 }
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
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
300 /*
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
301 * Allocate a list item.
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
302 * 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
303 */
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
304 listitem_T *
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
305 listitem_alloc(void)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
306 {
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
307 return ALLOC_ONE(listitem_T);
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
308 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
309
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
310 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
311 * 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
312 * 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
313 */
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
314 void
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
315 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
316 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
317 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
318 || 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
319 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
320 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
321
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
322 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
323 * 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
324 * 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
325 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
326 void
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
327 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
328 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
329 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
330 list_free_item(l, item);
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
331 }
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 /*
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
334 * 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
335 */
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
336 void
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
337 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
338 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
339 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
340 listitem_free(l, item);
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
341 }
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 /*
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
344 * 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
345 */
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
346 long
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
347 list_len(list_T *l)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
348 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
349 if (l == NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
350 return 0L;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
351 return l->lv_len;
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
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
354 /*
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
355 * 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
356 */
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
357 int
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
358 list_equal(
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
359 list_T *l1,
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
360 list_T *l2,
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
361 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
362 int recursive) // TRUE when used recursively
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
363 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
364 listitem_T *item1, *item2;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
365
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
366 if (l1 == NULL || l2 == NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
367 return FALSE;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
368 if (l1 == l2)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
369 return TRUE;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
370 if (list_len(l1) != list_len(l2))
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
371 return FALSE;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
372
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
373 range_list_materialize(l1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
374 range_list_materialize(l2);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
375
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
376 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
377 item1 != NULL && item2 != NULL;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
378 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
379 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
380 return FALSE;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
381 return item1 == NULL && item2 == NULL;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
382 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
383
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
384 /*
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
385 * 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
386 * 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
387 * 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
388 */
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
389 listitem_T *
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
390 list_find(list_T *l, long n)
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 listitem_T *item;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
393 long idx;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
394
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
395 if (l == NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
396 return NULL;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
397
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
398 // 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
399 if (n < 0)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
400 n = l->lv_len + n;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
401
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
402 // Check for index out of range.
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
403 if (n < 0 || n >= l->lv_len)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
404 return NULL;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
405
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
406 range_list_materialize(l);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
407
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
408 // 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
409 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
410 {
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19203
diff changeset
411 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
412 {
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
413 // 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
414 item = l->lv_first;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
415 idx = 0;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
416 }
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19203
diff changeset
417 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
418 {
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
419 // 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
420 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
421 idx = l->lv_len - 1;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
422 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
423 else
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
424 {
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
425 // 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
426 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
427 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
428 }
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 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
432 if (n < l->lv_len / 2)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
433 {
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
434 // 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
435 item = l->lv_first;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
436 idx = 0;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
437 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
438 else
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
439 {
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
440 // 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
441 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
442 idx = l->lv_len - 1;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
443 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
444 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
445
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
446 while (n > idx)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
447 {
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
448 // search forward
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
449 item = item->li_next;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
450 ++idx;
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 while (n < idx)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
453 {
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
454 // search backward
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
455 item = item->li_prev;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
456 --idx;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
457 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
458
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
459 // cache the used index
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19203
diff changeset
460 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
461 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
462
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
463 return item;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
464 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
465
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
466 /*
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
467 * 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
468 */
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
469 long
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
470 list_find_nr(
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
471 list_T *l,
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
472 long idx,
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
473 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
474 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
475 listitem_T *li;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
476
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
477 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
478 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
479 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
480
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
481 // 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
482 // 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
483 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
484 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
485
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
486 // 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
487 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
488 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
489 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
490 *errorp = TRUE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
491 return -1L;
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
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19203
diff changeset
494 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
495 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
496
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
497 li = list_find(l, idx);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
498 if (li == NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
499 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
500 if (errorp != NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
501 *errorp = TRUE;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
502 return -1L;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
503 }
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15209
diff changeset
504 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
505 }
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 /*
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
508 * 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
509 */
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
510 char_u *
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
511 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
512 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
513 listitem_T *li;
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 li = list_find(l, idx - 1);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
516 if (li == NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
517 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
518 semsg(_(e_listidx), idx);
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
519 return NULL;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
520 }
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15209
diff changeset
521 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
522 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
523
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
524 /*
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
525 * 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
526 * 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
527 */
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
528 long
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
529 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
530 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
531 long idx = 0;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
532 listitem_T *li;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
533
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
534 if (l == NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
535 return -1;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
536 range_list_materialize(l);
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
537 idx = 0;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
538 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
539 ++idx;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
540 if (li == NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
541 return -1;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
542 return idx;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
543 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
544
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
545 /*
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
546 * 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
547 */
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
548 void
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
549 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
550 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
551 range_list_materialize(l);
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19203
diff changeset
552 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
553 {
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
554 // empty list
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
555 l->lv_first = item;
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19203
diff changeset
556 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
557 item->li_prev = NULL;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
558 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
559 else
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
560 {
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19203
diff changeset
561 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
562 item->li_prev = l->lv_u.mat.lv_last;
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19203
diff changeset
563 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
564 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
565 ++l->lv_len;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
566 item->li_next = NULL;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
567 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
568
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
569 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
570 * Append typval_T "tv" to the end of list "l". "tv" is copied.
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
571 * Return FAIL when out of memory.
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 int
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
574 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
575 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
576 listitem_T *li = listitem_alloc();
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
577
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
578 if (li == NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
579 return FAIL;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
580 copy_tv(tv, &li->li_tv);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
581 list_append(l, li);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
582 return OK;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
583 }
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 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
586 * 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
587 * 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
588 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
589 int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
590 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
591 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
592 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
593
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
594 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
595 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
596 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
597 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
598 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
599 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
600
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
601 /*
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
602 * 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
603 * Return FAIL when out of memory.
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
604 */
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
605 int
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
606 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
607 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
608 listitem_T *li = listitem_alloc();
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
609
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
610 if (li == NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
611 return FAIL;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
612 li->li_tv.v_type = VAR_DICT;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
613 li->li_tv.v_lock = 0;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
614 li->li_tv.vval.v_dict = dict;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
615 list_append(list, li);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
616 ++dict->dv_refcount;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
617 return OK;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
618 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
619
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
620 /*
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
621 * 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
622 * 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
623 */
dd3b2ecf91f6 patch 8.0.1497: getting the jump list requires parsing the output of :jumps
Christian Brabandt <cb@256bit.org>
parents: 11973
diff changeset
624 int
14391
46f14852a919 patch 8.1.0210: still a few K&R function declarations
Christian Brabandt <cb@256bit.org>
parents: 13246
diff changeset
625 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
626 {
dd3b2ecf91f6 patch 8.0.1497: getting the jump list requires parsing the output of :jumps
Christian Brabandt <cb@256bit.org>
parents: 11973
diff changeset
627 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
628
dd3b2ecf91f6 patch 8.0.1497: getting the jump list requires parsing the output of :jumps
Christian Brabandt <cb@256bit.org>
parents: 11973
diff changeset
629 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
630 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
631 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
632 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
633 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
634 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
635 ++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
636 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
637 }
dd3b2ecf91f6 patch 8.0.1497: getting the jump list requires parsing the output of :jumps
Christian Brabandt <cb@256bit.org>
parents: 11973
diff changeset
638
dd3b2ecf91f6 patch 8.0.1497: getting the jump list requires parsing the output of :jumps
Christian Brabandt <cb@256bit.org>
parents: 11973
diff changeset
639 /*
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
640 * 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
641 * When "len" >= 0 use "str[len]".
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
642 * Returns FAIL when out of memory.
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
643 */
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
644 int
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
645 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
646 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
647 listitem_T *li = listitem_alloc();
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
648
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
649 if (li == NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
650 return FAIL;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
651 list_append(l, li);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
652 li->li_tv.v_type = VAR_STRING;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
653 li->li_tv.v_lock = 0;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
654 if (str == NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
655 li->li_tv.vval.v_string = NULL;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
656 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
657 : vim_strsave(str))) == NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
658 return FAIL;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
659 return OK;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
660 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
661
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
662 /*
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
663 * Append "n" to list "l".
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
664 * Returns FAIL when out of memory.
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
665 */
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
666 int
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
667 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
668 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
669 listitem_T *li;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
670
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
671 li = listitem_alloc();
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
672 if (li == NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
673 return FAIL;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
674 li->li_tv.v_type = VAR_NUMBER;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
675 li->li_tv.v_lock = 0;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
676 li->li_tv.vval.v_number = n;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
677 list_append(l, li);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
678 return OK;
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
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
681 /*
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
682 * 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
683 * If "item" is NULL append at the end.
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
684 * Return FAIL when out of memory.
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
685 */
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
686 int
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
687 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
688 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
689 listitem_T *ni = listitem_alloc();
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
690
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
691 if (ni == NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
692 return FAIL;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
693 copy_tv(tv, &ni->li_tv);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
694 list_insert(l, ni, item);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
695 return OK;
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
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
698 void
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
699 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
700 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
701 range_list_materialize(l);
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
702 if (item == NULL)
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
703 // 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
704 list_append(l, ni);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
705 else
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
706 {
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
707 // Insert new item before existing item.
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
708 ni->li_prev = item->li_prev;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
709 ni->li_next = item;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
710 if (item->li_prev == NULL)
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 l->lv_first = ni;
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19203
diff changeset
713 ++l->lv_u.mat.lv_idx;
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
714 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
715 else
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 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
718 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
719 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
720 item->li_prev = ni;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
721 ++l->lv_len;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
722 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
723 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
724
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
725 /*
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
726 * Extend "l1" with "l2".
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
727 * 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
728 * Returns FAIL when out of memory.
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
729 */
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
730 int
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
731 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
732 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
733 listitem_T *item;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
734 int todo = l2->lv_len;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
735
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
736 range_list_materialize(l1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
737 range_list_materialize(l2);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
738
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
739 // 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
740 // the list, avoid a hang when we extend a list with itself.
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
741 for (item = l2->lv_first; item != NULL && --todo >= 0; item = item->li_next)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
742 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
743 return FAIL;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
744 return OK;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
745 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
746
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 * 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
749 * Return FAIL when out of memory.
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 int
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
752 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
753 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
754 list_T *l;
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 if (l1 == NULL || l2 == NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
757 return FAIL;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
758
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
759 // make a copy of the first list.
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
760 l = list_copy(l1, FALSE, 0);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
761 if (l == NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
762 return FAIL;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
763 tv->v_type = VAR_LIST;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
764 tv->vval.v_list = l;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
765
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
766 // 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
767 return list_extend(l, l2, NULL);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
768 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
769
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
770 /*
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
771 * 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
772 * The refcount of the new list is set to 1.
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
773 * See item_copy() for "copyID".
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
774 * Returns NULL when out of memory.
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
775 */
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
776 list_T *
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
777 list_copy(list_T *orig, int deep, int copyID)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
778 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
779 list_T *copy;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
780 listitem_T *item;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
781 listitem_T *ni;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
782
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
783 if (orig == NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
784 return NULL;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
785
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
786 copy = list_alloc();
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
787 if (copy != NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
788 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
789 if (copyID != 0)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
790 {
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
791 // 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
792 // refer back to this list.
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
793 orig->lv_copyID = copyID;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
794 orig->lv_copylist = copy;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
795 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
796 range_list_materialize(orig);
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
797 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
798 item = item->li_next)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
799 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
800 ni = listitem_alloc();
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
801 if (ni == NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
802 break;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
803 if (deep)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
804 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
805 if (item_copy(&item->li_tv, &ni->li_tv, deep, copyID) == FAIL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
806 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
807 vim_free(ni);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
808 break;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
809 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
810 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
811 else
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
812 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
813 list_append(copy, ni);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
814 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
815 ++copy->lv_refcount;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
816 if (item != NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
817 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
818 list_unref(copy);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
819 copy = NULL;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
820 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
821 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
822
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
823 return copy;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
824 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
825
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
826 /*
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
827 * 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
828 * 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
829 * 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
830 * file.
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
831 */
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
832 void
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
833 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
834 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
835 listitem_T *ip;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
836
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
837 range_list_materialize(l);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
838
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
839 // notify watchers
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
840 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
841 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
842 --l->lv_len;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
843 list_fix_watch(l, ip);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
844 if (ip == item2)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
845 break;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
846 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
847
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
848 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
849 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
850 else
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
851 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
852 if (item->li_prev == NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
853 l->lv_first = item2->li_next;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
854 else
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
855 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
856 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
857 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
858
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
859 /*
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
860 * 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
861 * May return NULL.
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
862 */
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
863 char_u *
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
864 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
865 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
866 garray_T ga;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
867
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
868 if (tv->vval.v_list == NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
869 return NULL;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
870 ga_init2(&ga, (int)sizeof(char), 80);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
871 ga_append(&ga, '[');
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
872 range_list_materialize(tv->vval.v_list);
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
873 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
874 FALSE, restore_copyID, copyID) == FAIL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
875 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
876 vim_free(ga.ga_data);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
877 return NULL;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
878 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
879 ga_append(&ga, ']');
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
880 ga_append(&ga, NUL);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
881 return (char_u *)ga.ga_data;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
882 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
883
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
884 typedef struct join_S {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
885 char_u *s;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
886 char_u *tofree;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
887 } join_T;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
888
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
889 static int
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
890 list_join_inner(
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
891 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
892 list_T *l,
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
893 char_u *sep,
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
894 int echo_style,
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
895 int restore_copyID,
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
896 int copyID,
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
897 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
898 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
899 int i;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
900 join_T *p;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
901 int len;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
902 int sumlen = 0;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
903 int first = TRUE;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
904 char_u *tofree;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
905 char_u numbuf[NUMBUFLEN];
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
906 listitem_T *item;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
907 char_u *s;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
908
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
909 // Stringify each item in the list.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
910 range_list_materialize(l);
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
911 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
912 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
913 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
914 echo_style, restore_copyID, !echo_style);
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
915 if (s == NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
916 return FAIL;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
917
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
918 len = (int)STRLEN(s);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
919 sumlen += len;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
920
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
921 (void)ga_grow(join_gap, 1);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
922 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
923 if (tofree != NULL || s != numbuf)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
924 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
925 p->s = s;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
926 p->tofree = tofree;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
927 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
928 else
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
929 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
930 p->s = vim_strnsave(s, len);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
931 p->tofree = p->s;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
932 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
933
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
934 line_breakcheck();
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
935 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
936 break;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
937 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
938
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
939 // 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
940 // 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
941 if (join_gap->ga_len >= 2)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
942 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
943 if (ga_grow(gap, sumlen + 2) == FAIL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
944 return FAIL;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
945
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
946 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
947 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
948 if (first)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
949 first = FALSE;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
950 else
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
951 ga_concat(gap, sep);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
952 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
953
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
954 if (p->s != NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
955 ga_concat(gap, p->s);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
956 line_breakcheck();
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
957 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
958
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
959 return OK;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
960 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
961
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
962 /*
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
963 * 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
964 * 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
965 * Return FAIL or OK.
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
966 */
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
967 int
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
968 list_join(
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
969 garray_T *gap,
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
970 list_T *l,
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
971 char_u *sep,
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
972 int echo_style,
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
973 int restore_copyID,
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
974 int copyID)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
975 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
976 garray_T join_ga;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
977 int retval;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
978 join_T *p;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
979 int i;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
980
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
981 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
982 return OK; // nothing to do
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
983 ga_init2(&join_ga, (int)sizeof(join_T), l->lv_len);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
984 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
985 copyID, &join_ga);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
986
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
987 // Dispose each item in join_ga.
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
988 if (join_ga.ga_data != NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
989 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
990 p = (join_T *)join_ga.ga_data;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
991 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
992 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
993 vim_free(p->tofree);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
994 ++p;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
995 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
996 ga_clear(&join_ga);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
997 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
998
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
999 return retval;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1000 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1001
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1002 /*
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1003 * "join()" function
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1004 */
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1005 void
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1006 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
1007 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1008 garray_T ga;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1009 char_u *sep;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1010
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1011 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
1012 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1013 emsg(_(e_listreq));
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1014 return;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1015 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1016 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
1017 return;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1018 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
1019 sep = (char_u *)" ";
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1020 else
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1021 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
1022
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1023 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
1024
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1025 if (sep != NULL)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1026 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1027 ga_init2(&ga, (int)sizeof(char), 80);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1028 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
1029 ga_append(&ga, NUL);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1030 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
1031 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1032 else
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1033 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
1034 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1035
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1036 /*
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1037 * Allocate a variable for a List and fill it from "*arg".
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1038 * Return OK or FAIL.
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1039 */
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1040 int
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
1041 get_list_tv(char_u **arg, typval_T *rettv, int evaluate, int do_error)
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1042 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1043 list_T *l = NULL;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1044 typval_T tv;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1045 listitem_T *item;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1046
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1047 if (evaluate)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1048 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1049 l = list_alloc();
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1050 if (l == NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1051 return FAIL;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1052 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1053
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1054 *arg = skipwhite(*arg + 1);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1055 while (**arg != ']' && **arg != NUL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1056 {
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
1057 if (eval1(arg, &tv, evaluate) == FAIL) // recursive!
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1058 goto failret;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1059 if (evaluate)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1060 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1061 item = listitem_alloc();
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1062 if (item != NULL)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1063 {
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1064 item->li_tv = tv;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1065 item->li_tv.v_lock = 0;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1066 list_append(l, item);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1067 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1068 else
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1069 clear_tv(&tv);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1070 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1071
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1072 if (**arg == ']')
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1073 break;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1074 if (**arg != ',')
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1075 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
1076 if (do_error)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
1077 semsg(_("E696: Missing comma in List: %s"), *arg);
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1078 goto failret;
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1079 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1080 *arg = skipwhite(*arg + 1);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1081 }
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1082
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1083 if (**arg != ']')
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1084 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
1085 if (do_error)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
1086 semsg(_("E697: Missing end of List ']': %s"), *arg);
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1087 failret:
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1088 if (evaluate)
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1089 list_free(l);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1090 return FAIL;
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 *arg = skipwhite(*arg + 1);
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1094 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
1095 rettv_list_set(rettv, l);
9560
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1096
1e68dfd7931b commit https://github.com/vim/vim/commit/da861d631d7e22654faee2789286c685ad548911
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1097 return OK;
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
9571
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1100 /*
10549
055b1633aed7 patch 8.0.0164: outdated and misplaced comments
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
1101 * 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
1102 */
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1103 int
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1104 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
1105 {
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1106 listitem_T *li;
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1107 int c;
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1108 int ret = OK;
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1109 char_u *s;
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1110
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
1111 range_list_materialize(list);
9571
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1112 for (li = list->lv_first; li != NULL; li = li->li_next)
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1113 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15209
diff changeset
1114 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
1115 {
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1116 if (*s == '\n')
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1117 c = putc(NUL, fd);
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1118 else
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1119 c = putc(*s, fd);
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1120 if (c == EOF)
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1121 {
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1122 ret = FAIL;
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1123 break;
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1124 }
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1125 }
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1126 if (!binary || li->li_next != NULL)
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1127 if (putc('\n', fd) == EOF)
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1128 {
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1129 ret = FAIL;
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1130 break;
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1131 }
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1132 if (ret == FAIL)
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1133 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
1134 emsg(_(e_write));
9571
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1135 break;
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1136 }
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1137 }
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1138 return ret;
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1139 }
5eaa708ab50d commit https://github.com/vim/vim/commit/73dad1e64cb42842d8259cb1a255a6fa59822f76
Christian Brabandt <cb@256bit.org>
parents: 9560
diff changeset
1140
9626
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9571
diff changeset
1141 /*
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9571
diff changeset
1142 * 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
1143 */
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9571
diff changeset
1144 void
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9571
diff changeset
1145 init_static_list(staticList10_T *sl)
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9571
diff changeset
1146 {
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9571
diff changeset
1147 list_T *l = &sl->sl_list;
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9571
diff changeset
1148 int i;
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9571
diff changeset
1149
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9571
diff changeset
1150 memset(sl, 0, sizeof(staticList10_T));
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9571
diff changeset
1151 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
1152 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
1153 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
1154 l->lv_lock = VAR_FIXED;
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9571
diff changeset
1155 sl->sl_list.lv_len = 10;
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9571
diff changeset
1156
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9571
diff changeset
1157 for (i = 0; i < 10; ++i)
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9571
diff changeset
1158 {
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9571
diff changeset
1159 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
1160
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9571
diff changeset
1161 if (i == 0)
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9571
diff changeset
1162 li->li_prev = NULL;
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9571
diff changeset
1163 else
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9571
diff changeset
1164 li->li_prev = li - 1;
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9571
diff changeset
1165 if (i == 9)
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9571
diff changeset
1166 li->li_next = NULL;
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9571
diff changeset
1167 else
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9571
diff changeset
1168 li->li_next = li + 1;
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9571
diff changeset
1169 }
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9571
diff changeset
1170 }
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9571
diff changeset
1171
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1172 /*
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1173 * "list2str()" function
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1174 */
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1175 void
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1176 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
1177 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1178 list_T *l;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1179 listitem_T *li;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1180 garray_T ga;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1181 int utf8 = FALSE;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1182
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1183 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
1184 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
1185 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
1186 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1187 emsg(_(e_invarg));
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1188 return;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1189 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1190
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1191 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
1192 if (l == NULL)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1193 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
1194
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1195 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
1196 utf8 = (int)tv_get_number_chk(&argvars[1], NULL);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1197
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
1198 range_list_materialize(l);
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1199 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
1200 if (has_mbyte || utf8)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1201 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1202 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
1203 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
1204
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1205 if (utf8 || enc_utf8)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1206 char2bytes = utf_char2bytes;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1207 else
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1208 char2bytes = mb_char2bytes;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1209
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1210 for (li = l->lv_first; li != NULL; li = li->li_next)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1211 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1212 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
1213 ga_concat(&ga, buf);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1214 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1215 ga_append(&ga, NUL);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1216 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1217 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
1218 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1219 for (li = l->lv_first; li != NULL; li = li->li_next)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1220 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
1221 ga_append(&ga, NUL);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1222 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1223
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1224 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
1225 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
1226 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1227
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1228 void
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1229 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
1230 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1231 list_T *l;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1232 listitem_T *item, *item2;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1233 listitem_T *li;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1234 int error = FALSE;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1235 int idx;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1236
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1237 if ((l = 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
1238 || var_check_lock(l->lv_lock, arg_errmsg, TRUE))
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1239 return;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1240
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1241 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
1242 if (error)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1243 ; // type error: do nothing, errmsg already given
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1244 else if ((item = list_find(l, idx)) == NULL)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1245 semsg(_(e_listidx), idx);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1246 else
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1247 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1248 if (argvars[2].v_type == VAR_UNKNOWN)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1249 {
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
1250 // Remove one item, return its value.
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1251 vimlist_remove(l, item, item);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1252 *rettv = 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
1253 list_free_item(l, item);
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1254 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1255 else
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1256 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1257 // Remove range of items, return list with values.
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1258 int end = (long)tv_get_number_chk(&argvars[2], &error);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1259
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1260 if (error)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1261 ; // type error: do nothing
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1262 else if ((item2 = list_find(l, end)) == NULL)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1263 semsg(_(e_listidx), end);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1264 else
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1265 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1266 int cnt = 0;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1267
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1268 for (li = item; li != NULL; li = li->li_next)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1269 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1270 ++cnt;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1271 if (li == item2)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1272 break;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1273 }
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
1274 if (li == NULL) // didn't find "item2" after "item"
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1275 emsg(_(e_invrange));
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1276 else
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1277 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1278 vimlist_remove(l, item, item2);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1279 if (rettv_list_alloc(rettv) == OK)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1280 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1281 l = rettv->vval.v_list;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1282 l->lv_first = item;
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19203
diff changeset
1283 l->lv_u.mat.lv_last = item2;
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1284 item->li_prev = NULL;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1285 item2->li_next = NULL;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1286 l->lv_len = cnt;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1287 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1288 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1289 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1290 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1291 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1292 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1293
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1294 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
1295 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
1296
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
1297 // 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
1298 typedef struct
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1299 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1300 listitem_T *item;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1301 int idx;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1302 } sortItem_T;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1303
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
1304 // 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
1305 typedef struct
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1306 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1307 int item_compare_ic;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1308 int item_compare_numeric;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1309 int item_compare_numbers;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1310 #ifdef FEAT_FLOAT
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1311 int item_compare_float;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1312 #endif
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1313 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
1314 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
1315 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
1316 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
1317 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
1318 } sortinfo_T;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1319 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
1320 #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
1321
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1322 /*
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1323 * 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
1324 */
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1325 static int
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1326 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
1327 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1328 sortItem_T *si1, *si2;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1329 typval_T *tv1, *tv2;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1330 char_u *p1, *p2;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1331 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
1332 int res;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1333 char_u numbuf1[NUMBUFLEN];
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1334 char_u numbuf2[NUMBUFLEN];
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1335
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1336 si1 = (sortItem_T *)s1;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1337 si2 = (sortItem_T *)s2;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1338 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
1339 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
1340
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1341 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
1342 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1343 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
1344 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
1345
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1346 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
1347 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1348
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1349 #ifdef FEAT_FLOAT
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1350 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
1351 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1352 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
1353 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
1354
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1355 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
1356 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1357 #endif
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1358
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
1359 // 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
1360 // 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
1361 // 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
1362 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
1363 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1364 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
1365 p1 = (char_u *)"'";
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1366 else
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1367 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
1368 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1369 else
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1370 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
1371 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
1372 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1373 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
1374 p2 = (char_u *)"'";
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1375 else
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1376 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
1377 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1378 else
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1379 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
1380 if (p1 == NULL)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1381 p1 = (char_u *)"";
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1382 if (p2 == NULL)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1383 p2 = (char_u *)"";
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1384 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
1385 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1386 if (sortinfo->item_compare_ic)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1387 res = STRICMP(p1, p2);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1388 else
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1389 res = STRCMP(p1, p2);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1390 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1391 else
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1392 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1393 double n1, n2;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1394 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
1395 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
1396 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
1397 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1398
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
1399 // 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
1400 // sort stable.
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1401 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
1402 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
1403
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1404 vim_free(tofree1);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1405 vim_free(tofree2);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1406 return res;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1407 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1408
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1409 static int
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1410 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
1411 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1412 sortItem_T *si1, *si2;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1413 int res;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1414 typval_T rettv;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1415 typval_T argv[3];
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1416 char_u *func_name;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1417 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
1418 funcexe_T funcexe;
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1419
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
1420 // 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
1421 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
1422 return 0;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1423
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1424 si1 = (sortItem_T *)s1;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1425 si2 = (sortItem_T *)s2;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1426
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1427 if (partial == NULL)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1428 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
1429 else
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1430 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
1431
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
1432 // 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
1433 // 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
1434 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
1435 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
1436
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
1437 rettv.v_type = VAR_UNKNOWN; // clear_tv() uses this
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17530
diff changeset
1438 vim_memset(&funcexe, 0, sizeof(funcexe));
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17530
diff changeset
1439 funcexe.evaluate = TRUE;
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17530
diff changeset
1440 funcexe.partial = partial;
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17530
diff changeset
1441 funcexe.selfdict = sortinfo->item_compare_selfdict;
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17530
diff changeset
1442 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
1443 clear_tv(&argv[0]);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1444 clear_tv(&argv[1]);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1445
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1446 if (res == FAIL)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1447 res = ITEM_COMPARE_FAIL;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1448 else
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1449 res = (int)tv_get_number_chk(&rettv, &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
1450 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
1451 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
1452 clear_tv(&rettv);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1453
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
1454 // 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
1455 // the sort stable.
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1456 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
1457 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
1458
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1459 return res;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1460 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1461
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1462 /*
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1463 * "sort()" or "uniq()" function
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 static void
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1466 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
1467 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1468 list_T *l;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1469 listitem_T *li;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1470 sortItem_T *ptrs;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1471 sortinfo_T *old_sortinfo;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1472 sortinfo_T info;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1473 long len;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1474 long i;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1475
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
1476 // 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
1477 // 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
1478 old_sortinfo = sortinfo;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1479 sortinfo = &info;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1480
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1481 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
1482 semsg(_(e_listarg), sort ? "sort()" : "uniq()");
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1483 else
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1484 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1485 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
1486 if (l == NULL || var_check_lock(l->lv_lock,
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1487 (char_u *)(sort ? N_("sort() argument") : N_("uniq() argument")),
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1488 TRUE))
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1489 goto theend;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1490 rettv_list_set(rettv, l);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
1491 range_list_materialize(l);
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1492
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1493 len = list_len(l);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1494 if (len <= 1)
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
1495 goto theend; // short list sorts pretty quickly
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1496
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1497 info.item_compare_ic = FALSE;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1498 info.item_compare_numeric = FALSE;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1499 info.item_compare_numbers = FALSE;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1500 #ifdef FEAT_FLOAT
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1501 info.item_compare_float = FALSE;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1502 #endif
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1503 info.item_compare_func = NULL;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1504 info.item_compare_partial = NULL;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1505 info.item_compare_selfdict = NULL;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1506 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
1507 {
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
1508 // optional second argument: {func}
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1509 if (argvars[1].v_type == VAR_FUNC)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1510 info.item_compare_func = argvars[1].vval.v_string;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1511 else if (argvars[1].v_type == VAR_PARTIAL)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1512 info.item_compare_partial = argvars[1].vval.v_partial;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1513 else
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1514 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1515 int error = FALSE;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1516
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1517 i = (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
1518 if (error)
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
1519 goto theend; // type error; errmsg already given
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1520 if (i == 1)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1521 info.item_compare_ic = TRUE;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1522 else if (argvars[1].v_type != VAR_NUMBER)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1523 info.item_compare_func = tv_get_string(&argvars[1]);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1524 else if (i != 0)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1525 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1526 emsg(_(e_invarg));
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1527 goto theend;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1528 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1529 if (info.item_compare_func != NULL)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1530 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1531 if (*info.item_compare_func == NUL)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1532 {
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
1533 // empty string means default sort
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1534 info.item_compare_func = NULL;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1535 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1536 else if (STRCMP(info.item_compare_func, "n") == 0)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1537 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1538 info.item_compare_func = NULL;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1539 info.item_compare_numeric = TRUE;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1540 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1541 else if (STRCMP(info.item_compare_func, "N") == 0)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1542 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1543 info.item_compare_func = NULL;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1544 info.item_compare_numbers = TRUE;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1545 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1546 #ifdef FEAT_FLOAT
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1547 else if (STRCMP(info.item_compare_func, "f") == 0)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1548 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1549 info.item_compare_func = NULL;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1550 info.item_compare_float = TRUE;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1551 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1552 #endif
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1553 else if (STRCMP(info.item_compare_func, "i") == 0)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1554 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1555 info.item_compare_func = NULL;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1556 info.item_compare_ic = TRUE;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1557 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1558 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1559 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1560
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1561 if (argvars[2].v_type != VAR_UNKNOWN)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1562 {
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
1563 // optional third argument: {dict}
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1564 if (argvars[2].v_type != VAR_DICT)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1565 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1566 emsg(_(e_dictreq));
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1567 goto theend;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1568 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1569 info.item_compare_selfdict = argvars[2].vval.v_dict;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1570 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1571 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1572
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
1573 // Make an array with each entry pointing to an item in the List.
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1574 ptrs = ALLOC_MULT(sortItem_T, len);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1575 if (ptrs == NULL)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1576 goto theend;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1577
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1578 i = 0;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1579 if (sort)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1580 {
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
1581 // sort(): ptrs will be the list to sort
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1582 for (li = l->lv_first; li != NULL; li = li->li_next)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1583 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1584 ptrs[i].item = li;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1585 ptrs[i].idx = i;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1586 ++i;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1587 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1588
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1589 info.item_compare_func_err = FALSE;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1590 info.item_compare_keep_zero = FALSE;
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
1591 // test the compare function
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1592 if ((info.item_compare_func != NULL
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1593 || info.item_compare_partial != NULL)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1594 && item_compare2((void *)&ptrs[0], (void *)&ptrs[1])
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1595 == ITEM_COMPARE_FAIL)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1596 emsg(_("E702: Sort compare function failed"));
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1597 else
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1598 {
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
1599 // Sort the array with item pointers.
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1600 qsort((void *)ptrs, (size_t)len, sizeof(sortItem_T),
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1601 info.item_compare_func == NULL
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1602 && info.item_compare_partial == NULL
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1603 ? item_compare : item_compare2);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1604
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1605 if (!info.item_compare_func_err)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1606 {
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
1607 // Clear the List and append the items in sorted order.
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19203
diff changeset
1608 l->lv_first = l->lv_u.mat.lv_last
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19203
diff changeset
1609 = l->lv_u.mat.lv_idx_item = NULL;
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1610 l->lv_len = 0;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1611 for (i = 0; i < len; ++i)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1612 list_append(l, ptrs[i].item);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1613 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1614 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1615 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1616 else
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1617 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1618 int (*item_compare_func_ptr)(const void *, const void *);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1619
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
1620 // f_uniq(): ptrs will be a stack of items to remove
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1621 info.item_compare_func_err = FALSE;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1622 info.item_compare_keep_zero = TRUE;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1623 item_compare_func_ptr = info.item_compare_func != NULL
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1624 || info.item_compare_partial != NULL
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1625 ? item_compare2 : item_compare;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1626
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1627 for (li = l->lv_first; li != NULL && li->li_next != NULL;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1628 li = li->li_next)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1629 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1630 if (item_compare_func_ptr((void *)&li, (void *)&li->li_next)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1631 == 0)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1632 ptrs[i++].item = li;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1633 if (info.item_compare_func_err)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1634 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1635 emsg(_("E882: Uniq compare function failed"));
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1636 break;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1637 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1638 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1639
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1640 if (!info.item_compare_func_err)
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 while (--i >= 0)
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 li = ptrs[i].item->li_next;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1645 ptrs[i].item->li_next = li->li_next;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1646 if (li->li_next != NULL)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1647 li->li_next->li_prev = ptrs[i].item;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1648 else
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19203
diff changeset
1649 l->lv_u.mat.lv_last = ptrs[i].item;
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1650 list_fix_watch(l, li);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
1651 listitem_free(l, li);
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1652 l->lv_len--;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1653 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1654 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1655 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1656
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1657 vim_free(ptrs);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1658 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1659 theend:
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1660 sortinfo = old_sortinfo;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1661 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1662
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1663 /*
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1664 * "sort({list})" function
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 void
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1667 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
1668 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1669 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
1670 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1671
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1672 /*
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1673 * "uniq({list})" function
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1674 */
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1675 void
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1676 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
1677 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1678 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
1679 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17262
diff changeset
1680
17964
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1681 /*
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1682 * Handle one item for map() and filter().
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1683 */
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1684 static int
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1685 filter_map_one(typval_T *tv, typval_T *expr, int map, int *remp)
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1686 {
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1687 typval_T rettv;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1688 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
1689 int retval = FAIL;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1690
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1691 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
1692 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
1693 argv[1] = *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
1694 if (eval_expr_typval(expr, argv, 2, &rettv) == FAIL)
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1695 goto theend;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1696 if (map)
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1697 {
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1698 // map(): replace the list item value
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1699 clear_tv(tv);
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1700 rettv.v_lock = 0;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1701 *tv = rettv;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1702 }
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1703 else
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1704 {
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1705 int error = FALSE;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1706
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1707 // filter(): when expr is zero remove the item
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1708 *remp = (tv_get_number_chk(&rettv, &error) == 0);
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1709 clear_tv(&rettv);
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1710 // 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
1711 // 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
1712 if (error)
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1713 goto theend;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1714 }
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1715 retval = OK;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1716 theend:
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1717 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
1718 return retval;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1719 }
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1720
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1721 /*
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1722 * 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
1723 */
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1724 static void
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1725 filter_map(typval_T *argvars, typval_T *rettv, int map)
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1726 {
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1727 typval_T *expr;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1728 listitem_T *li, *nli;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1729 list_T *l = NULL;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1730 dictitem_T *di;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1731 hashtab_T *ht;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1732 hashitem_T *hi;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1733 dict_T *d = NULL;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1734 blob_T *b = NULL;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1735 int rem;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1736 int todo;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1737 char_u *ermsg = (char_u *)(map ? "map()" : "filter()");
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1738 char_u *arg_errmsg = (char_u *)(map ? N_("map() argument")
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1739 : N_("filter() argument"));
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1740 int save_did_emsg;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1741 int idx = 0;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1742
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1743 if (argvars[0].v_type == VAR_BLOB)
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1744 {
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1745 if ((b = argvars[0].vval.v_blob) == NULL)
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1746 return;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1747 }
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1748 else if (argvars[0].v_type == VAR_LIST)
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1749 {
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1750 if ((l = argvars[0].vval.v_list) == NULL
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1751 || (!map && var_check_lock(l->lv_lock, arg_errmsg, TRUE)))
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1752 return;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1753 }
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1754 else if (argvars[0].v_type == VAR_DICT)
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1755 {
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1756 if ((d = argvars[0].vval.v_dict) == NULL
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1757 || (!map && var_check_lock(d->dv_lock, arg_errmsg, TRUE)))
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1758 return;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1759 }
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1760 else
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1761 {
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1762 semsg(_(e_listdictarg), ermsg);
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1763 return;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1764 }
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1765
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1766 expr = &argvars[1];
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1767 // 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
1768 // 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
1769 // was not passed as argument.
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1770 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
1771 {
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1772 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
1773 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
1774
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1775 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
1776 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
1777
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1778 // 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
1779 // 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
1780 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
1781 did_emsg = FALSE;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1782
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1783 if (argvars[0].v_type == VAR_DICT)
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1784 {
19233
04c164c971a3 patch 8.2.0175: crash when removing list element in map()
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
1785 int prev_lock = d->dv_lock;
04c164c971a3 patch 8.2.0175: crash when removing list element in map()
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
1786
04c164c971a3 patch 8.2.0175: crash when removing list element in map()
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
1787 if (map && d->dv_lock == 0)
04c164c971a3 patch 8.2.0175: crash when removing list element in map()
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
1788 d->dv_lock = VAR_LOCKED;
17964
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1789 ht = &d->dv_hashtab;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1790 hash_lock(ht);
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1791 todo = (int)ht->ht_used;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1792 for (hi = ht->ht_array; todo > 0; ++hi)
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1793 {
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1794 if (!HASHITEM_EMPTY(hi))
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1795 {
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1796 int r;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1797
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1798 --todo;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1799 di = HI2DI(hi);
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1800 if (map && (var_check_lock(di->di_tv.v_lock,
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1801 arg_errmsg, TRUE)
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1802 || var_check_ro(di->di_flags,
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1803 arg_errmsg, TRUE)))
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1804 break;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1805 set_vim_var_string(VV_KEY, di->di_key, -1);
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1806 r = filter_map_one(&di->di_tv, expr, map, &rem);
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1807 clear_tv(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
1808 if (r == FAIL || did_emsg)
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1809 break;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1810 if (!map && rem)
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1811 {
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1812 if (var_check_fixed(di->di_flags, arg_errmsg, TRUE)
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1813 || var_check_ro(di->di_flags, arg_errmsg, TRUE))
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1814 break;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1815 dictitem_remove(d, di);
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1816 }
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1817 }
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1818 }
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1819 hash_unlock(ht);
19233
04c164c971a3 patch 8.2.0175: crash when removing list element in map()
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
1820 d->dv_lock = prev_lock;
17964
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1821 }
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1822 else if (argvars[0].v_type == VAR_BLOB)
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1823 {
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1824 int i;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1825 typval_T tv;
19123
09f28c17ac58 patch 8.2.0121: filter() and map() on blob don't work
Bram Moolenaar <Bram@vim.org>
parents: 18800
diff changeset
1826 varnumber_T val;
17964
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1827
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1828 // set_vim_var_nr() doesn't set the type
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1829 set_vim_var_type(VV_KEY, VAR_NUMBER);
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1830
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1831 for (i = 0; i < b->bv_ga.ga_len; i++)
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1832 {
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1833 tv.v_type = VAR_NUMBER;
19123
09f28c17ac58 patch 8.2.0121: filter() and map() on blob don't work
Bram Moolenaar <Bram@vim.org>
parents: 18800
diff changeset
1834 val = blob_get(b, i);
09f28c17ac58 patch 8.2.0121: filter() and map() on blob don't work
Bram Moolenaar <Bram@vim.org>
parents: 18800
diff changeset
1835 tv.vval.v_number = val;
17964
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1836 set_vim_var_nr(VV_KEY, idx);
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1837 if (filter_map_one(&tv, expr, map, &rem) == FAIL || did_emsg)
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1838 break;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1839 if (tv.v_type != VAR_NUMBER)
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1840 {
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1841 emsg(_(e_invalblob));
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1842 break;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1843 }
19123
09f28c17ac58 patch 8.2.0121: filter() and map() on blob don't work
Bram Moolenaar <Bram@vim.org>
parents: 18800
diff changeset
1844 if (map)
09f28c17ac58 patch 8.2.0121: filter() and map() on blob don't work
Bram Moolenaar <Bram@vim.org>
parents: 18800
diff changeset
1845 {
09f28c17ac58 patch 8.2.0121: filter() and map() on blob don't work
Bram Moolenaar <Bram@vim.org>
parents: 18800
diff changeset
1846 if (tv.vval.v_number != val)
09f28c17ac58 patch 8.2.0121: filter() and map() on blob don't work
Bram Moolenaar <Bram@vim.org>
parents: 18800
diff changeset
1847 blob_set(b, i, tv.vval.v_number);
09f28c17ac58 patch 8.2.0121: filter() and map() on blob don't work
Bram Moolenaar <Bram@vim.org>
parents: 18800
diff changeset
1848 }
09f28c17ac58 patch 8.2.0121: filter() and map() on blob don't work
Bram Moolenaar <Bram@vim.org>
parents: 18800
diff changeset
1849 else if (rem)
17964
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1850 {
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1851 char_u *p = (char_u *)argvars[0].vval.v_blob->bv_ga.ga_data;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1852
19123
09f28c17ac58 patch 8.2.0121: filter() and map() on blob don't work
Bram Moolenaar <Bram@vim.org>
parents: 18800
diff changeset
1853 mch_memmove(p + i, p + i + 1,
17964
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1854 (size_t)b->bv_ga.ga_len - i - 1);
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1855 --b->bv_ga.ga_len;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1856 --i;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1857 }
19123
09f28c17ac58 patch 8.2.0121: filter() and map() on blob don't work
Bram Moolenaar <Bram@vim.org>
parents: 18800
diff changeset
1858 ++idx;
17964
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1859 }
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1860 }
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1861 else // argvars[0].v_type == VAR_LIST
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1862 {
19233
04c164c971a3 patch 8.2.0175: crash when removing list element in map()
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
1863 int prev_lock = l->lv_lock;
04c164c971a3 patch 8.2.0175: crash when removing list element in map()
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
1864
17964
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1865 // set_vim_var_nr() doesn't set the type
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1866 set_vim_var_type(VV_KEY, VAR_NUMBER);
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1867
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19123
diff changeset
1868 range_list_materialize(l);
19233
04c164c971a3 patch 8.2.0175: crash when removing list element in map()
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
1869 if (map && l->lv_lock == 0)
04c164c971a3 patch 8.2.0175: crash when removing list element in map()
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
1870 l->lv_lock = VAR_LOCKED;
17964
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1871 for (li = l->lv_first; li != NULL; li = nli)
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1872 {
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1873 if (map && var_check_lock(li->li_tv.v_lock, arg_errmsg, TRUE))
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1874 break;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1875 nli = li->li_next;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1876 set_vim_var_nr(VV_KEY, idx);
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1877 if (filter_map_one(&li->li_tv, expr, map, &rem) == FAIL
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1878 || did_emsg)
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1879 break;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1880 if (!map && rem)
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1881 listitem_remove(l, li);
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1882 ++idx;
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1883 }
19233
04c164c971a3 patch 8.2.0175: crash when removing list element in map()
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
1884 l->lv_lock = prev_lock;
17964
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1885 }
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1886
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1887 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
1888 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
1889
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1890 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
1891 }
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1892
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1893 copy_tv(&argvars[0], rettv);
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1894 }
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1895
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1896 /*
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1897 * "filter()" function
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1898 */
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1899 void
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1900 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
1901 {
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1902 filter_map(argvars, rettv, FALSE);
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1903 }
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1904
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1905 /*
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1906 * "map()" function
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1907 */
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1908 void
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1909 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
1910 {
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1911 filter_map(argvars, rettv, TRUE);
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1912 }
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1913
17970
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1914 /*
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1915 * "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
1916 */
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1917 void
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1918 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
1919 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1920 list_T *l;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1921 blob_T *b;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1922
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
1923 rettv->vval.v_number = 1; // Default: Failed
17970
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1924 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
1925 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1926 if ((l = argvars[0].vval.v_list) != NULL
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1927 && !var_check_lock(l->lv_lock,
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1928 (char_u *)N_("add() argument"), TRUE)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1929 && list_append_tv(l, &argvars[1]) == OK)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1930 copy_tv(&argvars[0], rettv);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1931 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1932 else if (argvars[0].v_type == VAR_BLOB)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1933 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1934 if ((b = argvars[0].vval.v_blob) != NULL
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1935 && !var_check_lock(b->bv_lock,
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1936 (char_u *)N_("add() argument"), TRUE))
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1937 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1938 int error = FALSE;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1939 varnumber_T n = tv_get_number_chk(&argvars[1], &error);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1940
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1941 if (!error)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1942 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1943 ga_append(&b->bv_ga, (int)n);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1944 copy_tv(&argvars[0], rettv);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1945 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1946 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1947 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1948 else
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1949 emsg(_(e_listblobreq));
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1950 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1951
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1952 /*
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1953 * "count()" function
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1954 */
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1955 void
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1956 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
1957 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1958 long n = 0;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1959 int ic = FALSE;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1960 int error = FALSE;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1961
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1962 if (argvars[2].v_type != VAR_UNKNOWN)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1963 ic = (int)tv_get_number_chk(&argvars[2], &error);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1964
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1965 if (argvars[0].v_type == VAR_STRING)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1966 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1967 char_u *expr = tv_get_string_chk(&argvars[1]);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1968 char_u *p = argvars[0].vval.v_string;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1969 char_u *next;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1970
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1971 if (!error && expr != NULL && *expr != NUL && p != NULL)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1972 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1973 if (ic)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1974 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1975 size_t len = STRLEN(expr);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1976
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1977 while (*p != NUL)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1978 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1979 if (MB_STRNICMP(p, expr, len) == 0)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1980 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1981 ++n;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1982 p += len;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1983 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1984 else
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1985 MB_PTR_ADV(p);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1986 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1987 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1988 else
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1989 while ((next = (char_u *)strstr((char *)p, (char *)expr))
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1990 != NULL)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1991 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1992 ++n;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1993 p = next + STRLEN(expr);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1994 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1995 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1996
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1997 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
1998 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
1999 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2000 listitem_T *li;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2001 list_T *l;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2002 long idx;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2003
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2004 if ((l = argvars[0].vval.v_list) != NULL)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2005 {
19203
09f01421a356 patch 8.2.0160: range test fails
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
2006 range_list_materialize(l);
17970
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2007 li = l->lv_first;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2008 if (argvars[2].v_type != VAR_UNKNOWN)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2009 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2010 if (argvars[3].v_type != VAR_UNKNOWN)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2011 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2012 idx = (long)tv_get_number_chk(&argvars[3], &error);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2013 if (!error)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2014 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2015 li = list_find(l, idx);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2016 if (li == NULL)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2017 semsg(_(e_listidx), idx);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2018 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2019 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2020 if (error)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2021 li = NULL;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2022 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2023
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2024 for ( ; li != NULL; li = li->li_next)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2025 if (tv_equal(&li->li_tv, &argvars[1], ic, FALSE))
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2026 ++n;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2027 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2028 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2029 else 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
2030 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2031 int todo;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2032 dict_T *d;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2033 hashitem_T *hi;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2034
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2035 if ((d = argvars[0].vval.v_dict) != NULL)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2036 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2037 if (argvars[2].v_type != VAR_UNKNOWN)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2038 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2039 if (argvars[3].v_type != VAR_UNKNOWN)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2040 emsg(_(e_invarg));
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2041 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2042
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2043 todo = error ? 0 : (int)d->dv_hashtab.ht_used;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2044 for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2045 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2046 if (!HASHITEM_EMPTY(hi))
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2047 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2048 --todo;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2049 if (tv_equal(&HI2DI(hi)->di_tv, &argvars[1], ic, FALSE))
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2050 ++n;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2051 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2052 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2053 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2054 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2055 else
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2056 semsg(_(e_listdictarg), "count()");
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2057 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
2058 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2059
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2060 /*
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2061 * "extend(list, list [, idx])" function
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2062 * "extend(dict, dict [, action])" function
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2063 */
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2064 void
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2065 f_extend(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
2066 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2067 char_u *arg_errmsg = (char_u *)N_("extend() argument");
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2068
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2069 if (argvars[0].v_type == VAR_LIST && argvars[1].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
2070 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2071 list_T *l1, *l2;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2072 listitem_T *item;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2073 long before;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2074 int error = FALSE;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2075
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2076 l1 = argvars[0].vval.v_list;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2077 l2 = argvars[1].vval.v_list;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2078 if (l1 != NULL && !var_check_lock(l1->lv_lock, arg_errmsg, TRUE)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2079 && l2 != NULL)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2080 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2081 if (argvars[2].v_type != VAR_UNKNOWN)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2082 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2083 before = (long)tv_get_number_chk(&argvars[2], &error);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2084 if (error)
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
2085 return; // type error; errmsg already given
17970
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2086
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2087 if (before == l1->lv_len)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2088 item = NULL;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2089 else
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2090 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2091 item = list_find(l1, before);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2092 if (item == NULL)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2093 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2094 semsg(_(e_listidx), before);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2095 return;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2096 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2097 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2098 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2099 else
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2100 item = NULL;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2101 list_extend(l1, l2, item);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2102
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2103 copy_tv(&argvars[0], rettv);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2104 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2105 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2106 else if (argvars[0].v_type == VAR_DICT && argvars[1].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
2107 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2108 dict_T *d1, *d2;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2109 char_u *action;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2110 int i;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2111
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2112 d1 = argvars[0].vval.v_dict;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2113 d2 = argvars[1].vval.v_dict;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2114 if (d1 != NULL && !var_check_lock(d1->dv_lock, arg_errmsg, TRUE)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2115 && d2 != NULL)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2116 {
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
2117 // Check the third argument.
17970
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2118 if (argvars[2].v_type != VAR_UNKNOWN)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2119 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2120 static char *(av[]) = {"keep", "force", "error"};
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2121
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2122 action = tv_get_string_chk(&argvars[2]);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2123 if (action == NULL)
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
2124 return; // type error; errmsg already given
17970
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2125 for (i = 0; i < 3; ++i)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2126 if (STRCMP(action, av[i]) == 0)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2127 break;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2128 if (i == 3)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2129 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2130 semsg(_(e_invarg2), action);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2131 return;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2132 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2133 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2134 else
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2135 action = (char_u *)"force";
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2136
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2137 dict_extend(d1, d2, action);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2138
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2139 copy_tv(&argvars[0], rettv);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2140 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2141 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2142 else
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2143 semsg(_(e_listdictarg), "extend()");
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2144 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2145
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2146 /*
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2147 * "insert()" function
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2148 */
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2149 void
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2150 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
2151 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2152 long before = 0;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2153 listitem_T *item;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2154 list_T *l;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2155 int error = FALSE;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2156
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2157 if (argvars[0].v_type == VAR_BLOB)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2158 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2159 int val, len;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2160 char_u *p;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2161
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2162 len = blob_len(argvars[0].vval.v_blob);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2163 if (argvars[2].v_type != VAR_UNKNOWN)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2164 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2165 before = (long)tv_get_number_chk(&argvars[2], &error);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2166 if (error)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2167 return; // type error; errmsg already given
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2168 if (before < 0 || before > len)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2169 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2170 semsg(_(e_invarg2), tv_get_string(&argvars[2]));
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2171 return;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2172 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2173 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2174 val = tv_get_number_chk(&argvars[1], &error);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2175 if (error)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2176 return;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2177 if (val < 0 || val > 255)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2178 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2179 semsg(_(e_invarg2), tv_get_string(&argvars[1]));
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2180 return;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2181 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2182
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2183 if (ga_grow(&argvars[0].vval.v_blob->bv_ga, 1) == FAIL)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2184 return;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2185 p = (char_u *)argvars[0].vval.v_blob->bv_ga.ga_data;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2186 mch_memmove(p + before + 1, p + before, (size_t)len - before);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2187 *(p + before) = val;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2188 ++argvars[0].vval.v_blob->bv_ga.ga_len;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2189
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2190 copy_tv(&argvars[0], rettv);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2191 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2192 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
2193 semsg(_(e_listblobarg), "insert()");
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2194 else if ((l = argvars[0].vval.v_list) != NULL
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2195 && !var_check_lock(l->lv_lock,
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2196 (char_u *)N_("insert() argument"), TRUE))
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2197 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2198 if (argvars[2].v_type != VAR_UNKNOWN)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2199 before = (long)tv_get_number_chk(&argvars[2], &error);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2200 if (error)
18800
f41b55f9357c patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17970
diff changeset
2201 return; // type error; errmsg already given
17970
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2202
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2203 if (before == l->lv_len)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2204 item = NULL;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2205 else
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2206 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2207 item = list_find(l, before);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2208 if (item == NULL)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2209 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2210 semsg(_(e_listidx), before);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2211 l = NULL;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2212 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2213 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2214 if (l != NULL)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2215 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2216 list_insert_tv(l, &argvars[1], item);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2217 copy_tv(&argvars[0], rettv);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2218 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2219 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2220 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2221
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2222 /*
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2223 * "remove()" function
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2224 */
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2225 void
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2226 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
2227 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2228 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
2229
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2230 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
2231 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
2232 else if (argvars[0].v_type == VAR_BLOB)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2233 blob_remove(argvars, rettv);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2234 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
2235 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
2236 else
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2237 semsg(_(e_listdictblobarg), "remove()");
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2238 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2239
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2240 /*
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2241 * "reverse({list})" function
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2242 */
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2243 void
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2244 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
2245 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2246 list_T *l;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2247 listitem_T *li, *ni;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2248
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2249 if (argvars[0].v_type == VAR_BLOB)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2250 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2251 blob_T *b = argvars[0].vval.v_blob;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2252 int i, len = blob_len(b);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2253
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2254 for (i = 0; i < len / 2; i++)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2255 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2256 int tmp = blob_get(b, i);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2257
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2258 blob_set(b, i, blob_get(b, len - i - 1));
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2259 blob_set(b, len - i - 1, tmp);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2260 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2261 rettv_blob_set(rettv, b);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2262 return;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2263 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2264
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2265 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
2266 semsg(_(e_listblobarg), "reverse()");
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2267 else if ((l = argvars[0].vval.v_list) != NULL
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2268 && !var_check_lock(l->lv_lock,
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2269 (char_u *)N_("reverse() argument"), TRUE))
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2270 {
19203
09f01421a356 patch 8.2.0160: range test fails
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
2271 if (l->lv_first == &range_list_item)
09f01421a356 patch 8.2.0160: range test fails
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
2272 {
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19203
diff changeset
2273 varnumber_T new_start = l->lv_u.nonmat.lv_start
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19203
diff changeset
2274 + (l->lv_len - 1) * l->lv_u.nonmat.lv_stride;
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19203
diff changeset
2275 l->lv_u.nonmat.lv_end = new_start
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19203
diff changeset
2276 - (l->lv_u.nonmat.lv_end - l->lv_u.nonmat.lv_start);
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19203
diff changeset
2277 l->lv_u.nonmat.lv_start = new_start;
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19203
diff changeset
2278 l->lv_u.nonmat.lv_stride = -l->lv_u.nonmat.lv_stride;
19203
09f01421a356 patch 8.2.0160: range test fails
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
2279 rettv_list_set(rettv, l);
09f01421a356 patch 8.2.0160: range test fails
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
2280 return;
09f01421a356 patch 8.2.0160: range test fails
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
2281 }
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19203
diff changeset
2282 li = l->lv_u.mat.lv_last;
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19203
diff changeset
2283 l->lv_first = l->lv_u.mat.lv_last = NULL;
17970
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2284 l->lv_len = 0;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2285 while (li != NULL)
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2286 {
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2287 ni = li->li_prev;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2288 list_append(l, li);
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2289 li = ni;
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2290 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2291 rettv_list_set(rettv, l);
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19203
diff changeset
2292 l->lv_u.mat.lv_idx = l->lv_len - l->lv_u.mat.lv_idx - 1;
17970
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2293 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2294 }
684a15da9929 patch 8.1.1981: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17964
diff changeset
2295
17964
6d4d3bce365d patch 8.1.1978: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
2296 #endif // defined(FEAT_EVAL)