Mercurial > vim
annotate src/typval.c @ 21553:653fd30f7c53
Added tag v8.2.1326 for changeset cbc570e66d117c2c75f3a3cb38c6e717147b6349
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 30 Jul 2020 20:15:06 +0200 |
parents | a6c316ef161a |
children | d8422de73113 |
rev | line source |
---|---|
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 * |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 * |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 * typval.c: functions that deal with a typval |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 #include "vim.h" |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 #if defined(FEAT_EVAL) || defined(PROTO) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 * Allocate memory for a variable type-value, and make it empty (0 or NULL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 * value). |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 typval_T * |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 alloc_tv(void) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
24 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
25 return ALLOC_CLEAR_ONE(typval_T); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
27 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
28 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 * Allocate memory for a variable type-value, and assign a string to it. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 * The string "s" must have been allocated, it is consumed. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
31 * Return NULL for out of memory, the variable otherwise. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
33 typval_T * |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
34 alloc_string_tv(char_u *s) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
35 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 typval_T *rettv; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
37 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
38 rettv = alloc_tv(); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
39 if (rettv != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 rettv->v_type = VAR_STRING; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
42 rettv->vval.v_string = s; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
43 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 vim_free(s); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
46 return rettv; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
47 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
48 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
50 * Free the memory for a variable type-value. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
51 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
52 void |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
53 free_tv(typval_T *varp) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
54 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 if (varp != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
57 switch (varp->v_type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
59 case VAR_FUNC: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
60 func_unref(varp->vval.v_string); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
61 // FALLTHROUGH |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
62 case VAR_STRING: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 vim_free(varp->vval.v_string); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
64 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
65 case VAR_PARTIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 partial_unref(varp->vval.v_partial); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
67 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 case VAR_BLOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 blob_unref(varp->vval.v_blob); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
71 case VAR_LIST: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
72 list_unref(varp->vval.v_list); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
73 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 case VAR_DICT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
75 dict_unref(varp->vval.v_dict); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
76 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
77 case VAR_JOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
78 #ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
79 job_unref(varp->vval.v_job); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
80 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
81 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
82 case VAR_CHANNEL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
83 #ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
84 channel_unref(varp->vval.v_channel); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
85 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
86 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
87 case VAR_NUMBER: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
88 case VAR_FLOAT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
89 case VAR_ANY: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
90 case VAR_UNKNOWN: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
91 case VAR_VOID: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
92 case VAR_BOOL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
93 case VAR_SPECIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
94 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
95 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
96 vim_free(varp); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
97 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
98 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
99 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
100 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
101 * Free the memory for a variable value and set the value to NULL or 0. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
102 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
103 void |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
104 clear_tv(typval_T *varp) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
105 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
106 if (varp != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
107 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
108 switch (varp->v_type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
109 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
110 case VAR_FUNC: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
111 func_unref(varp->vval.v_string); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
112 // FALLTHROUGH |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
113 case VAR_STRING: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
114 VIM_CLEAR(varp->vval.v_string); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
115 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
116 case VAR_PARTIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
117 partial_unref(varp->vval.v_partial); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
118 varp->vval.v_partial = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
119 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
120 case VAR_BLOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
121 blob_unref(varp->vval.v_blob); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
122 varp->vval.v_blob = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
123 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
124 case VAR_LIST: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
125 list_unref(varp->vval.v_list); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
126 varp->vval.v_list = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
127 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
128 case VAR_DICT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
129 dict_unref(varp->vval.v_dict); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
130 varp->vval.v_dict = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
131 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
132 case VAR_NUMBER: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
133 case VAR_BOOL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
134 case VAR_SPECIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
135 varp->vval.v_number = 0; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
136 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
137 case VAR_FLOAT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
138 #ifdef FEAT_FLOAT |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
139 varp->vval.v_float = 0.0; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
140 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
141 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
142 case VAR_JOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
143 #ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
144 job_unref(varp->vval.v_job); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
145 varp->vval.v_job = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
146 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
147 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
148 case VAR_CHANNEL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
149 #ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
150 channel_unref(varp->vval.v_channel); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
151 varp->vval.v_channel = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
152 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
153 case VAR_UNKNOWN: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
154 case VAR_ANY: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
155 case VAR_VOID: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
156 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
157 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
158 varp->v_lock = 0; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
159 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
160 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
161 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
162 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
163 * Set the value of a variable to NULL without freeing items. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
164 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
165 void |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
166 init_tv(typval_T *varp) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
167 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
168 if (varp != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
169 CLEAR_POINTER(varp); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
170 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
171 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
172 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
173 * Get the number value of a variable. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
174 * If it is a String variable, uses vim_str2nr(). |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
175 * For incompatible types, return 0. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
176 * tv_get_number_chk() is similar to tv_get_number(), but informs the |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
177 * caller of incompatible types: it sets *denote to TRUE if "denote" |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
178 * is not NULL or returns -1 otherwise. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
179 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
180 varnumber_T |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
181 tv_get_number(typval_T *varp) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
182 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
183 int error = FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
184 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
185 return tv_get_number_chk(varp, &error); // return 0L on error |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
186 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
187 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
188 varnumber_T |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
189 tv_get_number_chk(typval_T *varp, int *denote) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
190 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
191 varnumber_T n = 0L; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
192 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
193 switch (varp->v_type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
194 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
195 case VAR_NUMBER: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
196 return varp->vval.v_number; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
197 case VAR_FLOAT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
198 #ifdef FEAT_FLOAT |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
199 emsg(_("E805: Using a Float as a Number")); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
200 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
201 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
202 case VAR_FUNC: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
203 case VAR_PARTIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
204 emsg(_("E703: Using a Funcref as a Number")); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
205 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
206 case VAR_STRING: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
207 if (varp->vval.v_string != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
208 vim_str2nr(varp->vval.v_string, NULL, NULL, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
209 STR2NR_ALL, &n, NULL, 0, FALSE); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
210 return n; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
211 case VAR_LIST: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
212 emsg(_("E745: Using a List as a Number")); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
213 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
214 case VAR_DICT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
215 emsg(_("E728: Using a Dictionary as a Number")); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
216 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
217 case VAR_BOOL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
218 case VAR_SPECIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
219 return varp->vval.v_number == VVAL_TRUE ? 1 : 0; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
220 case VAR_JOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
221 #ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
222 emsg(_("E910: Using a Job as a Number")); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
223 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
224 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
225 case VAR_CHANNEL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
226 #ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
227 emsg(_("E913: Using a Channel as a Number")); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
228 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
229 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
230 case VAR_BLOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
231 emsg(_("E974: Using a Blob as a Number")); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
232 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
233 case VAR_UNKNOWN: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
234 case VAR_ANY: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
235 case VAR_VOID: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
236 internal_error_no_abort("tv_get_number(UNKNOWN)"); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
237 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
238 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
239 if (denote == NULL) // useful for values that must be unsigned |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
240 n = -1; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
241 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
242 *denote = TRUE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
243 return n; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
244 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
245 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
246 #ifdef FEAT_FLOAT |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
247 float_T |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
248 tv_get_float(typval_T *varp) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
249 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
250 switch (varp->v_type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
251 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
252 case VAR_NUMBER: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
253 return (float_T)(varp->vval.v_number); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
254 case VAR_FLOAT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
255 return varp->vval.v_float; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
256 case VAR_FUNC: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
257 case VAR_PARTIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
258 emsg(_("E891: Using a Funcref as a Float")); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
259 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
260 case VAR_STRING: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
261 emsg(_("E892: Using a String as a Float")); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
262 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
263 case VAR_LIST: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
264 emsg(_("E893: Using a List as a Float")); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
265 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
266 case VAR_DICT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
267 emsg(_("E894: Using a Dictionary as a Float")); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
268 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
269 case VAR_BOOL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
270 emsg(_("E362: Using a boolean value as a Float")); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
271 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
272 case VAR_SPECIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
273 emsg(_("E907: Using a special value as a Float")); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
274 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
275 case VAR_JOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
276 # ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
277 emsg(_("E911: Using a Job as a Float")); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
278 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
279 # endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
280 case VAR_CHANNEL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
281 # ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
282 emsg(_("E914: Using a Channel as a Float")); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
283 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
284 # endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
285 case VAR_BLOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
286 emsg(_("E975: Using a Blob as a Float")); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
287 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
288 case VAR_UNKNOWN: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
289 case VAR_ANY: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
290 case VAR_VOID: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
291 internal_error_no_abort("tv_get_float(UNKNOWN)"); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
292 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
293 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
294 return 0; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
295 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
296 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
297 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
298 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
299 * Get the string value of a variable. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
300 * If it is a Number variable, the number is converted into a string. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
301 * tv_get_string() uses a single, static buffer. YOU CAN ONLY USE IT ONCE! |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
302 * tv_get_string_buf() uses a given buffer. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
303 * If the String variable has never been set, return an empty string. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
304 * Never returns NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
305 * tv_get_string_chk() and tv_get_string_buf_chk() are similar, but return |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
306 * NULL on error. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
307 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
308 char_u * |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
309 tv_get_string(typval_T *varp) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
310 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
311 static char_u mybuf[NUMBUFLEN]; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
312 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
313 return tv_get_string_buf(varp, mybuf); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
314 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
315 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
316 char_u * |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
317 tv_get_string_buf(typval_T *varp, char_u *buf) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
318 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
319 char_u *res = tv_get_string_buf_chk(varp, buf); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
320 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
321 return res != NULL ? res : (char_u *)""; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
322 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
323 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
324 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
325 * Careful: This uses a single, static buffer. YOU CAN ONLY USE IT ONCE! |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
326 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
327 char_u * |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
328 tv_get_string_chk(typval_T *varp) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
329 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
330 static char_u mybuf[NUMBUFLEN]; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
331 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
332 return tv_get_string_buf_chk(varp, mybuf); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
333 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
334 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
335 char_u * |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
336 tv_get_string_buf_chk(typval_T *varp, char_u *buf) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
337 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
338 switch (varp->v_type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
339 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
340 case VAR_NUMBER: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
341 vim_snprintf((char *)buf, NUMBUFLEN, "%lld", |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
342 (varnumber_T)varp->vval.v_number); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
343 return buf; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
344 case VAR_FUNC: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
345 case VAR_PARTIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
346 emsg(_("E729: using Funcref as a String")); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
347 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
348 case VAR_LIST: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
349 emsg(_("E730: using List as a String")); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
350 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
351 case VAR_DICT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
352 emsg(_("E731: using Dictionary as a String")); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
353 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
354 case VAR_FLOAT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
355 #ifdef FEAT_FLOAT |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
356 emsg(_(e_float_as_string)); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
357 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
358 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
359 case VAR_STRING: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
360 if (varp->vval.v_string != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
361 return varp->vval.v_string; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
362 return (char_u *)""; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
363 case VAR_BOOL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
364 case VAR_SPECIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
365 STRCPY(buf, get_var_special_name(varp->vval.v_number)); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
366 return buf; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
367 case VAR_BLOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
368 emsg(_("E976: using Blob as a String")); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
369 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
370 case VAR_JOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
371 #ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
372 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
373 job_T *job = varp->vval.v_job; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
374 char *status; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
375 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
376 if (job == NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
377 return (char_u *)"no process"; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
378 status = job->jv_status == JOB_FAILED ? "fail" |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
379 : job->jv_status >= JOB_ENDED ? "dead" |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
380 : "run"; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
381 # ifdef UNIX |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
382 vim_snprintf((char *)buf, NUMBUFLEN, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
383 "process %ld %s", (long)job->jv_pid, status); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
384 # elif defined(MSWIN) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
385 vim_snprintf((char *)buf, NUMBUFLEN, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
386 "process %ld %s", |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
387 (long)job->jv_proc_info.dwProcessId, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
388 status); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
389 # else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
390 // fall-back |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
391 vim_snprintf((char *)buf, NUMBUFLEN, "process ? %s", status); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
392 # endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
393 return buf; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
394 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
395 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
396 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
397 case VAR_CHANNEL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
398 #ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
399 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
400 channel_T *channel = varp->vval.v_channel; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
401 char *status = channel_status(channel, -1); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
402 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
403 if (channel == NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
404 vim_snprintf((char *)buf, NUMBUFLEN, "channel %s", status); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
405 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
406 vim_snprintf((char *)buf, NUMBUFLEN, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
407 "channel %d %s", channel->ch_id, status); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
408 return buf; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
409 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
410 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
411 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
412 case VAR_UNKNOWN: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
413 case VAR_ANY: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
414 case VAR_VOID: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
415 emsg(_(e_inval_string)); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
416 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
417 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
418 return NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
419 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
420 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
421 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
422 * Turn a typeval into a string. Similar to tv_get_string_buf() but uses |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
423 * string() on Dict, List, etc. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
424 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
425 char_u * |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
426 tv_stringify(typval_T *varp, char_u *buf) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
427 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
428 if (varp->v_type == VAR_LIST |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
429 || varp->v_type == VAR_DICT |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
430 || varp->v_type == VAR_BLOB |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
431 || varp->v_type == VAR_FUNC |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
432 || varp->v_type == VAR_PARTIAL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
433 || varp->v_type == VAR_FLOAT) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
434 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
435 typval_T tmp; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
436 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
437 f_string(varp, &tmp); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
438 tv_get_string_buf(&tmp, buf); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
439 clear_tv(varp); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
440 *varp = tmp; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
441 return tmp.vval.v_string; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
442 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
443 return tv_get_string_buf(varp, buf); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
444 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
445 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
446 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
447 * Return TRUE if typeval "tv" and its value are set to be locked (immutable). |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
448 * Also give an error message, using "name" or _("name") when use_gettext is |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
449 * TRUE. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
450 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
451 int |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
452 tv_check_lock(typval_T *tv, char_u *name, int use_gettext) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
453 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
454 int lock = 0; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
455 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
456 switch (tv->v_type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
457 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
458 case VAR_BLOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
459 if (tv->vval.v_blob != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
460 lock = tv->vval.v_blob->bv_lock; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
461 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
462 case VAR_LIST: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
463 if (tv->vval.v_list != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
464 lock = tv->vval.v_list->lv_lock; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
465 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
466 case VAR_DICT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
467 if (tv->vval.v_dict != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
468 lock = tv->vval.v_dict->dv_lock; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
469 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
470 default: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
471 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
472 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
473 return var_check_lock(tv->v_lock, name, use_gettext) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
474 || (lock != 0 && var_check_lock(lock, name, use_gettext)); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
475 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
476 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
477 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
478 * Copy the values from typval_T "from" to typval_T "to". |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
479 * When needed allocates string or increases reference count. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
480 * Does not make a copy of a list, blob or dict but copies the reference! |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
481 * It is OK for "from" and "to" to point to the same item. This is used to |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
482 * make a copy later. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
483 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
484 void |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
485 copy_tv(typval_T *from, typval_T *to) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
486 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
487 to->v_type = from->v_type; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
488 to->v_lock = 0; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
489 switch (from->v_type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
490 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
491 case VAR_NUMBER: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
492 case VAR_BOOL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
493 case VAR_SPECIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
494 to->vval.v_number = from->vval.v_number; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
495 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
496 case VAR_FLOAT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
497 #ifdef FEAT_FLOAT |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
498 to->vval.v_float = from->vval.v_float; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
499 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
500 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
501 case VAR_JOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
502 #ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
503 to->vval.v_job = from->vval.v_job; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
504 if (to->vval.v_job != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
505 ++to->vval.v_job->jv_refcount; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
506 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
507 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
508 case VAR_CHANNEL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
509 #ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
510 to->vval.v_channel = from->vval.v_channel; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
511 if (to->vval.v_channel != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
512 ++to->vval.v_channel->ch_refcount; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
513 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
514 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
515 case VAR_STRING: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
516 case VAR_FUNC: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
517 if (from->vval.v_string == NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
518 to->vval.v_string = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
519 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
520 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
521 to->vval.v_string = vim_strsave(from->vval.v_string); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
522 if (from->v_type == VAR_FUNC) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
523 func_ref(to->vval.v_string); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
524 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
525 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
526 case VAR_PARTIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
527 if (from->vval.v_partial == NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
528 to->vval.v_partial = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
529 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
530 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
531 to->vval.v_partial = from->vval.v_partial; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
532 ++to->vval.v_partial->pt_refcount; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
533 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
534 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
535 case VAR_BLOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
536 if (from->vval.v_blob == NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
537 to->vval.v_blob = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
538 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
539 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
540 to->vval.v_blob = from->vval.v_blob; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
541 ++to->vval.v_blob->bv_refcount; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
542 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
543 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
544 case VAR_LIST: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
545 if (from->vval.v_list == NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
546 to->vval.v_list = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
547 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
548 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
549 to->vval.v_list = from->vval.v_list; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
550 ++to->vval.v_list->lv_refcount; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
551 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
552 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
553 case VAR_DICT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
554 if (from->vval.v_dict == NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
555 to->vval.v_dict = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
556 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
557 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
558 to->vval.v_dict = from->vval.v_dict; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
559 ++to->vval.v_dict->dv_refcount; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
560 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
561 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
562 case VAR_UNKNOWN: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
563 case VAR_ANY: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
564 case VAR_VOID: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
565 internal_error_no_abort("copy_tv(UNKNOWN)"); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
566 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
567 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
568 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
569 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
570 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
571 * Compare "typ1" and "typ2". Put the result in "typ1". |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
572 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
573 int |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
574 typval_compare( |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
575 typval_T *typ1, // first operand |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
576 typval_T *typ2, // second operand |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
577 exptype_T type, // operator |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
578 int ic) // ignore case |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
579 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
580 int i; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
581 varnumber_T n1, n2; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
582 char_u *s1, *s2; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
583 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN]; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
584 int type_is = type == EXPR_IS || type == EXPR_ISNOT; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
585 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
586 if (type_is && typ1->v_type != typ2->v_type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
587 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
588 // For "is" a different type always means FALSE, for "notis" |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
589 // it means TRUE. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
590 n1 = (type == EXPR_ISNOT); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
591 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
592 else if (typ1->v_type == VAR_BLOB || typ2->v_type == VAR_BLOB) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
593 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
594 if (type_is) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
595 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
596 n1 = (typ1->v_type == typ2->v_type |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
597 && typ1->vval.v_blob == typ2->vval.v_blob); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
598 if (type == EXPR_ISNOT) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
599 n1 = !n1; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
600 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
601 else if (typ1->v_type != typ2->v_type |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
602 || (type != EXPR_EQUAL && type != EXPR_NEQUAL)) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
603 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
604 if (typ1->v_type != typ2->v_type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
605 emsg(_("E977: Can only compare Blob with Blob")); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
606 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
607 emsg(_(e_invalblob)); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
608 clear_tv(typ1); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
609 return FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
610 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
611 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
612 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
613 // Compare two Blobs for being equal or unequal. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
614 n1 = blob_equal(typ1->vval.v_blob, typ2->vval.v_blob); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
615 if (type == EXPR_NEQUAL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
616 n1 = !n1; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
617 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
618 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
619 else if (typ1->v_type == VAR_LIST || typ2->v_type == VAR_LIST) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
620 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
621 if (type_is) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
622 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
623 n1 = (typ1->v_type == typ2->v_type |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
624 && typ1->vval.v_list == typ2->vval.v_list); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
625 if (type == EXPR_ISNOT) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
626 n1 = !n1; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
627 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
628 else if (typ1->v_type != typ2->v_type |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
629 || (type != EXPR_EQUAL && type != EXPR_NEQUAL)) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
630 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
631 if (typ1->v_type != typ2->v_type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
632 emsg(_("E691: Can only compare List with List")); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
633 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
634 emsg(_("E692: Invalid operation for List")); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
635 clear_tv(typ1); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
636 return FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
637 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
638 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
639 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
640 // Compare two Lists for being equal or unequal. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
641 n1 = list_equal(typ1->vval.v_list, typ2->vval.v_list, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
642 ic, FALSE); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
643 if (type == EXPR_NEQUAL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
644 n1 = !n1; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
645 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
646 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
647 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
648 else if (typ1->v_type == VAR_DICT || typ2->v_type == VAR_DICT) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
649 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
650 if (type_is) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
651 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
652 n1 = (typ1->v_type == typ2->v_type |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
653 && typ1->vval.v_dict == typ2->vval.v_dict); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
654 if (type == EXPR_ISNOT) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
655 n1 = !n1; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
656 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
657 else if (typ1->v_type != typ2->v_type |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
658 || (type != EXPR_EQUAL && type != EXPR_NEQUAL)) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
659 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
660 if (typ1->v_type != typ2->v_type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
661 emsg(_("E735: Can only compare Dictionary with Dictionary")); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
662 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
663 emsg(_("E736: Invalid operation for Dictionary")); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
664 clear_tv(typ1); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
665 return FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
666 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
667 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
668 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
669 // Compare two Dictionaries for being equal or unequal. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
670 n1 = dict_equal(typ1->vval.v_dict, typ2->vval.v_dict, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
671 ic, FALSE); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
672 if (type == EXPR_NEQUAL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
673 n1 = !n1; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
674 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
675 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
676 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
677 else if (typ1->v_type == VAR_FUNC || typ2->v_type == VAR_FUNC |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
678 || typ1->v_type == VAR_PARTIAL || typ2->v_type == VAR_PARTIAL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
679 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
680 if (type != EXPR_EQUAL && type != EXPR_NEQUAL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
681 && type != EXPR_IS && type != EXPR_ISNOT) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
682 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
683 emsg(_("E694: Invalid operation for Funcrefs")); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
684 clear_tv(typ1); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
685 return FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
686 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
687 if ((typ1->v_type == VAR_PARTIAL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
688 && typ1->vval.v_partial == NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
689 || (typ2->v_type == VAR_PARTIAL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
690 && typ2->vval.v_partial == NULL)) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
691 // When both partials are NULL, then they are equal. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
692 // Otherwise they are not equal. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
693 n1 = (typ1->vval.v_partial == typ2->vval.v_partial); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
694 else if (type_is) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
695 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
696 if (typ1->v_type == VAR_FUNC && typ2->v_type == VAR_FUNC) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
697 // strings are considered the same if their value is |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
698 // the same |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
699 n1 = tv_equal(typ1, typ2, ic, FALSE); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
700 else if (typ1->v_type == VAR_PARTIAL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
701 && typ2->v_type == VAR_PARTIAL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
702 n1 = (typ1->vval.v_partial == typ2->vval.v_partial); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
703 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
704 n1 = FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
705 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
706 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
707 n1 = tv_equal(typ1, typ2, ic, FALSE); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
708 if (type == EXPR_NEQUAL || type == EXPR_ISNOT) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
709 n1 = !n1; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
710 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
711 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
712 #ifdef FEAT_FLOAT |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
713 // If one of the two variables is a float, compare as a float. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
714 // When using "=~" or "!~", always compare as string. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
715 else if ((typ1->v_type == VAR_FLOAT || typ2->v_type == VAR_FLOAT) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
716 && type != EXPR_MATCH && type != EXPR_NOMATCH) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
717 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
718 float_T f1, f2; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
719 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
720 f1 = tv_get_float(typ1); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
721 f2 = tv_get_float(typ2); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
722 n1 = FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
723 switch (type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
724 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
725 case EXPR_IS: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
726 case EXPR_EQUAL: n1 = (f1 == f2); break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
727 case EXPR_ISNOT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
728 case EXPR_NEQUAL: n1 = (f1 != f2); break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
729 case EXPR_GREATER: n1 = (f1 > f2); break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
730 case EXPR_GEQUAL: n1 = (f1 >= f2); break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
731 case EXPR_SMALLER: n1 = (f1 < f2); break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
732 case EXPR_SEQUAL: n1 = (f1 <= f2); break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
733 case EXPR_UNKNOWN: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
734 case EXPR_MATCH: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
735 default: break; // avoid gcc warning |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
736 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
737 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
738 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
739 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
740 // If one of the two variables is a number, compare as a number. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
741 // When using "=~" or "!~", always compare as string. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
742 else if ((typ1->v_type == VAR_NUMBER || typ2->v_type == VAR_NUMBER) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
743 && type != EXPR_MATCH && type != EXPR_NOMATCH) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
744 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
745 n1 = tv_get_number(typ1); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
746 n2 = tv_get_number(typ2); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
747 switch (type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
748 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
749 case EXPR_IS: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
750 case EXPR_EQUAL: n1 = (n1 == n2); break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
751 case EXPR_ISNOT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
752 case EXPR_NEQUAL: n1 = (n1 != n2); break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
753 case EXPR_GREATER: n1 = (n1 > n2); break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
754 case EXPR_GEQUAL: n1 = (n1 >= n2); break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
755 case EXPR_SMALLER: n1 = (n1 < n2); break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
756 case EXPR_SEQUAL: n1 = (n1 <= n2); break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
757 case EXPR_UNKNOWN: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
758 case EXPR_MATCH: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
759 default: break; // avoid gcc warning |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
760 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
761 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
762 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
763 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
764 s1 = tv_get_string_buf(typ1, buf1); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
765 s2 = tv_get_string_buf(typ2, buf2); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
766 if (type != EXPR_MATCH && type != EXPR_NOMATCH) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
767 i = ic ? MB_STRICMP(s1, s2) : STRCMP(s1, s2); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
768 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
769 i = 0; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
770 n1 = FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
771 switch (type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
772 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
773 case EXPR_IS: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
774 case EXPR_EQUAL: n1 = (i == 0); break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
775 case EXPR_ISNOT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
776 case EXPR_NEQUAL: n1 = (i != 0); break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
777 case EXPR_GREATER: n1 = (i > 0); break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
778 case EXPR_GEQUAL: n1 = (i >= 0); break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
779 case EXPR_SMALLER: n1 = (i < 0); break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
780 case EXPR_SEQUAL: n1 = (i <= 0); break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
781 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
782 case EXPR_MATCH: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
783 case EXPR_NOMATCH: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
784 n1 = pattern_match(s2, s1, ic); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
785 if (type == EXPR_NOMATCH) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
786 n1 = !n1; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
787 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
788 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
789 default: break; // avoid gcc warning |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
790 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
791 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
792 clear_tv(typ1); |
21425
a6c316ef161a
patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
793 if (in_vim9script()) |
a6c316ef161a
patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
794 { |
a6c316ef161a
patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
795 typ1->v_type = VAR_BOOL; |
a6c316ef161a
patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
796 typ1->vval.v_number = n1 ? VVAL_TRUE : VVAL_FALSE; |
a6c316ef161a
patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
797 } |
a6c316ef161a
patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
798 else |
a6c316ef161a
patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
799 { |
a6c316ef161a
patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
800 typ1->v_type = VAR_NUMBER; |
a6c316ef161a
patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
801 typ1->vval.v_number = n1; |
a6c316ef161a
patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
802 } |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
803 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
804 return OK; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
805 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
806 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
807 char_u * |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
808 typval_tostring(typval_T *arg) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
809 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
810 char_u *tofree; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
811 char_u numbuf[NUMBUFLEN]; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
812 char_u *ret = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
813 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
814 if (arg == NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
815 return vim_strsave((char_u *)"(does not exist)"); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
816 ret = tv2string(arg, &tofree, numbuf, 0); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
817 // Make a copy if we have a value but it's not in allocated memory. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
818 if (ret != NULL && tofree == NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
819 ret = vim_strsave(ret); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
820 return ret; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
821 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
822 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
823 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
824 * Return TRUE if typeval "tv" is locked: Either that value is locked itself |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
825 * or it refers to a List or Dictionary that is locked. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
826 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
827 int |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
828 tv_islocked(typval_T *tv) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
829 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
830 return (tv->v_lock & VAR_LOCKED) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
831 || (tv->v_type == VAR_LIST |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
832 && tv->vval.v_list != NULL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
833 && (tv->vval.v_list->lv_lock & VAR_LOCKED)) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
834 || (tv->v_type == VAR_DICT |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
835 && tv->vval.v_dict != NULL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
836 && (tv->vval.v_dict->dv_lock & VAR_LOCKED)); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
837 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
838 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
839 static int |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
840 func_equal( |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
841 typval_T *tv1, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
842 typval_T *tv2, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
843 int ic) // ignore case |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
844 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
845 char_u *s1, *s2; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
846 dict_T *d1, *d2; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
847 int a1, a2; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
848 int i; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
849 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
850 // empty and NULL function name considered the same |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
851 s1 = tv1->v_type == VAR_FUNC ? tv1->vval.v_string |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
852 : partial_name(tv1->vval.v_partial); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
853 if (s1 != NULL && *s1 == NUL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
854 s1 = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
855 s2 = tv2->v_type == VAR_FUNC ? tv2->vval.v_string |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
856 : partial_name(tv2->vval.v_partial); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
857 if (s2 != NULL && *s2 == NUL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
858 s2 = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
859 if (s1 == NULL || s2 == NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
860 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
861 if (s1 != s2) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
862 return FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
863 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
864 else if (STRCMP(s1, s2) != 0) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
865 return FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
866 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
867 // empty dict and NULL dict is different |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
868 d1 = tv1->v_type == VAR_FUNC ? NULL : tv1->vval.v_partial->pt_dict; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
869 d2 = tv2->v_type == VAR_FUNC ? NULL : tv2->vval.v_partial->pt_dict; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
870 if (d1 == NULL || d2 == NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
871 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
872 if (d1 != d2) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
873 return FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
874 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
875 else if (!dict_equal(d1, d2, ic, TRUE)) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
876 return FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
877 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
878 // empty list and no list considered the same |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
879 a1 = tv1->v_type == VAR_FUNC ? 0 : tv1->vval.v_partial->pt_argc; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
880 a2 = tv2->v_type == VAR_FUNC ? 0 : tv2->vval.v_partial->pt_argc; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
881 if (a1 != a2) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
882 return FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
883 for (i = 0; i < a1; ++i) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
884 if (!tv_equal(tv1->vval.v_partial->pt_argv + i, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
885 tv2->vval.v_partial->pt_argv + i, ic, TRUE)) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
886 return FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
887 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
888 return TRUE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
889 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
890 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
891 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
892 * Return TRUE if "tv1" and "tv2" have the same value. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
893 * Compares the items just like "==" would compare them, but strings and |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
894 * numbers are different. Floats and numbers are also different. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
895 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
896 int |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
897 tv_equal( |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
898 typval_T *tv1, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
899 typval_T *tv2, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
900 int ic, // ignore case |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
901 int recursive) // TRUE when used recursively |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
902 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
903 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN]; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
904 char_u *s1, *s2; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
905 static int recursive_cnt = 0; // catch recursive loops |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
906 int r; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
907 static int tv_equal_recurse_limit; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
908 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
909 // Catch lists and dicts that have an endless loop by limiting |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
910 // recursiveness to a limit. We guess they are equal then. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
911 // A fixed limit has the problem of still taking an awful long time. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
912 // Reduce the limit every time running into it. That should work fine for |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
913 // deeply linked structures that are not recursively linked and catch |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
914 // recursiveness quickly. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
915 if (!recursive) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
916 tv_equal_recurse_limit = 1000; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
917 if (recursive_cnt >= tv_equal_recurse_limit) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
918 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
919 --tv_equal_recurse_limit; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
920 return TRUE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
921 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
922 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
923 // For VAR_FUNC and VAR_PARTIAL compare the function name, bound dict and |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
924 // arguments. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
925 if ((tv1->v_type == VAR_FUNC |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
926 || (tv1->v_type == VAR_PARTIAL && tv1->vval.v_partial != NULL)) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
927 && (tv2->v_type == VAR_FUNC |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
928 || (tv2->v_type == VAR_PARTIAL && tv2->vval.v_partial != NULL))) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
929 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
930 ++recursive_cnt; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
931 r = func_equal(tv1, tv2, ic); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
932 --recursive_cnt; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
933 return r; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
934 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
935 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
936 if (tv1->v_type != tv2->v_type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
937 return FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
938 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
939 switch (tv1->v_type) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
940 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
941 case VAR_LIST: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
942 ++recursive_cnt; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
943 r = list_equal(tv1->vval.v_list, tv2->vval.v_list, ic, TRUE); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
944 --recursive_cnt; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
945 return r; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
946 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
947 case VAR_DICT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
948 ++recursive_cnt; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
949 r = dict_equal(tv1->vval.v_dict, tv2->vval.v_dict, ic, TRUE); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
950 --recursive_cnt; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
951 return r; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
952 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
953 case VAR_BLOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
954 return blob_equal(tv1->vval.v_blob, tv2->vval.v_blob); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
955 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
956 case VAR_NUMBER: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
957 case VAR_BOOL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
958 case VAR_SPECIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
959 return tv1->vval.v_number == tv2->vval.v_number; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
960 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
961 case VAR_STRING: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
962 s1 = tv_get_string_buf(tv1, buf1); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
963 s2 = tv_get_string_buf(tv2, buf2); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
964 return ((ic ? MB_STRICMP(s1, s2) : STRCMP(s1, s2)) == 0); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
965 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
966 case VAR_FLOAT: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
967 #ifdef FEAT_FLOAT |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
968 return tv1->vval.v_float == tv2->vval.v_float; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
969 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
970 case VAR_JOB: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
971 #ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
972 return tv1->vval.v_job == tv2->vval.v_job; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
973 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
974 case VAR_CHANNEL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
975 #ifdef FEAT_JOB_CHANNEL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
976 return tv1->vval.v_channel == tv2->vval.v_channel; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
977 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
978 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
979 case VAR_PARTIAL: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
980 return tv1->vval.v_partial == tv2->vval.v_partial; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
981 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
982 case VAR_FUNC: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
983 return tv1->vval.v_string == tv2->vval.v_string; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
984 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
985 case VAR_UNKNOWN: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
986 case VAR_ANY: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
987 case VAR_VOID: |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
988 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
989 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
990 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
991 // VAR_UNKNOWN can be the result of a invalid expression, let's say it |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
992 // does not equal anything, not even itself. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
993 return FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
994 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
995 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
996 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
997 * Get an option value. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
998 * "arg" points to the '&' or '+' before the option name. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
999 * "arg" is advanced to character after the option name. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1000 * Return OK or FAIL. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1001 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1002 int |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
20925
diff
changeset
|
1003 eval_option( |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1004 char_u **arg, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1005 typval_T *rettv, // when NULL, only check if option exists |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1006 int evaluate) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1007 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1008 char_u *option_end; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1009 long numval; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1010 char_u *stringval; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1011 int opt_type; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1012 int c; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1013 int working = (**arg == '+'); // has("+option") |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1014 int ret = OK; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1015 int opt_flags; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1016 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1017 // Isolate the option name and find its value. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1018 option_end = find_option_end(arg, &opt_flags); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1019 if (option_end == NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1020 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1021 if (rettv != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1022 semsg(_("E112: Option name missing: %s"), *arg); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1023 return FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1024 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1025 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1026 if (!evaluate) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1027 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1028 *arg = option_end; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1029 return OK; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1030 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1031 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1032 c = *option_end; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1033 *option_end = NUL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1034 opt_type = get_option_value(*arg, &numval, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1035 rettv == NULL ? NULL : &stringval, opt_flags); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1036 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1037 if (opt_type == -3) // invalid name |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1038 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1039 if (rettv != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1040 semsg(_(e_unknown_option), *arg); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1041 ret = FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1042 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1043 else if (rettv != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1044 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1045 if (opt_type == -2) // hidden string option |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1046 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1047 rettv->v_type = VAR_STRING; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1048 rettv->vval.v_string = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1049 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1050 else if (opt_type == -1) // hidden number option |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1051 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1052 rettv->v_type = VAR_NUMBER; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1053 rettv->vval.v_number = 0; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1054 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1055 else if (opt_type == 1) // number option |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1056 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1057 rettv->v_type = VAR_NUMBER; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1058 rettv->vval.v_number = numval; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1059 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1060 else // string option |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1061 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1062 rettv->v_type = VAR_STRING; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1063 rettv->vval.v_string = stringval; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1064 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1065 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1066 else if (working && (opt_type == -2 || opt_type == -1)) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1067 ret = FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1068 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1069 *option_end = c; // put back for error messages |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1070 *arg = option_end; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1071 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1072 return ret; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1073 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1074 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1075 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1076 * Allocate a variable for a number constant. Also deals with "0z" for blob. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1077 * Return OK or FAIL. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1078 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1079 int |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
20925
diff
changeset
|
1080 eval_number( |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1081 char_u **arg, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1082 typval_T *rettv, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1083 int evaluate, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1084 int want_string UNUSED) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1085 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1086 int len; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1087 #ifdef FEAT_FLOAT |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1088 char_u *p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1089 int get_float = FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1090 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1091 // We accept a float when the format matches |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1092 // "[0-9]\+\.[0-9]\+\([eE][+-]\?[0-9]\+\)\?". This is very |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1093 // strict to avoid backwards compatibility problems. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1094 // With script version 2 and later the leading digit can be |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1095 // omitted. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1096 // Don't look for a float after the "." operator, so that |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1097 // ":let vers = 1.2.3" doesn't fail. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1098 if (**arg == '.') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1099 p = *arg; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1100 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1101 p = skipdigits(*arg + 1); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1102 if (!want_string && p[0] == '.' && vim_isdigit(p[1])) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1103 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1104 get_float = TRUE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1105 p = skipdigits(p + 2); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1106 if (*p == 'e' || *p == 'E') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1107 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1108 ++p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1109 if (*p == '-' || *p == '+') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1110 ++p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1111 if (!vim_isdigit(*p)) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1112 get_float = FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1113 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1114 p = skipdigits(p + 1); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1115 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1116 if (ASCII_ISALPHA(*p) || *p == '.') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1117 get_float = FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1118 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1119 if (get_float) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1120 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1121 float_T f; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1122 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1123 *arg += string2float(*arg, &f); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1124 if (evaluate) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1125 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1126 rettv->v_type = VAR_FLOAT; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1127 rettv->vval.v_float = f; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1128 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1129 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1130 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1131 #endif |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1132 if (**arg == '0' && ((*arg)[1] == 'z' || (*arg)[1] == 'Z')) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1133 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1134 char_u *bp; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1135 blob_T *blob = NULL; // init for gcc |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1136 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1137 // Blob constant: 0z0123456789abcdef |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1138 if (evaluate) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1139 blob = blob_alloc(); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1140 for (bp = *arg + 2; vim_isxdigit(bp[0]); bp += 2) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1141 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1142 if (!vim_isxdigit(bp[1])) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1143 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1144 if (blob != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1145 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1146 emsg(_("E973: Blob literal should have an even number of hex characters")); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1147 ga_clear(&blob->bv_ga); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1148 VIM_CLEAR(blob); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1149 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1150 return FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1151 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1152 if (blob != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1153 ga_append(&blob->bv_ga, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1154 (hex2nr(*bp) << 4) + hex2nr(*(bp+1))); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1155 if (bp[2] == '.' && vim_isxdigit(bp[3])) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1156 ++bp; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1157 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1158 if (blob != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1159 rettv_blob_set(rettv, blob); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1160 *arg = bp; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1161 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1162 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1163 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1164 varnumber_T n; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1165 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1166 // decimal, hex or octal number |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1167 vim_str2nr(*arg, NULL, &len, current_sctx.sc_version >= 4 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1168 ? STR2NR_NO_OCT + STR2NR_QUOTE |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1169 : STR2NR_ALL, &n, NULL, 0, TRUE); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1170 if (len == 0) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1171 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1172 semsg(_(e_invexpr2), *arg); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1173 return FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1174 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1175 *arg += len; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1176 if (evaluate) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1177 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1178 rettv->v_type = VAR_NUMBER; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1179 rettv->vval.v_number = n; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1180 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1181 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1182 return OK; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1183 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1184 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1185 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1186 * Allocate a variable for a string constant. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1187 * Return OK or FAIL. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1188 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1189 int |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
20925
diff
changeset
|
1190 eval_string(char_u **arg, typval_T *rettv, int evaluate) |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1191 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1192 char_u *p; |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1193 char_u *end; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1194 int extra = 0; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1195 int len; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1196 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1197 // Find the end of the string, skipping backslashed characters. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1198 for (p = *arg + 1; *p != NUL && *p != '"'; MB_PTR_ADV(p)) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1199 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1200 if (*p == '\\' && p[1] != NUL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1201 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1202 ++p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1203 // A "\<x>" form occupies at least 4 characters, and produces up |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1204 // to 21 characters (3 * 6 for the char and 3 for a modifier): |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1205 // reserve space for 18 extra. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1206 // Each byte in the char could be encoded as K_SPECIAL K_EXTRA x. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1207 if (*p == '<') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1208 extra += 18; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1209 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1210 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1211 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1212 if (*p != '"') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1213 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1214 semsg(_("E114: Missing quote: %s"), *arg); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1215 return FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1216 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1217 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1218 // If only parsing, set *arg and return here |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1219 if (!evaluate) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1220 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1221 *arg = p + 1; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1222 return OK; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1223 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1224 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1225 // Copy the string into allocated memory, handling backslashed |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1226 // characters. |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1227 rettv->v_type = VAR_STRING; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1228 len = (int)(p - *arg + extra); |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1229 rettv->vval.v_string = alloc(len); |
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1230 if (rettv->vval.v_string == NULL) |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1231 return FAIL; |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1232 end = rettv->vval.v_string; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1233 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1234 for (p = *arg + 1; *p != NUL && *p != '"'; ) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1235 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1236 if (*p == '\\') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1237 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1238 switch (*++p) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1239 { |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1240 case 'b': *end++ = BS; ++p; break; |
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1241 case 'e': *end++ = ESC; ++p; break; |
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1242 case 'f': *end++ = FF; ++p; break; |
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1243 case 'n': *end++ = NL; ++p; break; |
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1244 case 'r': *end++ = CAR; ++p; break; |
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1245 case 't': *end++ = TAB; ++p; break; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1246 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1247 case 'X': // hex: "\x1", "\x12" |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1248 case 'x': |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1249 case 'u': // Unicode: "\u0023" |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1250 case 'U': |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1251 if (vim_isxdigit(p[1])) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1252 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1253 int n, nr; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1254 int c = toupper(*p); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1255 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1256 if (c == 'X') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1257 n = 2; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1258 else if (*p == 'u') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1259 n = 4; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1260 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1261 n = 8; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1262 nr = 0; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1263 while (--n >= 0 && vim_isxdigit(p[1])) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1264 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1265 ++p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1266 nr = (nr << 4) + hex2nr(*p); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1267 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1268 ++p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1269 // For "\u" store the number according to |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1270 // 'encoding'. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1271 if (c != 'X') |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1272 end += (*mb_char2bytes)(nr, end); |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1273 else |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1274 *end++ = nr; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1275 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1276 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1277 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1278 // octal: "\1", "\12", "\123" |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1279 case '0': |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1280 case '1': |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1281 case '2': |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1282 case '3': |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1283 case '4': |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1284 case '5': |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1285 case '6': |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1286 case '7': *end = *p++ - '0'; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1287 if (*p >= '0' && *p <= '7') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1288 { |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1289 *end = (*end << 3) + *p++ - '0'; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1290 if (*p >= '0' && *p <= '7') |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1291 *end = (*end << 3) + *p++ - '0'; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1292 } |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1293 ++end; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1294 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1295 |
20627
8bce783af0cb
patch 8.2.0867: using {xxx} for encoding a modifier is not nice
Bram Moolenaar <Bram@vim.org>
parents:
20603
diff
changeset
|
1296 // Special key, e.g.: "\<C-W>" |
20603
c2570baa2e4c
patch 8.2.0855: GUI tests fail because the test doesn't use a modifier
Bram Moolenaar <Bram@vim.org>
parents:
20587
diff
changeset
|
1297 case '<': |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1298 { |
20603
c2570baa2e4c
patch 8.2.0855: GUI tests fail because the test doesn't use a modifier
Bram Moolenaar <Bram@vim.org>
parents:
20587
diff
changeset
|
1299 int flags = FSK_KEYCODE | FSK_IN_STRING; |
c2570baa2e4c
patch 8.2.0855: GUI tests fail because the test doesn't use a modifier
Bram Moolenaar <Bram@vim.org>
parents:
20587
diff
changeset
|
1300 |
20627
8bce783af0cb
patch 8.2.0867: using {xxx} for encoding a modifier is not nice
Bram Moolenaar <Bram@vim.org>
parents:
20603
diff
changeset
|
1301 if (p[1] != '*') |
20603
c2570baa2e4c
patch 8.2.0855: GUI tests fail because the test doesn't use a modifier
Bram Moolenaar <Bram@vim.org>
parents:
20587
diff
changeset
|
1302 flags |= FSK_SIMPLIFY; |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1303 extra = trans_special(&p, end, flags, NULL); |
20603
c2570baa2e4c
patch 8.2.0855: GUI tests fail because the test doesn't use a modifier
Bram Moolenaar <Bram@vim.org>
parents:
20587
diff
changeset
|
1304 if (extra != 0) |
c2570baa2e4c
patch 8.2.0855: GUI tests fail because the test doesn't use a modifier
Bram Moolenaar <Bram@vim.org>
parents:
20587
diff
changeset
|
1305 { |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1306 end += extra; |
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1307 if (end >= rettv->vval.v_string + len) |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
20925
diff
changeset
|
1308 iemsg("eval_string() used more space than allocated"); |
20603
c2570baa2e4c
patch 8.2.0855: GUI tests fail because the test doesn't use a modifier
Bram Moolenaar <Bram@vim.org>
parents:
20587
diff
changeset
|
1309 break; |
c2570baa2e4c
patch 8.2.0855: GUI tests fail because the test doesn't use a modifier
Bram Moolenaar <Bram@vim.org>
parents:
20587
diff
changeset
|
1310 } |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1311 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1312 // FALLTHROUGH |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1313 |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1314 default: MB_COPY_CHAR(p, end); |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1315 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1316 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1317 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1318 else |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1319 MB_COPY_CHAR(p, end); |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1320 } |
20925
0aeac2b45846
patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20627
diff
changeset
|
1321 *end = NUL; |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1322 if (*p != NUL) // just in case |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1323 ++p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1324 *arg = p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1325 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1326 return OK; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1327 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1328 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1329 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1330 * Allocate a variable for a 'str''ing' constant. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1331 * Return OK or FAIL. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1332 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1333 int |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
20925
diff
changeset
|
1334 eval_lit_string(char_u **arg, typval_T *rettv, int evaluate) |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1335 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1336 char_u *p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1337 char_u *str; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1338 int reduce = 0; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1339 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1340 // Find the end of the string, skipping ''. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1341 for (p = *arg + 1; *p != NUL; MB_PTR_ADV(p)) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1342 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1343 if (*p == '\'') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1344 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1345 if (p[1] != '\'') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1346 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1347 ++reduce; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1348 ++p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1349 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1350 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1351 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1352 if (*p != '\'') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1353 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1354 semsg(_("E115: Missing quote: %s"), *arg); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1355 return FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1356 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1357 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1358 // If only parsing return after setting "*arg" |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1359 if (!evaluate) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1360 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1361 *arg = p + 1; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1362 return OK; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1363 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1364 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1365 // Copy the string into allocated memory, handling '' to ' reduction. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1366 str = alloc((p - *arg) - reduce); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1367 if (str == NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1368 return FAIL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1369 rettv->v_type = VAR_STRING; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1370 rettv->vval.v_string = str; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1371 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1372 for (p = *arg + 1; *p != NUL; ) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1373 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1374 if (*p == '\'') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1375 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1376 if (p[1] != '\'') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1377 break; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1378 ++p; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1379 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1380 MB_COPY_CHAR(p, str); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1381 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1382 *str = NUL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1383 *arg = p + 1; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1384 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1385 return OK; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1386 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1387 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1388 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1389 * Return a string with the string representation of a variable. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1390 * If the memory is allocated "tofree" is set to it, otherwise NULL. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1391 * "numbuf" is used for a number. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1392 * Puts quotes around strings, so that they can be parsed back by eval(). |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1393 * May return NULL. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1394 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1395 char_u * |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1396 tv2string( |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1397 typval_T *tv, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1398 char_u **tofree, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1399 char_u *numbuf, |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1400 int copyID) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1401 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1402 return echo_string_core(tv, tofree, numbuf, copyID, FALSE, TRUE, FALSE); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1403 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1404 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1405 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1406 * Get the value of an environment variable. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1407 * "arg" is pointing to the '$'. It is advanced to after the name. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1408 * If the environment variable was not set, silently assume it is empty. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1409 * Return FAIL if the name is invalid. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1410 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1411 int |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
20925
diff
changeset
|
1412 eval_env_var(char_u **arg, typval_T *rettv, int evaluate) |
20587
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1413 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1414 char_u *string = NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1415 int len; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1416 int cc; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1417 char_u *name; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1418 int mustfree = FALSE; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1419 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1420 ++*arg; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1421 name = *arg; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1422 len = get_env_len(arg); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1423 if (evaluate) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1424 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1425 if (len == 0) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1426 return FAIL; // invalid empty name |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1427 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1428 cc = name[len]; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1429 name[len] = NUL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1430 // first try vim_getenv(), fast for normal environment vars |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1431 string = vim_getenv(name, &mustfree); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1432 if (string != NULL && *string != NUL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1433 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1434 if (!mustfree) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1435 string = vim_strsave(string); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1436 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1437 else |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1438 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1439 if (mustfree) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1440 vim_free(string); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1441 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1442 // next try expanding things like $VIM and ${HOME} |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1443 string = expand_env_save(name - 1); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1444 if (string != NULL && *string == '$') |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1445 VIM_CLEAR(string); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1446 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1447 name[len] = cc; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1448 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1449 rettv->v_type = VAR_STRING; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1450 rettv->vval.v_string = string; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1451 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1452 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1453 return OK; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1454 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1455 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1456 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1457 * Get the lnum from the first argument. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1458 * Also accepts ".", "$", etc., but that only works for the current buffer. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1459 * Returns -1 on error. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1460 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1461 linenr_T |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1462 tv_get_lnum(typval_T *argvars) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1463 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1464 linenr_T lnum; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1465 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1466 lnum = (linenr_T)tv_get_number_chk(&argvars[0], NULL); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1467 if (lnum == 0) // no valid number, try using arg like line() |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1468 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1469 int fnum; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1470 pos_T *fp = var2fpos(&argvars[0], TRUE, &fnum); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1471 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1472 if (fp != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1473 lnum = fp->lnum; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1474 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1475 return lnum; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1476 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1477 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1478 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1479 * Get the lnum from the first argument. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1480 * Also accepts "$", then "buf" is used. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1481 * Returns 0 on error. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1482 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1483 linenr_T |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1484 tv_get_lnum_buf(typval_T *argvars, buf_T *buf) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1485 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1486 if (argvars[0].v_type == VAR_STRING |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1487 && argvars[0].vval.v_string != NULL |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1488 && argvars[0].vval.v_string[0] == '$' |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1489 && buf != NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1490 return buf->b_ml.ml_line_count; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1491 return (linenr_T)tv_get_number_chk(&argvars[0], NULL); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1492 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1493 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1494 /* |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1495 * Get buffer by number or pattern. |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1496 */ |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1497 buf_T * |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1498 tv_get_buf(typval_T *tv, int curtab_only) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1499 { |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1500 char_u *name = tv->vval.v_string; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1501 buf_T *buf; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1502 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1503 if (tv->v_type == VAR_NUMBER) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1504 return buflist_findnr((int)tv->vval.v_number); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1505 if (tv->v_type != VAR_STRING) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1506 return NULL; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1507 if (name == NULL || *name == NUL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1508 return curbuf; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1509 if (name[0] == '$' && name[1] == NUL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1510 return lastbuf; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1511 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1512 buf = buflist_find_by_name(name, curtab_only); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1513 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1514 // If not found, try expanding the name, like done for bufexists(). |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1515 if (buf == NULL) |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1516 buf = find_buffer(tv); |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1517 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1518 return buf; |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1519 } |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1520 |
f502455965c0
patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1521 #endif // FEAT_EVAL |