annotate src/blob.c @ 26668:f2579ccc97db v8.2.3863

patch 8.2.3863: various build flags accidentally enabled Commit: https://github.com/vim/vim/commit/8d95d7091da08d0a236be4a16616e3dda388e58d Author: Bram Moolenaar <Bram@vim.org> Date: Mon Dec 20 22:12:53 2021 +0000 patch 8.2.3863: various build flags accidentally enabled Problem: Various build flags accidentally enabled. Solution: Revert several lines in Makefile.
author Bram Moolenaar <Bram@vim.org>
date Mon, 20 Dec 2021 23:15:03 +0100
parents a3f38923c037
children 2126feddeda6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * blob.c: Blob support by Yasuhiro Matsumoto
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 */
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 #include "vim.h"
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 #if defined(FEAT_EVAL) || defined(PROTO)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 /*
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 * Allocate an empty blob.
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 * Caller should take care of the reference count.
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 */
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 blob_T *
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 blob_alloc(void)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 {
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16034
diff changeset
25 blob_T *blob = ALLOC_CLEAR_ONE(blob_T);
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 if (blob != NULL)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 ga_init2(&blob->bv_ga, 1, 100);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 return blob;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 /*
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 * Allocate an empty blob for a return value, with reference count set.
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 * Returns OK or FAIL.
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 */
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 int
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 rettv_blob_alloc(typval_T *rettv)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 blob_T *b = blob_alloc();
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 if (b == NULL)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 return FAIL;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 rettv_blob_set(rettv, b);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 return OK;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 /*
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 * Set a blob as the return value.
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 */
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 void
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 rettv_blob_set(typval_T *rettv, blob_T *b)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 rettv->v_type = VAR_BLOB;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 rettv->vval.v_blob = b;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 if (b != NULL)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 ++b->bv_refcount;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59
15581
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15515
diff changeset
60 int
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 18757
diff changeset
61 blob_copy(blob_T *from, typval_T *to)
15581
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15515
diff changeset
62 {
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15515
diff changeset
63 int ret = OK;
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15515
diff changeset
64
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15515
diff changeset
65 to->v_type = VAR_BLOB;
17344
a0eb2ff0f297 patch 8.1.1671: copying a blob may result in it being locked
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
66 to->v_lock = 0;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 18757
diff changeset
67 if (from == NULL)
15581
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15515
diff changeset
68 to->vval.v_blob = NULL;
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15515
diff changeset
69 else if (rettv_blob_alloc(to) == FAIL)
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15515
diff changeset
70 ret = FAIL;
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15515
diff changeset
71 else
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15515
diff changeset
72 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 18757
diff changeset
73 int len = from->bv_ga.ga_len;
15581
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15515
diff changeset
74
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15515
diff changeset
75 if (len > 0)
15589
44ea60ca593b patch 8.1.0802: negative index doesn't work for Blob
Bram Moolenaar <Bram@vim.org>
parents: 15581
diff changeset
76 {
15581
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15515
diff changeset
77 to->vval.v_blob->bv_ga.ga_data =
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 18757
diff changeset
78 vim_memsave(from->bv_ga.ga_data, len);
15589
44ea60ca593b patch 8.1.0802: negative index doesn't work for Blob
Bram Moolenaar <Bram@vim.org>
parents: 15581
diff changeset
79 if (to->vval.v_blob->bv_ga.ga_data == NULL)
44ea60ca593b patch 8.1.0802: negative index doesn't work for Blob
Bram Moolenaar <Bram@vim.org>
parents: 15581
diff changeset
80 len = 0;
44ea60ca593b patch 8.1.0802: negative index doesn't work for Blob
Bram Moolenaar <Bram@vim.org>
parents: 15581
diff changeset
81 }
15581
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15515
diff changeset
82 to->vval.v_blob->bv_ga.ga_len = len;
22635
9e249065aeac patch 8.2.1866: Vim9: appending to pushed blob gives wrong result
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
83 to->vval.v_blob->bv_ga.ga_maxlen = len;
15581
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15515
diff changeset
84 }
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15515
diff changeset
85 return ret;
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15515
diff changeset
86 }
c2382f0d1279 patch 8.1.0798: changing a blob while iterating over it works strangely
Bram Moolenaar <Bram@vim.org>
parents: 15515
diff changeset
87
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 void
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 blob_free(blob_T *b)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 ga_clear(&b->bv_ga);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 vim_free(b);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 /*
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 * Unreference a blob: decrement the reference count and free it when it
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 * becomes zero.
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 */
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 void
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 blob_unref(blob_T *b)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 if (b != NULL && --b->bv_refcount <= 0)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 blob_free(b);
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 /*
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 * Get the length of data.
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 */
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 long
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 blob_len(blob_T *b)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 if (b == NULL)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 return 0L;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 return b->bv_ga.ga_len;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 /*
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 * Get byte "idx" in blob "b".
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 * Caller must check that "idx" is valid.
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 */
15589
44ea60ca593b patch 8.1.0802: negative index doesn't work for Blob
Bram Moolenaar <Bram@vim.org>
parents: 15581
diff changeset
121 int
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 blob_get(blob_T *b, int idx)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 return ((char_u*)b->bv_ga.ga_data)[idx];
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 /*
24475
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24454
diff changeset
128 * Store one byte "byte" in blob "blob" at "idx".
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 * Caller must make sure that "idx" is valid.
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 */
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 void
24475
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24454
diff changeset
132 blob_set(blob_T *blob, int idx, int byte)
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24454
diff changeset
133 {
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24454
diff changeset
134 ((char_u*)blob->bv_ga.ga_data)[idx] = byte;
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24454
diff changeset
135 }
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24454
diff changeset
136
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24454
diff changeset
137 /*
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24454
diff changeset
138 * Store one byte "byte" in blob "blob" at "idx".
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24454
diff changeset
139 * Append one byte if needed.
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24454
diff changeset
140 */
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24454
diff changeset
141 void
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24454
diff changeset
142 blob_set_append(blob_T *blob, int idx, int byte)
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 {
24475
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24454
diff changeset
144 garray_T *gap = &blob->bv_ga;
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24454
diff changeset
145
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24454
diff changeset
146 // Allow for appending a byte. Setting a byte beyond
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24454
diff changeset
147 // the end is an error otherwise.
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24454
diff changeset
148 if (idx < gap->ga_len
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24454
diff changeset
149 || (idx == gap->ga_len && ga_grow(gap, 1) == OK))
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24454
diff changeset
150 {
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24454
diff changeset
151 blob_set(blob, idx, byte);
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24454
diff changeset
152 if (idx == gap->ga_len)
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24454
diff changeset
153 ++gap->ga_len;
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24454
diff changeset
154 }
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 /*
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 * Return TRUE when two blobs have exactly the same values.
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 */
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 int
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 blob_equal(
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 blob_T *b1,
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 blob_T *b2)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 {
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
165 int i;
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
166 int len1 = blob_len(b1);
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
167 int len2 = blob_len(b2);
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
169 // empty and NULL are considered the same
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
170 if (len1 == 0 && len2 == 0)
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
171 return TRUE;
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 if (b1 == b2)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 return TRUE;
15456
f01eb1aed348 patch 8.1.0736: code for Blob not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
174 if (len1 != len2)
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 return FALSE;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 for (i = 0; i < b1->bv_ga.ga_len; i++)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 if (blob_get(b1, i) != blob_get(b2, i)) return FALSE;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 return TRUE;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 /*
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 * Read "blob" from file "fd".
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 * Return OK or FAIL.
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 */
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 int
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 read_blob(FILE *fd, blob_T *blob)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 struct stat st;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 if (fstat(fileno(fd), &st) < 0)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 return FAIL;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 if (ga_grow(&blob->bv_ga, st.st_size) == FAIL)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 return FAIL;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 blob->bv_ga.ga_len = st.st_size;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 if (fread(blob->bv_ga.ga_data, 1, blob->bv_ga.ga_len, fd)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 < (size_t)blob->bv_ga.ga_len)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 return FAIL;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 return OK;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 /*
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 * Write "blob" to file "fd".
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 * Return OK or FAIL.
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 */
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 int
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 write_blob(FILE *fd, blob_T *blob)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 {
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 if (fwrite(blob->bv_ga.ga_data, 1, blob->bv_ga.ga_len, fd)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 < (size_t)blob->bv_ga.ga_len)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 {
26439
b18f3b0f317c patch 8.2.3750: error messages are everywhere
Bram Moolenaar <Bram@vim.org>
parents: 26394
diff changeset
212 emsg(_(e_error_while_writing));
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 return FAIL;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 return OK;
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 }
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217
15466
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
218 /*
15515
99a4cc4782ac patch 8.1.0765: string format of a Blob can't be parsed back
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
219 * Convert a blob to a readable form: "0z00112233.44556677.8899"
15466
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
220 */
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
221 char_u *
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
222 blob2string(blob_T *blob, char_u **tofree, char_u *numbuf)
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
223 {
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
224 int i;
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
225 garray_T ga;
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
226
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
227 if (blob == NULL)
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
228 {
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
229 *tofree = NULL;
15515
99a4cc4782ac patch 8.1.0765: string format of a Blob can't be parsed back
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
230 return (char_u *)"0z";
15466
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
231 }
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
232
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
233 // Store bytes in the growarray.
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
234 ga_init2(&ga, 1, 4000);
15515
99a4cc4782ac patch 8.1.0765: string format of a Blob can't be parsed back
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
235 ga_concat(&ga, (char_u *)"0z");
15466
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
236 for (i = 0; i < blob_len(blob); i++)
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
237 {
15515
99a4cc4782ac patch 8.1.0765: string format of a Blob can't be parsed back
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
238 if (i > 0 && (i & 3) == 0)
99a4cc4782ac patch 8.1.0765: string format of a Blob can't be parsed back
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
239 ga_concat(&ga, (char_u *)".");
99a4cc4782ac patch 8.1.0765: string format of a Blob can't be parsed back
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
240 vim_snprintf((char *)numbuf, NUMBUFLEN, "%02X", (int)blob_get(blob, i));
15466
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
241 ga_concat(&ga, numbuf);
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
242 }
26652
a3f38923c037 patch 8.2.3855: illegal memory access when displaying a blob
Bram Moolenaar <Bram@vim.org>
parents: 26439
diff changeset
243 ga_append(&ga, NUL); // append a NUL at the end
15466
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
244 *tofree = ga.ga_data;
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
245 return *tofree;
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
246 }
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
247
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
248 /*
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
249 * Convert a string variable, in the format of blob2string(), to a blob.
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
250 * Return NULL when conversion failed.
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
251 */
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
252 blob_T *
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
253 string2blob(char_u *str)
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
254 {
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
255 blob_T *blob = blob_alloc();
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
256 char_u *s = str;
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
257
16034
27f9f4c1400b patch 8.1.1022: may use NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 15589
diff changeset
258 if (blob == NULL)
27f9f4c1400b patch 8.1.1022: may use NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 15589
diff changeset
259 return NULL;
15515
99a4cc4782ac patch 8.1.0765: string format of a Blob can't be parsed back
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
260 if (s[0] != '0' || (s[1] != 'z' && s[1] != 'Z'))
15466
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
261 goto failed;
15515
99a4cc4782ac patch 8.1.0765: string format of a Blob can't be parsed back
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
262 s += 2;
99a4cc4782ac patch 8.1.0765: string format of a Blob can't be parsed back
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
263 while (vim_isxdigit(*s))
15466
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
264 {
15515
99a4cc4782ac patch 8.1.0765: string format of a Blob can't be parsed back
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
265 if (!vim_isxdigit(s[1]))
15466
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
266 goto failed;
15515
99a4cc4782ac patch 8.1.0765: string format of a Blob can't be parsed back
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
267 ga_append(&blob->bv_ga, (hex2nr(s[0]) << 4) + hex2nr(s[1]));
99a4cc4782ac patch 8.1.0765: string format of a Blob can't be parsed back
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
268 s += 2;
99a4cc4782ac patch 8.1.0765: string format of a Blob can't be parsed back
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
269 if (*s == '.' && vim_isxdigit(s[1]))
99a4cc4782ac patch 8.1.0765: string format of a Blob can't be parsed back
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
270 ++s;
15466
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
271 }
15515
99a4cc4782ac patch 8.1.0765: string format of a Blob can't be parsed back
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
272 if (*skipwhite(s) != NUL)
99a4cc4782ac patch 8.1.0765: string format of a Blob can't be parsed back
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
273 goto failed; // text after final digit
15466
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
274
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
275 ++blob->bv_refcount;
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
276 return blob;
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
277
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
278 failed:
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
279 blob_free(blob);
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
280 return NULL;
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
281 }
435fcefd2c8e patch 8.1.0741: viminfo with Blob is not tested
Bram Moolenaar <Bram@vim.org>
parents: 15456
diff changeset
282
24432
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
283 int
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
284 blob_slice_or_index(
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
285 blob_T *blob,
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
286 int is_range,
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
287 varnumber_T n1,
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
288 varnumber_T n2,
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
289 int exclusive,
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
290 typval_T *rettv)
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
291 {
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
292 long len = blob_len(blob);
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
293
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
294 if (is_range)
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
295 {
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
296 // The resulting variable is a sub-blob. If the indexes
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
297 // are out of range the result is empty.
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
298 if (n1 < 0)
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
299 {
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
300 n1 = len + n1;
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
301 if (n1 < 0)
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
302 n1 = 0;
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
303 }
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
304 if (n2 < 0)
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
305 n2 = len + n2;
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
306 else if (n2 >= len)
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
307 n2 = len - (exclusive ? 0 : 1);
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
308 if (exclusive)
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
309 --n2;
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
310 if (n1 >= len || n2 < 0 || n1 > n2)
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
311 {
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
312 clear_tv(rettv);
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
313 rettv->v_type = VAR_BLOB;
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
314 rettv->vval.v_blob = NULL;
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
315 }
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
316 else
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
317 {
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
318 blob_T *new_blob = blob_alloc();
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
319 long i;
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
320
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
321 if (new_blob != NULL)
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
322 {
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
323 if (ga_grow(&new_blob->bv_ga, n2 - n1 + 1) == FAIL)
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
324 {
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
325 blob_free(new_blob);
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
326 return FAIL;
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
327 }
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
328 new_blob->bv_ga.ga_len = n2 - n1 + 1;
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
329 for (i = n1; i <= n2; i++)
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
330 blob_set(new_blob, i - n1, blob_get(blob, i));
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
331
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
332 clear_tv(rettv);
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
333 rettv_blob_set(rettv, new_blob);
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
334 }
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
335 }
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
336 }
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
337 else
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
338 {
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
339 // The resulting variable is a byte value.
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
340 // If the index is too big or negative that is an error.
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
341 if (n1 < 0)
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
342 n1 = len + n1;
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
343 if (n1 < len && n1 >= 0)
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
344 {
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
345 int v = blob_get(blob, n1);
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
346
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
347 clear_tv(rettv);
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
348 rettv->v_type = VAR_NUMBER;
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
349 rettv->vval.v_number = v;
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
350 }
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
351 else
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
352 {
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
353 semsg(_(e_blobidx), n1);
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
354 return FAIL;
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
355 }
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
356 }
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
357 return OK;
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
358 }
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22635
diff changeset
359
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
360 /*
24450
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
361 * Check if "n1"- is a valid index for a blobl with length "bloblen".
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
362 */
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
363 int
24454
53216e87f21c patch 8.2.2767: compiler warning for unused argument
Bram Moolenaar <Bram@vim.org>
parents: 24450
diff changeset
364 check_blob_index(long bloblen, varnumber_T n1, int quiet)
24450
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
365 {
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
366 if (n1 < 0 || n1 > bloblen)
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
367 {
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
368 if (!quiet)
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
369 semsg(_(e_blobidx), n1);
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
370 return FAIL;
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
371 }
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
372 return OK;
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
373 }
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
374
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
375 /*
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
376 * Check if "n1"-"n2" is a valid range for a blob with length "bloblen".
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
377 */
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
378 int
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
379 check_blob_range(long bloblen, varnumber_T n1, varnumber_T n2, int quiet)
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
380 {
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
381 if (n2 < 0 || n2 >= bloblen || n2 < n1)
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
382 {
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
383 if (!quiet)
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
384 semsg(_(e_blobidx), n2);
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
385 return FAIL;
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
386 }
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
387 return OK;
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
388 }
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
389
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
390 /*
24434
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
391 * Set bytes "n1" to "n2" (inclusive) in "dest" to the value of "src".
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
392 * Caller must make sure "src" is a blob.
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
393 * Returns FAIL if the number of bytes does not match.
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
394 */
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
395 int
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
396 blob_set_range(blob_T *dest, long n1, long n2, typval_T *src)
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
397 {
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
398 int il, ir;
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
399
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
400 if (n2 - n1 + 1 != blob_len(src->vval.v_blob))
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
401 {
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
402 emsg(_("E972: Blob value does not have the right number of bytes"));
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
403 return FAIL;
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
404 }
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
405
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
406 ir = 0;
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
407 for (il = n1; il <= n2; il++)
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
408 blob_set(dest, il, blob_get(src->vval.v_blob, ir++));
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
409 return OK;
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
410 }
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
411
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
412 /*
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
413 * "remove({blob})" function
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
414 */
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
415 void
25495
7144d2ffc86b patch 8.2.3284: no error for insert() or remove() changing a locked blob
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
416 blob_remove(typval_T *argvars, typval_T *rettv, char_u *arg_errmsg)
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
417 {
25495
7144d2ffc86b patch 8.2.3284: no error for insert() or remove() changing a locked blob
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
418 blob_T *b = argvars[0].vval.v_blob;
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
419 int error = FALSE;
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24478
diff changeset
420 long idx;
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
421 long end;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
422
25495
7144d2ffc86b patch 8.2.3284: no error for insert() or remove() changing a locked blob
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
423 if (b != NULL && value_check_lock(b->bv_lock, arg_errmsg, TRUE))
7144d2ffc86b patch 8.2.3284: no error for insert() or remove() changing a locked blob
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
424 return;
7144d2ffc86b patch 8.2.3284: no error for insert() or remove() changing a locked blob
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
425
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24478
diff changeset
426 idx = (long)tv_get_number_chk(&argvars[1], &error);
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
427 if (!error)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
428 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
429 int len = blob_len(b);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
430 char_u *p;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
431
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
432 if (idx < 0)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
433 // count from the end
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
434 idx = len + idx;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
435 if (idx < 0 || idx >= len)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
436 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
437 semsg(_(e_blobidx), idx);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
438 return;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
439 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
440 if (argvars[2].v_type == VAR_UNKNOWN)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
441 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
442 // Remove one item, return its value.
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
443 p = (char_u *)b->bv_ga.ga_data;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
444 rettv->vval.v_number = (varnumber_T) *(p + idx);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
445 mch_memmove(p + idx, p + idx + 1, (size_t)len - idx - 1);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
446 --b->bv_ga.ga_len;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
447 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
448 else
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
449 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
450 blob_T *blob;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
451
24478
460b04d5897f patch 8.2.2779: memory access error in remove() for blob
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
452 // Remove range of items, return blob with values.
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
453 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: 17344
diff changeset
454 if (error)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
455 return;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
456 if (end < 0)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
457 // count from the end
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
458 end = len + end;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
459 if (end >= len || idx > end)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
460 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
461 semsg(_(e_blobidx), end);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
462 return;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
463 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
464 blob = blob_alloc();
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
465 if (blob == NULL)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
466 return;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
467 blob->bv_ga.ga_len = end - idx + 1;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
468 if (ga_grow(&blob->bv_ga, end - idx + 1) == FAIL)
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
469 {
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
470 vim_free(blob);
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
471 return;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
472 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
473 p = (char_u *)b->bv_ga.ga_data;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
474 mch_memmove((char_u *)blob->bv_ga.ga_data, p + idx,
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
475 (size_t)(end - idx + 1));
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
476 ++blob->bv_refcount;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
477 rettv->v_type = VAR_BLOB;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
478 rettv->vval.v_blob = blob;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
479
24478
460b04d5897f patch 8.2.2779: memory access error in remove() for blob
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
480 if (len - end - 1 > 0)
460b04d5897f patch 8.2.2779: memory access error in remove() for blob
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
481 mch_memmove(p + idx, p + end + 1, (size_t)(len - end - 1));
17530
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
482 b->bv_ga.ga_len -= end - idx + 1;
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
483 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
484 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
485 }
ef23ec1eee54 patch 8.1.1763: evalfunc.c is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17344
diff changeset
486
25806
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
487 /*
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
488 * blob2list() function
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
489 */
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
490 void
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
491 f_blob2list(typval_T *argvars, typval_T *rettv)
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
492 {
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
493 blob_T *blob;
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
494 list_T *l;
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
495 int i;
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
496
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
497 if (rettv_list_alloc(rettv) == FAIL)
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
498 return;
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
499
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
500 if (check_for_blob_arg(argvars, 0) == FAIL)
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
501 return;
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
502
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
503 blob = argvars->vval.v_blob;
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
504 l = rettv->vval.v_list;
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
505 for (i = 0; i < blob_len(blob); i++)
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
506 list_append_number(l, blob_get(blob, i));
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
507 }
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
508
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
509 /*
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
510 * list2blob() function
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
511 */
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
512 void
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
513 f_list2blob(typval_T *argvars, typval_T *rettv)
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
514 {
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
515 list_T *l;
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
516 listitem_T *li;
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
517 blob_T *blob;
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
518
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
519 if (rettv_blob_alloc(rettv) == FAIL)
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
520 return;
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
521 blob = rettv->vval.v_blob;
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
522
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
523 if (check_for_list_arg(argvars, 0) == FAIL)
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
524 return;
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
525
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
526 l = argvars->vval.v_list;
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
527 if (l == NULL)
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
528 return;
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
529
26394
43d196ca5e7a patch 8.2.3728: internal error when passing range() to list2blob()
Bram Moolenaar <Bram@vim.org>
parents: 25806
diff changeset
530 CHECK_LIST_MATERIALIZE(l);
25806
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
531 FOR_ALL_LIST_ITEMS(l, li)
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
532 {
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
533 int error;
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
534 varnumber_T n;
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
535
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
536 error = FALSE;
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
537 n = tv_get_number_chk(&li->li_tv, &error);
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
538 if (error == TRUE || n < 0 || n > 255)
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
539 {
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
540 if (!error)
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
541 semsg(_(e_invalid_value_for_blob_nr), n);
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
542 ga_clear(&blob->bv_ga);
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
543 return;
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
544 }
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
545 ga_append(&blob->bv_ga, n);
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
546 }
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
547 }
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25495
diff changeset
548
18757
c469e1930456 patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 17530
diff changeset
549 #endif // defined(FEAT_EVAL)